Search in sources :

Example 1 with CompletedTxnRecord

use of io.pravega.controller.store.stream.records.CompletedTxnRecord in project pravega by pravega.

the class ControllerMetadataJsonSerializerTest method testCompletedTxnRecord.

@Test
public void testCompletedTxnRecord() {
    CompletedTxnRecord record = new CompletedTxnRecord(1L, TxnStatus.COMMITTED);
    testRecordSerialization(record, CompletedTxnRecord.class);
}
Also used : CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) Test(org.junit.Test)

Example 2 with CompletedTxnRecord

use of io.pravega.controller.store.stream.records.CompletedTxnRecord in project pravega by pravega.

the class PersistentStreamBase method commitTransaction.

@VisibleForTesting
public CompletableFuture<TxnStatus> commitTransaction(final UUID txId, OperationContext context) {
    Preconditions.checkNotNull(context, "Operation context cannot be null");
    int epoch = RecordHelper.getTransactionEpoch(txId);
    return checkTransactionStatus(txId, context).thenApply(x -> {
        switch(x) {
            // Only sealed transactions can be committed
            case COMMITTED:
            case COMMITTING:
                return x;
            case OPEN:
            case ABORTING:
            case ABORTED:
                throw StoreException.create(StoreException.Type.ILLEGAL_STATE, String.format("Stream: %s Transaction: %s State: %s", getName(), txId.toString(), x.toString()));
            case UNKNOWN:
            default:
                throw StoreException.create(StoreException.Type.DATA_NOT_FOUND, String.format("Stream: %s Transaction: %s", getName(), txId.toString()));
        }
    }).thenCompose(x -> {
        if (x.equals(TxnStatus.COMMITTING)) {
            return createCompletedTxEntry(txId, new CompletedTxnRecord(System.currentTimeMillis(), TxnStatus.COMMITTED), context);
        } else {
            // already committed, do nothing
            return CompletableFuture.completedFuture(null);
        }
    }).thenCompose(x -> removeActiveTxEntry(epoch, txId, context)).thenApply(x -> TxnStatus.COMMITTED);
}
Also used : StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) SneakyThrows(lombok.SneakyThrows) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) TagLogger(io.pravega.common.tracing.TagLogger) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DataNotFoundException(io.pravega.controller.store.stream.StoreException.DataNotFoundException) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) ImmutableSet(com.google.common.collect.ImmutableSet) StreamCutReferenceRecord(io.pravega.controller.store.stream.records.StreamCutReferenceRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Optional(java.util.Optional) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) IntStream(java.util.stream.IntStream) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) NameUtils.computeSegmentId(io.pravega.shared.NameUtils.computeSegmentId) Exceptions(io.pravega.common.Exceptions) HistoryTimeSeriesRecord(io.pravega.controller.store.stream.records.HistoryTimeSeriesRecord) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RetentionSet(io.pravega.controller.store.stream.records.RetentionSet) DATA_NOT_FOUND_PREDICATE(io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_FOUND_PREDICATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StateRecord(io.pravega.controller.store.stream.records.StateRecord) StreamSubscriber(io.pravega.controller.store.stream.records.StreamSubscriber) LinkedList(java.util.LinkedList) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) SimpleEntry(java.util.AbstractMap.SimpleEntry) LongSummaryStatistics(java.util.LongSummaryStatistics) CollectionHelpers(io.pravega.common.util.CollectionHelpers) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) NameUtils(io.pravega.shared.NameUtils) Executor(java.util.concurrent.Executor) WriterMark(io.pravega.controller.store.stream.records.WriterMark) lombok.val(lombok.val) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Version(io.pravega.controller.store.Version) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with CompletedTxnRecord

use of io.pravega.controller.store.stream.records.CompletedTxnRecord in project pravega by pravega.

the class PravegaTablesStream method createCompletedTxEntries.

