private CheckAndSetRequest createSingleCellRequest(ShardAndStrategy shardAndStrategy, long oldVal, byte[] colValNew) { byte[] colValOld = createColumnValue(oldVal); return CheckAndSetRequest.singleCell(TABLE_REF, cellForShard(shardAndStrategy), colValOld, colValNew); } }
private long increaseValueFromToAtLeast(ShardAndStrategy shardAndStrategy, long oldVal, long newVal) { byte[] colValNew = createColumnValue(newVal); long currentValue = oldVal; while (currentValue < newVal) { CheckAndSetRequest casRequest = createRequest(shardAndStrategy, currentValue, colValNew); try { kvs.checkAndSet(casRequest); return newVal; } catch (CheckAndSetException e) { log.info("Failed to check and set from expected old value {} to new value {}. Retrying if the old " + "value changed under us.", SafeArg.of("old value", currentValue), SafeArg.of("new value", newVal)); currentValue = rethrowIfUnchanged(shardAndStrategy, currentValue, e); } } return currentValue; }
@Test public void canUpgradeNumberOfShardsIfPersistedDefaultValue() { byte[] defaultValue = ShardProgress.createColumnValue(AtlasDbConstants.DEFAULT_SWEEP_QUEUE_SHARDS); CheckAndSetRequest request = progress.createNewCellRequest(ShardProgress.SHARD_COUNT_SAS, defaultValue); kvs.checkAndSet(request); progress.updateNumberOfShards(128); assertThat(progress.getNumberOfShards()).isEqualTo(128); }
private CheckAndSetRequest createSingleCellRequest(ShardAndStrategy shardAndStrategy, long oldVal, byte[] colValNew) { byte[] colValOld = createColumnValue(oldVal); return CheckAndSetRequest.singleCell(TABLE_REF, cellForShard(shardAndStrategy), colValOld, colValNew); } }
private long increaseValueFromToAtLeast(ShardAndStrategy shardAndStrategy, long oldVal, long newVal) { byte[] colValNew = createColumnValue(newVal); long currentValue = oldVal; while (currentValue < newVal) { CheckAndSetRequest casRequest = createRequest(shardAndStrategy, currentValue, colValNew); try { kvs.checkAndSet(casRequest); return newVal; } catch (CheckAndSetException e) { log.info("Failed to check and set from expected old value {} to new value {}. Retrying if the old " + "value changed under us.", SafeArg.of("old value", currentValue), SafeArg.of("new value", newVal)); currentValue = rethrowIfUnchanged(shardAndStrategy, currentValue, e); } } return currentValue; }