@Test public void returnsIndeterminateIfCannotGetFreshTimestamp() { TimestampCorroborationConsistencyCheck checkFailingToGetFresh = ImmutableTimestampCorroborationConsistencyCheck.builder() .conservativeBound(txMgr -> 10L) .freshTimestampSource(EXCEPTION_THROWER) .build(); assertThat(checkFailingToGetFresh.apply(mock(TransactionManager.class))) .isEqualTo(ImmutableTransactionManagerConsistencyResult.builder() .consistencyState(TransactionManagerConsistencyResult.ConsistencyState.INDETERMINATE) .reasonForInconsistency(EXCEPTION) .build()); }
@Test public void returnsIndeterminateIfCannotGetConservativeBound() { TimestampCorroborationConsistencyCheck checkFailingToGetBound = ImmutableTimestampCorroborationConsistencyCheck.builder() .conservativeBound(EXCEPTION_THROWER) .freshTimestampSource(txMgr -> 7L) .build(); assertThat(checkFailingToGetBound.apply(mock(TransactionManager.class))) .isEqualTo(ImmutableTransactionManagerConsistencyResult.builder() .consistencyState(TransactionManagerConsistencyResult.ConsistencyState.INDETERMINATE) .reasonForInconsistency(EXCEPTION) .build()); }
private static Callback<TransactionManager> timelockConsistencyCheckCallback( AtlasDbConfig atlasDbConfig, AtlasDbRuntimeConfig initialRuntimeConfig, LockAndTimestampServices lockAndTimestampServices) { if (isUsingTimeLock(atlasDbConfig, initialRuntimeConfig)) { // Only do the consistency check if we're using TimeLock. // This avoids a bootstrapping problem with leader-block services without async initialisation, // where you need a working timestamp service to check consistency, you need to check consistency // before you can return a TM, you need to return a TM to listen on ports, and you need to listen on // ports in order to get a working timestamp service. return ConsistencyCheckRunner.create( ImmutableTimestampCorroborationConsistencyCheck.builder() .conservativeBound(TransactionManager::getUnreadableTimestamp) .freshTimestampSource(unused -> lockAndTimestampServices.timelock().getFreshTimestamp()) .build()); } return Callback.noOp(); }
private static Callback<TransactionManager> timelockConsistencyCheckCallback( AtlasDbConfig atlasDbConfig, AtlasDbRuntimeConfig initialRuntimeConfig, LockAndTimestampServices lockAndTimestampServices) { if (isUsingTimeLock(atlasDbConfig, initialRuntimeConfig)) { // Only do the consistency check if we're using TimeLock. // This avoids a bootstrapping problem with leader-block services without async initialisation, // where you need a working timestamp service to check consistency, you need to check consistency // before you can return a TM, you need to return a TM to listen on ports, and you need to listen on // ports in order to get a working timestamp service. return ConsistencyCheckRunner.create( ImmutableTimestampCorroborationConsistencyCheck.builder() .conservativeBound(TransactionManager::getUnreadableTimestamp) .freshTimestampSource(unused -> lockAndTimestampServices.timelock().getFreshTimestamp()) .build()); } return Callback.noOp(); }
private TimestampCorroborationConsistencyCheck createForTimestamps(long conservativeBound, long freshTimestamp) { return ImmutableTimestampCorroborationConsistencyCheck.builder() .conservativeBound(unused -> conservativeBound) .freshTimestampSource(unused -> freshTimestamp) .build(); } }