Search in sources :

Example 21 with MetadataBuilder

use of io.pravega.segmentstore.server.MetadataBuilder in project pravega by pravega.

the class StreamSegmentContainerMetadataTests method testTruncationMarkers.

/**
 * Tests the Truncation Marker functionality (truncation points is tested separately).
 */
@Test
public void testTruncationMarkers() {
    final long maxSeqNo = 1000;
    final int markerFrequency = 13;
    Function<Long, LogAddress> getFrameAddress = seqNo -> new TestLogAddress(Integer.MAX_VALUE + seqNo * seqNo);
    final UpdateableContainerMetadata m = new MetadataBuilder(CONTAINER_ID).build();
    // Record some truncation markers, starting a few steps after initial.
    for (long seqNo = markerFrequency; seqNo <= maxSeqNo; seqNo += markerFrequency) {
        m.recordTruncationMarker(seqNo, getFrameAddress.apply(seqNo));
    }
    // Verify them.
    for (long seqNo = 0; seqNo < maxSeqNo + markerFrequency; seqNo++) {
        LogAddress expectedTruncationMarker = null;
        if (seqNo >= markerFrequency) {
            long input = seqNo > maxSeqNo ? maxSeqNo : seqNo;
            expectedTruncationMarker = getFrameAddress.apply(input - input % markerFrequency);
        }
        LogAddress truncationMarker = m.getClosestTruncationMarker(seqNo);
        Assert.assertEquals("Unexpected truncation marker value for Op Sequence Number " + seqNo, expectedTruncationMarker, truncationMarker);
    }
    // Remove some truncation markers & verify again.
    for (long seqNo = 0; seqNo < maxSeqNo + markerFrequency; seqNo++) {
        m.removeTruncationMarkers(seqNo);
        // Check that the removal actually made sense (it should return -1 now).
        LogAddress truncationMarker = m.getClosestTruncationMarker(seqNo);
        Assert.assertNull("Unexpected truncation marker value after removal for Op Sequence Number " + seqNo, truncationMarker);
        // Check that the next higher up still works.
        long input = seqNo + markerFrequency;
        input = input > maxSeqNo ? maxSeqNo : input;
        LogAddress expectedTruncationMarker;
        if (seqNo > maxSeqNo - markerFrequency) {
            // We have already removed all possible truncation markers, so expect the result to be -1.
            expectedTruncationMarker = null;
        } else {
            expectedTruncationMarker = getFrameAddress.apply(input - input % markerFrequency);
        }
        truncationMarker = m.getClosestTruncationMarker(input);
        Assert.assertEquals("Unexpected truncation marker value for Op Sequence Number " + input + " after removing marker at Sequence Number " + seqNo, expectedTruncationMarker, truncationMarker);
    }
}
Also used : MetadataBuilder(io.pravega.segmentstore.server.MetadataBuilder) Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) Collection(java.util.Collection) lombok.val(lombok.val) ContainerMetadata(io.pravega.segmentstore.server.ContainerMetadata) HashMap(java.util.HashMap) Test(org.junit.Test) LogAddress(io.pravega.segmentstore.storage.LogAddress) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) List(java.util.List) Rule(org.junit.Rule) Map(java.util.Map) Timeout(org.junit.rules.Timeout) Assert(org.junit.Assert) LogAddress(io.pravega.segmentstore.storage.LogAddress) MetadataBuilder(io.pravega.segmentstore.server.MetadataBuilder) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) Test(org.junit.Test)

Aggregations

MetadataBuilder (io.pravega.segmentstore.server.MetadataBuilder)21 Test (org.junit.Test)21 UpdateableContainerMetadata (io.pravega.segmentstore.server.UpdateableContainerMetadata)16 StreamSegmentMapOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation)9 lombok.val (lombok.val)9 ArrayList (java.util.ArrayList)8 TestDurableDataLogFactory (io.pravega.segmentstore.server.TestDurableDataLogFactory)7 Operation (io.pravega.segmentstore.server.logs.operations.Operation)7 StorageOperation (io.pravega.segmentstore.server.logs.operations.StorageOperation)7 StreamSegmentAppendOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation)7 CacheManager (io.pravega.segmentstore.server.reading.CacheManager)7 ContainerReadIndex (io.pravega.segmentstore.server.reading.ContainerReadIndex)7 Storage (io.pravega.segmentstore.storage.Storage)7 InMemoryCacheFactory (io.pravega.segmentstore.storage.mocks.InMemoryCacheFactory)7 InMemoryDurableDataLogFactory (io.pravega.segmentstore.storage.mocks.InMemoryDurableDataLogFactory)7 Cleanup (lombok.Cleanup)7 ReadIndex (io.pravega.segmentstore.server.ReadIndex)6 SegmentMetadata (io.pravega.segmentstore.server.SegmentMetadata)6 UpdateableSegmentMetadata (io.pravega.segmentstore.server.UpdateableSegmentMetadata)6 MetadataCheckpointOperation (io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation)5