public static SweepTableFactory of(Namespace namespace) { return of(ImmutableList.<Function<? super Transaction, SharedTriggers>>of(), namespace); }
Map<String, Long> getHistory(Transaction tx) { Map<String, Long> tableToLastTimeSwept = new HashMap<>(); SweepPriorityTable sweepPriorityTable = SweepTableFactory.of().getSweepPriorityTable(tx); sweepPriorityTable.getRange(RangeRequest.builder() .retainColumns(SweepPriorityTable.getColumnSelection(SweepPriorityNamedColumn.LAST_SWEEP_TIME)) .batchHint(READ_BATCH_SIZE) .build()) .forEach(row -> { Long lastSweepTime = row.getLastSweepTime(); String tableName = row.getRowName().getFullTableName(); tableToLastTimeSwept.put(tableName, lastSweepTime); }); return tableToLastTimeSwept; } }
public static SweepTableFactory of(List<Function<? super Transaction, SharedTriggers>> sharedTriggers) { return new SweepTableFactory(sharedTriggers, defaultNamespace); }
@Override public void delete(Transaction tx, Collection<TableReference> tableRefs) { sweepTableFactory.getSweepPriorityTable(tx).delete( Collections2.transform(tableRefs, tr -> SweepPriorityRow.of(tr.getQualifiedName()))); }
private List<SweepPriority> loadPriorities(Transaction tx) { SweepPriorityTable table = sweepTableFactory.getSweepPriorityTable(tx); // Load a single column first for each row. This is a much more efficient query on Cassandra // than the full table scan that occurs otherwise. List<SweepPriorityRowResult> rows = table.getRange(RangeRequest.builder() .retainColumns(SweepPriorityTable.getColumnSelection(SweepPriorityNamedColumn.CELLS_DELETED)) .batchHint(READ_BATCH_SIZE) .build()) .immutableCopy(); // Fetch all columns for the above rows directly return Lists.transform(table.getRows(Lists.transform(rows, SweepPriorityRowResult::getRowName)), SweepPriorityStoreImpl::hydrate); }
public static SweepTableFactory of() { return of(ImmutableList.<Function<? super Transaction, SharedTriggers>>of(), defaultNamespace); }
SweepPriorityTable priorityTable = SweepTableFactory.of().getSweepPriorityTable(t); SweepPriorityTable.SweepPriorityRow row1 = SweepPriorityTable.SweepPriorityRow.of( tableToSweep.getQualifiedName());
@Override public void update(Transaction tx, TableReference tableRef, UpdateSweepPriority update) { SweepPriorityRow row = SweepPriorityRow.of(tableRef.getQualifiedName()); SweepPriorityTable table = sweepTableFactory.getSweepPriorityTable(tx); update.newStaleValuesDeleted().ifPresent(n -> table.putCellsDeleted(row, n)); update.newCellTsPairsExamined().ifPresent(n -> table.putCellsExamined(row, n)); update.newLastSweepTimeMillis().ifPresent(t -> table.putLastSweepTime(row, t)); update.newMinimumSweptTimestamp().ifPresent(t -> table.putMinimumSweptTimestamp(row, t)); update.newWriteCount().ifPresent(c -> table.putWriteCount(row, c)); }
public static SweepTableFactory of(List<Function<? super Transaction, SharedTriggers>> sharedTriggers, Namespace namespace) { return new SweepTableFactory(sharedTriggers, namespace); }
private static SpecificTableSweeper initializeSweepEndpoint( Consumer<Object> env, KeyValueService kvs, TransactionManager transactionManager, SweepTaskRunner sweepRunner, BackgroundSweeperPerformanceLogger sweepPerfLogger, LegacySweepMetrics sweepMetrics, boolean initializeAsync, AdjustableSweepBatchConfigSource sweepBatchConfigSource) { SpecificTableSweeper specificTableSweeper = SpecificTableSweeper.create( transactionManager, kvs, sweepRunner, SweepTableFactory.of(), sweepPerfLogger, sweepMetrics, initializeAsync); env.accept(new SweeperServiceImpl(specificTableSweeper, sweepBatchConfigSource)); return specificTableSweeper; }
Map<String, Long> getHistory(Transaction tx) { Map<String, Long> tableToLastTimeSwept = new HashMap<>(); SweepPriorityTable sweepPriorityTable = SweepTableFactory.of().getSweepPriorityTable(tx); sweepPriorityTable.getRange(RangeRequest.builder() .retainColumns(SweepPriorityTable.getColumnSelection(SweepPriorityNamedColumn.LAST_SWEEP_TIME)) .batchHint(READ_BATCH_SIZE) .build()) .forEach(row -> { Long lastSweepTime = row.getLastSweepTime(); String tableName = row.getRowName().getFullTableName(); tableToLastTimeSwept.put(tableName, lastSweepTime); }); return tableToLastTimeSwept; } }
@Override public void delete(Transaction tx, Collection<TableReference> tableRefs) { sweepTableFactory.getSweepPriorityTable(tx).delete( Collections2.transform(tableRefs, tr -> SweepPriorityRow.of(tr.getQualifiedName()))); }
public static SweepTableFactory of(List<Function<? super Transaction, SharedTriggers>> sharedTriggers) { return new SweepTableFactory(sharedTriggers, defaultNamespace); }
@Before public void setup() { exec = PTExecutors.newCachedThreadPool(); KeyValueService kvs = new InMemoryKeyValueService(false, exec); txManager = SweepTestUtils.setupTxManager(kvs); priorityStore = SweepPriorityStoreImpl.create(kvs, SweepTableFactory.of(), false); }
SweepPriorityTable priorityTable = SweepTableFactory.of().getSweepPriorityTable(t); SweepPriorityTable.SweepPriorityRow row1 = SweepPriorityTable.SweepPriorityRow.of( tableToSweep.getQualifiedName());
private List<SweepPriority> loadPriorities(Transaction tx) { SweepPriorityTable table = sweepTableFactory.getSweepPriorityTable(tx); // Load a single column first for each row. This is a much more efficient query on Cassandra // than the full table scan that occurs otherwise. List<SweepPriorityRowResult> rows = table.getRange(RangeRequest.builder() .retainColumns(SweepPriorityTable.getColumnSelection(SweepPriorityNamedColumn.CELLS_DELETED)) .batchHint(READ_BATCH_SIZE) .build()) .immutableCopy(); // Fetch all columns for the above rows directly return Lists.transform(table.getRows(Lists.transform(rows, SweepPriorityRowResult::getRowName)), SweepPriorityStoreImpl::hydrate); }
public static SweepTableFactory of(List<Function<? super Transaction, SharedTriggers>> sharedTriggers, Namespace namespace) { return new SweepTableFactory(sharedTriggers, namespace); }
@Test public void smokeTest() throws Exception { createTable(TABLE_1, SweepStrategy.CONSERVATIVE); createTable(TABLE_2, SweepStrategy.THOROUGH); createTable(TABLE_3, SweepStrategy.NOTHING); putManyCells(TABLE_1, 100, 110); putManyCells(TABLE_1, 103, 113); putManyCells(TABLE_1, 105, 115); putManyCells(TABLE_2, 101, 111); putManyCells(TABLE_2, 104, 114); putManyCells(TABLE_3, 120, 130); try (SingleLockService sweepLocks = backgroundSweeper.createSweepLocks()) { for (int i = 0; i < 50; ++i) { backgroundSweeper.checkConfigAndRunSweep(sweepLocks); } } verifyTableSwept(TABLE_1, 75, true); verifyTableSwept(TABLE_2, 58, false); List<SweepPriority> priorities = txManager.runTaskReadOnly( tx -> SweepPriorityStoreImpl.create(kvs, SweepTableFactory.of(), false).loadNewPriorities(tx)); Assert.assertTrue(priorities.stream().anyMatch(p -> p.tableRef().equals(TABLE_1))); Assert.assertTrue(priorities.stream().anyMatch(p -> p.tableRef().equals(TABLE_2))); }
@Override public void update(Transaction tx, TableReference tableRef, UpdateSweepPriority update) { SweepPriorityRow row = SweepPriorityRow.of(tableRef.getQualifiedName()); SweepPriorityTable table = sweepTableFactory.getSweepPriorityTable(tx); update.newStaleValuesDeleted().ifPresent(n -> table.putCellsDeleted(row, n)); update.newCellTsPairsExamined().ifPresent(n -> table.putCellsExamined(row, n)); update.newLastSweepTimeMillis().ifPresent(t -> table.putLastSweepTime(row, t)); update.newMinimumSweptTimestamp().ifPresent(t -> table.putMinimumSweptTimestamp(row, t)); update.newWriteCount().ifPresent(c -> table.putWriteCount(row, c)); }
public static SweepTableFactory of() { return of(ImmutableList.<Function<? super Transaction, SharedTriggers>>of(), defaultNamespace); }