use of io.pravega.segmentstore.contracts.ExtendedChunkInfo in project pravega by pravega.
the class AdminRequestProcessorImplTest method testListStorageChunks.
@Test(timeout = 60000)
public void testListStorageChunks() {
String segmentName = "dummy";
ExtendedChunkInfo chunk = ExtendedChunkInfo.builder().lengthInMetadata(10).lengthInStorage(10).startOffset(10).chunkName("chunk").existsInStorage(false).build();
WireCommands.ChunkInfo chunkInfo = new WireCommands.ChunkInfo(10, 10, 10, "chunk", false);
StreamSegmentStore store = mock(StreamSegmentStore.class);
when(store.getExtendedChunkInfo(segmentName, TIMEOUT)).thenReturn(CompletableFuture.completedFuture(List.of(chunk)));
ServerConnection connection = mock(ServerConnection.class);
InOrder order = inOrder(connection);
AdminRequestProcessor processor = new AdminRequestProcessorImpl(store, mock(TableStore.class), connection);
processor.listStorageChunks(new WireCommands.ListStorageChunks("dummy", "", 1));
order.verify(connection).send(new WireCommands.StorageChunksListed(1, List.of(chunkInfo)));
}
use of io.pravega.segmentstore.contracts.ExtendedChunkInfo in project pravega by pravega.
the class SynchronousStreamSegmentStoreTests method testGetExtendedChunkInfo.
@Test
public void testGetExtendedChunkInfo() {
ExtendedChunkInfo chunk = ExtendedChunkInfo.builder().lengthInMetadata(10).lengthInStorage(10).startOffset(10).chunkName("chunk").existsInStorage(false).build();
StreamSegmentStore store = mock(StreamSegmentStore.class);
when(store.getExtendedChunkInfo(anyString(), any())).thenReturn(CompletableFuture.completedFuture(List.of(chunk)));
SynchronousStreamSegmentStore syncStore = new SynchronousStreamSegmentStore(store);
assertEquals(chunk, syncStore.getExtendedChunkInfo("segment", Duration.ofSeconds(1)).join().get(0));
}
use of io.pravega.segmentstore.contracts.ExtendedChunkInfo in project pravega by pravega.
the class UtilsWrapper method getExtendedChunkInfoList.
/**
* Returns the list of {@link ExtendedChunkInfo} which contain data about all chunks for the segment.
*
* @param streamSegmentName Name of the segment.
* @param checkStorage Whether to retrieve information from underlying {@link ChunkStorage}.
* @return A CompletableFuture that, when completed, will contain a list of {@link ExtendedChunkInfo} objects associated with the segment.
* If the operation failed, it will be completed with the appropriate exception.
*/
public CompletableFuture<List<ExtendedChunkInfo>> getExtendedChunkInfoList(String streamSegmentName, boolean checkStorage) {
Preconditions.checkNotNull(streamSegmentName, "streamSegmentName");
val infoList = Collections.synchronizedList(new ArrayList<ExtendedChunkInfo>());
return chunkedSegmentStorage.executeSerialized(() -> chunkedSegmentStorage.tryWith(chunkedSegmentStorage.getMetadataStore().beginTransaction(true, streamSegmentName), txn -> txn.get(streamSegmentName).thenComposeAsync(storageMetadata -> {
val segmentMetadata = (SegmentMetadata) storageMetadata;
segmentMetadata.checkInvariants();
val iterator = new ChunkIterator(chunkedSegmentStorage.getExecutor(), txn, segmentMetadata);
val startOffset = new AtomicLong(segmentMetadata.getFirstChunkStartOffset());
iterator.forEach((metadata, name) -> {
infoList.add(ExtendedChunkInfo.builder().chunkName(name).startOffset(startOffset.get()).lengthInMetadata(metadata.getLength()).build());
startOffset.addAndGet(metadata.getLength());
});
return completedFuture(infoList);
}, chunkedSegmentStorage.getExecutor()).thenComposeAsync(v -> {
val futures = new ArrayList<CompletableFuture<Void>>();
if (checkStorage) {
for (val info : infoList) {
futures.add(chunkedSegmentStorage.getChunkStorage().exists(info.getChunkName()).thenComposeAsync(doesExist -> {
if (doesExist) {
return chunkedSegmentStorage.getChunkStorage().getInfo(info.getChunkName()).thenAcceptAsync(chunkInfo -> {
info.setLengthInStorage(chunkInfo.getLength());
info.setExistsInStorage(true);
}, chunkedSegmentStorage.getExecutor());
} else {
return completedFuture(null);
}
}, chunkedSegmentStorage.getExecutor()));
}
}
return Futures.allOf(futures);
}, chunkedSegmentStorage.getExecutor()).thenApplyAsync(vv -> infoList, chunkedSegmentStorage.getExecutor()), chunkedSegmentStorage.getExecutor()), streamSegmentName);
}
Aggregations