mirror of https://github.com/apache/druid.git
Improved support for PostgreSQL in config management
This commit is contained in:
parent
8fac0b0b7a
commit
d089f05127
|
@ -28,6 +28,7 @@ import com.metamx.common.concurrent.ScheduledExecutors;
|
||||||
import com.metamx.common.lifecycle.LifecycleStart;
|
import com.metamx.common.lifecycle.LifecycleStart;
|
||||||
import com.metamx.common.lifecycle.LifecycleStop;
|
import com.metamx.common.lifecycle.LifecycleStop;
|
||||||
import com.metamx.common.logger.Logger;
|
import com.metamx.common.logger.Logger;
|
||||||
|
import io.druid.db.DbConnector;
|
||||||
import io.druid.db.DbTablesConfig;
|
import io.druid.db.DbTablesConfig;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.skife.jdbi.v2.Handle;
|
import org.skife.jdbi.v2.Handle;
|
||||||
|
@ -79,6 +80,12 @@ public class ConfigManager
|
||||||
|
|
||||||
this.selectStatement = String.format("SELECT payload FROM %s WHERE name = :name", configTable);
|
this.selectStatement = String.format("SELECT payload FROM %s WHERE name = :name", configTable);
|
||||||
this.insertStatement = String.format(
|
this.insertStatement = String.format(
|
||||||
|
DbConnector.isPostgreSQL(dbi) ?
|
||||||
|
"BEGIN;\n" +
|
||||||
|
"LOCK TABLE %1$s IN SHARE ROW EXCLUSIVE MODE;\n" +
|
||||||
|
"WITH upsert AS (UPDATE %1$s SET payload=:payload WHERE name=:name RETURNING *)\n" +
|
||||||
|
" INSERT INTO %1$s (name, payload) SELECT :name, :payload WHERE NOT EXISTS (SELECT * FROM upsert)\n;" +
|
||||||
|
"COMMIT;" :
|
||||||
"INSERT INTO %s (name, payload) VALUES (:name, :payload) ON DUPLICATE KEY UPDATE payload = :payload",
|
"INSERT INTO %s (name, payload) VALUES (:name, :payload) ON DUPLICATE KEY UPDATE payload = :payload",
|
||||||
configTable
|
configTable
|
||||||
);
|
);
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class DbConnector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Boolean isPostgreSQL(final IDBI dbi)
|
public static Boolean isPostgreSQL(final IDBI dbi)
|
||||||
{
|
{
|
||||||
return dbi.withHandle(
|
return dbi.withHandle(
|
||||||
new HandleCallback<Boolean>()
|
new HandleCallback<Boolean>()
|
||||||
|
|
Loading…
Reference in New Issue