Search in sources :

Example 36 with UpdateableContainerMetadata

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

the class OperationMetadataUpdaterTests method testCommitRollbackAlternate.

/**
 * Tests a mixed scenario where we commit one UpdateTransaction and then rollback the next one, one after another.
 * testRollback() verifies a bunch of rollbacks and then commits in sequence; this test alternates one with the other.
 */
@Test
public void testCommitRollbackAlternate() throws Exception {
    Predicate<Integer> shouldFail = index -> index % 2 == 1;
    val referenceMetadata = createBlankMetadata();
    val metadata = createBlankMetadata();
    val updater = new OperationMetadataUpdater(metadata);
    val lastSegmentId = new AtomicLong(-1);
    val lastSegmentTxnId = new AtomicLong(-1);
    for (int i = 0; i < TRANSACTION_COUNT; i++) {
        // Check to see if this UpdateTransaction is going to end up being rolled back. If so, we should not update
        // the reference metadata at all.
        UpdateableContainerMetadata txnReferenceMetadata = shouldFail.test(i) ? null : referenceMetadata;
        populateUpdateTransaction(updater, txnReferenceMetadata, lastSegmentId, lastSegmentTxnId);
        if (shouldFail.test(i)) {
            updater.rollback(0);
            ContainerMetadataUpdateTransactionTests.assertMetadataSame("After rollback " + i, referenceMetadata, metadata);
        } else {
            updater.commitAll();
            ContainerMetadataUpdateTransactionTests.assertMetadataSame("After commit " + i, referenceMetadata, metadata);
        }
    }
}
Also used : Arrays(java.util.Arrays) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) ContainerMetadata(io.pravega.segmentstore.server.ContainerMetadata) HashMap(java.util.HashMap) LogAddress(io.pravega.segmentstore.storage.LogAddress) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) Map(java.util.Map) Timeout(org.junit.rules.Timeout) Operation(io.pravega.segmentstore.server.logs.operations.Operation) StreamSegmentMapOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation) Attributes(io.pravega.segmentstore.contracts.Attributes) Predicate(java.util.function.Predicate) lombok.val(lombok.val) Test(org.junit.Test) UUID(java.util.UUID) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractMap(java.util.AbstractMap) Rule(org.junit.Rule) StreamSegmentContainerMetadata(io.pravega.segmentstore.server.containers.StreamSegmentContainerMetadata) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) Assert(org.junit.Assert) MergeTransactionOperation(io.pravega.segmentstore.server.logs.operations.MergeTransactionOperation) StreamSegmentSealOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation) lombok.val(lombok.val) AtomicLong(java.util.concurrent.atomic.AtomicLong) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) Test(org.junit.Test)

Example 37 with UpdateableContainerMetadata

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

the class StreamSegmentContainerMetadataTests method testEpoch.

/**
 * Tests Epoch-related operations.
 */
@Test
public void testEpoch() {
    final int epoch = 10;
    final UpdateableContainerMetadata m = new MetadataBuilder(CONTAINER_ID).build();
    AssertExtensions.assertThrows("setContainerEpoch allowed updating the sequence number in non-recovery mode.", () -> m.setContainerEpoch(Integer.MAX_VALUE), ex -> ex instanceof IllegalStateException);
    // In recovery mode: setContainerEpoch should work.
    m.enterRecoveryMode();
    m.setContainerEpoch(epoch);
    Assert.assertEquals("Unexpected value from getContainerEpoch.", epoch, m.getContainerEpoch());
    AssertExtensions.assertThrows("setContainerEpoch allowed updating the epoch after the initial set.", () -> m.setContainerEpoch(11), ex -> ex instanceof IllegalStateException);
    Assert.assertEquals("Unexpected value from getContainerEpoch after rejected update.", epoch, m.getContainerEpoch());
    m.exitRecoveryMode();
    Assert.assertEquals("Unexpected value from getContainerEpoch after exit from recovery mode.", epoch, m.getContainerEpoch());
}
Also used : MetadataBuilder(io.pravega.segmentstore.server.MetadataBuilder) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) Test(org.junit.Test)

Example 38 with UpdateableContainerMetadata

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

the class StreamSegmentContainerMetadataTests method testValidTruncationPoints.

/**
 * Tests the ability to set and retrieve truncation points (truncation markers is tested separately).
 */
@Test
public void testValidTruncationPoints() {
    final UpdateableContainerMetadata m = new MetadataBuilder(CONTAINER_ID).build();
    for (int i = 0; i < 100; i += 2) {
        m.setValidTruncationPoint(i);
    }
    for (int i = 0; i < 100; i++) {
        boolean expectedValid = i % 2 == 0;
        Assert.assertEquals("Unexpected result from isValidTruncationPoint.", expectedValid, m.isValidTruncationPoint(i));
    }
}
Also used : MetadataBuilder(io.pravega.segmentstore.server.MetadataBuilder) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) Test(org.junit.Test)

Example 39 with UpdateableContainerMetadata

use of io.pravega.segmentstore.server.UpdateableContainerMetadata 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

UpdateableContainerMetadata (io.pravega.segmentstore.server.UpdateableContainerMetadata)39 Test (org.junit.Test)35 lombok.val (lombok.val)26 StreamSegmentMapOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation)17 StreamSegmentAppendOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation)16 MetadataBuilder (io.pravega.segmentstore.server.MetadataBuilder)15 Operation (io.pravega.segmentstore.server.logs.operations.Operation)12 ArrayList (java.util.ArrayList)12 StorageOperation (io.pravega.segmentstore.server.logs.operations.StorageOperation)11 MergeTransactionOperation (io.pravega.segmentstore.server.logs.operations.MergeTransactionOperation)10 MetadataCheckpointOperation (io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation)10 StorageMetadataCheckpointOperation (io.pravega.segmentstore.server.logs.operations.StorageMetadataCheckpointOperation)10 StreamSegmentSealOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation)9 SegmentMetadata (io.pravega.segmentstore.server.SegmentMetadata)7 UpdateableSegmentMetadata (io.pravega.segmentstore.server.UpdateableSegmentMetadata)7 HashMap (java.util.HashMap)7 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)6 UUID (java.util.UUID)6 ReadIndex (io.pravega.segmentstore.server.ReadIndex)5 LogAddress (io.pravega.segmentstore.storage.LogAddress)5