Package org.apache.druid.metadata
Class SQLMetadataConnector
- java.lang.Object
-
- org.apache.druid.metadata.SQLMetadataConnector
-
- All Implemented Interfaces:
org.apache.druid.metadata.MetadataStorageConnector
- Direct Known Subclasses:
DerbyConnector
public abstract class SQLMetadataConnector extends Object implements org.apache.druid.metadata.MetadataStorageConnector
-
-
Constructor Summary
Constructors Constructor Description SQLMetadataConnector(com.google.common.base.Supplier<org.apache.druid.metadata.MetadataStorageConnectorConfig> config, com.google.common.base.Supplier<org.apache.druid.metadata.MetadataStorageTablesConfig> tablesConfigSupplier)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidalterSegmentTableAddUsedFlagLastUpdated()Adds the used_status_last_updated column to the "segments" table.booleancompareAndSwap(List<org.apache.druid.metadata.MetadataCASUpdate> updates)protected booleanconnectorIsTransientException(Throwable e)Vendor specific errors that are not covered byisTransientException(Throwable)voidcreateAuditTable()voidcreateConfigTable()voidcreateConfigTable(String tableName)voidcreateDataSourceTable()voidcreateDataSourceTable(String tableName)voidcreateEntryTable(String tableName)voidcreateIndex(String tableName, String indexName, List<String> indexCols, Set<String> createdIndexSet)create index on the table with retry if not already exist, to be called after createTablevoidcreateLockTable(String tableName, String entryTypeName)voidcreateLogTable(String tableName, String entryTypeName)voidcreatePendingSegmentsTable()voidcreatePendingSegmentsTable(String tableName)voidcreateRulesTable()voidcreateRulesTable(String tableName)voidcreateSegmentTable()voidcreateSegmentTable(String tableName)voidcreateSupervisorsTable()voidcreateSupervisorsTable(String tableName)voidcreateTable(String tableName, Iterable<String> sql)Creates the given table and indexes if the table doesn't already exist.voidcreateTaskTables()voidcreateUpgradeSegmentsTable()voiddeleteAllRecords(String tableName)StringgetCollation()The character set and collation for case-sensitive nonbinary string comparisonorg.apache.druid.metadata.MetadataStorageConnectorConfiggetConfig()protected org.apache.commons.dbcp2.BasicDataSourcegetDatasource()abstract org.skife.jdbi.v2.DBIgetDBI()ResultSetgetIndexInfo(DatabaseMetaData databaseMetaData, String tableName)Get the ResultSet for indexInfo for given tableSet<String>getIndexOnTable(String tableName)Get the Set of the index on given tableStringgetPayloadType()SQL type to use for payload data (e.g.abstract StringgetQuoteString()abstract StringgetSerialType()Auto-incrementing integer SQL type to use for IDs.abstract intgetStreamingFetchSize()Returns the value that should be passed to statement.setFetchSize to ensure results are streamed back from the database instead of fetching the entire result set in memory.StringgetValidationQuery()protected <T> TinReadOnlyTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback)VoidinsertOrUpdate(String tableName, String keyColumn, String valueColumn, String key, byte[] value)protected booleanisRootCausePacketTooBigException(Throwable t)Checks if the root cause of the given exception is a PacketTooBigException.booleanisTransientException(Throwable e)abstract StringlimitClause(int limit)byte[]lookup(String tableName, String keyColumn, String valueColumn, String key)byte[]lookupWithHandle(org.skife.jdbi.v2.Handle handle, String tableName, String keyColumn, String valueColumn, String key)protected static org.apache.commons.dbcp2.BasicDataSourcemakeDatasource(org.apache.druid.metadata.MetadataStorageConnectorConfig connectorConfig, String validationQuery)voidprepareTaskEntryTable(String tableName)<T> TretryTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback, int quietTries, int maxTries)<T> TretryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback)<T> TretryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback, com.google.common.base.Predicate<Throwable> myShouldRetry)abstract booleantableExists(org.skife.jdbi.v2.Handle handle, String tableName)protected booleantableHasColumn(String tableName, String columnName)Checks table metadata to determine if the given column exists in the table.
-
-
-
Method Detail
-
getPayloadType
public String getPayloadType()
SQL type to use for payload data (e.g. JSON blobs). Must be a binary type, which values can be accessed using ResultSet.getBytes() The resulting string will be interpolated into the table creation statement, e.g.CREATE TABLE druid_table ( payloadNOT NULL, ... ) - Returns:
- String representing the SQL type
-
getCollation
public String getCollation()
The character set and collation for case-sensitive nonbinary string comparison- Returns:
- the collation for the character set
-
getSerialType
public abstract String getSerialType()
Auto-incrementing integer SQL type to use for IDs. The returned string is interpolated into the table creation statement as follows:CREATE TABLE druid_table ( id <serial-type> NOT NULL, col_2 VARCHAR(255) NOT NULL, col_3 VARCHAR(255) NOT NULL ... )
- Returns:
- String representing auto-incrementing SQL integer type to use for IDs.
-
getStreamingFetchSize
public abstract int getStreamingFetchSize()
Returns the value that should be passed to statement.setFetchSize to ensure results are streamed back from the database instead of fetching the entire result set in memory.- Returns:
- optimal fetch size to stream results back
-
getQuoteString
public abstract String getQuoteString()
- Returns:
- the string that should be used to quote string fields
-
getValidationQuery
public String getValidationQuery()
-
tableExists
public abstract boolean tableExists(org.skife.jdbi.v2.Handle handle, String tableName)
-
limitClause
public abstract String limitClause(int limit)
-
retryWithHandle
public <T> T retryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback, com.google.common.base.Predicate<Throwable> myShouldRetry)
-
retryWithHandle
public <T> T retryWithHandle(org.skife.jdbi.v2.tweak.HandleCallback<T> callback)
-
retryTransaction
public <T> T retryTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback, int quietTries, int maxTries)
-
isTransientException
public final boolean isTransientException(Throwable e)
-
connectorIsTransientException
protected boolean connectorIsTransientException(Throwable e)
Vendor specific errors that are not covered byisTransientException(Throwable)
-
isRootCausePacketTooBigException
protected boolean isRootCausePacketTooBigException(Throwable t)
Checks if the root cause of the given exception is a PacketTooBigException.- Returns:
- false by default. Specific implementations should override this method to correctly classify their packet exceptions.
-
createTable
public void createTable(String tableName, Iterable<String> sql)
Creates the given table and indexes if the table doesn't already exist.
-
createPendingSegmentsTable
public void createPendingSegmentsTable(String tableName)
-
createDataSourceTable
public void createDataSourceTable(String tableName)
-
createSegmentTable
public void createSegmentTable(String tableName)
-
createRulesTable
public void createRulesTable(String tableName)
-
createConfigTable
public void createConfigTable(String tableName)
-
prepareTaskEntryTable
public void prepareTaskEntryTable(String tableName)
-
createEntryTable
public void createEntryTable(String tableName)
-
createSupervisorsTable
public void createSupervisorsTable(String tableName)
-
alterSegmentTableAddUsedFlagLastUpdated
protected void alterSegmentTableAddUsedFlagLastUpdated()
Adds the used_status_last_updated column to the "segments" table.
-
insertOrUpdate
public Void insertOrUpdate(String tableName, String keyColumn, String valueColumn, String key, byte[] value)
- Specified by:
insertOrUpdatein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
compareAndSwap
public boolean compareAndSwap(List<org.apache.druid.metadata.MetadataCASUpdate> updates)
- Specified by:
compareAndSwapin interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
getDBI
public abstract org.skife.jdbi.v2.DBI getDBI()
-
createDataSourceTable
public void createDataSourceTable()
- Specified by:
createDataSourceTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
createPendingSegmentsTable
public void createPendingSegmentsTable()
- Specified by:
createPendingSegmentsTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
createSegmentTable
public void createSegmentTable()
- Specified by:
createSegmentTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
createUpgradeSegmentsTable
public void createUpgradeSegmentsTable()
- Specified by:
createUpgradeSegmentsTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
createRulesTable
public void createRulesTable()
- Specified by:
createRulesTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
createConfigTable
public void createConfigTable()
- Specified by:
createConfigTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
createTaskTables
public void createTaskTables()
- Specified by:
createTaskTablesin interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
createSupervisorsTable
public void createSupervisorsTable()
- Specified by:
createSupervisorsTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
lookup
@Nullable public byte[] lookup(String tableName, String keyColumn, String valueColumn, String key)
- Specified by:
lookupin interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
lookupWithHandle
@Nullable public byte[] lookupWithHandle(org.skife.jdbi.v2.Handle handle, String tableName, String keyColumn, String valueColumn, String key)
-
getConfig
public org.apache.druid.metadata.MetadataStorageConnectorConfig getConfig()
-
makeDatasource
protected static org.apache.commons.dbcp2.BasicDataSource makeDatasource(org.apache.druid.metadata.MetadataStorageConnectorConfig connectorConfig, String validationQuery)
-
getDatasource
protected org.apache.commons.dbcp2.BasicDataSource getDatasource()
-
inReadOnlyTransaction
protected final <T> T inReadOnlyTransaction(org.skife.jdbi.v2.TransactionCallback<T> callback)
-
createAuditTable
public void createAuditTable()
- Specified by:
createAuditTablein interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
deleteAllRecords
public void deleteAllRecords(String tableName)
- Specified by:
deleteAllRecordsin interfaceorg.apache.druid.metadata.MetadataStorageConnector
-
getIndexOnTable
public Set<String> getIndexOnTable(String tableName)
Get the Set of the index on given table- Parameters:
tableName- name of the table to fetch the index map- Returns:
- Set of the uppercase index names, returns empty set if table does not exist
-
getIndexInfo
public ResultSet getIndexInfo(DatabaseMetaData databaseMetaData, String tableName) throws SQLException
Get the ResultSet for indexInfo for given table- Parameters:
databaseMetaData- DatabaseMetaDatatableName- Name of table- Returns:
- ResultSet with index info
- Throws:
SQLException
-
createIndex
public void createIndex(String tableName, String indexName, List<String> indexCols, Set<String> createdIndexSet)
create index on the table with retry if not already exist, to be called after createTable- Parameters:
tableName- Name of the table to create index onindexName- case-insensitive string index name, it helps to check the existing index on tableindexCols- List of columns to be indexed oncreatedIndexSet-
-
-