Search in sources :

Example 56 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractSerializableTransactionTest method testClassicWriteSkewCell.

@Test
public void testClassicWriteSkewCell() {
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", "100");
    put(t0, "row2", "col1", "100");
    t0.commit();
    Transaction t1 = startTransaction();
    Transaction t2 = startTransaction();
    withdrawMoney(t1, true, true);
    withdrawMoney(t2, false, true);
    t1.commit();
    try {
        t2.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // this is expectecd to throw because it is a write skew
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Test(org.junit.Test)

Example 57 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractSerializableTransactionTest method testColumnSelection.

@Test
public void testColumnSelection() {
    String initialValue = "100";
    Transaction t0 = startTransaction();
    String firstCol = "col1";
    put(t0, "row1", firstCol, initialValue);
    put(t0, "row1", "col2", initialValue);
    put(t0, "row2", firstCol, initialValue);
    t0.commit();
    Transaction t1 = startTransaction();
    BatchingVisitables.copyToList(getRangeRetainingCol(t1, firstCol));
    get(t1, "row1", "col2");
    // We need to do at least one put so we don't get caught by the read only code path
    put(t1, "row22", "col2", initialValue);
    t1.commit();
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) Test(org.junit.Test)

Example 58 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractSerializableTransactionTest method testCycleWithReadOnly.

@Test
public void testCycleWithReadOnly() {
    // readOnly has a r/w dep on t2 and t2 has a r/w on t1 and t1 has a w/r dep on readOnly
    // This creates a cycle that is valid under SI, but not SSI
    // The main issue is that readOnly reads an invalid state of the world. because it reads the updated value of
    // t1, but the old value of t2.
    String initialValue = "100";
    String newValue = "101";
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", initialValue);
    put(t0, "row2", "col1", initialValue);
    t0.commit();
    Transaction t1 = startTransaction();
    put(t1, "row1", "col1", newValue);
    Transaction t2 = startTransaction();
    String row1Get = get(t2, "row1", "col1");
    assertEquals(initialValue, row1Get);
    put(t2, "row2", "col1", row1Get);
    t1.commit();
    Transaction readOnly = startTransaction();
    assertEquals(newValue, get(readOnly, "row1", "col1"));
    assertEquals(initialValue, get(readOnly, "row2", "col1"));
    try {
        t2.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // this is expectecd to throw because it is a write skew
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Test(org.junit.Test)

Example 59 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractSerializableTransactionTest method testColumnRangeReadWriteNoConflict.

@Test
public void testColumnRangeReadWriteNoConflict() {
    byte[] row = PtBytes.toBytes("row1");
    writeColumns();
    Transaction t1 = startTransaction();
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t1.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    // Serializable transaction records only the first column as read.
    Map.Entry<Cell, byte[]> read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values()));
    assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey());
    // Write to avoid the read only path.
    put(t1, "row1_1", "col0", "v0");
    Transaction t2 = startTransaction();
    put(t2, "row1", "col1", "v0_0");
    t2.commit();
    t1.commit();
}
Also used : BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 60 with Transaction

use of com.palantir.atlasdb.transaction.api.Transaction in project atlasdb by palantir.

the class AbstractSerializableTransactionTest method testClassicWriteSkew2.

@Test
public void testClassicWriteSkew2() {
    Transaction t0 = startTransaction();
    put(t0, "row1", "col1", "100");
    put(t0, "row2", "col1", "100");
    t0.commit();
    Transaction t1 = startTransaction();
    Transaction t2 = startTransaction();
    withdrawMoney(t1, true, false);
    withdrawMoney(t2, false, false);
    t2.commit();
    try {
        t1.commit();
        fail();
    } catch (TransactionSerializableConflictException e) {
    // this is expectecd to throw because it is a write skew
    }
}
Also used : Transaction(com.palantir.atlasdb.transaction.api.Transaction) TransactionSerializableConflictException(com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException) Test(org.junit.Test)

Aggregations

Transaction (com.palantir.atlasdb.transaction.api.Transaction)60 Test (org.junit.Test)51 Cell (com.palantir.atlasdb.keyvalue.api.Cell)26 Map (java.util.Map)18 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)14 TransactionSerializableConflictException (com.palantir.atlasdb.transaction.api.TransactionSerializableConflictException)14 BatchingVisitable (com.palantir.common.base.BatchingVisitable)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 TransactionConflictException (com.palantir.atlasdb.transaction.api.TransactionConflictException)13 List (java.util.List)13 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)12 PtBytes (com.palantir.atlasdb.encoding.PtBytes)10 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)10 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)10 ExecutionException (java.util.concurrent.ExecutionException)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collectors (java.util.stream.Collectors)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 Multimap (com.google.common.collect.Multimap)8 Multimaps (com.google.common.collect.Multimaps)8