Search in sources :

Example 1 with TransactionOutcomeMetrics

use of com.palantir.atlasdb.transaction.impl.metrics.TransactionOutcomeMetrics in project atlasdb by palantir.

the class SnapshotTransactionTest method commitThrowsIfRolledBackAtCommitTime_expiredLocks.

@Test
public void commitThrowsIfRolledBackAtCommitTime_expiredLocks() {
    final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1"));
    TimelockService timelockService = spy(inMemoryTimeLockRule.getLegacyTimelockService());
    // expire the locks when the pre-commit check happens - this is guaranteed to be after we've written the data
    PreCommitCondition condition = unused -> doReturn(ImmutableSet.of()).when(timelockService).refreshLockLeases(any());
    ConjureStartTransactionsResponse conjureResponse = startTransactionWithWatches();
    LockImmutableTimestampResponse res = conjureResponse.getImmutableTimestamp();
    long transactionTs = conjureResponse.getTimestamps().start();
    Transaction snapshot = getSnapshotTransactionWith(timelockService, () -> transactionTs, res, condition);
    // simulate roll back at commit time
    transactionService.putUnlessExists(snapshot.getTimestamp(), TransactionConstants.FAILED_COMMIT_TS);
    snapshot.put(TABLE, ImmutableMap.of(cell, PtBytes.toBytes("value")));
    assertThatExceptionOfType(TransactionLockTimeoutException.class).isThrownBy(snapshot::commit);
    timelockService.unlock(ImmutableSet.of(res.getLock()));
    TransactionOutcomeMetricsAssert.assertThat(transactionOutcomeMetrics).hasFailedCommits(1).hasLocksExpired(1);
}
Also used : Arrays(java.util.Arrays) AutoDelegate_KeyValueService(com.palantir.atlasdb.keyvalue.api.AutoDelegate_KeyValueService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Throwables(com.palantir.common.base.Throwables) LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) Mockito.doThrow(org.mockito.Mockito.doThrow) Future(java.util.concurrent.Future) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableGetRangesQuery(com.palantir.atlasdb.transaction.api.ImmutableGetRangesQuery) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Duration(java.time.Duration) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) BigInteger(java.math.BigInteger) Mockito.doReturn(org.mockito.Mockito.doReturn) AtlasFutures(com.palantir.atlasdb.futures.AtlasFutures) ToplistDeltaFilteringTableLevelMetricsController(com.palantir.atlasdb.transaction.impl.metrics.ToplistDeltaFilteringTableLevelMetricsController) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Set(java.util.Set) LockMode(com.palantir.lock.LockMode) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Assertions.fail(org.assertj.core.api.Assertions.fail) Stream(java.util.stream.Stream) Transaction(com.palantir.atlasdb.transaction.api.Transaction) DefaultMetricsFilterEvaluationContext(com.palantir.atlasdb.transaction.impl.metrics.DefaultMetricsFilterEvaluationContext) TransactionLockTimeoutNonRetriableException(com.palantir.atlasdb.transaction.api.TransactionLockTimeoutNonRetriableException) DeterministicScheduler(org.jmock.lib.concurrent.DeterministicScheduler) Awaitility(org.awaitility.Awaitility) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Mockito.mock(org.mockito.Mockito.mock) Joiner(com.google.common.base.Joiner) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) Expectations(org.jmock.Expectations) TransactionFailedRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedRetriableException) RunWith(org.junit.runner.RunWith) Synchroniser(org.jmock.lib.concurrent.Synchroniser) Callable(java.util.concurrent.Callable) SimpleTimeDuration(com.palantir.lock.SimpleTimeDuration) Mockito.spy(org.mockito.Mockito.spy) Supplier(java.util.function.Supplier) AtlasDbTestCase(com.palantir.atlasdb.AtlasDbTestCase) PtBytes(com.palantir.atlasdb.encoding.PtBytes) LockAwareTransactionTask(com.palantir.atlasdb.transaction.api.LockAwareTransactionTask) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AbortingVisitors(com.palantir.common.base.AbortingVisitors) StreamSupport(java.util.stream.StreamSupport) LockRequest(com.palantir.lock.LockRequest) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) NoOpLockWatchManager(com.palantir.atlasdb.keyvalue.api.watch.NoOpLockWatchManager) TableLevelMetricsController(com.palantir.atlasdb.transaction.impl.metrics.TableLevelMetricsController) LockCollections(com.palantir.lock.LockCollections) LongStream(java.util.stream.LongStream) Mockito.times(org.mockito.Mockito.times) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) Test(org.junit.Test) TimelockService(com.palantir.lock.v2.TimelockService) Mockery(org.jmock.Mockery) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) ExecutionException(java.util.concurrent.ExecutionException) TimeDuration(com.palantir.lock.TimeDuration) Mockito.never(org.mockito.Mockito.never) Futures(com.google.common.util.concurrent.Futures) LockService(com.palantir.lock.LockService) LockClient(com.palantir.lock.LockClient) BatchingVisitableView(com.palantir.common.base.BatchingVisitableView) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) ConflictTracer(com.palantir.atlasdb.debug.ConflictTracer) TransactionLockTimeoutException(com.palantir.atlasdb.transaction.api.TransactionLockTimeoutException) MutableInt(org.apache.commons.lang3.mutable.MutableInt) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BiFunction(java.util.function.BiFunction) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Random(java.util.Random) SettableFuture(com.google.common.util.concurrent.SettableFuture) BatchingVisitable(com.palantir.common.base.BatchingVisitable) ByteBuffer(java.nio.ByteBuffer) CompletionService(java.util.concurrent.CompletionService) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) TransactionConfig(com.palantir.atlasdb.transaction.TransactionConfig) PTExecutors(com.palantir.common.concurrent.PTExecutors) Assertions(org.assertj.core.api.Assertions) Parameterized(org.junit.runners.Parameterized) LockDescriptor(com.palantir.lock.LockDescriptor) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) KeyedStream(com.palantir.common.streams.KeyedStream) Collection(java.util.Collection) Streams(com.google.common.collect.Streams) SweepStrategy(com.palantir.atlasdb.protos.generated.TableMetadataPersistence.SweepStrategy) Collectors(java.util.stream.Collectors) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) List(java.util.List) MultiDelegateProxy(com.palantir.common.proxy.MultiDelegateProxy) ForwardingKeyValueService(com.palantir.atlasdb.keyvalue.impl.ForwardingKeyValueService) Optional(java.util.Optional) SortedMap(java.util.SortedMap) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HeldLocksToken(com.palantir.lock.HeldLocksToken) Iterators(com.google.common.collect.Iterators) TransactionCommitFailedException(com.palantir.atlasdb.transaction.api.TransactionCommitFailedException) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Suppliers(com.google.common.base.Suppliers) TransactionOutcomeMetrics(com.palantir.atlasdb.transaction.impl.metrics.TransactionOutcomeMetrics) ImmutableTransactionConfig(com.palantir.atlasdb.transaction.ImmutableTransactionConfig) ExecutorService(java.util.concurrent.ExecutorService) EncodingUtils(com.palantir.atlasdb.ptobject.EncodingUtils) InOrder(org.mockito.InOrder) Value(com.palantir.atlasdb.keyvalue.api.Value) PreCommitCondition(com.palantir.atlasdb.transaction.api.PreCommitCondition) Iterator(java.util.Iterator) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) Mockito.when(org.mockito.Mockito.when) Maps(com.google.common.collect.Maps) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Ordering(com.google.common.collect.Ordering) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) TransactionFailedNonRetriableException(com.palantir.atlasdb.transaction.api.TransactionFailedNonRetriableException) DefaultTimestampCache(com.palantir.atlasdb.cache.DefaultTimestampCache) Comparator(java.util.Comparator) AbortingVisitor(com.palantir.common.base.AbortingVisitor) Collections(java.util.Collections) TransactionOutcomeMetricsAssert(com.palantir.atlasdb.transaction.impl.metrics.TransactionOutcomeMetricsAssert) TransactionLockTimeoutException(com.palantir.atlasdb.transaction.api.TransactionLockTimeoutException) ConjureStartTransactionsResponse(com.palantir.atlasdb.timelock.api.ConjureStartTransactionsResponse) Transaction(com.palantir.atlasdb.transaction.api.Transaction) LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) TimelockService(com.palantir.lock.v2.TimelockService) Cell(com.palantir.atlasdb.keyvalue.api.Cell) PreCommitCondition(com.palantir.atlasdb.transaction.api.PreCommitCondition) Test(org.junit.Test)

Aggregations

Joiner (com.google.common.base.Joiner)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Ordering (com.google.common.collect.Ordering)1 Streams (com.google.common.collect.Streams)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 AtlasDbTestCase (com.palantir.atlasdb.AtlasDbTestCase)1 DefaultTimestampCache (com.palantir.atlasdb.cache.DefaultTimestampCache)1 TimestampCache (com.palantir.atlasdb.cache.TimestampCache)1