use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.
the class KeyValueBinaryViewImpl method removeAllAsync.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public CompletableFuture<Collection<Tuple>> removeAllAsync(@Nullable Transaction tx, @NotNull Collection<Tuple> keys) {
Objects.requireNonNull(keys);
List<BinaryRow> keyRows = new ArrayList<>(keys.size());
for (Tuple keyRec : keys) {
final Row keyRow = marshal(keyRec, null);
keyRows.add(keyRow);
}
return tbl.deleteAll(keyRows, (InternalTransaction) tx).thenApply(t -> t.stream().filter(Objects::nonNull).map(this::wrap).map(TableRow::valueTuple).collect(Collectors.toList()));
}
use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.
the class RecordBinaryViewImpl method getAsync.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public CompletableFuture<Tuple> getAsync(@Nullable Transaction tx, @NotNull Tuple keyRec) {
Objects.requireNonNull(keyRec);
// Convert to portable format to pass TX/storage layer.
final Row keyRow = marshal(keyRec, true);
return tbl.get(keyRow, (InternalTransaction) tx).thenApply(this::wrap);
}
use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.
the class TxAbstractTest method testGetAllConflict.
/**
* Tests if a transaction is rolled back if one of the batch keys can't be locked.
*/
@Test
public void testGetAllConflict() throws Exception {
accounts.recordView().upsertAll(null, List.of(makeValue(1, 100.), makeValue(2, 200.)));
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
RecordView<Tuple> txAcc = accounts.recordView();
RecordView<Tuple> txAcc2 = accounts.recordView();
txAcc2.upsert(tx2, makeValue(1, 300.));
txAcc.upsert(tx, makeValue(2, 400.));
Exception err = assertThrows(Exception.class, () -> txAcc.getAll(tx, List.of(makeKey(2), makeKey(1))));
assertTrue(err.getMessage().contains("Failed to acquire a lock"), err.getMessage());
validateBalance(txAcc2.getAll(tx2, List.of(makeKey(2), makeKey(1))), 200., 300.);
validateBalance(txAcc2.getAll(tx2, List.of(makeKey(1), makeKey(2))), 300., 200.);
assertTrue(IgniteTestUtils.waitForCondition(() -> TxState.ABORTED == tx.state(), 5_000), tx.state().toString());
tx2.commit();
validateBalance(accounts.recordView().getAll(null, List.of(makeKey(2), makeKey(1))), 200., 300.);
}
use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.
the class TxAbstractTest method testCommit.
@Test
public void testCommit() throws TransactionException {
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
Tuple key = makeKey(1);
var table = accounts.recordView();
table.upsert(tx, makeValue(1, 100.));
assertEquals(100., table.get(tx, key).doubleValue("balance"));
table.upsert(tx, makeValue(1, 200.));
assertEquals(200., table.get(tx, key).doubleValue("balance"));
tx.commit();
assertEquals(200., accounts.recordView().get(null, key).doubleValue("balance"));
assertEquals(COMMITED, txManager(accounts).state(tx.timestamp()));
}
use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.
the class TxAbstractTest method testAbort.
@Test
public void testAbort() throws TransactionException {
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
Tuple key = makeKey(1);
var table = accounts.recordView();
table.upsert(tx, makeValue(1, 100.));
assertEquals(100., table.get(tx, key).doubleValue("balance"));
table.upsert(tx, makeValue(1, 200.));
assertEquals(200., table.get(tx, key).doubleValue("balance"));
tx.rollback();
assertNull(accounts.recordView().get(null, key));
assertEquals(ABORTED, txManager(accounts).state(tx.timestamp()));
}
Aggregations