public static ShardAndStrategy conservative(int shard) { return ShardAndStrategy.of(shard, TableMetadataPersistence.SweepStrategy.CONSERVATIVE); }
public static ShardAndStrategy thorough(int shard) { return ShardAndStrategy.of(shard, TableMetadataPersistence.SweepStrategy.THOROUGH); }
@Test public void usingStrategyNothingThrows() { assertThatThrownBy(() -> ShardAndStrategy.of(5, TableMetadataPersistence.SweepStrategy.NOTHING)) .isInstanceOf(IllegalArgumentException.class); } }
public static Optional<TargetedSweeperLock> tryAcquire(int shard, TableMetadataPersistence.SweepStrategy strategy, TimelockService timeLock) { ShardAndStrategy shardStrategy = ShardAndStrategy.of(shard, strategy); LockDescriptor lock = StringLockDescriptor.of(shardStrategy.toText()); // We do not want the timeout to be too low to avoid a race condition where we give up too soon LockRequest request = LockRequest.of(ImmutableSet.of(lock), 100L); return timeLock.lock(request) .getTokenOrEmpty() .map(lockToken -> new TargetedSweeperLock(shardStrategy, timeLock, lockToken)); }
public static ShardAndStrategy thorough(int shard) { return ShardAndStrategy.of(shard, TableMetadataPersistence.SweepStrategy.THOROUGH); }
public static ShardAndStrategy conservative(int shard) { return ShardAndStrategy.of(shard, TableMetadataPersistence.SweepStrategy.CONSERVATIVE); }
public static Optional<TargetedSweeperLock> tryAcquire(int shard, TableMetadataPersistence.SweepStrategy strategy, TimelockService timeLock) { ShardAndStrategy shardStrategy = ShardAndStrategy.of(shard, strategy); LockDescriptor lock = StringLockDescriptor.of(shardStrategy.toText()); // We do not want the timeout to be too low to avoid a race condition where we give up too soon LockRequest request = LockRequest.of(ImmutableSet.of(lock), 100L); return timeLock.lock(request) .getTokenOrEmpty() .map(lockToken -> new TargetedSweeperLock(shardStrategy, timeLock, lockToken)); }