Skip to content

Commit

Permalink
SQLMetadataConnector: Retry table creation, in case something goes wr…
Browse files Browse the repository at this point in the history
…ong.

Also rejigger table creation methods to not take a DBI. It's already available
inside the connector, and everyone was just using that one anyway.
  • Loading branch information
gianm committed Sep 25, 2015
1 parent a5718ee commit 3aba401
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
Expand Up @@ -232,7 +232,7 @@ public Void withHandle(Handle handle) throws Exception
@Override
public boolean run()
{
connector.createSegmentTable(connector.getDBI(), metadataStorageUpdaterJobSpec.getSegmentTable());
connector.createSegmentTable(metadataStorageUpdaterJobSpec.getSegmentTable());
return true;
}
},
Expand Down
39 changes: 16 additions & 23 deletions server/src/main/java/io/druid/metadata/SQLMetadataConnector.java
Expand Up @@ -151,10 +151,10 @@ protected boolean connectorIsTransientException(Throwable e)
return false;
}

public void createTable(final IDBI dbi, final String tableName, final Iterable<String> sql)
public void createTable(final String tableName, final Iterable<String> sql)
{
try {
dbi.withHandle(
retryWithHandle(
new HandleCallback<Void>()
{
@Override
Expand All @@ -180,10 +180,9 @@ public Void withHandle(Handle handle) throws Exception
}
}

public void createSegmentTable(final IDBI dbi, final String tableName)
public void createSegmentTable(final String tableName)
{
createTable(
dbi,
tableName,
ImmutableList.of(
String.format(
Expand All @@ -207,10 +206,9 @@ tableName, getPayloadType()
);
}

public void createRulesTable(final IDBI dbi, final String tableName)
public void createRulesTable(final String tableName)
{
createTable(
dbi,
tableName,
ImmutableList.of(
String.format(
Expand All @@ -228,10 +226,9 @@ tableName, getPayloadType()
);
}

public void createConfigTable(final IDBI dbi, final String tableName)
public void createConfigTable(final String tableName)
{
createTable(
dbi,
tableName,
ImmutableList.of(
String.format(
Expand All @@ -246,10 +243,9 @@ tableName, getPayloadType()
);
}

public void createEntryTable(final IDBI dbi, final String tableName)
public void createEntryTable(final String tableName)
{
createTable(
dbi,
tableName,
ImmutableList.of(
String.format(
Expand All @@ -269,10 +265,9 @@ tableName, getPayloadType()
);
}

public void createLogTable(final IDBI dbi, final String tableName, final String entryTypeName)
public void createLogTable(final String tableName, final String entryTypeName)
{
createTable(
dbi,
tableName,
ImmutableList.of(
String.format(
Expand All @@ -289,10 +284,9 @@ tableName, getSerialType(), getPayloadType(), entryTypeName
);
}

public void createLockTable(final IDBI dbi, final String tableName, final String entryTypeName)
public void createLockTable(final String tableName, final String entryTypeName)
{
createTable(
dbi,
tableName,
ImmutableList.of(
String.format(
Expand Down Expand Up @@ -363,21 +357,21 @@ public Void inTransaction(Handle handle, TransactionStatus transactionStatus) th
@Override
public void createSegmentTable() {
if (config.get().isCreateTables()) {
createSegmentTable(getDBI(), tablesConfigSupplier.get().getSegmentsTable());
createSegmentTable(tablesConfigSupplier.get().getSegmentsTable());
}
}

@Override
public void createRulesTable() {
if (config.get().isCreateTables()) {
createRulesTable(getDBI(), tablesConfigSupplier.get().getRulesTable());
createRulesTable(tablesConfigSupplier.get().getRulesTable());
}
}

@Override
public void createConfigTable() {
if (config.get().isCreateTables()) {
createConfigTable(getDBI(), tablesConfigSupplier.get().getConfigTable());
createConfigTable(tablesConfigSupplier.get().getConfigTable());
}
}

Expand All @@ -386,9 +380,9 @@ public void createTaskTables() {
if (config.get().isCreateTables()) {
final MetadataStorageTablesConfig tablesConfig = tablesConfigSupplier.get();
final String entryType = tablesConfig.getTaskEntryType();
createEntryTable(getDBI(), tablesConfig.getEntryTable(entryType));
createLogTable(getDBI(), tablesConfig.getLogTable(entryType), entryType);
createLockTable(getDBI(), tablesConfig.getLockTable(entryType), entryType);
createEntryTable(tablesConfig.getEntryTable(entryType));
createLogTable(tablesConfig.getLogTable(entryType), entryType);
createLockTable(tablesConfig.getLockTable(entryType), entryType);
}
}

Expand Down Expand Up @@ -446,10 +440,9 @@ protected BasicDataSource getDatasource()
return dataSource;
}

private void createAuditTable(final IDBI dbi, final String tableName)
private void createAuditTable(final String tableName)
{
createTable(
dbi,
tableName,
ImmutableList.of(
String.format(
Expand All @@ -474,7 +467,7 @@ tableName, getSerialType(), getPayloadType()
@Override
public void createAuditTable() {
if (config.get().isCreateTables()) {
createAuditTable(getDBI(), tablesConfigSupplier.get().getAuditTable());
createAuditTable(tablesConfigSupplier.get().getAuditTable());
}
}

Expand Down
Expand Up @@ -87,7 +87,7 @@ public Void withHandle(Handle handle) throws Exception
public void testInsertOrUpdate() throws Exception
{
final String tableName = "test";
connector.createConfigTable(connector.getDBI(), tableName);
connector.createConfigTable(tableName);

Assert.assertNull(connector.lookup(tableName, "name", "payload", "emperor"));

Expand Down
Expand Up @@ -53,9 +53,9 @@ public void setUp() throws Exception
final String lockTable = "locks";


connector.createEntryTable(connector.getDBI(), entryTable);
connector.createLockTable(connector.getDBI(), lockTable, entryType);
connector.createLogTable(connector.getDBI(), logTable, entryType);
connector.createEntryTable(entryTable);
connector.createLockTable(lockTable, entryType);
connector.createLogTable(logTable, entryType);


handler = new SQLMetadataStorageActionHandler<>(
Expand Down

0 comments on commit 3aba401

Please sign in to comment.