use of io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation in project pravega by pravega.
the class OperationMetadataUpdaterTests method mapTransaction.
private long mapTransaction(long parentSegmentId, OperationMetadataUpdater updater, UpdateableContainerMetadata referenceMetadata) throws Exception {
String segmentName = "Transaction_" + updater.nextOperationSequenceNumber();
val mapOp = new StreamSegmentMapOperation(StreamSegmentInformation.builder().name(segmentName).attributes(Collections.singletonMap(PARENT_ID, parentSegmentId)).build());
process(mapOp, updater);
if (referenceMetadata != null) {
val rsm = referenceMetadata.mapStreamSegmentId(segmentName, mapOp.getStreamSegmentId());
rsm.setLength(0);
rsm.setStorageLength(0);
rsm.updateAttributes(mapOp.getAttributes());
}
return mapOp.getStreamSegmentId();
}
use of io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation in project pravega by pravega.
the class DurableDataLogRepairCommand method createUserDefinedOperation.
/**
* Guides the user to generate a new {@link Operation} that will eventually modify the Original Log.
*
* @return New {@link Operation} to be added in the Original Log.
*/
@VisibleForTesting
Operation createUserDefinedOperation() {
Operation result;
final String operations = "[DeleteSegmentOperation|MergeSegmentOperation|MetadataCheckpointOperation|" + "StorageMetadataCheckpointOperation|StreamSegmentAppendOperation|StreamSegmentMapOperation|" + "StreamSegmentSealOperation|StreamSegmentTruncateOperation|UpdateAttributesOperation]";
switch(getStringUserInput("Type one of the following Operations to instantiate: " + operations)) {
case "DeleteSegmentOperation":
long segmentId = getLongUserInput("Input Segment Id for DeleteSegmentOperation:");
result = new DeleteSegmentOperation(segmentId);
long offset = getLongUserInput("Input Segment Offset for DeleteSegmentOperation:");
((DeleteSegmentOperation) result).setStreamSegmentOffset(offset);
break;
case "MergeSegmentOperation":
long targetSegmentId = getLongUserInput("Input Target Segment Id for MergeSegmentOperation:");
long sourceSegmentId = getLongUserInput("Input Source Segment Id for MergeSegmentOperation:");
result = new MergeSegmentOperation(targetSegmentId, sourceSegmentId, createAttributeUpdateCollection());
offset = getLongUserInput("Input Segment Offset for MergeSegmentOperation:");
((MergeSegmentOperation) result).setStreamSegmentOffset(offset);
break;
case "MetadataCheckpointOperation":
result = new MetadataCheckpointOperation();
((MetadataCheckpointOperation) result).setContents(createOperationContents());
break;
case "StorageMetadataCheckpointOperation":
result = new StorageMetadataCheckpointOperation();
((StorageMetadataCheckpointOperation) result).setContents(createOperationContents());
break;
case "StreamSegmentAppendOperation":
segmentId = getLongUserInput("Input Segment Id for StreamSegmentAppendOperation:");
offset = getLongUserInput("Input Segment Offset for StreamSegmentAppendOperation:");
result = new StreamSegmentAppendOperation(segmentId, offset, createOperationContents(), createAttributeUpdateCollection());
break;
case "StreamSegmentMapOperation":
result = new StreamSegmentMapOperation(createSegmentProperties());
break;
case "StreamSegmentSealOperation":
segmentId = getLongUserInput("Input Segment Id for StreamSegmentSealOperation:");
result = new StreamSegmentSealOperation(segmentId);
offset = getLongUserInput("Input Segment Offset for StreamSegmentSealOperation:");
((StreamSegmentSealOperation) result).setStreamSegmentOffset(offset);
break;
case "StreamSegmentTruncateOperation":
segmentId = getLongUserInput("Input Segment Id for StreamSegmentTruncateOperation:");
offset = getLongUserInput("Input Offset for StreamSegmentTruncateOperation:");
result = new StreamSegmentTruncateOperation(segmentId, offset);
break;
case "UpdateAttributesOperation":
segmentId = getLongUserInput("Input Segment Id for UpdateAttributesOperation:");
result = new UpdateAttributesOperation(segmentId, createAttributeUpdateCollection());
break;
default:
output("Invalid operation, please select one of " + operations);
throw new UnsupportedOperationException();
}
return result;
}
use of io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation in project pravega by pravega.
the class ContainerMetadataUpdateTransactionTests method testProcessMetadataCheckpointIgnored.
/**
* Tests the processMetadataOperation method with MetadataCheckpoint operations, when such checkpoints are skipped over
* because they are after other operations.
*/
@Test
public void testProcessMetadataCheckpointIgnored() throws Exception {
long newSegmentId = 897658;
String newSegmentName = "NewSegmentId";
AtomicLong seqNo = new AtomicLong();
// Create a non-empty metadata.
UpdateableContainerMetadata metadata = createMetadata();
val txn = createUpdateTransaction(metadata);
MetadataCheckpointOperation op1 = createMetadataCheckpoint();
val checkpoint1 = processCheckpointOperation(op1, txn, seqNo::incrementAndGet);
// Create a blank metadata, and add an operation to the updater (which would result in mapping a new StreamSegment).
metadata = createBlankMetadata();
metadata.enterRecoveryMode();
val txn2 = createUpdateTransaction(metadata);
StreamSegmentMapOperation mapOp = createMap(newSegmentName);
mapOp.setStreamSegmentId(newSegmentId);
processOperation(mapOp, txn2, seqNo::incrementAndGet);
// Now try to process the checkpoint
MetadataCheckpointOperation op2 = createCheckpoint(MetadataCheckpointOperation::new, checkpoint1, op1.getSequenceNumber());
processOperation(op2, txn2, seqNo::incrementAndGet);
Assert.assertNull("Expected checkpoint operation contents to be null after processing.", op2.getContents());
txn2.commit(metadata);
// Verify the checkpointed metadata hasn't been applied
Assert.assertNull("Newly added StreamSegment Id was not removed after applying checkpoint.", metadata.getStreamSegmentMetadata(mapOp.getStreamSegmentId()));
Assert.assertNotNull("Checkpoint seems to have not been applied.", metadata.getStreamSegmentMetadata(SEGMENT_ID));
}
use of io.pravega.segmentstore.server.logs.operations.StreamSegmentMapOperation in project pravega by pravega.
the class ContainerMetadataUpdateTransactionTests method testSegmentMapMax.
/**
* Tests the ability to reject new StreamSegment/Transaction map operations that would exceed the max allowed counts.
*/
@Test
public void testSegmentMapMax() throws Exception {
UpdateableContainerMetadata metadata = new MetadataBuilder(CONTAINER_ID).withMaxActiveSegmentCount(3).build();
metadata.mapStreamSegmentId("a", SEGMENT_ID);
metadata.mapStreamSegmentId("b", 123457);
// Non-recovery mode.
val txn1 = createUpdateTransaction(metadata);
// Map one segment, which should fill up the quota.
StreamSegmentMapOperation acceptedMap = createMap();
txn1.preProcessOperation(acceptedMap);
txn1.acceptOperation(acceptedMap);
// Verify non-recovery mode.
AssertExtensions.assertThrows("Unexpected behavior from preProcessOperation when attempting to map a StreamSegment that would exceed the active segment quota.", () -> txn1.preProcessOperation(createMap("foo")), ex -> ex instanceof TooManyActiveSegmentsException);
// Verify recovery mode.
metadata.enterRecoveryMode();
val txn2 = createUpdateTransaction(metadata);
// updater.setOperationSequenceNumber(10000);
StreamSegmentMapOperation secondMap = createMap("c");
secondMap.setStreamSegmentId(1234);
txn2.preProcessOperation(secondMap);
txn2.acceptOperation(secondMap);
StreamSegmentMapOperation thirdMap = createTransactionMap("a_txn2");
thirdMap.setStreamSegmentId(1235);
txn2.preProcessOperation(thirdMap);
txn2.acceptOperation(thirdMap);
txn2.commit(metadata);
metadata.exitRecoveryMode();
Assert.assertNotNull("Updater did not create metadata for new segment in recovery mode even if quota is exceeded (1).", metadata.getStreamSegmentMetadata(secondMap.getStreamSegmentId()));
Assert.assertNotNull("Updater did not create metadata for new segment in recovery mode even if quota is exceeded (2).", metadata.getStreamSegmentMetadata(thirdMap.getStreamSegmentId()));
}
Aggregations