private CompletableFuture<Void> createCompletedTxEntries(List<Map.Entry<String, CompletedTxnRecord>> complete, OperationContext context) {
    Preconditions.checkNotNull(context, "operation context cannot be null");
    Integer batch = currentBatchSupplier.get();
    String tableName = getCompletedTransactionsBatchTableName(batch);
    return Futures.toVoid(Futures.exceptionallyComposeExpecting(storeHelper.addNewEntriesIfAbsent(tableName, complete, CompletedTxnRecord::toBytes, context.getRequestId()), DATA_NOT_FOUND_PREDICATE, () -> tryCreateBatchTable(batch, context).thenCompose(v -> storeHelper.addNewEntriesIfAbsent(tableName, complete, CompletedTxnRecord::toBytes, context.getRequestId())))).exceptionally(e -> {
        throw new CompletionException(e);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DATA_NOT_EMPTY_PREDICATE(io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_EMPTY_PREDICATE) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) NameUtils.getQualifiedTableName(io.pravega.shared.NameUtils.getQualifiedTableName) COMPLETED_TRANSACTIONS_BATCHES_TABLE(io.pravega.shared.NameUtils.COMPLETED_TRANSACTIONS_BATCHES_TABLE) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ByteBuffer(java.nio.ByteBuffer) TagLogger(io.pravega.common.tracing.TagLogger) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SEPARATOR(io.pravega.shared.NameUtils.SEPARATOR) Map(java.util.Map) CONFIGURATION_KEY(io.pravega.shared.NameUtils.CONFIGURATION_KEY) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) Subscribers(io.pravega.controller.store.stream.records.Subscribers) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) BYTES_TO_UUID_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_UUID_FUNCTION) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WRITERS_POSITIONS_TABLE(io.pravega.shared.NameUtils.WRITERS_POSITIONS_TABLE) CompletionException(java.util.concurrent.CompletionException) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) List(java.util.List) BYTES_TO_INTEGER_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_INTEGER_FUNCTION) Optional(java.util.Optional) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) LONG_TO_BYTES_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.LONG_TO_BYTES_FUNCTION) EPOCH_TRANSITION_KEY(io.pravega.shared.NameUtils.EPOCH_TRANSITION_KEY) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) RETENTION_SET_KEY(io.pravega.shared.NameUtils.RETENTION_SET_KEY) Exceptions(io.pravega.common.Exceptions) EPOCH_RECORD_KEY_FORMAT(io.pravega.shared.NameUtils.EPOCH_RECORD_KEY_FORMAT) WAITING_REQUEST_PROCESSOR_PATH(io.pravega.shared.NameUtils.WAITING_REQUEST_PROCESSOR_PATH) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) DATA_NOT_FOUND_PREDICATE(io.pravega.controller.store.stream.PravegaTablesStreamMetadataStore.DATA_NOT_FOUND_PREDICATE) COMMITTING_TRANSACTIONS_RECORD_KEY(io.pravega.shared.NameUtils.COMMITTING_TRANSACTIONS_RECORD_KEY) RetentionSet(io.pravega.controller.store.stream.records.RetentionSet) SUBSCRIBER_KEY_PREFIX(io.pravega.shared.NameUtils.SUBSCRIBER_KEY_PREFIX) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) CURRENT_EPOCH_KEY(io.pravega.shared.NameUtils.CURRENT_EPOCH_KEY) Strings(com.google.common.base.Strings) HISTORY_TIMESERIES_CHUNK_FORMAT(io.pravega.shared.NameUtils.HISTORY_TIMESERIES_CHUNK_FORMAT) TRANSACTIONS_IN_EPOCH_TABLE_FORMAT(io.pravega.shared.NameUtils.TRANSACTIONS_IN_EPOCH_TABLE_FORMAT) StateRecord(io.pravega.controller.store.stream.records.StateRecord) BYTES_TO_LONG_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.BYTES_TO_LONG_FUNCTION) SEGMENT_MARKER_PATH_FORMAT(io.pravega.shared.NameUtils.SEGMENT_MARKER_PATH_FORMAT) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSubscriber(io.pravega.controller.store.stream.records.StreamSubscriber) SEGMENTS_SEALED_SIZE_MAP_SHARD_FORMAT(io.pravega.shared.NameUtils.SEGMENTS_SEALED_SIZE_MAP_SHARD_FORMAT) INTEGER_TO_BYTES_FUNCTION(io.pravega.controller.store.PravegaTablesStoreHelper.INTEGER_TO_BYTES_FUNCTION) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) METADATA_TABLE(io.pravega.shared.NameUtils.METADATA_TABLE) STATE_KEY(io.pravega.shared.NameUtils.STATE_KEY) EPOCHS_WITH_TRANSACTIONS_TABLE(io.pravega.shared.NameUtils.EPOCHS_WITH_TRANSACTIONS_TABLE) WriterMark(io.pravega.controller.store.stream.records.WriterMark) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) TRUNCATION_KEY(io.pravega.shared.NameUtils.TRUNCATION_KEY) INTERNAL_SCOPE_NAME(io.pravega.shared.NameUtils.INTERNAL_SCOPE_NAME) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) AbstractMap(java.util.AbstractMap) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) Version(io.pravega.controller.store.Version) COMPLETED_TRANSACTIONS_BATCH_TABLE_FORMAT(io.pravega.shared.NameUtils.COMPLETED_TRANSACTIONS_BATCH_TABLE_FORMAT) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) CREATION_TIME_KEY(io.pravega.shared.NameUtils.CREATION_TIME_KEY) SUBSCRIBER_SET_KEY(io.pravega.shared.NameUtils.SUBSCRIBER_SET_KEY) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RETENTION_STREAM_CUT_RECORD_KEY_FORMAT(io.pravega.shared.NameUtils.RETENTION_STREAM_CUT_RECORD_KEY_FORMAT) Collections(java.util.Collections) SEGMENT_SEALED_EPOCH_KEY_FORMAT(io.pravega.shared.NameUtils.SEGMENT_SEALED_EPOCH_KEY_FORMAT) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) CompletionException(java.util.concurrent.CompletionException)

