Search in sources :

Example 11 with VersionedRowStore

use of org.apache.ignite.internal.table.distributed.storage.VersionedRowStore in project ignite-3 by apache.

the class KeyValueViewOperationsTest method kvView.

/**
 * Creates key-value view.
 */
private KeyValueViewImpl<TestKeyObject, TestObjectWithAllTypes> kvView() {
    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<TestKeyObject> keyMapper = Mapper.of(TestKeyObject.class);
    Mapper<TestObjectWithAllTypes> valMapper = 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("primitiveLongCol".toUpperCase(), INT64, 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("id".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 KeyValueViewImpl<>(table, new DummySchemaManagerImpl(schema), keyMapper, valMapper);
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) 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) KeyValueView(org.apache.ignite.table.KeyValueView) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) 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) 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) Objects(java.util.Objects) 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) 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 12 with VersionedRowStore

use of org.apache.ignite.internal.table.distributed.storage.VersionedRowStore in project ignite-3 by apache.

the class SchemaValidationTest method createTable.

/**
 * Creates a table for tests.
 *
 * @return The test table.
 */
private InternalTable createTable() {
    clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    TxManagerImpl txManager = new TxManagerImpl(clusterService, new HeapLockManager());
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    return new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) 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) MessagingService(org.apache.ignite.network.MessagingService)

Example 13 with VersionedRowStore

use of org.apache.ignite.internal.table.distributed.storage.VersionedRowStore in project ignite-3 by apache.

the class TxLocalTest method before.

/**
 * Initialize the test state.
 */
@Override
@BeforeEach
public void before() {
    ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
    Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
    lockManager = new HeapLockManager();
    txManager = new TxManagerImpl(clusterService, lockManager);
    MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
    Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
    igniteTransactions = new IgniteTransactionsImpl(txManager);
    InternalTable table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    accounts = new TableImpl(table, new DummySchemaManagerImpl(ACCOUNTS_SCHEMA));
    InternalTable table2 = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
    customers = new TableImpl(table2, new DummySchemaManagerImpl(CUSTOMERS_SCHEMA));
}
Also used : VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) ClusterService(org.apache.ignite.network.ClusterService) IgniteTransactionsImpl(org.apache.ignite.internal.tx.impl.IgniteTransactionsImpl) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) DummyInternalTableImpl(org.apache.ignite.internal.table.impl.DummyInternalTableImpl) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) MessagingService(org.apache.ignite.network.MessagingService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with VersionedRowStore

use of org.apache.ignite.internal.table.distributed.storage.VersionedRowStore in project ignite-3 by apache.

the class ItTxDistributedTestSingleNode method startTable.

/**
 * Starts a table.
 *
 * @param name The name.
 * @param tblId Table id.
 * @return Groups map.
 */
protected Int2ObjectOpenHashMap<RaftGroupService> startTable(String name, UUID tblId) throws Exception {
    List<List<ClusterNode>> assignment = RendezvousAffinityFunction.assignPartitions(cluster.stream().map(node -> node.topologyService().localMember()).collect(Collectors.toList()), 1, replicas(), false, null);
    Int2ObjectOpenHashMap<RaftGroupService> clients = new Int2ObjectOpenHashMap<>();
    for (int p = 0; p < assignment.size(); p++) {
        List<ClusterNode> partNodes = assignment.get(p);
        String grpId = name + "-part-" + p;
        List<Peer> conf = partNodes.stream().map(n -> n.address()).map(Peer::new).collect(Collectors.toList());
        for (ClusterNode node : partNodes) {
            raftServers.get(node).prepareRaftGroup(grpId, partNodes, () -> new PartitionListener(tblId, new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManagers.get(node))));
        }
        if (startClient()) {
            RaftGroupService service = RaftGroupServiceImpl.start(grpId, client, FACTORY, 10_000, conf, true, 200, executor).get(5, TimeUnit.SECONDS);
            clients.put(p, service);
        } else {
            // Create temporary client to find a leader address.
            ClusterService tmpSvc = raftServers.values().stream().findFirst().get().service();
            RaftGroupService service = RaftGroupServiceImpl.start(grpId, tmpSvc, FACTORY, 10_000, conf, true, 200, executor).get(5, TimeUnit.SECONDS);
            Peer leader = service.leader();
            service.shutdown();
            Loza leaderSrv = raftServers.get(tmpSvc.topologyService().getByAddress(leader.address()));
            RaftGroupService leaderClusterSvc = RaftGroupServiceImpl.start(grpId, leaderSrv.service(), FACTORY, 10_000, conf, true, 200, executor).get(5, TimeUnit.SECONDS);
            clients.put(p, leaderClusterSvc);
        }
    }
    return clients;
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Peer(org.apache.ignite.raft.client.Peer) Loza(org.apache.ignite.internal.raft.Loza) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) ClusterService(org.apache.ignite.network.ClusterService) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 15 with VersionedRowStore

use of org.apache.ignite.internal.table.distributed.storage.VersionedRowStore in project ignite-3 by apache.

the class ItTxDistributedTestSingleNode method assertPartitionsSame.

/**
 * {@inheritDoc}
 */
@Override
protected boolean assertPartitionsSame(Table table, int partId) {
    int hash = 0;
    for (Map.Entry<ClusterNode, Loza> entry : raftServers.entrySet()) {
        Loza svc = (Loza) entry.getValue();
        JraftServerImpl server = (JraftServerImpl) svc.server();
        org.apache.ignite.raft.jraft.RaftGroupService grp = server.raftGroupService(table.name() + "-part-" + partId);
        JraftServerImpl.DelegatingStateMachine fsm = (JraftServerImpl.DelegatingStateMachine) grp.getRaftNode().getOptions().getFsm();
        PartitionListener listener = (PartitionListener) fsm.getListener();
        VersionedRowStore storage = listener.getStorage();
        if (hash == 0) {
            hash = storage.delegate().hashCode();
        } else if (hash != storage.delegate().hashCode()) {
            return false;
        }
    }
    return true;
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) Loza(org.apache.ignite.internal.raft.Loza) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) Map(java.util.Map) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) HashMap(java.util.HashMap)

Aggregations

VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)15 ConcurrentHashMapPartitionStorage (org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage)10 HeapLockManager (org.apache.ignite.internal.tx.impl.HeapLockManager)10 TxManagerImpl (org.apache.ignite.internal.tx.impl.TxManagerImpl)10 ClusterService (org.apache.ignite.network.ClusterService)10 TxManager (org.apache.ignite.internal.tx.TxManager)8 DummyInternalTableImpl (org.apache.ignite.internal.table.impl.DummyInternalTableImpl)7 MessagingService (org.apache.ignite.network.MessagingService)7 List (java.util.List)6 PartitionListener (org.apache.ignite.internal.table.distributed.raft.PartitionListener)6 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)6 NotNull (org.jetbrains.annotations.NotNull)6 Map (java.util.Map)5 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)5 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)5 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)4 Set (java.util.Set)4 UUID (java.util.UUID)4 Collectors (java.util.stream.Collectors)4 NetworkAddress (org.apache.ignite.network.NetworkAddress)4