/** * Returns the version of the transactions schema associated with the provided timestamp. * * This method may perpetuate the existing state one or more times to achieve consensus. It will repeatedly * attempt to perpetuate the existing state until a consensus for the provided timestamp argument is achieved. * * This method should only be called with timestamps that have already been given out by the timestamp service; * otherwise, achieving a consensus may take a long time. */ public int getTransactionsSchemaVersion(long timestamp) { if (timestamp < AtlasDbConstants.STARTING_TS) { throw new SafeIllegalStateException("Query attempted for timestamp {} which was never given out by the" + " timestamp service, as timestamps start at {}", SafeArg.of("queriedTimestamp", timestamp), SafeArg.of("startOfTime", AtlasDbConstants.STARTING_TS)); } Optional<Integer> possibleVersion = extractTimestampVersion(coordinationService.getValueForTimestamp(timestamp), timestamp); while (!possibleVersion.isPresent()) { CheckAndSetResult<ValueAndBound<InternalSchemaMetadata>> casResult = tryPerpetuateExistingState(); possibleVersion = extractTimestampVersion(casResult.existingValues() .stream() .filter(valueAndBound -> valueAndBound.bound() >= timestamp) .findAny(), timestamp); } return possibleVersion.get(); }
/** * Returns the version of the transactions schema associated with the provided timestamp. * * This method may perpetuate the existing state one or more times to achieve consensus. It will repeatedly * attempt to perpetuate the existing state until a consensus for the provided timestamp argument is achieved. * * This method should only be called with timestamps that have already been given out by the timestamp service; * otherwise, achieving a consensus may take a long time. */ public int getTransactionsSchemaVersion(long timestamp) { if (timestamp < AtlasDbConstants.STARTING_TS) { throw new SafeIllegalStateException("Query attempted for timestamp {} which was never given out by the" + " timestamp service, as timestamps start at {}", SafeArg.of("queriedTimestamp", timestamp), SafeArg.of("startOfTime", AtlasDbConstants.STARTING_TS)); } Optional<Integer> possibleVersion = extractTimestampVersion(coordinationService.getValueForTimestamp(timestamp), timestamp); while (!possibleVersion.isPresent()) { CheckAndSetResult<ValueAndBound<InternalSchemaMetadata>> casResult = tryPerpetuateExistingState(); possibleVersion = extractTimestampVersion(casResult.existingValues() .stream() .filter(valueAndBound -> valueAndBound.bound() >= timestamp) .findAny(), timestamp); } return possibleVersion.get(); }