Example 4 with CompletedTxnRecord

use of io.pravega.controller.store.stream.records.CompletedTxnRecord in project pravega by pravega.

the class PersistentStreamBase method abortTransaction.

@Override
public CompletableFuture<TxnStatus> abortTransaction(final UUID txId, OperationContext context) {
    Preconditions.checkNotNull(context, "Operation context cannot be null");
    int epoch = RecordHelper.getTransactionEpoch(txId);
    return checkTransactionStatus(txId, context).thenApply(x -> {
        switch(x) {
            case ABORTING:
            case ABORTED:
                return x;
            case OPEN:
            case COMMITTING:
            case COMMITTED:
                throw StoreException.create(StoreException.Type.ILLEGAL_STATE, "Stream: " + getName() + " Transaction: " + txId.toString() + " State: " + x.name());
            case UNKNOWN:
            default:
                throw StoreException.create(StoreException.Type.DATA_NOT_FOUND, "Stream: " + getName() + " Transaction: " + txId.toString());
        }
    }).thenCompose(x -> {
        if (x.equals(TxnStatus.ABORTING)) {
            return createCompletedTxEntry(txId, new CompletedTxnRecord(System.currentTimeMillis(), TxnStatus.ABORTED), context);
        } else {
            // already aborted, do nothing
            return CompletableFuture.completedFuture(null);
        }
    }).thenCompose(y -> removeActiveTxEntry(epoch, txId, context)).thenApply(y -> TxnStatus.ABORTED);
}
Also used : StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) SneakyThrows(lombok.SneakyThrows) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) TagLogger(io.pravega.common.tracing.TagLogger) VersionedMetadata(io.pravega.controller.store.VersionedMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DataNotFoundException(io.pravega.controller.store.stream.StoreException.DataNotFoundException) EpochTransitionRecord(io.pravega.controller.store.stream.records.EpochTransitionRecord) ImmutableSet(com.google.common.collect.ImmutableSet) StreamCutReferenceRecord(io.pravega.controller.store.stream.records.StreamCutReferenceRecord) StreamTruncationRecord(io.pravega.controller.store.stream.records.StreamTruncationRecord) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Optional(java.util.Optional) HistoryTimeSeries(io.pravega.controller.store.stream.records.HistoryTimeSeries) Futures(io.pravega.common.concurrent.Futures) IntStream(java.util.stream.IntStream) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) CommittingTransactionsRecord(io.pravega.controller.store.stream.records.CommittingTransactionsRecord) NameUtils.computeSegmentId(io.pravega.shared.NameUtils.computeSegmentId) Exceptions(io.pravega.common.Exceptions) HistoryTimeSeriesRecord(io.pravega.controller.store.stream.records.HistoryTimeSeriesRecord) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) RetentionSet(io.pravega.controller.store.stream.records.RetentionSet) DATA_NOT_FOUND_PREDICATE(io.pravega.controller.store.stream.AbstractStreamMetadataStore.DATA_NOT_FOUND_PREDICATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StateRecord(io.pravega.controller.store.stream.records.StateRecord) StreamSubscriber(io.pravega.controller.store.stream.records.StreamSubscriber) LinkedList(java.util.LinkedList) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) SimpleEntry(java.util.AbstractMap.SimpleEntry) LongSummaryStatistics(java.util.LongSummaryStatistics) CollectionHelpers(io.pravega.common.util.CollectionHelpers) SealedSegmentsMapShard(io.pravega.controller.store.stream.records.SealedSegmentsMapShard) NameUtils(io.pravega.shared.NameUtils) Executor(java.util.concurrent.Executor) WriterMark(io.pravega.controller.store.stream.records.WriterMark) lombok.val(lombok.val) StreamCutRecord(io.pravega.controller.store.stream.records.StreamCutRecord) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamConfigurationRecord(io.pravega.controller.store.stream.records.StreamConfigurationRecord) EpochRecord(io.pravega.controller.store.stream.records.EpochRecord) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Version(io.pravega.controller.store.Version) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord)

