Search in sources :

Example 1 with RaftGroupListener

use of org.apache.ignite.raft.client.service.RaftGroupListener in project ignite-3 by apache.

the class ItTablePersistenceTest method createListener.

/**
 * {@inheritDoc}
 */
@Override
public RaftGroupListener createListener(ClusterService service, Path workDir) {
    return paths.entrySet().stream().filter(entry -> entry.getValue().equals(workDir)).map(Map.Entry::getKey).findAny().orElseGet(() -> {
        TableTxManagerImpl txManager = new TableTxManagerImpl(service, new HeapLockManager());
        // Init listener.
        txManager.start();
        PartitionListener listener = new PartitionListener(UUID.randomUUID(), new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager));
        paths.put(listener, workDir);
        return listener;
    });
}
Also used : ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ItAbstractListenerSnapshotTest(org.apache.ignite.raft.client.service.ItAbstractListenerSnapshotTest) RaftGroupListener(org.apache.ignite.raft.client.service.RaftGroupListener) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) Row(org.apache.ignite.internal.schema.row.Row) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) Path(java.nio.file.Path) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Int2ObjectMaps(it.unimi.dsi.fastutil.ints.Int2ObjectMaps) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TxManagerImpl(org.apache.ignite.internal.tx.impl.TxManagerImpl) UUID(java.util.UUID) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) TxManager(org.apache.ignite.internal.tx.TxManager) NetworkAddress(org.apache.ignite.network.NetworkAddress) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) AfterEach(org.junit.jupiter.api.AfterEach) Column(org.apache.ignite.internal.schema.Column) ClusterService(org.apache.ignite.network.ClusterService) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) Mockito.mock(org.mockito.Mockito.mock) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) HeapLockManager(org.apache.ignite.internal.tx.impl.HeapLockManager) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) ConcurrentHashMapPartitionStorage(org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage) TableTxManagerImpl(org.apache.ignite.internal.table.distributed.TableTxManagerImpl)

Example 2 with RaftGroupListener

use of org.apache.ignite.raft.client.service.RaftGroupListener in project ignite-3 by apache.

the class RaftServerImpl method processQueue.

/**
 * Process the queue.
 *
 * @param queue The queue.
 * @param clo   The closure.
 * @param <T>   Command type.
 */
private <T extends Command> void processQueue(BlockingQueue<CommandClosureEx<T>> queue, BiConsumer<RaftGroupListener, Iterator<CommandClosure<T>>> clo) {
    while (!Thread.interrupted()) {
        try {
            CommandClosureEx<T> cmdClo = queue.take();
            RaftGroupListener lsnr = cmdClo.listener();
            clo.accept(lsnr, List.<CommandClosure<T>>of(cmdClo).iterator());
        } catch (InterruptedException e0) {
            return;
        } catch (Exception e) {
            LOG.error("Failed to process the command", e);
        }
    }
}
Also used : RaftGroupListener(org.apache.ignite.raft.client.service.RaftGroupListener) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) CommandClosure(org.apache.ignite.raft.client.service.CommandClosure)

Example 3 with RaftGroupListener

use of org.apache.ignite.raft.client.service.RaftGroupListener in project ignite-3 by apache.

the class LozaTest method testLozaStop.

/**
 * Checks that the all API methods throw the exception ({@link org.apache.ignite.lang.NodeStoppingException})
 * when Loza is closed.
 *
 * @throws Exception If fail.
 */
@Test
public void testLozaStop() throws Exception {
    Mockito.doReturn(new ClusterLocalConfiguration("test_node", null)).when(clusterNetSvc).localConfiguration();
    Mockito.doReturn(Mockito.mock(MessagingService.class)).when(clusterNetSvc).messagingService();
    Mockito.doReturn(Mockito.mock(TopologyService.class)).when(clusterNetSvc).topologyService();
    Loza loza = new Loza(clusterNetSvc, workDir);
    loza.start();
    loza.beforeNodeStop();
    loza.stop();
    String raftGroupId = "test_raft_group";
    List<ClusterNode> nodes = List.of(new ClusterNode(UUID.randomUUID().toString(), UUID.randomUUID().toString(), NetworkAddress.from("127.0.0.1:123")));
    List<ClusterNode> newNodes = List.of(new ClusterNode(UUID.randomUUID().toString(), UUID.randomUUID().toString(), NetworkAddress.from("127.0.0.1:124")), new ClusterNode(UUID.randomUUID().toString(), UUID.randomUUID().toString(), NetworkAddress.from("127.0.0.1:125")));
    Supplier<RaftGroupListener> lsnrSupplier = () -> null;
    assertThrows(NodeStoppingException.class, () -> loza.updateRaftGroup(raftGroupId, nodes, newNodes, lsnrSupplier));
    assertThrows(NodeStoppingException.class, () -> loza.stopRaftGroup(raftGroupId));
    assertThrows(NodeStoppingException.class, () -> loza.prepareRaftGroup(raftGroupId, nodes, lsnrSupplier));
    assertThrows(NodeStoppingException.class, () -> loza.changePeers(raftGroupId, nodes, newNodes));
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) RaftGroupListener(org.apache.ignite.raft.client.service.RaftGroupListener) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) MessagingService(org.apache.ignite.network.MessagingService) TopologyService(org.apache.ignite.network.TopologyService) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Aggregations

RaftGroupListener (org.apache.ignite.raft.client.service.RaftGroupListener)3 Int2ObjectMaps (it.unimi.dsi.fastutil.ints.Int2ObjectMaps)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BooleanSupplier (java.util.function.BooleanSupplier)1 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)1 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)1 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)1 Column (org.apache.ignite.internal.schema.Column)1 NativeTypes (org.apache.ignite.internal.schema.NativeTypes)1 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)1 Row (org.apache.ignite.internal.schema.row.Row)1 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)1 ConcurrentHashMapPartitionStorage (org.apache.ignite.internal.storage.basic.ConcurrentHashMapPartitionStorage)1 TableStorage (org.apache.ignite.internal.storage.engine.TableStorage)1