use of io.pravega.segmentstore.server.ContainerMetadata in project pravega by pravega.
the class OperationMetadataUpdater method getOrCreateTransaction.
private ContainerMetadataUpdateTransaction getOrCreateTransaction() {
if (this.transactions.isEmpty() || this.transactions.peekLast().isSealed()) {
// No transactions or last transaction is sealed. Create a new one.
ContainerMetadata previous = this.metadata;
if (!this.transactions.isEmpty()) {
previous = this.transactions.peekLast();
}
ContainerMetadataUpdateTransaction txn = new ContainerMetadataUpdateTransaction(previous, this.metadata, this.nextTransactionId);
this.nextTransactionId++;
this.transactions.addLast(txn);
}
return this.transactions.peekLast();
}
use of io.pravega.segmentstore.server.ContainerMetadata in project pravega by pravega.
the class OperationLogTestBase method createStreamSegmentsWithOperations.
/**
* Creates a number of StreamSegments in the given Metadata and OperationLog.
*/
HashSet<Long> createStreamSegmentsWithOperations(int streamSegmentCount, ContainerMetadata containerMetadata, OperationLog durableLog, Storage storage) {
StreamSegmentMapper mapper = new StreamSegmentMapper(containerMetadata, durableLog, new InMemoryStateStore(), NO_OP_METADATA_CLEANUP, storage, ForkJoinPool.commonPool());
HashSet<Long> result = new HashSet<>();
for (int i = 0; i < streamSegmentCount; i++) {
String name = getStreamSegmentName(i);
long streamSegmentId = mapper.createNewStreamSegment(name, null, Duration.ZERO).thenCompose(v -> mapper.getOrAssignStreamSegmentId(name, Duration.ZERO)).join();
result.add(streamSegmentId);
}
return result;
}
use of io.pravega.segmentstore.server.ContainerMetadata in project pravega by pravega.
the class OperationLogTestBase method createTransactionsWithOperations.
/**
* Creates a number of Transaction Segments in the given Metadata and OperationLog.
*/
AbstractMap<Long, Long> createTransactionsWithOperations(HashSet<Long> streamSegmentIds, int transactionsPerStreamSegment, ContainerMetadata containerMetadata, OperationLog durableLog, Storage storage) {
HashMap<Long, Long> result = new HashMap<>();
StreamSegmentMapper mapper = new StreamSegmentMapper(containerMetadata, durableLog, new InMemoryStateStore(), NO_OP_METADATA_CLEANUP, storage, ForkJoinPool.commonPool());
for (long streamSegmentId : streamSegmentIds) {
String streamSegmentName = containerMetadata.getStreamSegmentMetadata(streamSegmentId).getName();
for (int i = 0; i < transactionsPerStreamSegment; i++) {
long transactionId = mapper.createNewTransactionStreamSegment(streamSegmentName, UUID.randomUUID(), null, Duration.ZERO).thenCompose(v -> mapper.getOrAssignStreamSegmentId(v, Duration.ZERO)).join();
result.put(transactionId, streamSegmentId);
}
}
return result;
}
use of io.pravega.segmentstore.server.ContainerMetadata in project pravega by pravega.
the class OperationMetadataUpdaterTests method testCommit.
/**
* Tests the ability to successively commit update transactions to the base metadata.
*/
@Test
public void testCommit() throws Exception {
// Commit 1 at a time, then 2, then 3, then 4, etc until we have nothing left to commit.
// At each step verify that the base metadata has been properly updated.
val referenceMetadata = createBlankMetadata();
val metadata = createBlankMetadata();
val updater = new OperationMetadataUpdater(metadata);
val lastSegmentId = new AtomicLong(-1);
val lastSegmentTxnId = new AtomicLong(-1);
long lastCommittedTxnId = -1;
int txnGroupSize = 1;
val updateTransactions = new ArrayList<Map.Entry<Long, ContainerMetadata>>();
while (updateTransactions.size() < TRANSACTION_COUNT) {
populateUpdateTransaction(updater, referenceMetadata, lastSegmentId, lastSegmentTxnId);
long utId = updater.sealTransaction();
if (updateTransactions.size() > 0) {
long prevUtId = updateTransactions.get(updateTransactions.size() - 1).getKey();
Assert.assertEquals("UpdateTransaction.Id is not sequential and increasing.", prevUtId + 1, utId);
}
updateTransactions.add(new AbstractMap.SimpleImmutableEntry<>(utId, clone(referenceMetadata)));
}
ContainerMetadata previousMetadata = null;
for (val t : updateTransactions) {
val utId = t.getKey();
val expectedMetadata = t.getValue();
// Check to see if it's time to commit.
if (utId - lastCommittedTxnId >= txnGroupSize) {
if (previousMetadata != null) {
// Verify no changes to the metadata prior to commit.
ContainerMetadataUpdateTransactionTests.assertMetadataSame("Before commit " + utId, previousMetadata, metadata);
}
// Commit and verify.
updater.commit(utId);
ContainerMetadataUpdateTransactionTests.assertMetadataSame("After commit " + utId, expectedMetadata, metadata);
lastCommittedTxnId = utId;
txnGroupSize++;
previousMetadata = expectedMetadata;
}
}
}
use of io.pravega.segmentstore.server.ContainerMetadata in project pravega by pravega.
the class OperationMetadataUpdaterTests method testRollback.
/**
* Tests the ability to rollback update transactions.
*/
@Test
public void testRollback() throws Exception {
// 2 out of 3 UpdateTransactions are failed (to verify multi-failure).
// Commit the rest and verify final metadata is as it should.
final int failEvery = 3;
Predicate<Integer> isIgnored = index -> index % failEvery > 0;
Predicate<Integer> shouldFail = index -> index % failEvery == failEvery - 1;
val referenceMetadata = createBlankMetadata();
val metadata = createBlankMetadata();
val updater = new OperationMetadataUpdater(metadata);
val lastSegmentId = new AtomicLong(-1);
val lastSegmentTxnId = new AtomicLong(-1);
val updateTransactions = new ArrayList<Map.Entry<Long, ContainerMetadata>>();
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 = isIgnored.test(i) ? null : referenceMetadata;
populateUpdateTransaction(updater, txnReferenceMetadata, lastSegmentId, lastSegmentTxnId);
if (shouldFail.test(i)) {
long prevUtId = updateTransactions.get(updateTransactions.size() - 1).getKey();
updater.rollback(prevUtId + 1);
} else if (txnReferenceMetadata != null) {
// Not failing and not ignored: this UpdateTransaction will survive, so record it.
long utId = updater.sealTransaction();
if (updateTransactions.size() > 0) {
long prevUtId = updateTransactions.get(updateTransactions.size() - 1).getKey();
Assert.assertEquals("Unexpected UpdateTransaction.Id.", prevUtId + failEvery - 1, utId);
}
updateTransactions.add(new AbstractMap.SimpleImmutableEntry<>(utId, clone(txnReferenceMetadata)));
}
}
ContainerMetadata previousMetadata = null;
for (val t : updateTransactions) {
val utId = t.getKey();
val expectedMetadata = t.getValue();
// Check to see if it's time to commit.
if (previousMetadata != null) {
// Verify no changes to the metadata prior to commit.
ContainerMetadataUpdateTransactionTests.assertMetadataSame("Before commit " + utId, previousMetadata, metadata);
}
// Commit and verify.
updater.commit(utId);
ContainerMetadataUpdateTransactionTests.assertMetadataSame("After commit " + utId, expectedMetadata, metadata);
previousMetadata = expectedMetadata;
}
}
Aggregations