@Inject public SQLMetadataStorageUpdaterJobHandler(SQLMetadataConnector connector) { this.connector = connector; this.dbi = connector.getDBI(); }
@Inject public SQLMetadataRuleManagerProvider( ObjectMapper jsonMapper, MetadataRuleManagerConfig config, MetadataStorageTablesConfig dbTables, SQLMetadataConnector connector, Lifecycle lifecycle, SQLAuditManager auditManager ) { this.jsonMapper = jsonMapper; this.config = config; this.dbTables = dbTables; this.connector = connector; this.dbi = connector.getDBI(); this.lifecycle = lifecycle; this.auditManager = auditManager; }
@Inject public SQLMetadataSupervisorManager( @Json ObjectMapper jsonMapper, SQLMetadataConnector connector, Supplier<MetadataStorageTablesConfig> dbTables ) { this.jsonMapper = jsonMapper; this.connector = connector; this.dbTables = dbTables; this.dbi = connector.getDBI(); }
@Inject public SQLAuditManager( SQLMetadataConnector connector, Supplier<MetadataStorageTablesConfig> dbTables, ServiceEmitter emitter, @Json ObjectMapper jsonMapper, SQLAuditManagerConfig config ) { this.dbi = connector.getDBI(); this.dbTables = dbTables; this.emitter = emitter; this.jsonMapper = jsonMapper; this.config = config; }
@Override public void deleteSegments(final Set<DataSegment> segments) { connector.getDBI().inTransaction( new TransactionCallback<Void>() { @Override public Void inTransaction(Handle handle, TransactionStatus transactionStatus) { for (final DataSegment segment : segments) { deleteSegment(handle, segment); } return null; } } ); }
@Override public void updateSegmentMetadata(final Set<DataSegment> segments) { connector.getDBI().inTransaction( new TransactionCallback<Void>() { @Override public Void inTransaction(Handle handle, TransactionStatus transactionStatus) throws Exception { for (final DataSegment segment : segments) { updatePayload(handle, segment); } return null; } } ); }
@Override public byte[] lookup( final String tableName, final String keyColumn, final String valueColumn, final String key ) { return getDBI().withHandle( new HandleCallback<byte[]>() { @Override public byte[] withHandle(Handle handle) { return lookupWithHandle(handle, tableName, keyColumn, valueColumn, key); } } ); }
public <T> T retryTransaction(final TransactionCallback<T> callback, final int quietTries, final int maxTries) { try { return RetryUtils.retry(() -> getDBI().inTransaction(TransactionIsolationLevel.READ_COMMITTED, callback), shouldRetry, quietTries, maxTries); } catch (Exception e) { throw Throwables.propagate(e); } }
public <T> T retryWithHandle( final HandleCallback<T> callback, final Predicate<Throwable> myShouldRetry ) { try { return RetryUtils.retry(() -> getDBI().withHandle(callback), myShouldRetry, DEFAULT_MAX_TRIES); } catch (Exception e) { throw Throwables.propagate(e); } }
protected final <T> T inReadOnlyTransaction( final TransactionCallback<T> callback ) { return getDBI().withHandle( new HandleCallback<T>() { @Override public T withHandle(Handle handle) throws Exception { final Connection connection = handle.getConnection(); final boolean readOnly = connection.isReadOnly(); connection.setReadOnly(true); try { return handle.inTransaction(callback); } finally { try { connection.setReadOnly(readOnly); } catch (SQLException e) { // at least try to log it so we don't swallow exceptions log.error(e, "Unable to reset connection read-only state"); } } } } ); }
return getDBI().inTransaction( new TransactionCallback<Void>()
return getDBI().inTransaction( new TransactionCallback<Boolean>()
@Inject public SQLMetadataRuleManager( @Json ObjectMapper jsonMapper, MetadataRuleManagerConfig config, MetadataStorageTablesConfig dbTables, SQLMetadataConnector connector, AuditManager auditManager ) { this.jsonMapper = jsonMapper; this.config = config; this.dbTables = dbTables; this.dbi = connector.getDBI(); this.auditManager = auditManager; // Verify configured Periods can be treated as Durations (fail-fast before they're needed). Preconditions.checkNotNull(config.getAlertThreshold().toStandardDuration()); Preconditions.checkNotNull(config.getPollDuration().toStandardDuration()); this.rules = new AtomicReference<>(ImmutableMap.of()); }
@Override public boolean enableSegment(final String segmentId) { try { connector.getDBI().withHandle( new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) { handle.createStatement(StringUtils.format("UPDATE %s SET used=true WHERE id = :id", getSegmentsTable())) .bind("id", segmentId) .execute(); return null; } } ); } catch (Exception e) { log.error(e, "Exception enabling segment %s", segmentId); return false; } return true; }
@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 Collection<String> getAllDataSourceNames() { return connector.getDBI().withHandle( handle -> handle.createQuery( StringUtils.format("SELECT DISTINCT(datasource) FROM %s", getSegmentsTable()) ) .fold( new ArrayList<>(), new Folder3<List<String>, Map<String, Object>>() { @Override public List<String> fold( List<String> druidDataSources, Map<String, Object> stringObjectMap, FoldController foldController, StatementContext statementContext ) { druidDataSources.add( MapUtils.getString(stringObjectMap, "datasource") ); return druidDataSources; } } ) ); }
private boolean removeSegmentFromTable(String segmentId) { final int removed = connector.getDBI().withHandle( handle -> handle .createStatement(StringUtils.format("UPDATE %s SET used=false WHERE id = :segmentID", getSegmentsTable())) .bind("segmentID", segmentId) .execute() ); return removed > 0; }
@Override public boolean removeDataSource(final String dataSource) { try { final int removed = connector.getDBI().withHandle( handle -> handle.createStatement( StringUtils.format("UPDATE %s SET used=false WHERE dataSource = :dataSource", getSegmentsTable()) ).bind("dataSource", dataSource).execute() ); dataSources.remove(dataSource); if (removed == 0) { return false; } } catch (Exception e) { log.error(e, "Error removing datasource %s", dataSource); return false; } return true; }
@Override public int deletePendingSegments(String dataSource, Interval deleteInterval) { return connector.getDBI().inTransaction( (handle, status) -> handle .createStatement( StringUtils.format( "delete from %s where datasource = :dataSource and created_date >= :start and created_date < :end", dbTables.getPendingSegmentsTable() ) ) .bind("dataSource", dataSource) .bind("start", deleteInterval.getStart().toString()) .bind("end", deleteInterval.getEnd().toString()) .execute() ); }
final IDBI dbi = connector.getDBI(); VersionedIntervalTimeline<String, DataSegment> segmentTimeline = connector.inReadOnlyTransaction( (handle, status) -> VersionedIntervalTimeline.forSegments(