Search in sources :

Example 21 with ChunkMetadataStore

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

the class GarbageCollectorTests method testMaxAttemptsWithSegment.

/**
 * Test for Max Attempts.
 */
@Test
public void testMaxAttemptsWithSegment() throws Exception {
    @Cleanup ChunkStorage chunkStorage = getChunkStorage();
    @Cleanup ChunkMetadataStore metadataStore = spy(getMetadataStore());
    int containerId = CONTAINER_ID;
    int dataSize = 1;
    Function<Duration, CompletableFuture<Void>> noDelay = d -> CompletableFuture.completedFuture(null);
    val testTaskQueue = new InMemoryTaskQueueManager();
    val config = ChunkedSegmentStorageConfig.DEFAULT_CONFIG.toBuilder().garbageCollectionDelay(Duration.ofMillis(1)).garbageCollectionSleep(Duration.ofMillis(1)).build();
    @Cleanup GarbageCollector garbageCollector = new GarbageCollector(containerId, chunkStorage, metadataStore, config, executorService(), System::currentTimeMillis, noDelay);
    // Now actually start run
    garbageCollector.initialize(testTaskQueue).join();
    Assert.assertNotNull(garbageCollector.getTaskQueue());
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
    insertSegment(metadataStore, chunkStorage, config, "testSegment", 10, 1, new long[] {}, false, 0);
    // Add some garbage
    garbageCollector.addSegmentToGarbage(TXN_ID, "testSegment").join();
    // Validate state before
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    Assert.assertEquals("testSegment", testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).peek().getName());
    for (int i = 0; i < 3; i++) {
        val list = testTaskQueue.drain(garbageCollector.getTaskQueueName(), 1);
        Assert.assertEquals(0, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
        Assert.assertEquals(1, garbageCollector.getQueueSize().get());
        // Step 2: Inject fault.
        CompletableFuture f = new CompletableFuture();
        f.completeExceptionally(new StorageMetadataException("Test Exception"));
        doReturn(f).when(metadataStore).commit(any());
        garbageCollector.processBatch(list).join();
        // Validate state after
        Assert.assertEquals(1, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
        Assert.assertEquals(1, garbageCollector.getQueueSize().get());
        Assert.assertNotNull(getSegmentMetadata(metadataStore, "testSegment"));
    }
    val list = testTaskQueue.drain(garbageCollector.getTaskQueueName(), 1);
    Assert.assertEquals(0, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    garbageCollector.processBatch(list).join();
    // Validate state after
    Assert.assertEquals(0, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
    Assert.assertEquals(1, testTaskQueue.getTaskQueueMap().get(garbageCollector.getFailedQueueName()).size());
    Assert.assertEquals("testSegment", testTaskQueue.getTaskQueueMap().get(garbageCollector.getFailedQueueName()).peek().getName());
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
    Assert.assertNotNull(getSegmentMetadata(metadataStore, "testSegment"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) Function(java.util.function.Function) HashSet(java.util.HashSet) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) After(org.junit.After) Duration(java.time.Duration) Timeout(org.junit.rules.Timeout) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ChunkMetadata(io.pravega.segmentstore.storage.metadata.ChunkMetadata) NameUtils(io.pravega.shared.NameUtils) lombok.val(lombok.val) Test(org.junit.Test) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) StatusFlags(io.pravega.segmentstore.storage.metadata.StatusFlags) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) TreeMap(java.util.TreeMap) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) ReadIndexBlockMetadata(io.pravega.segmentstore.storage.metadata.ReadIndexBlockMetadata) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) Collections(java.util.Collections) lombok.val(lombok.val) Duration(java.time.Duration) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) Test(org.junit.Test)

Example 22 with ChunkMetadataStore

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

the class GarbageCollectorTests method testNonExistentChunk.

/**
 * Test for chunk that does not exist in metadata but added as garbage.
 */
@Test
public void testNonExistentChunk() throws Exception {
    @Cleanup ChunkStorage chunkStorage = getChunkStorage();
    @Cleanup ChunkMetadataStore metadataStore = getMetadataStore();
    int containerId = CONTAINER_ID;
    Function<Duration, CompletableFuture<Void>> noDelay = d -> CompletableFuture.completedFuture(null);
    val testTaskQueue = new InMemoryTaskQueueManager();
    @Cleanup GarbageCollector garbageCollector = new GarbageCollector(containerId, chunkStorage, metadataStore, ChunkedSegmentStorageConfig.DEFAULT_CONFIG.toBuilder().garbageCollectionDelay(Duration.ofMillis(1)).garbageCollectionSleep(Duration.ofMillis(1)).build(), executorService(), System::currentTimeMillis, noDelay);
    // Now actually start run
    garbageCollector.initialize(testTaskQueue).join();
    Assert.assertNotNull(garbageCollector.getTaskQueue());
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
    Assert.assertFalse(chunkStorage.exists("nonExistingChunk").join());
    // Add some garbage
    garbageCollector.addChunksToGarbage(TXN_ID, Collections.singleton("nonExistingChunk")).join();
    // Validate state before
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    Assert.assertEquals("nonExistingChunk", testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).peek().getName());
    val list = testTaskQueue.drain(garbageCollector.getTaskQueueName(), 1);
    Assert.assertEquals(0, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    garbageCollector.processBatch(list).join();
    // Validate state after
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) Function(java.util.function.Function) HashSet(java.util.HashSet) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) After(org.junit.After) Duration(java.time.Duration) Timeout(org.junit.rules.Timeout) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ChunkMetadata(io.pravega.segmentstore.storage.metadata.ChunkMetadata) NameUtils(io.pravega.shared.NameUtils) lombok.val(lombok.val) Test(org.junit.Test) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) StatusFlags(io.pravega.segmentstore.storage.metadata.StatusFlags) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) TreeMap(java.util.TreeMap) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) ReadIndexBlockMetadata(io.pravega.segmentstore.storage.metadata.ReadIndexBlockMetadata) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) Collections(java.util.Collections) lombok.val(lombok.val) CompletableFuture(java.util.concurrent.CompletableFuture) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) Duration(java.time.Duration) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) Test(org.junit.Test)

Example 23 with ChunkMetadataStore

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

the class GarbageCollectorTests method testMetadataExceptionWithSegment.

/**
 * Test for segment that is marked active and added as garbage.
 */
@Test
public void testMetadataExceptionWithSegment() throws Exception {
    @Cleanup ChunkStorage chunkStorage = getChunkStorage();
    @Cleanup ChunkMetadataStore metadataStore = spy(getMetadataStore());
    int containerId = CONTAINER_ID;
    int dataSize = 1;
    Function<Duration, CompletableFuture<Void>> noDelay = d -> CompletableFuture.completedFuture(null);
    val testTaskQueue = new InMemoryTaskQueueManager();
    val config = ChunkedSegmentStorageConfig.DEFAULT_CONFIG.toBuilder().garbageCollectionDelay(Duration.ofMillis(1)).garbageCollectionSleep(Duration.ofMillis(1)).build();
    @Cleanup GarbageCollector garbageCollector = new GarbageCollector(containerId, chunkStorage, metadataStore, config, executorService(), System::currentTimeMillis, noDelay);
    // Now actually start run
    garbageCollector.initialize(testTaskQueue).join();
    Assert.assertNotNull(garbageCollector.getTaskQueue());
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
    insertSegment(metadataStore, chunkStorage, config, "testSegment", 10, 1, new long[] { 1, 2, 3, 4 }, false, 0);
    val chunkNames = TestUtils.getChunkNameList(metadataStore, "testSegment");
    // Add some garbage
    garbageCollector.addSegmentToGarbage(TXN_ID, "testSegment").join();
    // Validate state before
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    Assert.assertEquals("testSegment", testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).peek().getName());
    val list = testTaskQueue.drain(garbageCollector.getTaskQueueName(), 1);
    Assert.assertEquals(0, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    // Step 2: Inject fault.
    CompletableFuture f = new CompletableFuture();
    f.completeExceptionally(new StorageMetadataException("Test Exception"));
    doReturn(f).when(metadataStore).commit(any());
    garbageCollector.processBatch(list).join();
    // Validate state after
    Assert.assertEquals(1, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    Assert.assertNotNull(getSegmentMetadata(metadataStore, "testSegment"));
    chunkNames.stream().forEach(chunkName -> Assert.assertTrue(chunkStorage.exists(chunkName).join()));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) Function(java.util.function.Function) HashSet(java.util.HashSet) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) After(org.junit.After) Duration(java.time.Duration) Timeout(org.junit.rules.Timeout) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ChunkMetadata(io.pravega.segmentstore.storage.metadata.ChunkMetadata) NameUtils(io.pravega.shared.NameUtils) lombok.val(lombok.val) Test(org.junit.Test) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) StatusFlags(io.pravega.segmentstore.storage.metadata.StatusFlags) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) TreeMap(java.util.TreeMap) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) ReadIndexBlockMetadata(io.pravega.segmentstore.storage.metadata.ReadIndexBlockMetadata) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) Collections(java.util.Collections) lombok.val(lombok.val) Duration(java.time.Duration) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) Test(org.junit.Test)

Example 24 with ChunkMetadataStore

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

the class GarbageCollectorTests method testNonExistentSegment.

/**
 * Test for segment that does not exist and added as garbage.
 */
