mirror of https://github.com/apache/druid.git
Added support for PostgreSQL on overlord nodes
This commit is contained in:
parent
a835db2a3c
commit
e40725d5f3
|
@ -29,6 +29,7 @@ import org.skife.jdbi.v2.IDBI;
|
||||||
import org.skife.jdbi.v2.tweak.HandleCallback;
|
import org.skife.jdbi.v2.tweak.HandleCallback;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -212,12 +213,17 @@ public class DbConnector
|
||||||
@Override
|
@Override
|
||||||
public Boolean withHandle(Handle handle) throws Exception
|
public Boolean withHandle(Handle handle) throws Exception
|
||||||
{
|
{
|
||||||
return handle.getConnection().getMetaData().getDatabaseProductName().contains("PostgreSQL");
|
return isPostgreSQL(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Boolean isPostgreSQL(final Handle handle) throws SQLException
|
||||||
|
{
|
||||||
|
return handle.getConnection().getMetaData().getDatabaseProductName().contains("PostgreSQL");
|
||||||
|
}
|
||||||
|
|
||||||
private final Supplier<DbConnectorConfig> config;
|
private final Supplier<DbConnectorConfig> config;
|
||||||
private final Supplier<DbTablesConfig> dbTables;
|
private final Supplier<DbTablesConfig> dbTables;
|
||||||
private final DBI dbi;
|
private final DBI dbi;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.google.common.collect.Ordering;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
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 io.druid.timeline.DataSegment;
|
import io.druid.timeline.DataSegment;
|
||||||
import io.druid.timeline.TimelineObjectHolder;
|
import io.druid.timeline.TimelineObjectHolder;
|
||||||
|
@ -179,8 +180,11 @@ public class IndexerDBCoordinator
|
||||||
try {
|
try {
|
||||||
handle.createStatement(
|
handle.createStatement(
|
||||||
String.format(
|
String.format(
|
||||||
"INSERT INTO %s (id, dataSource, created_date, start, end, partitioned, version, used, payload) "
|
DbConnector.isPostgreSQL(handle) ?
|
||||||
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
|
"INSERT INTO %s (id, dataSource, created_date, start, \"end\", partitioned, version, used, payload) "
|
||||||
|
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)":
|
||||||
|
"INSERT INTO %s (id, dataSource, created_date, start, end, partitioned, version, used, payload) "
|
||||||
|
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
|
||||||
dbTables.getSegmentsTable()
|
dbTables.getSegmentsTable()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -196,7 +200,9 @@ public class IndexerDBCoordinator
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
log.info("Published segment [%s] to DB", segment.getIdentifier());
|
log.info("Published segment [%s] to DB", segment.getIdentifier());
|
||||||
} catch (Exception e) {
|
} catch(SQLException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
} catch(Exception e) {
|
||||||
if (e.getCause() instanceof SQLException && segmentExists(handle, segment)) {
|
if (e.getCause() instanceof SQLException && segmentExists(handle, segment)) {
|
||||||
log.info("Found [%s] in DB, not updating DB", segment.getIdentifier());
|
log.info("Found [%s] in DB, not updating DB", segment.getIdentifier());
|
||||||
} else {
|
} else {
|
||||||
|
@ -293,11 +299,13 @@ public class IndexerDBCoordinator
|
||||||
new HandleCallback<List<DataSegment>>()
|
new HandleCallback<List<DataSegment>>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public List<DataSegment> withHandle(Handle handle) throws IOException
|
public List<DataSegment> withHandle(Handle handle) throws IOException, SQLException
|
||||||
{
|
{
|
||||||
return handle.createQuery(
|
return handle.createQuery(
|
||||||
String.format(
|
String.format(
|
||||||
"SELECT payload FROM %s WHERE dataSource = :dataSource and start >= :start and end <= :end and used = 0",
|
DbConnector.isPostgreSQL(handle)?
|
||||||
|
"SELECT payload FROM %s WHERE dataSource = :dataSource and start >= :start and \"end\" <= :end and used = 0":
|
||||||
|
"SELECT payload FROM %s WHERE dataSource = :dataSource and start >= :start and end <= :end and used = 0",
|
||||||
dbTables.getSegmentsTable()
|
dbTables.getSegmentsTable()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue