Merge pull request #1775 from gianm/retry-table-creation

SQLMetadataConnector: Retry table creation, in case something goes wrong.
This commit is contained in:
Fangjin Yang 2015-09-24 22:24:03 -07:00
commit d60610ced3
4 changed files with 21 additions and 28 deletions

View File

@ -232,7 +232,7 @@ public class HadoopConverterJobTest
@Override @Override
public boolean run() public boolean run()
{ {
connector.createSegmentTable(connector.getDBI(), metadataStorageUpdaterJobSpec.getSegmentTable()); connector.createSegmentTable(metadataStorageUpdaterJobSpec.getSegmentTable());
return true; return true;
} }
}, },

View File

@ -151,10 +151,10 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
return false; 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 { try {
dbi.withHandle( retryWithHandle(
new HandleCallback<Void>() new HandleCallback<Void>()
{ {
@Override @Override
@ -180,10 +180,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
} }
} }
public void createSegmentTable(final IDBI dbi, final String tableName) public void createSegmentTable(final String tableName)
{ {
createTable( createTable(
dbi,
tableName, tableName,
ImmutableList.of( ImmutableList.of(
String.format( String.format(
@ -207,10 +206,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
); );
} }
public void createRulesTable(final IDBI dbi, final String tableName) public void createRulesTable(final String tableName)
{ {
createTable( createTable(
dbi,
tableName, tableName,
ImmutableList.of( ImmutableList.of(
String.format( String.format(
@ -228,10 +226,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
); );
} }
public void createConfigTable(final IDBI dbi, final String tableName) public void createConfigTable(final String tableName)
{ {
createTable( createTable(
dbi,
tableName, tableName,
ImmutableList.of( ImmutableList.of(
String.format( String.format(
@ -246,10 +243,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
); );
} }
public void createEntryTable(final IDBI dbi, final String tableName) public void createEntryTable(final String tableName)
{ {
createTable( createTable(
dbi,
tableName, tableName,
ImmutableList.of( ImmutableList.of(
String.format( String.format(
@ -269,10 +265,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
); );
} }
public void createLogTable(final IDBI dbi, final String tableName, final String entryTypeName) public void createLogTable(final String tableName, final String entryTypeName)
{ {
createTable( createTable(
dbi,
tableName, tableName,
ImmutableList.of( ImmutableList.of(
String.format( String.format(
@ -289,10 +284,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
); );
} }
public void createLockTable(final IDBI dbi, final String tableName, final String entryTypeName) public void createLockTable(final String tableName, final String entryTypeName)
{ {
createTable( createTable(
dbi,
tableName, tableName,
ImmutableList.of( ImmutableList.of(
String.format( String.format(
@ -363,21 +357,21 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
@Override @Override
public void createSegmentTable() { public void createSegmentTable() {
if (config.get().isCreateTables()) { if (config.get().isCreateTables()) {
createSegmentTable(getDBI(), tablesConfigSupplier.get().getSegmentsTable()); createSegmentTable(tablesConfigSupplier.get().getSegmentsTable());
} }
} }
@Override @Override
public void createRulesTable() { public void createRulesTable() {
if (config.get().isCreateTables()) { if (config.get().isCreateTables()) {
createRulesTable(getDBI(), tablesConfigSupplier.get().getRulesTable()); createRulesTable(tablesConfigSupplier.get().getRulesTable());
} }
} }
@Override @Override
public void createConfigTable() { public void createConfigTable() {
if (config.get().isCreateTables()) { if (config.get().isCreateTables()) {
createConfigTable(getDBI(), tablesConfigSupplier.get().getConfigTable()); createConfigTable(tablesConfigSupplier.get().getConfigTable());
} }
} }
@ -386,9 +380,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
if (config.get().isCreateTables()) { if (config.get().isCreateTables()) {
final MetadataStorageTablesConfig tablesConfig = tablesConfigSupplier.get(); final MetadataStorageTablesConfig tablesConfig = tablesConfigSupplier.get();
final String entryType = tablesConfig.getTaskEntryType(); final String entryType = tablesConfig.getTaskEntryType();
createEntryTable(getDBI(), tablesConfig.getEntryTable(entryType)); createEntryTable(tablesConfig.getEntryTable(entryType));
createLogTable(getDBI(), tablesConfig.getLogTable(entryType), entryType); createLogTable(tablesConfig.getLogTable(entryType), entryType);
createLockTable(getDBI(), tablesConfig.getLockTable(entryType), entryType); createLockTable(tablesConfig.getLockTable(entryType), entryType);
} }
} }
@ -446,10 +440,9 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
return dataSource; return dataSource;
} }
private void createAuditTable(final IDBI dbi, final String tableName) private void createAuditTable(final String tableName)
{ {
createTable( createTable(
dbi,
tableName, tableName,
ImmutableList.of( ImmutableList.of(
String.format( String.format(
@ -474,7 +467,7 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
@Override @Override
public void createAuditTable() { public void createAuditTable() {
if (config.get().isCreateTables()) { if (config.get().isCreateTables()) {
createAuditTable(getDBI(), tablesConfigSupplier.get().getAuditTable()); createAuditTable(tablesConfigSupplier.get().getAuditTable());
} }
} }

View File

@ -87,7 +87,7 @@ public class SQLMetadataConnectorTest
public void testInsertOrUpdate() throws Exception public void testInsertOrUpdate() throws Exception
{ {
final String tableName = "test"; final String tableName = "test";
connector.createConfigTable(connector.getDBI(), tableName); connector.createConfigTable(tableName);
Assert.assertNull(connector.lookup(tableName, "name", "payload", "emperor")); Assert.assertNull(connector.lookup(tableName, "name", "payload", "emperor"));

View File

@ -53,9 +53,9 @@ public class SQLMetadataStorageActionHandlerTest
final String lockTable = "locks"; final String lockTable = "locks";
connector.createEntryTable(connector.getDBI(), entryTable); connector.createEntryTable(entryTable);
connector.createLockTable(connector.getDBI(), lockTable, entryType); connector.createLockTable(lockTable, entryType);
connector.createLogTable(connector.getDBI(), logTable, entryType); connector.createLogTable(logTable, entryType);
handler = new SQLMetadataStorageActionHandler<>( handler = new SQLMetadataStorageActionHandler<>(