Search in sources :

Example 16 with TransactionsLockWatchUpdate

use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.

the class ClientLogEventsTest method toTransactionsWithUpToDateClientVersion.

@Test
public void toTransactionsWithUpToDateClientVersion() {
    LockWatchEvents events = LockWatchEvents.builder().build();
    ClientLogEvents clientLogEvents = ClientLogEvents.builder().clearCache(false).events(events).build();
    TimestampMapping mapping = createTimestampMappingWithSequences(SEQUENCE_4, SEQUENCE_4);
    TransactionsLockWatchUpdate update = clientLogEvents.toTransactionsLockWatchUpdate(mapping, Optional.of(VERSION_4));
    assertThat(update.events()).isEmpty();
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Example 17 with TransactionsLockWatchUpdate

use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.

the class LockWatchEventCacheImplTest method processStartTransactionsUpdateAssignsUpdateVersionToTimestamps.

@Test
public void processStartTransactionsUpdateAssignsUpdateVersionToTimestamps() {
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_1), SNAPSHOT_VERSION_1);
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(), SUCCESS_VERSION_2);
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(), SUCCESS_VERSION_3);
    assertThat(eventCache.lastKnownVersion().map(LockWatchVersion::version)).hasValue(SEQUENCE_3);
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_2), SUCCESS_VERSION_2);
    verify(eventLog).processUpdate(SNAPSHOT_VERSION_1);
    verify(eventLog, times(2)).processUpdate(SUCCESS_VERSION_2);
    verify(eventLog).processUpdate(SUCCESS_VERSION_3);
    assertThat(eventCache.lastKnownVersion().map(LockWatchVersion::version)).as("event cache does not go backwards when processing an earlier update").hasValue(SEQUENCE_3);
    TransactionsLockWatchUpdate update = eventCache.getUpdateForTransactions(ImmutableSet.of(TIMESTAMP_1, TIMESTAMP_2), Optional.of(VERSION_1));
    assertThat(update.clearCache()).as("reasonably up-to-date version provided").isFalse();
    assertThat(update.events()).as("only events from version 1 (exclusive) to version 2 (inclusive) required").containsExactly(LOCK_DESCRIPTOR_2_VERSION_2);
    assertThat(update.startTsToSequence()).as("TIMESTAMP_2 should not have a version newer than it knows about").containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(TIMESTAMP_1, VERSION_1, TIMESTAMP_2, VERSION_2));
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) Test(org.junit.Test)

Example 18 with TransactionsLockWatchUpdate

use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.

the class LockWatchEventIntegrationTest method upToDateVersionReturnsOnlyNecessaryEvents.

@Test
public void upToDateVersionReturnsOnlyNecessaryEvents() {
    LockWatchVersion baseVersion = getCurrentVersion();
    performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_1, DATA_1));
    OpenTransaction secondTxn = startSingleTransaction();
    performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_2, DATA_2));
    LockWatchVersion currentVersion = getCurrentVersion();
    performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_3, DATA_3));
    OpenTransaction fifthTxn = startSingleTransaction();
    TransactionsLockWatchUpdate update = getUpdateForTransactions(Optional.of(currentVersion), secondTxn, fifthTxn);
    assertThat(update.clearCache()).isFalse();
    assertThat(update.startTsToSequence().get(secondTxn.getTimestamp()).version()).isEqualTo(baseVersion.version() + 2);
    assertThat(update.startTsToSequence().get(fifthTxn.getTimestamp()).version()).isEqualTo(currentVersion.version() + 2);
    // Note that the lock/unlock events for CELL_2 are not present because a more up-to-date version was passed in
    assertThat(lockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_3));
    assertThat(unlockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_3));
    assertThat(watchDescriptors(update.events())).isEmpty();
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) OpenTransaction(com.palantir.atlasdb.transaction.api.OpenTransaction) Test(org.junit.Test)

Example 19 with TransactionsLockWatchUpdate

use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.

the class LockWatchEventIntegrationTest method multipleTransactionVersionsReturnsSnapshotAndOnlyRelevantRecentEvents.

@Test
public void multipleTransactionVersionsReturnsSnapshotAndOnlyRelevantRecentEvents() {
    LockWatchVersion baseVersion = getCurrentVersion();
    performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_1, DATA_1, CELL_2, DATA_2));
    OpenTransaction secondTxn = startSingleTransaction();
    performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_3, DATA_3));
    // The purpose of this transaction is to test when we can guarantee that there are some locks taken out
    // without the subsequent unlock event.
    Runnable cleanup = performWriteTransactionThatBlocksAfterLockingCells();
    OpenTransaction fifthTxn = startSingleTransaction();
    TransactionsLockWatchUpdate update = getUpdateForTransactions(Optional.empty(), secondTxn, fifthTxn);
    /*
        There are five transactions in this test, with the following events:

        Transaction 1: lock C1, C2; unlock C1, C2.
        Transaction 2: uncommitted, no events
        Transaction 3: lock C3; unlock C3
        Transaction 4: lock C1, C4; no unlocks (as stuck in commit stage)
        Transaction 5: uncommitted, no events

        From the above, Transactions 1 and 3 should increment the version by 2 each; Transaction 4 by 1. Thus,
        Transaction 2 should be at base + 2, and Transaction 5 at base + 5.
         */
    assertThat(update.clearCache()).isTrue();
    assertThat(update.startTsToSequence().get(secondTxn.getTimestamp()).version()).isEqualTo(baseVersion.version() + 2);
    assertThat(update.startTsToSequence().get(fifthTxn.getTimestamp()).version()).isEqualTo(baseVersion.version() + 5);
    assertThat(lockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_1, CELL_3, CELL_4));
    assertThat(unlockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_3));
    assertThat(watchDescriptors(update.events())).isEmpty();
    secondTxn.finish(_unused -> null);
    fifthTxn.finish(_unused -> null);
    cleanup.run();
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) LockWatchVersion(com.palantir.lock.watch.LockWatchVersion) OpenTransaction(com.palantir.atlasdb.transaction.api.OpenTransaction) Test(org.junit.Test)

Aggregations

TransactionsLockWatchUpdate (com.palantir.lock.watch.TransactionsLockWatchUpdate)19 Test (org.junit.Test)18 LockWatchVersion (com.palantir.lock.watch.LockWatchVersion)5 OpenTransaction (com.palantir.atlasdb.transaction.api.OpenTransaction)2 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)1 LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)1 UUID (java.util.UUID)1