Search in sources :

Example 21 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ItJraftCounterServerTest method startServer.

/**
 * Starts server.
 *
 * @param idx The index.
 * @param clo Init closure.
 * @param cons Node options updater.
 *
 * @return Raft server instance.
 */
private JraftServerImpl startServer(int idx, Consumer<RaftServer> clo, Consumer<NodeOptions> cons) {
    var addr = new NetworkAddress(getLocalAddress(), PORT);
    ClusterService service = clusterService(PORT + idx, List.of(addr), true);
    NodeOptions opts = new NodeOptions();
    cons.accept(opts);
    JraftServerImpl server = new JraftServerImpl(service, dataPath, opts) {

        @Override
        public void stop() {
            servers.remove(this);
            super.stop();
            service.stop();
        }
    };
    server.start();
    clo.accept(server);
    servers.add(server);
    assertTrue(waitForTopology(service, servers.size(), 15_000));
    return server;
}
Also used : ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl)

Example 22 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ItSimpleCounterServerTest method before.

/**
 * Before each.
 */
@BeforeEach
void before() throws Exception {
    LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
    var addr = new NetworkAddress("localhost", PORT);
    ClusterService service = clusterService(PORT, List.of(addr), true);
    server = new JraftServerImpl(service, dataPath) {

        @Override
        public synchronized void stop() {
            super.stop();
            service.stop();
        }
    };
    server.start();
    ClusterNode serverNode = server.clusterService().topologyService().localMember();
    assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_0, new CounterListener(), List.of(new Peer(serverNode.address()))));
    assertTrue(server.startRaftGroup(COUNTER_GROUP_ID_1, new CounterListener(), List.of(new Peer(serverNode.address()))));
    ClusterService clientNode1 = clusterService(PORT + 1, List.of(addr), true);
    executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
    client1 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_0, clientNode1, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
    ClusterService clientNode2 = clusterService(PORT + 2, List.of(addr), true);
    client2 = RaftGroupServiceImpl.start(COUNTER_GROUP_ID_1, clientNode2, FACTORY, 1000, List.of(new Peer(serverNode.address())), false, 200, executor).get(3, TimeUnit.SECONDS);
    assertTrue(waitForTopology(service, 3, 1000));
    assertTrue(waitForTopology(clientNode1, 3, 1000));
    assertTrue(waitForTopology(clientNode2, 3, 1000));
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) Peer(org.apache.ignite.raft.client.Peer) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class JraftServerImpl method startRaftGroup.

/**
 * {@inheritDoc}
 */
@Override
public synchronized boolean startRaftGroup(String groupId, RaftGroupListener lsnr, @Nullable List<Peer> initialConf) {
    if (groups.containsKey(groupId)) {
        return false;
    }
    // Thread pools are shared by all raft groups.
    NodeOptions nodeOptions = opts.copy();
    Path serverDataPath = getServerDataPath(groupId);
    try {
        Files.createDirectories(serverDataPath);
    } catch (IOException e) {
        throw new IgniteInternalException(e);
    }
    nodeOptions.setLogUri(serverDataPath.resolve("logs").toString());
    nodeOptions.setRaftMetaUri(serverDataPath.resolve("meta").toString());
    nodeOptions.setSnapshotUri(serverDataPath.resolve("snapshot").toString());
    nodeOptions.setFsm(new DelegatingStateMachine(lsnr));
    if (initialConf != null) {
        List<PeerId> mapped = initialConf.stream().map(PeerId::fromPeer).collect(Collectors.toList());
        nodeOptions.setInitialConf(new Configuration(mapped, null));
    }
    IgniteRpcClient client = new IgniteRpcClient(service);
    nodeOptions.setRpcClient(client);
    NetworkAddress addr = service.topologyService().localMember().address();
    var peerId = new PeerId(addr.host(), addr.port(), 0, ElectionPriority.DISABLED);
    var server = new RaftGroupService(groupId, peerId, nodeOptions, rpcServer, nodeManager);
    server.start();
    groups.put(groupId, server);
    return true;
}
Also used : Path(java.nio.file.Path) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) NetworkAddress(org.apache.ignite.network.NetworkAddress) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteRpcClient(org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient) RaftGroupService(org.apache.ignite.raft.jraft.RaftGroupService) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) IOException(java.io.IOException) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 24 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ItAbstractListenerSnapshotTest method startServer.

/**
 * Starts a raft server.
 *
 * @param testInfo Test info.
 * @param idx      Server index (affects port of the server).
 * @return Server.
 */
private JraftServerImpl startServer(TestInfo testInfo, int idx) {
    var addr = new NetworkAddress(getLocalAddress(), PORT);
    ClusterService service = clusterService(testInfo, PORT + idx, addr);
    Path jraft = workDir.resolve("jraft" + idx);
    JraftServerImpl server = new JraftServerImpl(service, jraft) {

        @Override
        public void stop() {
            super.stop();
            service.stop();
        }
    };
    server.start();
    Path listenerPersistencePath = workDir.resolve("db" + idx);
    servers.add(server);
    server.startRaftGroup(raftGroupId(), createListener(service, listenerPersistencePath), INITIAL_CONF);
    return server;
}
Also used : Path(java.nio.file.Path) ClusterService(org.apache.ignite.network.ClusterService) NetworkAddress(org.apache.ignite.network.NetworkAddress) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl)

Example 25 with NetworkAddress

use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.

the class ScaleCubeDirectMarshallerTransport method send.

/**
 * {@inheritDoc}
 */
@Override
public Mono<Void> send(Address address, Message message) {
    var addr = InetSocketAddress.createUnresolved(address.host(), address.port());
    return Mono.fromFuture(() -> {
        NetworkAddress networkAddress = NetworkAddress.from(addr);
        ClusterNode node = topologyService.getByAddress(networkAddress);
        if (node == null) {
            node = new ClusterNode(null, null, networkAddress);
        }
        return messagingService.send(node, fromMessage(message));
    });
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) NetworkAddress(org.apache.ignite.network.NetworkAddress)

Aggregations

NetworkAddress (org.apache.ignite.network.NetworkAddress)32 ClusterService (org.apache.ignite.network.ClusterService)18 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)12 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)11 Peer (org.apache.ignite.raft.client.Peer)11 Test (org.junit.jupiter.api.Test)11 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ClusterNode (org.apache.ignite.network.ClusterNode)8 List (java.util.List)7 ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)6 JraftServerImpl (org.apache.ignite.internal.raft.server.impl.JraftServerImpl)6 TestScaleCubeClusterServiceFactory (org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory)6 Path (java.nio.file.Path)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)5 InternalTableImpl (org.apache.ignite.internal.table.distributed.storage.InternalTableImpl)5 NamedThreadFactory (org.apache.ignite.internal.thread.NamedThreadFactory)5 TxManager (org.apache.ignite.internal.tx.TxManager)5 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)5