use of io.pravega.segmentstore.contracts.StreamSegmentNotExistsException in project pravega by pravega.
the class MemoryStateUpdater method addToReadIndex.
/**
* Registers the given operation in the ReadIndex.
*
* @param operation The operation to register.
*/
private void addToReadIndex(StorageOperation operation) {
try {
if (operation instanceof StreamSegmentAppendOperation) {
// Record a StreamSegmentAppendOperation. Just in case, we also support this type of operation, but we need to
// log a warning indicating so. This means we do not optimize memory properly, and we end up storing data
// in two different places.
StreamSegmentAppendOperation appendOperation = (StreamSegmentAppendOperation) operation;
this.readIndex.append(appendOperation.getStreamSegmentId(), appendOperation.getStreamSegmentOffset(), appendOperation.getData());
} else if (operation instanceof MergeTransactionOperation) {
// Record a MergeTransactionOperation. We call beginMerge here, and the StorageWriter will call completeMerge.
MergeTransactionOperation mergeOperation = (MergeTransactionOperation) operation;
this.readIndex.beginMerge(mergeOperation.getStreamSegmentId(), mergeOperation.getStreamSegmentOffset(), mergeOperation.getTransactionSegmentId());
} else {
assert !(operation instanceof CachedStreamSegmentAppendOperation) : "attempted to add a CachedStreamSegmentAppendOperation to the ReadIndex";
}
} catch (ObjectClosedException | StreamSegmentNotExistsException ex) {
// The Segment is in the process of being deleted. We usually end up in here because a concurrent delete
// request has updated the metadata while we were executing.
log.warn("Not adding operation '{}' to ReadIndex because it refers to a deleted StreamSegment.", operation);
}
}
use of io.pravega.segmentstore.contracts.StreamSegmentNotExistsException in project pravega by pravega.
the class ContainerReadIndex method getOrCreateIndex.
/**
* Gets a reference to the existing StreamSegmentRead index for the given StreamSegment Id. Creates a new one if
* necessary.
*
* @param streamSegmentId The Id of the StreamSegment whose ReadIndex to get.
*/
private StreamSegmentReadIndex getOrCreateIndex(long streamSegmentId) throws StreamSegmentNotExistsException {
StreamSegmentReadIndex index;
synchronized (this.lock) {
// Try to see if we have the index already in memory.
index = getIndex(streamSegmentId);
if (index == null) {
// We don't have it, create one.
SegmentMetadata segmentMetadata = this.metadata.getStreamSegmentMetadata(streamSegmentId);
Exceptions.checkArgument(segmentMetadata != null, "streamSegmentId", "StreamSegmentId %s does not exist in the metadata.", streamSegmentId);
if (segmentMetadata.isDeleted()) {
throw new StreamSegmentNotExistsException(segmentMetadata.getName());
}
index = new StreamSegmentReadIndex(this.config, segmentMetadata, this.cache, this.storage, this.executor, isRecoveryMode());
this.cacheManager.register(index);
this.readIndices.put(streamSegmentId, index);
}
}
return index;
}
use of io.pravega.segmentstore.contracts.StreamSegmentNotExistsException in project pravega by pravega.
the class PravegaRequestProcessorTest method testMergedTransaction.
@Test(timeout = 20000)
public void testMergedTransaction() throws Exception {
String streamSegmentName = "testMergedTxn";
UUID txnid = UUID.randomUUID();
@Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
serviceBuilder.initialize();
StreamSegmentStore store = spy(serviceBuilder.createStreamSegmentService());
ServerConnection connection = mock(ServerConnection.class);
InOrder order = inOrder(connection);
doReturn(Futures.failedFuture(new StreamSegmentMergedException(streamSegmentName))).when(store).sealStreamSegment(anyString(), any());
doReturn(Futures.failedFuture(new StreamSegmentMergedException(streamSegmentName))).when(store).mergeTransaction(anyString(), any());
PravegaRequestProcessor processor = new PravegaRequestProcessor(store, connection);
processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, ""));
order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName));
processor.createTransaction(new WireCommands.CreateTransaction(1, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.TransactionCreated(1, streamSegmentName, txnid));
processor.commitTransaction(new WireCommands.CommitTransaction(2, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.TransactionCommitted(2, streamSegmentName, txnid));
txnid = UUID.randomUUID();
doReturn(Futures.failedFuture(new StreamSegmentNotExistsException(streamSegmentName))).when(store).sealStreamSegment(anyString(), any());
doReturn(Futures.failedFuture(new StreamSegmentNotExistsException(streamSegmentName))).when(store).mergeTransaction(anyString(), any());
processor.createTransaction(new WireCommands.CreateTransaction(3, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.TransactionCreated(3, streamSegmentName, txnid));
processor.commitTransaction(new WireCommands.CommitTransaction(4, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.NoSuchSegment(4, StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid)));
}
use of io.pravega.segmentstore.contracts.StreamSegmentNotExistsException in project pravega by pravega.
the class StreamSegmentContainer method deleteStreamSegment.
@Override
public CompletableFuture<Void> deleteStreamSegment(String streamSegmentName, Duration timeout) {
ensureRunning();
logRequest("deleteStreamSegment", streamSegmentName);
this.metrics.deleteSegment();
TimeoutTimer timer = new TimeoutTimer(timeout);
// metadata.deleteStreamSegment will delete the given StreamSegment and all Transactions associated with it.
// It returns a mapping of segment ids to names of StreamSegments that were deleted.
// As soon as this happens, all operations that deal with those segments will start throwing appropriate exceptions
// or ignore the segments altogether (such as StorageWriter).
Collection<SegmentMetadata> deletedSegments = this.metadata.deleteStreamSegment(streamSegmentName);
val deletionFutures = new ArrayList<CompletableFuture<Void>>();
for (SegmentMetadata toDelete : deletedSegments) {
deletionFutures.add(this.storage.openWrite(toDelete.getName()).thenComposeAsync(handle -> this.storage.delete(handle, timer.getRemaining()), this.executor).thenComposeAsync(v -> this.stateStore.remove(toDelete.getName(), timer.getRemaining()), this.executor).exceptionally(ex -> {
ex = Exceptions.unwrap(ex);
if (ex instanceof StreamSegmentNotExistsException && toDelete.isTransaction()) {
// did not get a chance to get updated.
return null;
}
throw new CompletionException(ex);
}));
}
notifyMetadataRemoved(deletedSegments);
return Futures.allOf(deletionFutures);
}
use of io.pravega.segmentstore.contracts.StreamSegmentNotExistsException in project pravega by pravega.
the class StreamSegmentContainer method read.
@Override
public CompletableFuture<ReadResult> read(String streamSegmentName, long offset, int maxLength, Duration timeout) {
ensureRunning();
logRequest("read", streamSegmentName, offset, maxLength);
this.metrics.read();
TimeoutTimer timer = new TimeoutTimer(timeout);
return this.segmentMapper.getOrAssignStreamSegmentId(streamSegmentName, timer.getRemaining(), streamSegmentId -> {
try {
return CompletableFuture.completedFuture(this.readIndex.read(streamSegmentId, offset, maxLength, timer.getRemaining()));
} catch (StreamSegmentNotExistsException ex) {
return Futures.failedFuture(ex);
}
});
}
Aggregations