use of io.pravega.controller.store.VersionedMetadata in project pravega by pravega.
the class StreamMetadataTasks method checkScale.
/**
* Helper method to check if scale operation against an epoch completed or not.
*
* @param scope scope.
* @param stream stream name.
* @param epoch stream epoch.
* @param requestId request id.
* @return returns the newly created segments.
*/
public CompletableFuture<ScaleStatusResponse> checkScale(String scope, String stream, int epoch, long requestId) {
OperationContext context = streamMetadataStore.createStreamContext(scope, stream, requestId);
CompletableFuture<EpochRecord> activeEpochFuture = streamMetadataStore.getActiveEpoch(scope, stream, context, true, executor);
CompletableFuture<State> stateFuture = streamMetadataStore.getState(scope, stream, true, context, executor);
CompletableFuture<EpochTransitionRecord> etrFuture = streamMetadataStore.getEpochTransition(scope, stream, context, executor).thenApply(VersionedMetadata::getObject);
return CompletableFuture.allOf(stateFuture, activeEpochFuture, etrFuture).handle((r, ex) -> {
ScaleStatusResponse.Builder response = ScaleStatusResponse.newBuilder();
if (ex != null) {
Throwable e = Exceptions.unwrap(ex);
if (e instanceof StoreException.DataNotFoundException) {
response.setStatus(ScaleStatusResponse.ScaleStatus.INVALID_INPUT);
} else {
response.setStatus(ScaleStatusResponse.ScaleStatus.INTERNAL_ERROR);
}
} else {
EpochRecord activeEpoch = activeEpochFuture.join();
State state = stateFuture.join();
EpochTransitionRecord etr = etrFuture.join();
if (epoch > activeEpoch.getEpoch()) {
response.setStatus(ScaleStatusResponse.ScaleStatus.INVALID_INPUT);
} else if (activeEpoch.getEpoch() == epoch || activeEpoch.getReferenceEpoch() == epoch) {
response.setStatus(ScaleStatusResponse.ScaleStatus.IN_PROGRESS);
} else {
// has not completed.
if (epoch + 1 == activeEpoch.getReferenceEpoch() && state.equals(State.SCALING) && (etr.equals(EpochTransitionRecord.EMPTY) || etr.getNewEpoch() == activeEpoch.getEpoch())) {
response.setStatus(ScaleStatusResponse.ScaleStatus.IN_PROGRESS);
} else {
response.setStatus(ScaleStatusResponse.ScaleStatus.SUCCESS);
}
}
}
return response.build();
});
}
use of io.pravega.controller.store.VersionedMetadata in project pravega by pravega.
the class StreamMetadataTasks method isUpdated.
@VisibleForTesting
CompletableFuture<Boolean> isUpdated(String scope, String stream, StreamConfiguration newConfig, OperationContext context) {
CompletableFuture<State> stateFuture = streamMetadataStore.getState(scope, stream, true, context, executor);
CompletableFuture<StreamConfigurationRecord> configPropertyFuture = streamMetadataStore.getConfigurationRecord(scope, stream, context, executor).thenApply(VersionedMetadata::getObject);
return CompletableFuture.allOf(stateFuture, configPropertyFuture).thenApply(v -> {
State state = stateFuture.join();
StreamConfigurationRecord configProperty = configPropertyFuture.join();
// if property is updating and doesn't match our request, it's a subsequent update
if (configProperty.isUpdating()) {
return !configProperty.getStreamConfiguration().equals(newConfig);
} else {
// if stream is sealed then update should not be allowed
if (state.equals(State.SEALED)) {
log.error("Cannot update a sealed stream {}/{}", scope, stream);
throw new UnsupportedOperationException("Cannot update a sealed stream: " + NameUtils.getScopedStreamName(scope, stream));
}
// and state is not updating
return !(configProperty.getStreamConfiguration().equals(newConfig) && state.equals(State.UPDATING));
}
});
}
use of io.pravega.controller.store.VersionedMetadata in project pravega by pravega.
the class PersistentStreamBase method startRollingTxn.
@Override
public CompletableFuture<VersionedMetadata<CommittingTransactionsRecord>> startRollingTxn(int activeEpoch, VersionedMetadata<CommittingTransactionsRecord> existing, OperationContext context) {
Preconditions.checkNotNull(context, "Operation context cannot be null");
CommittingTransactionsRecord record = existing.getObject();
if (record.isRollingTxnRecord()) {
return CompletableFuture.completedFuture(existing);
} else {
CommittingTransactionsRecord update = record.createRollingTxnRecord(activeEpoch);
return updateCommittingTxnRecord(new VersionedMetadata<>(update, existing.getVersion()), context).thenApply(version -> new VersionedMetadata<>(update, version));
}
}
use of io.pravega.controller.store.VersionedMetadata in project pravega by pravega.
the class PersistentStreamBase method deleteStreamCutBefore.
@Override
public CompletableFuture<Void> deleteStreamCutBefore(StreamCutReferenceRecord record, OperationContext context) {
Preconditions.checkNotNull(context, "Operation context cannot be null");
return getRetentionSetData(context).thenCompose(data -> {
RetentionSet retention = data.getObject();
RetentionSet update = RetentionSet.removeStreamCutBefore(retention, record);
List<StreamCutReferenceRecord> toRemove = retention.retentionRecordsBefore(record);
return Futures.allOf(toRemove.stream().map(x -> deleteStreamCutRecordData(x.getRecordingTime(), context)).collect(Collectors.toList())).thenCompose(x -> Futures.toVoid(updateRetentionSetData(new VersionedMetadata<>(update, data.getVersion()), context)));
});
}
use of io.pravega.controller.store.VersionedMetadata in project pravega by pravega.
the class PersistentStreamBase method completeUpdateConfiguration.
/**
* Update configuration at configurationPath.
*
* @return future of operation
*/
@Override
public CompletableFuture<Void> completeUpdateConfiguration(VersionedMetadata<StreamConfigurationRecord> existing, OperationContext context) {
StreamConfigurationRecord current = existing.getObject();
Preconditions.checkNotNull(current);
if (current.isUpdating()) {
StreamConfigurationRecord newProperty = StreamConfigurationRecord.complete(scope, name, current.getStreamConfiguration());
log.debug(context.getRequestId(), "Completing update configuration for stream {}/{}", scope, name);
return Futures.toVoid(setConfigurationData(new VersionedMetadata<>(newProperty, existing.getVersion()), context));
} else {
// idempotent
return CompletableFuture.completedFuture(null);
}
}
Aggregations