Search in sources :

Example 11 with BaseMetadataStore

use of io.pravega.segmentstore.storage.metadata.BaseMetadataStore in project pravega by pravega.

the class ChunkedSegmentStorageMockTests method testExceptionDuringMetadataRead.

public void testExceptionDuringMetadataRead(Exception exceptionToThrow, Class clazz) throws Exception {
    String testSegmentName = "test";
    String concatSegmentName = "concat";
    // Force rollover after every 2 byte.
    SegmentRollingPolicy policy = new SegmentRollingPolicy(2);
    val config = ChunkedSegmentStorageConfig.DEFAULT_CONFIG.toBuilder().storageMetadataRollingPolicy(policy).build();
    @Cleanup BaseMetadataStore spyMetadataStore = spy(new InMemoryMetadataStore(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService()));
    spyMetadataStore.setMaxEntriesInTxnBuffer(0);
    @Cleanup BaseChunkStorage spyChunkStorage = spy(new NoOpChunkStorage(executorService()));
    @Cleanup ChunkedSegmentStorage chunkedSegmentStorage = new ChunkedSegmentStorage(CONTAINER_ID, spyChunkStorage, spyMetadataStore, executorService(), config);
    chunkedSegmentStorage.initialize(1);
    chunkedSegmentStorage.getGarbageCollector().initialize(new InMemoryTaskQueueManager()).join();
    // Step 1: Create segment and write some data.
    val h1 = chunkedSegmentStorage.create(testSegmentName, policy, null).get();
    Assert.assertEquals(h1.getSegmentName(), testSegmentName);
    Assert.assertFalse(h1.isReadOnly());
    chunkedSegmentStorage.write(h1, 0, new ByteArrayInputStream(new byte[10]), 10, null).get();
    // Step 2: Increase epoch.
    chunkedSegmentStorage.initialize(2);
    val h2 = chunkedSegmentStorage.create(concatSegmentName, policy, null).get();
    chunkedSegmentStorage.write(h2, 0, new ByteArrayInputStream(new byte[10]), 10, null).get();
    chunkedSegmentStorage.seal(h2, null).get();
    // Step 3: Inject fault.
    CompletableFuture f = new CompletableFuture();
    f.completeExceptionally(exceptionToThrow);
    doReturn(f).when(spyMetadataStore).get(any(), anyString());
    // These calls are all read calls they can potentially run in parallel,
    // therefore we must force them to be synchronous to avoid org.mockito.exceptions.misusing.UnfinishedStubbingException
    AssertExtensions.assertThrows("write succeeded when exception was expected.", () -> chunkedSegmentStorage.write(h2, 10, new ByteArrayInputStream(new byte[10]), 10, null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("Seal succeeded when exception was expected.", () -> chunkedSegmentStorage.seal(SegmentStorageHandle.writeHandle(testSegmentName), null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("openWrite succeeded when exception was expected.", () -> chunkedSegmentStorage.openWrite(testSegmentName).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("delete succeeded when exception was expected.", () -> chunkedSegmentStorage.delete(SegmentStorageHandle.writeHandle(testSegmentName), null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("truncate succeeded when exception was expected.", () -> chunkedSegmentStorage.truncate(SegmentStorageHandle.writeHandle(testSegmentName), 2, null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("create succeeded when exception was expected.", () -> chunkedSegmentStorage.create("foo", policy, null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("concat succeeded when exception was expected.", () -> chunkedSegmentStorage.concat(h1, 10, h2.getSegmentName(), null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("getStreamSegmentInfo succeeded  when exception was expected.", () -> chunkedSegmentStorage.getStreamSegmentInfo(testSegmentName, null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("read  succeeded when exception was expected.", () -> chunkedSegmentStorage.read(SegmentStorageHandle.readHandle(testSegmentName), 0, new byte[1], 0, 1, null).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("openRead  succeeded when exception was expected.", () -> chunkedSegmentStorage.openRead(testSegmentName).get(), ex -> clazz.equals(ex.getClass()));
    AssertExtensions.assertThrows("exists  succeeded when exception was expected.", () -> chunkedSegmentStorage.exists(testSegmentName, null).get(), ex -> clazz.equals(ex.getClass()));
}
Also used : lombok.val(lombok.val) BaseMetadataStore(io.pravega.segmentstore.storage.metadata.BaseMetadataStore) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentRollingPolicy(io.pravega.segmentstore.storage.SegmentRollingPolicy) ByteArrayInputStream(java.io.ByteArrayInputStream) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) NoOpChunkStorage(io.pravega.segmentstore.storage.noop.NoOpChunkStorage)

Example 12 with BaseMetadataStore

use of io.pravega.segmentstore.storage.metadata.BaseMetadataStore in project pravega by pravega.

the class UtilsWrapper method evictMetadataCache.

/**
 * Evicts all eligible entries from buffer cache and all entries from guava cache.
 * This should be invoked after directly changing the metadata in table segment to ignore cached values.
 *
 * @return A CompletableFuture that, when completed, will indicate that the operation completed.
 *         If the operation failed, it will be completed with the appropriate exception.
 */
public CompletableFuture<Void> evictMetadataCache() {
    return CompletableFuture.runAsync(() -> {
        val metadataStore = (BaseMetadataStore) chunkedSegmentStorage.getMetadataStore();
        metadataStore.evictAllEligibleEntriesFromBuffer();
        metadataStore.evictFromCache();
    }, chunkedSegmentStorage.getExecutor());
}
Also used : lombok.val(lombok.val) BaseMetadataStore(io.pravega.segmentstore.storage.metadata.BaseMetadataStore)

Aggregations

BaseMetadataStore (io.pravega.segmentstore.storage.metadata.BaseMetadataStore)12 lombok.val (lombok.val)12 InMemoryMetadataStore (io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore)11 Cleanup (lombok.Cleanup)11 NoOpChunkStorage (io.pravega.segmentstore.storage.noop.NoOpChunkStorage)9 InMemoryTaskQueueManager (io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Test (org.junit.Test)7 StorageFullException (io.pravega.segmentstore.storage.StorageFullException)6 StorageNotPrimaryException (io.pravega.segmentstore.storage.StorageNotPrimaryException)6 StorageMetadataException (io.pravega.segmentstore.storage.metadata.StorageMetadataException)6 StorageMetadataVersionMismatchException (io.pravega.segmentstore.storage.metadata.StorageMetadataVersionMismatchException)6 StorageMetadataWritesFencedOutException (io.pravega.segmentstore.storage.metadata.StorageMetadataWritesFencedOutException)6 IntentionalException (io.pravega.test.common.IntentionalException)6 IOException (java.io.IOException)6 CompletionException (java.util.concurrent.CompletionException)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 SegmentRollingPolicy (io.pravega.segmentstore.storage.SegmentRollingPolicy)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 InMemoryChunkStorage (io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage)2