use of io.pravega.controller.store.Version in project pravega by pravega.
the class StreamMetadataStoreTest method txnHostIndexTest.
@Test(timeout = 30000)
public void txnHostIndexTest() {
String host1 = "host1";
String host2 = "host2";
TxnResource txn1 = new TxnResource(scope, stream1, UUID.randomUUID());
TxnResource txn2 = new TxnResource(scope, stream1, UUID.randomUUID());
addTxnToHost(host1, txn1, new Version.IntVersion(0));
Assert.assertEquals(1, store.listHostsOwningTxn().join().size());
Optional<TxnResource> txn = store.getRandomTxnFromIndex(host1).join();
Assert.assertTrue(txn.isPresent());
Assert.assertEquals(txn1.getTxnId().toString(), txn.get().getTxnId().toString());
// Adding a txn again should not fail.
addTxnToHost(host1, txn1, new Version.IntVersion(0));
addTxnToHost(host1, txn2, new Version.IntVersion(5));
Assert.assertEquals(1, store.listHostsOwningTxn().join().size());
// Fetching version of txn not existing in the index should return null.
Assert.assertNull(store.getTxnVersionFromIndex(host1, new TxnResource(scope, stream1, UUID.randomUUID())).join());
txn = store.getRandomTxnFromIndex(host1).join();
Assert.assertTrue(txn.isPresent());
UUID randomTxnId = txn.get().getTxnId();
Assert.assertTrue(randomTxnId.equals(txn1.getTxnId()) || randomTxnId.equals(txn2.getTxnId()));
Assert.assertEquals(scope, txn.get().getScope());
Assert.assertEquals(stream1, txn.get().getStream());
// Test remove txn from index.
store.removeTxnFromIndex(host1, txn1, true).join();
// Test remove is idempotent operation.
store.removeTxnFromIndex(host1, txn1, true).join();
// Test remove last txn from the index.
store.removeTxnFromIndex(host1, txn2, false).join();
Assert.assertEquals(1, store.listHostsOwningTxn().join().size());
// Test remove is idempotent operation.
store.removeTxnFromIndex(host1, txn2, true).join();
Assert.assertTrue(store.listHostsOwningTxn().join().size() <= 1);
// Test removal of txn that was never added.
store.removeTxnFromIndex(host1, new TxnResource(scope, stream1, UUID.randomUUID()), true).join();
// Test host removal.
store.removeHostFromIndex(host1).join();
Assert.assertEquals(0, store.listHostsOwningTxn().join().size());
// Test host removal is idempotent.
store.removeHostFromIndex(host1).join();
Assert.assertEquals(0, store.listHostsOwningTxn().join().size());
// Test removal of host that was never added.
store.removeHostFromIndex(host2).join();
Assert.assertEquals(0, store.listHostsOwningTxn().join().size());
}
use of io.pravega.controller.store.Version in project pravega by pravega.
the class StreamTestBase method testWriterMark.
@Test(timeout = 30000L)
public void testWriterMark() {
OperationContext context = getContext();
PersistentStreamBase stream = spy(createStream("writerMark", "writerMark", System.currentTimeMillis(), 3, 0));
Map<String, WriterMark> marks = stream.getAllWriterMarks(context).join();
assertTrue(marks.isEmpty());
// call noteWritermark --> this should call createMarkerRecord
String writer = "writer";
long timestamp = 0L;
Map<Long, Long> position = Collections.singletonMap(0L, 1L);
ImmutableMap<Long, Long> immutablePos = ImmutableMap.copyOf(position);
stream.noteWriterMark(writer, timestamp, position, context).join();
marks = stream.getAllWriterMarks(context).join();
assertEquals(marks.size(), 1);
verify(stream, times(1)).createWriterMarkRecord(writer, timestamp, immutablePos, context);
VersionedMetadata<WriterMark> mark = stream.getWriterMarkRecord(writer, context).join();
Version version = mark.getVersion();
// call noteWritermark --> this should call update
stream.noteWriterMark(writer, timestamp, position, context).join();
marks = stream.getAllWriterMarks(context).join();
assertEquals(marks.size(), 1);
mark = stream.getWriterMarkRecord(writer, context).join();
assertNotEquals(mark.getVersion(), version);
verify(stream, times(1)).updateWriterMarkRecord(anyString(), anyLong(), any(), anyBoolean(), any(), any());
AssertExtensions.assertFutureThrows("", stream.createWriterMarkRecord(writer, timestamp, immutablePos, context), e -> Exceptions.unwrap(e) instanceof StoreException.DataExistsException);
// update
mark = stream.getWriterMarkRecord(writer, context).join();
stream.updateWriterMarkRecord(writer, timestamp, immutablePos, true, mark.getVersion(), context).join();
// verify bad version on update
AssertExtensions.assertFutureThrows("", stream.updateWriterMarkRecord(writer, timestamp, immutablePos, true, mark.getVersion(), context), e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
mark = stream.getWriterMarkRecord(writer, context).join();
// update deleted writer --> data not found
stream.removeWriter(writer, mark.getObject(), context).join();
marks = stream.getAllWriterMarks(context).join();
assertEquals(marks.size(), 0);
AssertExtensions.assertFutureThrows("", stream.updateWriterMarkRecord(writer, timestamp, immutablePos, true, mark.getVersion(), context), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException);
// create writer record
stream.createWriterMarkRecord(writer, timestamp, immutablePos, context).join();
// Mock to throw DataNotFound for getWriterMark. This should result in noteWriterMark to attempt to create.
// That should fail with DataExists resulting in recursive call into noteWriterMark to do get and update.
AtomicBoolean callRealMethod = new AtomicBoolean(false);
doAnswer(x -> {
if (callRealMethod.compareAndSet(false, true)) {
return Futures.failedFuture(StoreException.create(StoreException.Type.DATA_NOT_FOUND, "writer mark"));
} else {
return x.callRealMethod();
}
}).when(stream).getWriterMarkRecord(writer, context);
timestamp = 1L;
position = Collections.singletonMap(0L, 2L);
AssertExtensions.assertFutureThrows("Expecting WriteConflict", stream.noteWriterMark(writer, timestamp, position, context), e -> Exceptions.unwrap(e) instanceof StoreException.WriteConflictException);
}
use of io.pravega.controller.store.Version in project pravega by pravega.
the class VersionTest method testAsVersionType.
@Test
public void testAsVersionType() {
Version version = new Version.IntVersion(100);
Version.IntVersion intVersion = version.asIntVersion();
assertEquals(100, intVersion.getIntValue());
}
use of io.pravega.controller.store.Version in project pravega by pravega.
the class TimeoutServiceTest method testPingLeaseTooLarge.
@Test(timeout = 10000)
public void testPingLeaseTooLarge() {
UUID txnId = streamStore.generateTransactionId(SCOPE, STREAM, null, executor).join();
VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, null, executor).join();
timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime());
Version version = txData.getVersion();
PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), version, Config.MAX_LEASE_VALUE + 1);
Assert.assertEquals(PingTxnStatus.Status.LEASE_TOO_LARGE, pingStatus.getStatus());
pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), version, 10 * LEASE + 1);
Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
}
use of io.pravega.controller.store.Version in project pravega by pravega.
the class StreamTransactionMetadataTasksTest method idempotentOperationsTests.
@Test(timeout = 10000)
public void idempotentOperationsTests() throws CheckpointStoreException, InterruptedException {
// Create mock writer objects.
EventStreamWriterMock<CommitEvent> commitWriter = new EventStreamWriterMock<>();
EventStreamWriterMock<AbortEvent> abortWriter = new EventStreamWriterMock<>();
EventStreamReader<CommitEvent> commitReader = commitWriter.getReader();
EventStreamReader<AbortEvent> abortReader = abortWriter.getReader();
// Create transaction tasks.
txnTasks = new StreamTransactionMetadataTasks(streamStore, segmentHelperMock, executor, "host", GrpcAuthHelper.getDisabledAuthHelper());
txnTasks.initializeStreamWriters(commitWriter, abortWriter);
consumer = new ControllerService(kvtStore, kvtMetadataTasks, streamStore, bucketStore, streamMetadataTasks, txnTasks, segmentHelperMock, executor, null, requestTracker);
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
// Create stream and scope
Assert.assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, consumer.createScope(SCOPE, 0L).join().getStatus());
Assert.assertEquals(Controller.CreateStreamStatus.Status.SUCCESS, streamMetadataTasks.createStream(SCOPE, STREAM, configuration1, System.currentTimeMillis(), 0L).join());
// Create 2 transactions
final long lease = 5000;
VersionedTransactionData txData1 = txnTasks.createTxn(SCOPE, STREAM, lease, 0L, 1024 * 1024L).join().getKey();
VersionedTransactionData txData2 = txnTasks.createTxn(SCOPE, STREAM, lease, 0L, 1024 * 1024L).join().getKey();
UUID tx1 = txData1.getId();
UUID tx2 = txData2.getId();
Version tx2Version = txData2.getVersion();
// Commit the first one
Assert.assertEquals(TxnStatus.COMMITTING, txnTasks.commitTxn(SCOPE, STREAM, tx1, 0L).join());
// Ensure that transaction state is COMMITTING.
assertEquals(TxnStatus.COMMITTING, streamStore.transactionStatus(SCOPE, STREAM, tx1, null, executor).join());
// Abort the second one
Assert.assertEquals(TxnStatus.ABORTING, txnTasks.abortTxn(SCOPE, STREAM, tx2, tx2Version, 0L).join());
// Ensure that transactions state is ABORTING.
assertEquals(TxnStatus.ABORTING, streamStore.transactionStatus(SCOPE, STREAM, tx2, null, executor).join());
// Ensure that commit (resp. abort) transaction tasks are idempotent
// when transaction is in COMMITTING state (resp. ABORTING state).
assertEquals(TxnStatus.COMMITTING, txnTasks.commitTxn(SCOPE, STREAM, tx1, 0L).join());
assertEquals(TxnStatus.ABORTING, txnTasks.abortTxn(SCOPE, STREAM, tx2, null, 0L).join());
// Create commit and abort event processors.
BlockingQueue<CommitEvent> processedCommitEvents = new LinkedBlockingQueue<>();
BlockingQueue<AbortEvent> processedAbortEvents = new LinkedBlockingQueue<>();
createEventProcessor("commitRG", "commitStream", commitReader, commitWriter, () -> new ConcurrentEventProcessor<>(new CommitRequestHandler(streamStore, streamMetadataTasks, txnTasks, bucketStore, executor, processedCommitEvents), executor));
createEventProcessor("abortRG", "abortStream", abortReader, abortWriter, () -> new ConcurrentEventProcessor<>(new AbortRequestHandler(streamStore, streamMetadataTasks, executor, processedAbortEvents), executor));
// Wait until the commit event is processed and ensure that the txn state is COMMITTED.
CommitEvent commitEvent = processedCommitEvents.take();
assertEquals(0, commitEvent.getEpoch());
assertEquals(TxnStatus.COMMITTED, streamStore.transactionStatus(SCOPE, STREAM, tx1, null, executor).join());
// Wait until the abort event is processed and ensure that the txn state is ABORTED.
AbortEvent abortEvent = processedAbortEvents.take();
assertEquals(tx2, abortEvent.getTxid());
assertEquals(TxnStatus.ABORTED, streamStore.transactionStatus(SCOPE, STREAM, tx2, null, executor).join());
// Ensure that commit (resp. abort) transaction tasks are idempotent
// even after transaction is committed (resp. aborted)
assertEquals(TxnStatus.COMMITTED, txnTasks.commitTxn(SCOPE, STREAM, tx1, 0L).join());
assertEquals(TxnStatus.ABORTED, txnTasks.abortTxn(SCOPE, STREAM, tx2, null, 0L).join());
}
Aggregations