@Test
public void testNonExistentSegment() throws Exception {
    @Cleanup ChunkStorage chunkStorage = getChunkStorage();
    @Cleanup ChunkMetadataStore metadataStore = getMetadataStore();
    int containerId = CONTAINER_ID;
    int dataSize = 1;
    Function<Duration, CompletableFuture<Void>> noDelay = d -> CompletableFuture.completedFuture(null);
    val testTaskQueue = new InMemoryTaskQueueManager();
    val config = ChunkedSegmentStorageConfig.DEFAULT_CONFIG.toBuilder().garbageCollectionDelay(Duration.ofMillis(1)).garbageCollectionSleep(Duration.ofMillis(1)).build();
    @Cleanup GarbageCollector garbageCollector = new GarbageCollector(containerId, chunkStorage, metadataStore, config, executorService(), System::currentTimeMillis, noDelay);
    // Now actually start run
    garbageCollector.initialize(testTaskQueue).join();
    Assert.assertNotNull(garbageCollector.getTaskQueue());
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
    // Add some garbage
    Assert.assertNull(getSegmentMetadata(metadataStore, "testSegment"));
    garbageCollector.addSegmentToGarbage(TXN_ID, "testSegment").join();
    // Validate state before
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    Assert.assertEquals("testSegment", testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).peek().getName());
    val list = testTaskQueue.drain(garbageCollector.getTaskQueueName(), 1);
    Assert.assertEquals(0, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
    Assert.assertEquals(1, garbageCollector.getQueueSize().get());
    garbageCollector.processBatch(list).join();
    // Validate state after
    Assert.assertEquals(0, testTaskQueue.getTaskQueueMap().get(garbageCollector.getTaskQueueName()).size());
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
    Assert.assertNull(getSegmentMetadata(metadataStore, "testSegment"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) InMemoryMetadataStore(io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) Function(java.util.function.Function) HashSet(java.util.HashSet) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) After(org.junit.After) Duration(java.time.Duration) Timeout(org.junit.rules.Timeout) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) ChunkMetadata(io.pravega.segmentstore.storage.metadata.ChunkMetadata) NameUtils(io.pravega.shared.NameUtils) lombok.val(lombok.val) Test(org.junit.Test) StorageMetadataException(io.pravega.segmentstore.storage.metadata.StorageMetadataException) StatusFlags(io.pravega.segmentstore.storage.metadata.StatusFlags) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) TreeMap(java.util.TreeMap) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) ReadIndexBlockMetadata(io.pravega.segmentstore.storage.metadata.ReadIndexBlockMetadata) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) Collections(java.util.Collections) lombok.val(lombok.val) CompletableFuture(java.util.concurrent.CompletableFuture) InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) Duration(java.time.Duration) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) Test(org.junit.Test)

Example 25 with ChunkMetadataStore

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

the class GarbageCollectorTests method testInitializationInvalidArgs.

/**
 * Test Initialization
 */
@Test
public void testInitializationInvalidArgs() throws Exception {
    @Cleanup ChunkStorage chunkStorage = getChunkStorage();
    @Cleanup ChunkMetadataStore metadataStore = getMetadataStore();
    int containerId = CONTAINER_ID;
    @Cleanup GarbageCollector garbageCollector = new GarbageCollector(containerId, chunkStorage, metadataStore, ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService());
    garbageCollector.initialize(new InMemoryTaskQueueManager()).join();
    Assert.assertNotNull(garbageCollector.getTaskQueue());
    Assert.assertEquals(0, garbageCollector.getQueueSize().get());
}
Also used : InMemoryTaskQueueManager(io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager) InMemoryChunkStorage(io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage) Cleanup(lombok.Cleanup) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) Test(org.junit.Test)

Aggregations

ChunkMetadataStore (io.pravega.segmentstore.storage.metadata.ChunkMetadataStore)36 Cleanup (lombok.Cleanup)36 InMemoryChunkStorage (io.pravega.segmentstore.storage.mocks.InMemoryChunkStorage)35 InMemoryTaskQueueManager (io.pravega.segmentstore.storage.mocks.InMemoryTaskQueueManager)35 lombok.val (lombok.val)35 Test (org.junit.Test)34 ByteArrayInputStream (java.io.ByteArrayInputStream)29 Preconditions (com.google.common.base.Preconditions)18 ChunkMetadata (io.pravega.segmentstore.storage.metadata.ChunkMetadata)18 ReadIndexBlockMetadata (io.pravega.segmentstore.storage.metadata.ReadIndexBlockMetadata)18 SegmentMetadata (io.pravega.segmentstore.storage.metadata.SegmentMetadata)18 StatusFlags (io.pravega.segmentstore.storage.metadata.StatusFlags)18 StorageMetadataException (io.pravega.segmentstore.storage.metadata.StorageMetadataException)18 InMemoryMetadataStore (io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore)18 NameUtils (io.pravega.shared.NameUtils)18 AssertExtensions (io.pravega.test.common.AssertExtensions)18 ThreadPooledTestSuite (io.pravega.test.common.ThreadPooledTestSuite)18 Duration (java.time.Duration)18 Arrays (java.util.Arrays)18 Collections (java.util.Collections)18