Search in sources :

Example 16 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class RecordBinaryViewImpl method getAndReplaceAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Tuple> getAndReplaceAsync(@Nullable Transaction tx, @NotNull Tuple rec) {
    Objects.requireNonNull(rec);
    final Row row = marshal(rec, false);
    return tbl.getAndReplace(row, (InternalTransaction) tx).thenApply(this::wrap);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class RecordBinaryViewImpl method getAndDeleteAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Tuple> getAndDeleteAsync(@Nullable Transaction tx, @NotNull Tuple keyRec) {
    Objects.requireNonNull(keyRec);
    final Row keyRow = marshal(keyRec, true);
    return tbl.getAndDelete(keyRow, (InternalTransaction) tx).thenApply(this::wrap);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class RecordBinaryViewImpl method getAndUpsertAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Tuple> getAndUpsertAsync(@Nullable Transaction tx, @NotNull Tuple rec) {
    Objects.requireNonNull(rec);
    final Row row = marshal(rec, false);
    return tbl.getAndUpsert(row, (InternalTransaction) tx).thenApply(this::wrap);
}
Also used : BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class TxAbstractTest method testAbortWithValue.

@Test
public void testAbortWithValue() throws TransactionException {
    accounts.recordView().upsert(null, makeValue(0, 100.));
    assertEquals(100., accounts.recordView().get(null, makeKey(0)).doubleValue("balance"));
    InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
    var table = accounts.recordView();
    table.upsert(tx, makeValue(0, 200.));
    assertEquals(200., table.get(tx, makeKey(0)).doubleValue("balance"));
    tx.rollback();
    assertEquals(100., accounts.recordView().get(null, makeKey(0)).doubleValue("balance"));
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 20 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class TxAbstractTest method testUpgradedLockInvalidation.

@Test
// TODO asch IGNITE-15938
@Disabled("https://issues.apache.org/jira/browse/IGNITE-15938")
public void testUpgradedLockInvalidation() throws Exception {
    accounts.recordView().upsert(null, makeValue(1, 100.));
    InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
    InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
    var table = accounts.recordView();
    var table2 = accounts.recordView();
    double v0 = table.get(tx, makeKey(1)).doubleValue("balance");
    double v1 = table2.get(tx2, makeKey(1)).doubleValue("balance");
    assertEquals(v0, v1);
    // Try to upgrade a lock.
    table2.upsertAsync(tx2, makeValue(1, v0 + 10));
    // Give some time to update lock queue TODO asch IGNITE-15928
    Thread.sleep(300);
    table.upsert(tx, makeValue(1, v0 + 20));
    tx.commit();
    assertThrows(Exception.class, () -> tx2.commit());
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)24 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)14 Test (org.junit.jupiter.api.Test)14 Tuple (org.apache.ignite.table.Tuple)12 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)8 NotNull (org.jetbrains.annotations.NotNull)8 Row (org.apache.ignite.internal.schema.row.Row)6 ArrayList (java.util.ArrayList)4 IgniteException (org.apache.ignite.lang.IgniteException)4 TransactionException (org.apache.ignite.tx.TransactionException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2