Search in sources :

Example 1 with TxManagerImpl

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

the class ItInternalTableScanTest method setUp.

/**
 * Prepare test environment.
 * <ol>
 * <li>Start network node.</li>
 * <li>Start raft server.</li>
 * <li>Prepare partitioned raft group.</li>
 * <li>Prepare partitioned raft group service.</li>
 * <li>Prepare internal table as a test object.</li>
 * </ol>
 *
 * @throws Exception If any.
 */
@BeforeEach
public void setUp(TestInfo testInfo) throws Exception {
    NetworkAddress nodeNetworkAddress = new NetworkAddress("localhost", 20_000);
    network = ClusterServiceTestUtils.clusterService(testInfo, 20_000, new StaticNodeFinder(List.of(nodeNetworkAddress)), NETWORK_FACTORY);
    network.start();
    raftSrv = new RaftServerImpl(network, FACTORY);
    raftSrv.start();
    String grpName = "test_part_grp";
    List<Peer> conf = List.of(new Peer(nodeNetworkAddress));
    mockStorage = mock(PartitionStorage.class);
    txManager = new TxManagerImpl(network, new HeapLockManager());
    txManager.start();
    UUID tblId = UUID.randomUUID();
    raftSrv.startRaftGroup(grpName, new PartitionListener(tblId, new VersionedRowStore(mockStorage, txManager) {

        @Override
        protected Pair<BinaryRow, BinaryRow> versionedRow(@Nullable DataRow row, Timestamp timestamp) {
            // Return as is.
            return new Pair<>(new ByteBufferRow(row.valueBytes()), null);
        }
    }), conf);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    RaftGroupService raftGrpSvc = RaftGroupServiceImpl.start(RAFT_GRP_ID, network, FACTORY, 10_000, conf, true, 200, executor).get(3, TimeUnit.SECONDS);
    internalTbl = new InternalTableImpl(TEST_TABLE_NAME, tblId, Int2ObjectMaps.singleton(0, raftGrpSvc), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) Timestamp(org.apache.ignite.internal.tx.Timestamp) RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable) PartitionStorage(org.apache.ignite.internal.storage.PartitionStorage) Pair(org.apache.ignite.internal.util.Pair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with TxManagerImpl

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

the class ItTablePersistenceTest method afterSnapshot.

/**
 * {@inheritDoc}
 */
@Override
public void afterSnapshot(RaftGroupService service) throws Exception {
    TxManager txManager = new TxManagerImpl(clientService(), new HeapLockManager());
    managers.add(txManager);
    txManager.start();
    var table = new InternalTableImpl("table", UUID.randomUUID(), Int2ObjectMaps.singleton(0, service), 1, NetworkAddress::toString, txManager, mock(TableStorage.class));
    table.upsert(SECOND_VALUE, null).get();
    assertNotNull(table.get(SECOND_KEY, null).join());
    txManager.stop();
}
Also used : TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) NetworkAddress(org.apache.ignite.network.NetworkAddress) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl) TxManager(org.apache.ignite.internal.tx.TxManager)

Example 3 with TxManagerImpl

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

the class RecordBinaryViewOperationsTest method createTableImpl.

@NotNull
private TableImpl createTableImpl(SchemaDescriptor schema) {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    LockManager lockManager = new HeapLockManager();
    TxManager txManager = new TxManagerImpl(clusterService, lockManager);
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    return new TableImpl(table, new DummySchemaManagerImpl(schema));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) LockManager(org.apache.ignite.internal.tx.LockManager) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TxManagerImpl

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

the class RecordViewOperationsTest method recordView.

/**
 * Creates RecordView.
 */
private RecordViewImpl<TestObjectWithAllTypes> recordView() {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    Mapper<TestObjectWithAllTypes> recMapper = Mapper.of(TestObjectWithAllTypes.class);
    Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primitiveLongCol".toUpperCase(), NativeTypes.INT64, false) }, valCols);
    // Validate all types are tested.
    Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
    Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
    assertEquals(Collections.emptySet(), missedTypes);
    return new RecordViewImpl<>(table, new DummySchemaManagerImpl(schema), recMapper);
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) RecordView(org.apache.ignite.table.RecordView) Arrays(java.util.Arrays) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DOUBLE(org.apache.ignite.internal.schema.NativeTypes.DOUBLE) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) INT8(org.apache.ignite.internal.schema.NativeTypes.INT8) Mapper(org.apache.ignite.table.mapper.Mapper) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MessagingService(org.apache.ignite.network.MessagingService) FLOAT(org.apache.ignite.internal.schema.NativeTypes.FLOAT) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) NativeTypes.datetime(org.apache.ignite.internal.schema.NativeTypes.datetime) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) NativeTypes.timestamp(org.apache.ignite.internal.schema.NativeTypes.timestamp) Collection(java.util.Collection) Set(java.util.Set) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) Collectors(java.util.stream.Collectors) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) BYTES(org.apache.ignite.internal.schema.NativeTypes.BYTES) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) STRING(org.apache.ignite.internal.schema.NativeTypes.STRING) Column(org.apache.ignite.internal.schema.Column) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NativeTypes.time(org.apache.ignite.internal.schema.NativeTypes.time) ClusterService(org.apache.ignite.network.ClusterService) INT16(org.apache.ignite.internal.schema.NativeTypes.INT16) INT32(org.apache.ignite.internal.schema.NativeTypes.INT32) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) TxManager(org.apache.ignite.internal.tx.TxManager) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Column(org.apache.ignite.internal.schema.Column) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl)

Example 5 with TxManagerImpl

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

the class KeyValueBinaryViewOperationsTest method createTable.

@NotNull
private TableImpl createTable(SchemaDescriptor schema) {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    LockManager lockManager = new HeapLockManager();
    TxManager txManager = new TxManagerImpl(clusterService, lockManager);
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    return new TableImpl(table, new DummySchemaManagerImpl(schema));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) LockManager(org.apache.ignite.internal.tx.LockManager) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) TxManager(org.apache.ignite.internal.tx.TxManager) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HeapLockManager (org.apache.ignite.internal.tx.impl.HeapLockManager)14 TxManagerImpl (org.apache.ignite.internal.tx.impl.TxManagerImpl)14 VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)10 ClusterService (org.apache.ignite.network.ClusterService)10 ConcurrentHashMapPartitionStorage (org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage)9 DummyInternalTableImpl (org.apache.ignite.internal.table.impl.DummyInternalTableImpl)7 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)7 TxManager (org.apache.ignite.internal.tx.TxManager)7 MessagingService (org.apache.ignite.network.MessagingService)7 NetworkAddress (org.apache.ignite.network.NetworkAddress)6 InternalTableImpl (org.apache.ignite.internal.table.distributed.storage.InternalTableImpl)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 TableStorage (org.apache.ignite.internal.storage.engine.TableStorage)3 TableTxManagerImpl (org.apache.ignite.internal.table.distributed.TableTxManagerImpl)3 NotNull (org.jetbrains.annotations.NotNull)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2