public void runIterationOfTargetedSweep() { targetedSweeper.get().sweepNextBatch(ShardAndStrategy.conservative(0)); targetedSweeper.get().sweepNextBatch(ShardAndStrategy.thorough(0)); }
@Override protected Optional<SweepResults> completeSweep(TableReference ignored, long ts) { when(timestampsSupplier.getUnreadableTimestamp()).thenReturn(ts); when(timestampsSupplier.getImmutableTimestamp()).thenReturn(ts); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(0)); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(0)); return Optional.empty(); }
private SweepBatch readThorough(long partition, long minExclusive, long maxExclusive) { return sweepableCells.getBatchForPartition(thorough(shardThor), partition, minExclusive, maxExclusive); }
@Test public void thoroughSweepCallsFollower() { enqueueWriteCommitted(TABLE_THOR, LOW_TS); enqueueWriteCommitted(TABLE_THOR, LOW_TS2); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(THOR_SHARD)); ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class); verify(mockFollower, times(1)).run(eq(TABLE_THOR), captor.capture()); assertThat(Iterables.getOnlyElement(captor.getAllValues())).containsExactly(DEFAULT_CELL); }
public static ShardAndStrategy fromInfo(PartitionInfo info) { if (info.isConservative().isTrue()) { return ShardAndStrategy.conservative(info.shard()); } return ShardAndStrategy.thorough(info.shard()); } }
@Test public void thoroughSweepDeletesAllButLatestWithSingleDeleteAllTimestampsIncludingSentinels() { long lastWriteTs = TS_FINE_GRANULARITY - 1; for (long i = 1; i <= lastWriteTs; i++) { enqueueWriteCommitted(TABLE_THOR, i); } sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(THOR_SHARD)); assertReadAtTimestampReturnsNothing(TABLE_THOR, lastWriteTs); assertTestValueEnqueuedAtGivenTimestampStillPresent(TABLE_THOR, lastWriteTs); verify(spiedKvs, times(1)).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(true)); }
@Test public void canReadNextIfNotProgressedBeyondForThorough() { progress.updateLastSweptTimestamp(thorough(shardThor), TS2 - 1); assertThat(readThorough(shardThor)).contains(TS2_FINE_PARTITION); }
@Test public void canReadNextTimestampIfProgressedBeyondButInSamePartitionForForThorough() { progress.updateLastSweptTimestamp(thorough(shardThor), maxTsForFinePartition(TS2_FINE_PARTITION) - 1); assertThat(readThorough(shardThor)).contains(TS2_FINE_PARTITION); }
@Test public void noNextTimestampIfProgressedToEndOfPartitionForThorough() { progress.updateLastSweptTimestamp(thorough(shardThor), maxTsForFinePartition(TS2_FINE_PARTITION)); assertThat(readThorough(shardThor)).isEmpty(); }
@Test public void canReadNextWhenOtherShardsAndStrategiesProgressToEndOfPartitionForConservative() { progress.updateLastSweptTimestamp(thorough(shardCons), maxTsForFinePartition(TS_FINE_PARTITION)); progress.updateLastSweptTimestamp(conservative(shardThor), maxTsForFinePartition(TS_FINE_PARTITION)); progress.updateLastSweptTimestamp(thorough(shardThor), maxTsForFinePartition(TS_FINE_PARTITION)); assertThat(readConservative(shardCons)).contains(TS_FINE_PARTITION); }
@Test public void thoroughSweepDeletesExistingSentinel() { spiedKvs.addGarbageCollectionSentinelValues(TABLE_THOR, ImmutableList.of(DEFAULT_CELL)); assertReadAtTimestampReturnsSentinel(TABLE_THOR, 0L); enqueueWriteCommitted(TABLE_THOR, 10L); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(THOR_SHARD)); assertReadAtTimestampReturnsNothing(TABLE_THOR, 0L); }
@Test public void thoroughSweepDoesNotAddSentinelAndLeavesSingleValue() { enqueueWriteCommitted(TABLE_THOR, LOW_TS); assertReadAtTimestampReturnsNothing(TABLE_THOR, LOW_TS); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(THOR_SHARD)); assertReadAtTimestampReturnsNothing(TABLE_THOR, LOW_TS); assertTestValueEnqueuedAtGivenTimestampStillPresent(TABLE_THOR, LOW_TS); }
@Test public void thoroughSweepDeletesLowerValue() { enqueueWriteCommitted(TABLE_THOR, LOW_TS); enqueueWriteCommitted(TABLE_THOR, LOW_TS2); assertTestValueEnqueuedAtGivenTimestampStillPresent(TABLE_THOR, LOW_TS); assertTestValueEnqueuedAtGivenTimestampStillPresent(TABLE_THOR, LOW_TS2); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(THOR_SHARD)); assertReadAtTimestampReturnsNothing(TABLE_THOR, LOW_TS + 1); assertTestValueEnqueuedAtGivenTimestampStillPresent(TABLE_THOR, LOW_TS2); }
@Test public void canReadNextWhenOtherShardsAndStrategiesProgressToEndOfPartitionForThorough() { progress.updateLastSweptTimestamp(thorough(shardCons), maxTsForFinePartition(TS2_FINE_PARTITION)); progress.updateLastSweptTimestamp(conservative(shardThor), maxTsForFinePartition(TS2_FINE_PARTITION)); progress.updateLastSweptTimestamp(conservative(shardCons), maxTsForFinePartition(TS2_FINE_PARTITION)); assertThat(readThorough(shardThor)).contains(TS2_FINE_PARTITION); }
@Test public void testSweepTimestampMetric() { unreadableTs = 17; immutableTs = 40; sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(0)); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(0)); assertThat(metricsManager).hasSweepTimestampConservativeEqualTo(17L); assertThat(metricsManager).hasSweepTimestampThoroughEqualTo(40); immutableTs = 5; sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(0)); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(0)); assertThat(metricsManager).hasSweepTimestampConservativeEqualTo(5L); assertThat(metricsManager).hasSweepTimestampThoroughEqualTo(5); }
@Test public void thoroughSweepDeletesTombstoneIfLatestWrite() { enqueueTombstone(TABLE_THOR, LOW_TS); enqueueTombstone(TABLE_THOR, LOW_TS2); assertReadAtTimestampReturnsTombstoneAtTimestamp(TABLE_THOR, LOW_TS + 1, LOW_TS); assertReadAtTimestampReturnsTombstoneAtTimestamp(TABLE_THOR, LOW_TS2 + 1, LOW_TS2); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(THOR_SHARD)); assertReadAtTimestampReturnsNothing(TABLE_THOR, LOW_TS + 1); assertReadAtTimestampReturnsNothing(TABLE_THOR, LOW_TS2 + 1); }
@Test public void sweepDeletesAllIfLatestCommittedTombstoneInThorough() { useOneSweepQueueShard(); WriteReference writeToThorough = WriteReference.write(TABLE_THOR, TEST_CELL); WriteReference tombstoneToThorough = WriteReference.tombstone(TABLE_THOR, TEST_CELL); long firstStart = writeInTransactionAndGetStartTimestamp(writeToThorough); long secondStart = writeInTransactionAndGetStartTimestamp(tombstoneToThorough); assertLatestEntryBeforeTsIs(Long.MAX_VALUE, TABLE_THOR, TEST_CELL, PtBytes.EMPTY_BYTE_ARRAY, secondStart); assertLatestEntryBeforeTsIs(secondStart, TABLE_THOR, TEST_CELL, TEST_DATA, firstStart); serializableTxManager.setUnreadableTimestamp(secondStart + 1); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(0)); assertNoEntryForCellInKvs(TABLE_THOR, TEST_CELL); }
@Override protected Optional<SweepResults> completeSweep(TableReference ignored, long ts) { when(timestampsSupplier.getUnreadableTimestamp()).thenReturn(ts); when(timestampsSupplier.getImmutableTimestamp()).thenReturn(ts); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(0)); sweepQueue.sweepNextBatch(ShardAndStrategy.thorough(0)); return Optional.empty(); }
public static ShardAndStrategy fromInfo(PartitionInfo info) { if (info.isConservative().isTrue()) { return ShardAndStrategy.conservative(info.shard()); } return ShardAndStrategy.thorough(info.shard()); } }