Search in sources :

Example 1 with ExtendedChunkInfo

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)));
}
Also used : ExtendedChunkInfo(io.pravega.segmentstore.contracts.ExtendedChunkInfo) InOrder(org.mockito.InOrder) ExtendedChunkInfo(io.pravega.segmentstore.contracts.ExtendedChunkInfo) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) AdminRequestProcessor(io.pravega.shared.protocol.netty.AdminRequestProcessor) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 2 with ExtendedChunkInfo

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));
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) ExtendedChunkInfo(io.pravega.segmentstore.contracts.ExtendedChunkInfo) Test(org.junit.Test)

Example 3 with ExtendedChunkInfo

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);
}
Also used : lombok.val(lombok.val) OutputStream(java.io.OutputStream) NonNull(lombok.NonNull) ExtendedChunkInfo(io.pravega.segmentstore.contracts.ExtendedChunkInfo) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) lombok.val(lombok.val) BaseMetadataStore(io.pravega.segmentstore.storage.metadata.BaseMetadataStore) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) AtomicLong(java.util.concurrent.atomic.AtomicLong) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Duration(java.time.Duration) Data(lombok.Data) Preconditions(com.google.common.base.Preconditions) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) InputStream(java.io.InputStream) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) AtomicLong(java.util.concurrent.atomic.AtomicLong) CompletableFuture(java.util.concurrent.CompletableFuture) ExtendedChunkInfo(io.pravega.segmentstore.contracts.ExtendedChunkInfo)

Aggregations

ExtendedChunkInfo (io.pravega.segmentstore.contracts.ExtendedChunkInfo)3 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)2 Test (org.junit.Test)2 Preconditions (com.google.common.base.Preconditions)1 Futures (io.pravega.common.concurrent.Futures)1 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)1 BaseMetadataStore (io.pravega.segmentstore.storage.metadata.BaseMetadataStore)1 SegmentMetadata (io.pravega.segmentstore.storage.metadata.SegmentMetadata)1 AdminRequestProcessor (io.pravega.shared.protocol.netty.AdminRequestProcessor)1 WireCommands (io.pravega.shared.protocol.netty.WireCommands)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1