Search in sources :

Example 6 with Timestamp

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

the class PartitionListener method handleFinishTxCommand.

/**
 * Handler for the {@link FinishTxCommand}.
 *
 * @param cmd Command.
 * @return Result.
 */
private boolean handleFinishTxCommand(FinishTxCommand cmd) {
    Timestamp ts = cmd.timestamp();
    boolean commit = cmd.finish();
    return txManager.changeState(ts, TxState.PENDING, commit ? TxState.COMMITED : TxState.ABORTED);
}
Also used : Timestamp(org.apache.ignite.internal.tx.Timestamp)

Example 7 with Timestamp

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

the class PartitionCommandListenerTest method upsert.

/**
 * Upserts rows.
 */
private void upsert() {
    Timestamp ts = Timestamp.nextVersion();
    commandListener.onWrite(iterator((i, clo) -> {
        when(clo.command()).thenReturn(new UpsertCommand(getTestRow(i, i), ts));
        doAnswer(invocation -> {
            assertNull(invocation.getArgument(0));
            return null;
        }).when(clo).result(any());
    }));
}
Also used : DeleteCommand(org.apache.ignite.internal.table.distributed.command.DeleteCommand) BeforeEach(org.junit.jupiter.api.BeforeEach) InsertCommand(org.apache.ignite.internal.table.distributed.command.InsertCommand) DeleteAllCommand(org.apache.ignite.internal.table.distributed.command.DeleteAllCommand) DeleteExactAllCommand(org.apache.ignite.internal.table.distributed.command.DeleteExactAllCommand) GetAndDeleteCommand(org.apache.ignite.internal.table.distributed.command.GetAndDeleteCommand) Row(org.apache.ignite.internal.schema.row.Row) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CommandClosure(org.apache.ignite.raft.client.service.CommandClosure) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) GetAllCommand(org.apache.ignite.internal.table.distributed.command.GetAllCommand) Set(java.util.Set) UUID(java.util.UUID) ReplaceCommand(org.apache.ignite.internal.table.distributed.command.ReplaceCommand) Command(org.apache.ignite.raft.client.Command) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.any(org.mockito.Mockito.any) NotNull(org.jetbrains.annotations.NotNull) Mockito.mock(org.mockito.Mockito.mock) GetAndReplaceCommand(org.apache.ignite.internal.table.distributed.command.GetAndReplaceCommand) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) UpsertCommand(org.apache.ignite.internal.table.distributed.command.UpsertCommand) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Function(java.util.function.Function) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HashSet(java.util.HashSet) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) GetAndUpsertCommand(org.apache.ignite.internal.table.distributed.command.GetAndUpsertCommand) DeleteExactCommand(org.apache.ignite.internal.table.distributed.command.DeleteExactCommand) BiConsumer(java.util.function.BiConsumer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ReplaceIfExistCommand(org.apache.ignite.internal.table.distributed.command.ReplaceIfExistCommand) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Iterator(java.util.Iterator) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) Mockito.when(org.mockito.Mockito.when) Timestamp(org.apache.ignite.internal.tx.Timestamp) MultiRowsResponse(org.apache.ignite.internal.table.distributed.command.response.MultiRowsResponse) NetworkAddress(org.apache.ignite.network.NetworkAddress) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) Column(org.apache.ignite.internal.schema.Column) GetCommand(org.apache.ignite.internal.table.distributed.command.GetCommand) UpsertAllCommand(org.apache.ignite.internal.table.distributed.command.UpsertAllCommand) ClusterService(org.apache.ignite.network.ClusterService) InsertAllCommand(org.apache.ignite.internal.table.distributed.command.InsertAllCommand) SingleRowResponse(org.apache.ignite.internal.table.distributed.command.response.SingleRowResponse) UpsertCommand(org.apache.ignite.internal.table.distributed.command.UpsertCommand) GetAndUpsertCommand(org.apache.ignite.internal.table.distributed.command.GetAndUpsertCommand) Timestamp(org.apache.ignite.internal.tx.Timestamp)

Example 8 with Timestamp

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

the class TxManagerImpl method begin.

/**
 * {@inheritDoc}
 */
@Override
public InternalTransaction begin() {
    Timestamp ts = Timestamp.nextVersion();
    states.put(ts, TxState.PENDING);
    return new TransactionImpl(this, ts, clusterService.topologyService().localMember().address());
}
Also used : Timestamp(org.apache.ignite.internal.tx.Timestamp)

Example 9 with Timestamp

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

the class ItTxDistributedTestThreeNodesThreeReplicasCollocated method testTxStateReplication.

@Test
public void testTxStateReplication() {
    TransactionImpl tx = (TransactionImpl) igniteTransactions.begin();
    Timestamp txTimestamp = tx.timestamp();
    accounts.recordView().upsert(tx, makeValue(1, 200.));
    tx.commit();
    assertTrue(TestUtils.waitForCondition(() -> txManagers.values().stream().filter(txManager -> txManager.state(txTimestamp) != null && txManager.state(txTimestamp).equals(TxState.COMMITED)).collect(Collectors.toList()).size() >= 2, 5_000));
}
Also used : Test(org.junit.jupiter.api.Test) BeforeEach(org.junit.jupiter.api.BeforeEach) TxState(org.apache.ignite.internal.tx.TxState) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Timestamp(org.apache.ignite.internal.tx.Timestamp) TransactionImpl(org.apache.ignite.internal.tx.impl.TransactionImpl) Collectors(java.util.stream.Collectors) TestUtils(org.apache.ignite.raft.jraft.test.TestUtils) TestInfo(org.junit.jupiter.api.TestInfo) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) TransactionImpl(org.apache.ignite.internal.tx.impl.TransactionImpl) Timestamp(org.apache.ignite.internal.tx.Timestamp) Test(org.junit.jupiter.api.Test)

Aggregations

Timestamp (org.apache.ignite.internal.tx.Timestamp)9 TxState (org.apache.ignite.internal.tx.TxState)4 Set (java.util.Set)3 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)3 NetworkAddress (org.apache.ignite.network.NetworkAddress)3 Nullable (org.jetbrains.annotations.Nullable)3 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)2 VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)2 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)2 TxManager (org.apache.ignite.internal.tx.TxManager)2 HeapLockManager (org.apache.ignite.internal.tx.impl.HeapLockManager)2 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)2 TransactionException (org.apache.ignite.tx.TransactionException)2