use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaDatabase method dropDatabase.
void dropDatabase(@NotNull final String database) {
log.info("Dropping database: {}", database);
try (Handle handle = jdbi.open()) {
disableForeignKeyChecks(handle);
MysqlSchemaUtil.VOID_RETRYER.call(() -> {
MysqlSchemaUtil.executeSQL(handle, null, String.format(DROP_DATABASES_QUERY, MysqlSchemaUtil.escapeBackQuote(getSchemaDatabaseName(source, database))));
return null;
});
} catch (Exception ex) {
log.error(String.format("Failed to drop database %s. (Exception: %s)", database, ex));
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaStore method getAll.
@Override
public Table<String, String, TreeMap<Integer, MysqlTableSchema>> getAll() {
Table<String, String, TreeMap<Integer, MysqlTableSchema>> allSchemaTable = Tables.newCustomTable(Maps.newHashMap(), Maps::newHashMap);
List<String> allSchemaInfo;
try (Handle handle = jdbi.open()) {
allSchemaInfo = MysqlSchemaUtil.LIST_STRING_RETRYER.call(() -> handle.createQuery(String.format(GET_ALL_SCHEMA_QUERY, source)).map(StringColumnMapper.INSTANCE).list());
} catch (Exception ex) {
log.error(String.format("Failed to get all schema for source: %s", source), ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
allSchemaInfo.stream().map(MysqlSchemaStore::deserializeSchemaInfo).forEach(schemaInfo -> {
String database = schemaInfo.getDatabase();
String table = schemaInfo.getTable();
int version = schemaInfo.getVersion();
if (!allSchemaTable.contains(database, table)) {
allSchemaTable.put(database, table, Maps.newTreeMap());
}
allSchemaTable.get(database, table).put(version, schemaInfo);
});
return allSchemaTable;
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaStore method archive.
public void archive() {
try (Handle handle = jdbi.open()) {
String archiveTableName = String.format("%s_%s", source, new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
MysqlSchemaUtil.VOID_RETRYER.call(() -> {
handle.execute(String.format(ARCHIVE_SCHEMA_STORE_TABLE_QUERY, source, archiveDatabase, archiveTableName));
return null;
});
log.info("Schema store for {} has been archived as {}", source, archiveTableName);
} catch (Exception ex) {
log.error(String.format("Failed to archive schema store for source: %s. (Exception: %s)", source, ex));
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaStore method put.
@Override
public void put(@NotNull final MysqlTableSchema schema) {
try (Handle handle = jdbi.open()) {
MysqlSchemaUtil.VOID_RETRYER.call(() -> {
handle.insert(String.format(PUT_SCHEMA_QUERY, source), schema.getVersion(), schema.getSource(), schema.getDatabase(), schema.getTable(), schema.getBinlogFilePos().getFileName(), schema.getBinlogFilePos().getPosition(), OBJECT_MAPPER.writeValueAsString(schema));
return null;
});
metrics.schemaStorePutSuccess(schema.getDatabase(), schema.getTable());
} catch (Exception ex) {
log.error("Failed to put schema {}.", schema);
metrics.schemaStorePutFailure(schema.getDatabase(), schema.getTable(), ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaStore method getLatest.
@Override
public MysqlTableSchema getLatest(@NotNull final String database, @NotNull final String table) {
try (Handle handle = jdbi.open()) {
String schemaInfo = MysqlSchemaUtil.STRING_RETRYER.call(() -> handle.createQuery(String.format(GET_LATEST_SCHEMA_QUERY, source)).bind("database", database).bind("table", table).map(StringColumnMapper.INSTANCE).first());
metrics.schemaStoreGetSuccess(database, table);
return deserializeSchemaInfo(schemaInfo);
} catch (Exception ex) {
log.error(String.format("Failed to get latest schema of database: %s table: %s. Does it exist?", database, table), ex);
metrics.schemaStoreGetFailure(database, table, ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
}
Aggregations