use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class StreamSegmentContainer method updateAttributes.
@Override
public CompletableFuture<Void> updateAttributes(String streamSegmentName, AttributeUpdateCollection attributeUpdates, Duration timeout) {
ensureRunning();
TimeoutTimer timer = new TimeoutTimer(timeout);
logRequest("updateAttributes", streamSegmentName, attributeUpdates);
this.metrics.updateAttributes();
return this.metadataStore.getOrAssignSegmentId(streamSegmentName, timer.getRemaining(), streamSegmentId -> updateAttributesForSegment(streamSegmentId, attributeUpdates, timer.getRemaining()));
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class StreamSegmentContainer method getAttributes.
@Override
public CompletableFuture<Map<AttributeId, Long>> getAttributes(String streamSegmentName, Collection<AttributeId> attributeIds, boolean cache, Duration timeout) {
ensureRunning();
TimeoutTimer timer = new TimeoutTimer(timeout);
logRequest("getAttributes", streamSegmentName, attributeIds, cache);
this.metrics.getAttributes();
return this.metadataStore.getOrAssignSegmentId(streamSegmentName, timer.getRemaining(), streamSegmentId -> getAttributesForSegment(streamSegmentId, attributeIds, cache, timer));
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class TableMetadataStore method applyToSegment.
private <T> CompletableFuture<T> applyToSegment(String segmentName, BiFunction<TableEntry, Duration, CompletableFuture<T>> ifExists, Supplier<CompletableFuture<T>> ifNotExists, Duration timeout) {
ensureInitialized();
ArrayView key = getTableKey(segmentName);
TimeoutTimer timer = new TimeoutTimer(timeout);
return this.tableStore.get(this.metadataSegmentName, Collections.singletonList(key), timer.getRemaining()).thenComposeAsync(existingData -> {
assert existingData.size() == 1 : "Expecting only one result";
if (existingData.get(0) == null) {
// We don't know anything about this Segment.
return ifNotExists.get();
}
// We have an entry.
return ifExists.apply(existingData.get(0), timer.getRemaining());
}, this.executor);
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class ExecutorServiceHelpers method shutdown.
/**
* Shuts down the given ExecutorServices in two phases:
* 1. Prevents new tasks from being submitted.
* 2. Awaits for currently running tasks to terminate. If they don't terminate within the given timeout, they will be
* forcibly cancelled.
*
* This is implemented as per the guidelines in the ExecutorService Javadoc:
* https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html
*
* @param timeout Grace period that will be given to tasks to complete.
* @param pools The ExecutorServices to shut down.
*/
public static void shutdown(Duration timeout, ExecutorService... pools) {
// Prevent new tasks from being submitted.
for (ExecutorService pool : pools) {
pool.shutdown();
}
TimeoutTimer timer = new TimeoutTimer(timeout);
for (ExecutorService pool : pools) {
try {
// since they all started shutting down at the same time (above), and they can shut down in parallel.
if (!pool.awaitTermination(timer.getRemaining().toMillis(), TimeUnit.MILLISECONDS)) {
// Cancel currently executing tasks and wait for them to respond to being cancelled.
pool.shutdownNow();
if (!pool.awaitTermination(timer.getRemaining().toMillis(), TimeUnit.MILLISECONDS)) {
List<Runnable> remainingTasks = pool.shutdownNow();
log.warn("One or more threads from pool " + pool + " did not shutdown properly. Waiting tasks: " + remainingTasks);
}
}
} catch (InterruptedException ie) {
pool.shutdownNow();
Thread.currentThread().interrupt();
}
}
}
use of io.pravega.common.TimeoutTimer in project pravega by pravega.
the class FixedKeyLengthTableSegmentLayout method get.
@Override
CompletableFuture<List<TableEntry>> get(@NonNull DirectSegmentAccess segment, @NonNull List<BufferView> keys, TimeoutTimer timer) {
val segmentInfo = segment.getInfo();
ensureSegmentType(segmentInfo.getName(), segmentInfo.getType());
val attributes = keys.stream().map(key -> {
ensureValidKeyLength(segmentInfo.getName(), key.getLength());
return AttributeId.from(key.getCopy());
}).collect(Collectors.toList());
logRequest("get", segmentInfo.getName(), keys.size());
return getByAttributes(segment, attributes, timer);
}
Aggregations