/** * Read dataSource metadata as bytes, from a specific handle. Returns null if there is no metadata. */ private byte[] getDataSourceMetadataWithHandleAsBytes( final Handle handle, final String dataSource ) { return connector.lookupWithHandle( handle, dbTables.getDataSourceTable(), "dataSource", "commit_metadata_payload", dataSource ); }
/** * Read dataSource metadata. Returns null if there is no metadata. */ @Override public DataSourceMetadata getDataSourceMetadata(final String dataSource) { final byte[] bytes = connector.lookup( dbTables.getDataSourceTable(), "dataSource", "commit_metadata_payload", dataSource ); if (bytes == null) { return null; } try { return jsonMapper.readValue(bytes, DataSourceMetadata.class); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void createDataSourceTable() { if (config.get().isCreateTables()) { createDataSourceTable(tablesConfigSupplier.get().getDataSourceTable()); } }
@Override public Boolean withHandle(Handle handle) { int rows = handle.createStatement( StringUtils.format("DELETE from %s WHERE dataSource = :dataSource", dbTables.getDataSourceTable()) ) .bind("dataSource", dataSource) .execute(); return rows > 0; } }
@Override public boolean insertDataSourceMetadata(String dataSource, DataSourceMetadata metadata) { return 1 == connector.getDBI().inTransaction( (handle, status) -> handle .createStatement( StringUtils.format( "INSERT INTO %s (dataSource, created_date, commit_metadata_payload, commit_metadata_sha1) VALUES" + " (:dataSource, :created_date, :commit_metadata_payload, :commit_metadata_sha1)", dbTables.getDataSourceTable() ) ) .bind("dataSource", dataSource) .bind("created_date", DateTimes.nowUtc().toString()) .bind("commit_metadata_payload", jsonMapper.writeValueAsBytes(metadata)) .bind("commit_metadata_sha1", BaseEncoding.base16().encode( Hashing.sha1().hashBytes(jsonMapper.writeValueAsBytes(metadata)).asBytes())) .execute() ); } }
handle -> handle.createQuery( StringUtils.format("SELECT DISTINCT dataSource,commit_metadata_payload FROM %1$s", dbTables.get().getDataSourceTable())
@Override public Boolean withHandle(Handle handle) { final int numRows = handle.createStatement( StringUtils.format( "UPDATE %s SET " + "commit_metadata_payload = :new_commit_metadata_payload, " + "commit_metadata_sha1 = :new_commit_metadata_sha1 " + "WHERE dataSource = :dataSource", dbTables.getDataSourceTable() ) ) .bind("dataSource", dataSource) .bind("new_commit_metadata_payload", newCommitMetadataBytes) .bind("new_commit_metadata_sha1", newCommitMetadataSha1) .execute(); return numRows == 1; } }
"INSERT INTO %s (dataSource, created_date, commit_metadata_payload, commit_metadata_sha1) " + "VALUES (:dataSource, :created_date, :commit_metadata_payload, :commit_metadata_sha1)", dbTables.getDataSourceTable() + "commit_metadata_sha1 = :new_commit_metadata_sha1 " + "WHERE dataSource = :dataSource AND commit_metadata_sha1 = :old_commit_metadata_sha1", dbTables.getDataSourceTable()
private void resetMetadataStore(Injector injector) { log.info("==========================================================================="); log.info("Deleting all Records from Metadata Storage."); log.info("==========================================================================="); MetadataStorageConnector connector = injector.getInstance(MetadataStorageConnector.class); MetadataStorageTablesConfig tablesConfig = injector.getInstance(MetadataStorageTablesConfig.class); String[] tables = new String[]{ tablesConfig.getDataSourceTable(), tablesConfig.getPendingSegmentsTable(), tablesConfig.getSegmentsTable(), tablesConfig.getRulesTable(), tablesConfig.getConfigTable(), tablesConfig.getTasksTable(), tablesConfig.getTaskLockTable(), tablesConfig.getTaskLogTable(), tablesConfig.getAuditTable(), tablesConfig.getSupervisorTable() }; for (String table : tables) { connector.deleteAllRecords(table); } }
config.getLockTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE) ); Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.dataSource"), config.getDataSourceTable()); Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.supervisors"), config.getSupervisorTable());
/** * Read dataSource metadata as bytes, from a specific handle. Returns null if there is no metadata. */ private byte[] getDataSourceMetadataWithHandleAsBytes( final Handle handle, final String dataSource ) { return connector.lookupWithHandle( handle, dbTables.getDataSourceTable(), "dataSource", "commit_metadata_payload", dataSource ); }
@Override public void createDataSourceTable() { if (config.get().isCreateTables()) { createDataSourceTable(tablesConfigSupplier.get().getDataSourceTable()); } }
/** * Read dataSource metadata. Returns null if there is no metadata. */ @Override public DataSourceMetadata getDataSourceMetadata(final String dataSource) { final byte[] bytes = connector.lookup( dbTables.getDataSourceTable(), "dataSource", "commit_metadata_payload", dataSource ); if (bytes == null) { return null; } try { return jsonMapper.readValue(bytes, DataSourceMetadata.class); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public Boolean withHandle(Handle handle) { int rows = handle.createStatement( StringUtils.format("DELETE from %s WHERE dataSource = :dataSource", dbTables.getDataSourceTable()) ) .bind("dataSource", dataSource) .execute(); return rows > 0; } }
@Override public boolean insertDataSourceMetadata(String dataSource, DataSourceMetadata metadata) { return 1 == connector.getDBI().inTransaction( (handle, status) -> handle .createStatement( StringUtils.format( "INSERT INTO %s (dataSource, created_date, commit_metadata_payload, commit_metadata_sha1) VALUES" + " (:dataSource, :created_date, :commit_metadata_payload, :commit_metadata_sha1)", dbTables.getDataSourceTable() ) ) .bind("dataSource", dataSource) .bind("created_date", DateTimes.nowUtc().toString()) .bind("commit_metadata_payload", jsonMapper.writeValueAsBytes(metadata)) .bind("commit_metadata_sha1", BaseEncoding.base16().encode( Hashing.sha1().hashBytes(jsonMapper.writeValueAsBytes(metadata)).asBytes())) .execute() ); } }
@Override public Boolean withHandle(Handle handle) { final int numRows = handle.createStatement( StringUtils.format( "UPDATE %s SET " + "commit_metadata_payload = :new_commit_metadata_payload, " + "commit_metadata_sha1 = :new_commit_metadata_sha1 " + "WHERE dataSource = :dataSource", dbTables.getDataSourceTable() ) ) .bind("dataSource", dataSource) .bind("new_commit_metadata_payload", newCommitMetadataBytes) .bind("new_commit_metadata_sha1", newCommitMetadataSha1) .execute(); return numRows == 1; } }
"INSERT INTO %s (dataSource, created_date, commit_metadata_payload, commit_metadata_sha1) " + "VALUES (:dataSource, :created_date, :commit_metadata_payload, :commit_metadata_sha1)", dbTables.getDataSourceTable() + "commit_metadata_sha1 = :new_commit_metadata_sha1 " + "WHERE dataSource = :dataSource AND commit_metadata_sha1 = :old_commit_metadata_sha1", dbTables.getDataSourceTable()
private void resetMetadataStore(Injector injector) { log.info("==========================================================================="); log.info("Deleting all Records from Metadata Storage."); log.info("==========================================================================="); MetadataStorageConnector connector = injector.getInstance(MetadataStorageConnector.class); MetadataStorageTablesConfig tablesConfig = injector.getInstance(MetadataStorageTablesConfig.class); String[] tables = new String[]{ tablesConfig.getDataSourceTable(), tablesConfig.getPendingSegmentsTable(), tablesConfig.getSegmentsTable(), tablesConfig.getRulesTable(), tablesConfig.getConfigTable(), tablesConfig.getTasksTable(), tablesConfig.getTaskLockTable(), tablesConfig.getTaskLogTable(), tablesConfig.getAuditTable(), tablesConfig.getSupervisorTable() }; for (String table : tables) { connector.deleteAllRecords(table); } }