@Override CompletableFuture<Void> createStreamCutRecordData(long recordingTime, byte[] record) { String path = String.format(retentionStreamCutRecordPathFormat, recordingTime); return Futures.toVoid(store.createZNodeIfNotExist(path, record)); }
@Override CompletableFuture<Void> createWaitingRequestNodeIfAbsent(byte[] waitingRequestProcessor) { return Futures.toVoid(store.createZNodeIfNotExist(waitingRequestProcessorPath, waitingRequestProcessor)); }
@Override CompletableFuture<Void> createHistoryTimeSeriesChunkDataIfAbsent(int chunkNumber, byte[] data) { String path = String.format(historyTimeSeriesChunkPathFormat, chunkNumber); return Futures.toVoid(store.createZNodeIfNotExist(path, data)); }
@Override CompletableFuture<Void> createSealedSegmentSizesMapShardDataIfAbsent(int shard, byte[] data) { String path = String.format(segmentsSealedSizeMapShardPathFormat, shard); return Futures.toVoid(store.createZNodeIfNotExist(path, data)); }
public CompletableFuture<Void> notifyTruncateSegment(String scope, String stream, Map.Entry<Long, Long> segmentCut, String delegationToken, long requestId) { return Futures.toVoid(withRetries(() -> segmentHelper.truncateSegment(scope, stream, segmentCut.getKey(), segmentCut.getValue(), hostControllerStore, this.connectionFactory, delegationToken, requestId), executor)); }
public CompletableFuture<Void> notifyPolicyUpdates(String scope, String stream, List<Segment> activeSegments, ScalingPolicy policy, String delegationToken, long requestId) { return Futures.toVoid(Futures.allOfWithResults(activeSegments .stream() .parallel() .map(segment -> notifyPolicyUpdate(scope, stream, policy, segment.segmentId(), delegationToken, requestId)) .collect(Collectors.toList()))); }
@Override CompletableFuture<Void> createSegmentSealedEpochRecordData(long segmentToSeal, int epoch) { String path = String.format(segmentSealedEpochPathFormat, segmentToSeal); byte[] epochData = new byte[Integer.BYTES]; BitConverter.writeInt(epochData, 0, epoch); return Futures.toVoid(store.createZNodeIfNotExist(path, epochData)); }
private CompletableFuture<Void> createStream(String scope, String streamName, final StreamConfiguration streamConfig) { return Futures.toVoid(Retry.indefinitelyWithExpBackoff(DELAY, MULTIPLIER, MAX_DELAY, e -> log.warn("Error creating event processor stream " + streamName, e)) .runAsync(() -> controller.createStream(scope, streamName, streamConfig) .thenAccept(x -> log.info("Created stream {}/{}", scope, streamName)), executor)); }
public CompletableFuture<Void> notifyDeleteSegment(String scope, String stream, long segmentId, String delegationToken, long requestId) { return Futures.toVoid(withRetries(() -> segmentHelper.deleteSegment(scope, stream, segmentId, hostControllerStore, this.connectionFactory, delegationToken, requestId), executor)); }
public CompletableFuture<Void> notifyNewSegment(String scope, String stream, long segmentId, ScalingPolicy policy, String controllerToken) { return Futures.toVoid(withRetries(() -> segmentHelper.createSegment(scope, stream, segmentId, policy, hostControllerStore, this.connectionFactory, controllerToken, RequestTag.NON_EXISTENT_ID), executor)); }
public CompletableFuture<Void> notifyNewSegment(String scope, String stream, long segmentId, ScalingPolicy policy, String controllerToken, long requestId) { return Futures.toVoid(withRetries(() -> segmentHelper.createSegment(scope, stream, segmentId, policy, hostControllerStore, this.connectionFactory, controllerToken, requestId), executor)); }
private CompletableFuture<Void> notifySealedSegment(final String scope, final String stream, final long sealedSegment, String delegationToken, long requestId) { return Futures.toVoid(withRetries(() -> segmentHelper.sealSegment( scope, stream, sealedSegment, hostControllerStore, this.connectionFactory, delegationToken, requestId), executor)); }
private CompletableFuture<Void> processUpdate(String scope, String stream, VersionedMetadata<StreamConfigurationRecord> record, VersionedMetadata<State> state, OperationContext context, long requestId) { StreamConfigurationRecord configProperty = record.getObject(); return Futures.toVoid(streamMetadataStore.updateVersionedState(scope, stream, State.UPDATING, state, context, executor) .thenCompose(updated -> updateStreamForAutoStreamCut(scope, stream, context, configProperty, updated) .thenCompose(x -> notifyPolicyUpdate(context, scope, stream, configProperty.getStreamConfiguration(), requestId)) .thenCompose(x -> streamMetadataStore.completeUpdateConfiguration(scope, stream, record, context, executor)) .thenCompose(x -> streamMetadataStore.updateVersionedState(scope, stream, State.ACTIVE, updated, context, executor)))); }
private ArrayList<StoreRequest> createSealSegmentsRequests(Collection<String> segmentNames) { val result = new ArrayList<StoreRequest>(); for (String segmentName : segmentNames) { result.add(store -> Futures.toVoid(store.sealStreamSegment(segmentName, TIMEOUT))); } return result; }
@Override public CompletableFuture<Void> scaleOldSegmentsSealed(Map<Long, Long> sealedSegmentSizes, VersionedMetadata<EpochTransitionRecord> record) { EpochTransitionRecord epochTransition = record.getObject(); return Futures.toVoid(clearMarkers(epochTransition.getSegmentsToSeal()) .thenCompose(x -> updateSealedSegmentSizes(sealedSegmentSizes)) .thenCompose(x -> updateCurrentEpochRecord(epochTransition.getNewEpoch()))); }
@Override public CompletableFuture<Void> deleteStreamCutBefore(StreamCutReferenceRecord record) { return getRetentionSetData() .thenCompose(data -> { RetentionSet retention = RetentionSet.fromBytes(data.getData()); RetentionSet update = RetentionSet.removeStreamCutBefore(retention, record); List<StreamCutReferenceRecord> toRemove = retention.retentionRecordsBefore(record); return Futures.allOf(toRemove.stream().map(x -> deleteStreamCutRecordData(x.getRecordingTime())).collect(Collectors.toList())) .thenCompose(x -> Futures.toVoid(updateRetentionSetData(new Data(update.toBytes(), data.getVersion())))); }); }
@Override public CompletableFuture<Void> completeTruncation(VersionedMetadata<StreamTruncationRecord> record) { Preconditions.checkNotNull(record); Preconditions.checkArgument(record.getObject().isUpdating()); StreamTruncationRecord current = record.getObject(); if (current.isUpdating()) { StreamTruncationRecord completedProp = StreamTruncationRecord.complete(current); return Futures.toVoid(setTruncationData(new Data(completedProp.toBytes(), record.getVersion()))); } else { // idempotent return CompletableFuture.completedFuture(null); } }
@Override public CompletableFuture<Void> updateState(final State state) { return getStateData(true) .thenCompose(currState -> { VersionedMetadata<State> currentState = new VersionedMetadata<State>(StateRecord.fromBytes(currState.getData()).getState(), currState.getVersion()); return Futures.toVoid(updateVersionedState(currentState, state)); }); }
@Override public CompletableFuture<Void> append(String logName, Event event, Duration timeout) { ensureRunning(); DurableDataLog log = this.logs.getOrDefault(logName, null); if (log == null) { return Futures.failedFuture(new StreamSegmentNotExistsException(logName)); } ArrayView s = event.getSerialization(); return Futures.toVoid(log.append(s, timeout)); }
@Override public CompletableFuture<Void> addStreamCutToRetentionSet(StreamCutRecord record) { return getRetentionSetData() .thenCompose(data -> { RetentionSet retention = RetentionSet.fromBytes(data.getData()); RetentionSet update = RetentionSet.addReferenceToStreamCutIfLatest(retention, record); return createStreamCutRecordData(record.getRecordingTime(), record.toBytes()) .thenCompose(v -> Futures.toVoid(updateRetentionSetData(new Data(update.toBytes(), data.getVersion())))); }); }