use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class ContainerKeyIndex method update.
/**
* Performs a Batch Update or Removal.
*
* If {@link TableKeyBatch#isConditional()} returns true, this will execute an atomic Conditional Update/Removal based
* on the condition items in the batch ({@link TableKeyBatch#getVersionedItems}. The entire TableKeyBatch will be
* conditioned on those items, including those items that do not have a condition set. The entire TableKeyBatch will
* either all be committed as one unit or not at all.
*
* Otherwise this will perform an Unconditional Update/Removal, where all the {@link TableKeyBatch.Item}s in
* {@link TableKeyBatch#getItems()} will be applied regardless of whether they already exist or what their versions are.
*
* @param segment The Segment to perform the update/removal on.
* @param batch The {@link TableKeyBatch} to apply.
* @param persist A Supplier that, when invoked, will persist the contents of the batch to the Segment and return
* a CompletableFuture to indicate when the operation is done, containing the offset at which the
* batch has been written to the Segment. This Future must complete successfully before the effects
* of the {@link TableKeyBatch} are applied to the in-memory Index or before downstream conditional
* updates on the affected keys are initiated.
* @param timer Timer for the operation.
* @return A CompletableFuture that, when completed, will contain a list of offsets (within the Segment) where each
* of the items in the batch has been persisted. If the update failed, it will be failed with the appropriate exception.
* Notable exceptions:
* <ul>
* <li>{@link KeyNotExistsException} If a Key in the TableKeyBatch does not exist and was conditioned as having to exist.
* <li>{@link BadKeyVersionException} If a Key does exist but had a version mismatch.
* </ul>
*/
CompletableFuture<List<Long>> update(DirectSegmentAccess segment, TableKeyBatch batch, Supplier<CompletableFuture<Long>> persist, TimeoutTimer timer) {
Exceptions.checkNotClosed(this.closed.get(), this);
Supplier<CompletableFuture<List<Long>>> update;
if (batch.isConditional()) {
// Conditional update.
// Collect all Cache Keys for the Update Items that have a condition on them; we need this on order to
// serialize execution across them.
val keys = batch.getVersionedItems().stream().map(item -> Maps.immutableEntry(segment.getSegmentId(), item.getHash())).collect(Collectors.toList());
// Serialize the execution (queue it up to run only after all other currently queued up conditional updates
// for touched keys have finished).
update = () -> this.conditionalUpdateProcessor.add(keys, () -> validateConditionalUpdate(segment, batch, timer).thenComposeAsync(v -> persist.get(), this.executor).thenApplyAsync(batchOffset -> updateCache(segment, batch, batchOffset), this.executor));
} else {
// Unconditional update: persist the entries and update the cache.
update = () -> persist.get().thenApplyAsync(batchOffset -> updateCache(segment, batch, batchOffset), this.executor);
}
// Throttle any requests, if needed.
return this.segmentTracker.throttleIfNeeded(segment, update, batch.getLength());
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class ContainerTableExtensionImpl method getInfo.
@Override
public CompletableFuture<TableSegmentInfo> getInfo(String segmentName, Duration timeout) {
Exceptions.checkNotClosed(this.closed.get(), this);
logRequest("getInfo", segmentName);
val timer = new TimeoutTimer(timeout);
return this.segmentContainer.forSegment(segmentName, timer.getRemaining()).thenComposeAsync(segment -> selectLayout(segment.getInfo()).getInfo(segment, timer.getRemaining()), this.executor);
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class ContainerTableExtensionImpl method put.
@Override
public CompletableFuture<List<Long>> put(@NonNull String segmentName, @NonNull List<TableEntry> entries, long tableSegmentOffset, Duration timeout) {
Exceptions.checkNotClosed(this.closed.get(), this);
TimeoutTimer timer = new TimeoutTimer(timeout);
return this.segmentContainer.forSegment(segmentName, timer.getRemaining()).thenComposeAsync(segment -> selectLayout(segment.getInfo()).put(segment, entries, tableSegmentOffset, timer), this.executor);
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class ContainerTableExtensionImpl method remove.
@Override
public CompletableFuture<Void> remove(@NonNull String segmentName, @NonNull Collection<TableKey> keys, long tableSegmentOffset, Duration timeout) {
Exceptions.checkNotClosed(this.closed.get(), this);
TimeoutTimer timer = new TimeoutTimer(timeout);
return this.segmentContainer.forSegment(segmentName, timer.getRemaining()).thenComposeAsync(segment -> selectLayout(segment.getInfo()).remove(segment, keys, tableSegmentOffset, timer), this.executor);
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class ContainerTableExtensionImpl method get.
@Override
public CompletableFuture<List<TableEntry>> get(@NonNull String segmentName, @NonNull List<BufferView> keys, Duration timeout) {
Exceptions.checkNotClosed(this.closed.get(), this);
TimeoutTimer timer = new TimeoutTimer(timeout);
return this.segmentContainer.forSegment(segmentName, timer.getRemaining()).thenComposeAsync(segment -> selectLayout(segment.getInfo()).get(segment, keys, timer), this.executor);
}
Aggregations