Example 5 with CompletedTxnRecord

use of io.pravega.controller.store.stream.records.CompletedTxnRecord in project pravega by pravega.

the class PravegaTablesStreamMetadataStoreTest method testGarbageCollection.

@Test
public void testGarbageCollection() {
    try (PravegaTablesStreamMetadataStore testStore = new PravegaTablesStreamMetadataStore(segmentHelperMockForTables, PRAVEGA_ZK_CURATOR_RESOURCE.client, executor, Duration.ofSeconds(100), GrpcAuthHelper.getDisabledAuthHelper())) {
        AtomicInteger currentBatch = new AtomicInteger(0);
        Supplier<Integer> supplier = currentBatch::get;
        ZKGarbageCollector gc = mock(ZKGarbageCollector.class);
        doAnswer(x -> supplier.get()).when(gc).getLatestBatch();
        testStore.setCompletedTxnGCRef(gc);
        String scope = "scopeGC";
        String stream = "streamGC";
        testStore.createScope(scope, null, executor).join();
        StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
        testStore.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
        // batch 0
        UUID txnId0 = testStore.generateTransactionId(scope, stream, null, executor).join();
        createAndCommitTransaction(scope, stream, txnId0, testStore);
        UUID txnId1 = testStore.generateTransactionId(scope, stream, null, executor).join();
        createAndCommitTransaction(scope, stream, txnId1, testStore);
        // verify that the completed txn record is created in batch 0
        Set<Integer> batches = getAllBatches(testStore);
        assertEquals(batches.size(), 1);
        assertTrue(batches.contains(0));
        Map<String, CompletedTxnRecord> transactions = getAllTransactionsInBatch(testStore, 0);
        // verify that transaction is present in batch 0
        assertTrue(transactions.containsKey(PravegaTablesStream.getCompletedTransactionKey(scope, stream, txnId1.toString())));
        // run gc. There should be no purge.
        testStore.gcCompletedTxn().join();
        batches = getAllBatches(testStore);
        // verify no purge of batch
        assertEquals(batches.size(), 1);
        assertTrue(batches.contains(0));
        TxnStatus status = testStore.transactionStatus(scope, stream, txnId1, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        // create batch 1
        currentBatch.incrementAndGet();
        UUID txnId2 = testStore.generateTransactionId(scope, stream, null, executor).join();
        createAndCommitTransaction(scope, stream, txnId2, testStore);
        // verify that the completed txn record is created in batch 1
        batches = getAllBatches(testStore);
        assertEquals(batches.size(), 2);
        transactions = getAllTransactionsInBatch(testStore, 1);
        // verify that transaction is present in batch 1
        assertTrue(transactions.containsKey(PravegaTablesStream.getCompletedTransactionKey(scope, stream, txnId2.toString())));
        // run gc. There should be no purge.
        testStore.gcCompletedTxn().join();
        batches = getAllBatches(testStore);
        // verify no purge of batch
        assertEquals(batches.size(), 2);
        assertTrue(batches.contains(0));
        assertTrue(batches.contains(1));
        status = testStore.transactionStatus(scope, stream, txnId1, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId2, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        // create batch 2
        currentBatch.incrementAndGet();
        UUID txnId3 = testStore.generateTransactionId(scope, stream, null, executor).join();
        createAndCommitTransaction(scope, stream, txnId3, testStore);
        // verify that the completed txn record is created in batch 2
        batches = getAllBatches(testStore);
        assertEquals(batches.size(), 3);
        assertTrue(batches.contains(0));
        assertTrue(batches.contains(1));
        assertTrue(batches.contains(2));
        status = testStore.transactionStatus(scope, stream, txnId1, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId2, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId3, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        // dont run gc. let batches get accumulated.
        transactions = getAllTransactionsInBatch(testStore, 2);
        // verify that transaction is present in batch 2
        assertTrue(transactions.containsKey(PravegaTablesStream.getCompletedTransactionKey(scope, stream, txnId3.toString())));
        // create batch 3
        currentBatch.incrementAndGet();
        UUID txnId4 = testStore.generateTransactionId(scope, stream, null, executor).join();
        createAndCommitTransaction(scope, stream, txnId4, testStore);
        // verify that the completed txn record is created in batch 3
        batches = getAllBatches(testStore);
        assertEquals(batches.size(), 4);
        assertTrue(batches.contains(0));
        assertTrue(batches.contains(1));
        assertTrue(batches.contains(2));
        assertTrue(batches.contains(3));
        status = testStore.transactionStatus(scope, stream, txnId1, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId2, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId3, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId4, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        transactions = getAllTransactionsInBatch(testStore, 3);
        // verify that transaction is present in batch 3
        assertTrue(transactions.containsKey(PravegaTablesStream.getCompletedTransactionKey(scope, stream, txnId4.toString())));
        // check that we are able to get status for all 4 transactions.
        status = testStore.transactionStatus(scope, stream, txnId1, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId2, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId3, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId4, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        // run gc. There should be two purges.
        testStore.gcCompletedTxn().join();
        batches = getAllBatches(testStore);
        assertEquals(batches.size(), 2);
        assertTrue(batches.contains(2));
        assertTrue(batches.contains(3));
        // we should be able to get txn status for txn3 and txn4 but should get unknown for txn1 and txn2
        status = testStore.transactionStatus(scope, stream, txnId1, null, executor).join();
        assertEquals(status, TxnStatus.UNKNOWN);
        status = testStore.transactionStatus(scope, stream, txnId2, null, executor).join();
        assertEquals(status, TxnStatus.UNKNOWN);
        status = testStore.transactionStatus(scope, stream, txnId3, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
        status = testStore.transactionStatus(scope, stream, txnId4, null, executor).join();
        assertEquals(status, TxnStatus.COMMITTED);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletedTxnRecord(io.pravega.controller.store.stream.records.CompletedTxnRecord) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Mockito.anyString(org.mockito.Mockito.anyString) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

CompletedTxnRecord (io.pravega.controller.store.stream.records.CompletedTxnRecord)5 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Preconditions (com.google.common.base.Preconditions)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Exceptions (io.pravega.common.Exceptions)3 Futures (io.pravega.common.concurrent.Futures)3 TagLogger (io.pravega.common.tracing.TagLogger)3 Version (io.pravega.controller.store.Version)3 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)3 ActiveTxnRecord (io.pravega.controller.store.stream.records.ActiveTxnRecord)3 CommittingTransactionsRecord (io.pravega.controller.store.stream.records.CommittingTransactionsRecord)3 EpochRecord (io.pravega.controller.store.stream.records.EpochRecord)3 EpochTransitionRecord (io.pravega.controller.store.stream.records.EpochTransitionRecord)3 HistoryTimeSeries (io.pravega.controller.store.stream.records.HistoryTimeSeries)3 RetentionSet (io.pravega.controller.store.stream.records.RetentionSet)3 SealedSegmentsMapShard (io.pravega.controller.store.stream.records.SealedSegmentsMapShard)3 StateRecord (io.pravega.controller.store.stream.records.StateRecord)3 StreamConfigurationRecord (io.pravega.controller.store.stream.records.StreamConfigurationRecord)3 StreamCutRecord (io.pravega.controller.store.stream.records.StreamCutRecord)3