private static Optional<Integer> extractTimestampVersion( Optional<ValueAndBound<InternalSchemaMetadata>> valueAndBound, long timestamp) { return valueAndBound .flatMap(ValueAndBound::value) .map(InternalSchemaMetadata::timestampToTransactionsTableSchemaVersion) .map(versionMap -> versionMap.getValueForTimestamp(timestamp)); } }
private static Optional<Integer> extractTimestampVersion( Optional<ValueAndBound<InternalSchemaMetadata>> valueAndBound, long timestamp) { return valueAndBound .flatMap(ValueAndBound::value) .map(InternalSchemaMetadata::timestampToTransactionsTableSchemaVersion) .map(versionMap -> versionMap.getValueForTimestamp(timestamp)); } }
@Test public void copiesWithNewVersions() { TimestampPartitioningMap newMap = DEFAULT_INITIAL_MAPPING.copyInstallingNewValue(TIMESTAMP_1, 2); assertThat(newMap.getValueForTimestamp(TIMESTAMP_1 - 1)).isEqualTo(1); assertThat(newMap.getValueForTimestamp(TIMESTAMP_1)).isEqualTo(2); assertThat(newMap.getValueForTimestamp(TIMESTAMP_2)).isEqualTo(2); }
@Test public void getsVersionForTimestamp() { assertThat(DEFAULT_INITIAL_MAPPING.getValueForTimestamp(68)).isEqualTo(1); }
/** * Registers a gauge which tracks the eventual transactions schema version - that is, at the end of the current * period of validity for the bound, what the metadata says the transactions schema version should be. * * @param metricsManager metrics manager to register the gauge on * @param metadataCoordinationService metadata coordination service that should be tracked */ private static void registerEventualTransactionsSchemaVersionMetric(MetricsManager metricsManager, CoordinationService<InternalSchemaMetadata> metadataCoordinationService) { metricsManager.registerMetric( MetadataCoordinationServiceMetrics.class, AtlasDbMetricNames.COORDINATION_EVENTUAL_TRANSACTIONS_SCHEMA_VERSION, TrackerUtils.createCachingExceptionHandlingGauge( log, Clock.defaultClock(), AtlasDbMetricNames.COORDINATION_EVENTUAL_TRANSACTIONS_SCHEMA_VERSION, () -> { Optional<ValueAndBound<InternalSchemaMetadata>> latestValue = metadataCoordinationService.getLastKnownLocalValue(); return latestValue .map(ValueAndBound::value) .flatMap(Function.identity()) .map(InternalSchemaMetadata::timestampToTransactionsTableSchemaVersion) .map(timestampMap -> timestampMap.getValueForTimestamp(latestValue.get().bound())) .orElse(null); })); }
/** * Attempts to install a new transactions table schema version, by submitting a relevant transform. * * The execution of this method does not guarantee that the provided version will eventually be installed. * This method returns true if and only if in the map agreed by the coordination service evaluated at the validity * bound, the transactions schema version is equal to newVersion. */ public boolean tryInstallNewTransactionsSchemaVersion(int newVersion) { List<Integer> presentVersionPeakValidity = coordinationService.tryTransformCurrentValue( valueAndBound -> installNewVersionInMapOrDefault(newVersion, valueAndBound)) .existingValues() .stream() .map(valueAndBound -> valueAndBound.value() .orElseThrow(() -> new SafeIllegalStateException("Unexpectedly found no value in store")) .timestampToTransactionsTableSchemaVersion() .getValueForTimestamp(valueAndBound.bound())) .collect(Collectors.toList()); return Iterables.getOnlyElement(presentVersionPeakValidity) == newVersion; }
@Test public void supportsRevertingVersions() { TimestampPartitioningMap newMap = DEFAULT_INITIAL_MAPPING .copyInstallingNewValue(TIMESTAMP_1, 2) .copyInstallingNewValue(TIMESTAMP_2, 1); assertThat(newMap.getValueForTimestamp(TIMESTAMP_2 - 1)).isEqualTo(2); assertThat(newMap.getValueForTimestamp(TIMESTAMP_2)).isEqualTo(1); }
private static Optional<Integer> extractTimestampVersion( Optional<ValueAndBound<InternalSchemaMetadata>> valueAndBound, long timestamp) { return valueAndBound .flatMap(ValueAndBound::value) .map(InternalSchemaMetadata::timestampToTransactionsTableSchemaVersion) .map(versionMap -> versionMap.getValueForTimestamp(timestamp)); } }
private static Optional<Integer> extractTimestampVersion( Optional<ValueAndBound<InternalSchemaMetadata>> valueAndBound, long timestamp) { return valueAndBound .flatMap(ValueAndBound::value) .map(InternalSchemaMetadata::timestampToTransactionsTableSchemaVersion) .map(versionMap -> versionMap.getValueForTimestamp(timestamp)); } }
/** * Registers a gauge which tracks the eventual transactions schema version - that is, at the end of the current * period of validity for the bound, what the metadata says the transactions schema version should be. * * @param metricsManager metrics manager to register the gauge on * @param metadataCoordinationService metadata coordination service that should be tracked */ private static void registerEventualTransactionsSchemaVersionMetric(MetricsManager metricsManager, CoordinationService<InternalSchemaMetadata> metadataCoordinationService) { metricsManager.registerMetric( MetadataCoordinationServiceMetrics.class, AtlasDbMetricNames.COORDINATION_EVENTUAL_TRANSACTIONS_SCHEMA_VERSION, TrackerUtils.createCachingExceptionHandlingGauge( log, Clock.defaultClock(), AtlasDbMetricNames.COORDINATION_EVENTUAL_TRANSACTIONS_SCHEMA_VERSION, () -> { Optional<ValueAndBound<InternalSchemaMetadata>> latestValue = metadataCoordinationService.getLastKnownLocalValue(); return latestValue .map(ValueAndBound::value) .flatMap(Function.identity()) .map(InternalSchemaMetadata::timestampToTransactionsTableSchemaVersion) .map(timestampMap -> timestampMap.getValueForTimestamp(latestValue.get().bound())) .orElse(null); })); }
/** * Attempts to install a new transactions table schema version, by submitting a relevant transform. * * The execution of this method does not guarantee that the provided version will eventually be installed. * This method returns true if and only if in the map agreed by the coordination service evaluated at the validity * bound, the transactions schema version is equal to newVersion. */ public boolean tryInstallNewTransactionsSchemaVersion(int newVersion) { List<Integer> presentVersionPeakValidity = coordinationService.tryTransformCurrentValue( valueAndBound -> installNewVersionInMapOrDefault(newVersion, valueAndBound)) .existingValues() .stream() .map(valueAndBound -> valueAndBound.value() .orElseThrow(() -> new SafeIllegalStateException("Unexpectedly found no value in store")) .timestampToTransactionsTableSchemaVersion() .getValueForTimestamp(valueAndBound.bound())) .collect(Collectors.toList()); return Iterables.getOnlyElement(presentVersionPeakValidity) == newVersion; }