Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLMetadataConnector: Retry table creation, in case something goes wrong. #1775

Merged
merged 1 commit into from
Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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