Search in sources :

Example 1 with Peer

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

the class ItMetaStorageServiceTest method prepareMetaStorage.

/**
 * Prepares meta storage by instantiating corresponding raft server with {@link MetaStorageListener} and {@link
 * MetaStorageServiceImpl}.
 *
 * @return {@link MetaStorageService} instance.
 */
private MetaStorageService prepareMetaStorage() throws Exception {
    List<Peer> peers = List.of(new Peer(cluster.get(0).topologyService().localMember().address()));
    metaStorageRaftSrv = new RaftServerImpl(cluster.get(0), FACTORY);
    metaStorageRaftSrv.start();
    metaStorageRaftSrv.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
    metaStorageRaftGrpSvc = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(1), FACTORY, 10_000, peers, true, 200, executor).get(3, TimeUnit.SECONDS);
    return new MetaStorageServiceImpl(metaStorageRaftGrpSvc, NODE_ID_0);
}
Also used : RaftServerImpl(org.apache.ignite.internal.raft.server.impl.RaftServerImpl) Peer(org.apache.ignite.raft.client.Peer) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener)

Example 2 with Peer

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

the class ItMetaStorageRaftGroupTest method prepareJraftMetaStorages.

private List<Pair<RaftServer, RaftGroupService>> prepareJraftMetaStorages(AtomicInteger replicatorStartedCounter, AtomicInteger replicatorStoppedCounter) throws InterruptedException, ExecutionException {
    List<Peer> peers = new ArrayList<>();
    cluster.forEach(c -> peers.add(new Peer(c.topologyService().localMember().address())));
    assertTrue(cluster.size() > 1);
    NodeOptions opt1 = new NodeOptions();
    opt1.setReplicationStateListeners(List.of(new UserReplicatorStateListener(replicatorStartedCounter, replicatorStoppedCounter)));
    NodeOptions opt2 = new NodeOptions();
    opt2.setReplicationStateListeners(List.of(new UserReplicatorStateListener(replicatorStartedCounter, replicatorStoppedCounter)));
    NodeOptions opt3 = new NodeOptions();
    opt3.setReplicationStateListeners(List.of(new UserReplicatorStateListener(replicatorStartedCounter, replicatorStoppedCounter)));
    metaStorageRaftSrv1 = new JraftServerImpl(cluster.get(0), dataPath, opt1);
    metaStorageRaftSrv2 = new JraftServerImpl(cluster.get(1), dataPath, opt2);
    metaStorageRaftSrv3 = new JraftServerImpl(cluster.get(2), dataPath, opt3);
    metaStorageRaftSrv1.start();
    metaStorageRaftSrv2.start();
    metaStorageRaftSrv3.start();
    metaStorageRaftSrv1.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
    metaStorageRaftSrv2.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
    metaStorageRaftSrv3.startRaftGroup(METASTORAGE_RAFT_GROUP_NAME, new MetaStorageListener(mockStorage), peers);
    metaStorageRaftGrpSvc1 = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(0), FACTORY, 10_000, peers, true, 200, executor).get();
    metaStorageRaftGrpSvc2 = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(1), FACTORY, 10_000, peers, true, 200, executor).get();
    metaStorageRaftGrpSvc3 = RaftGroupServiceImpl.start(METASTORAGE_RAFT_GROUP_NAME, cluster.get(2), FACTORY, 10_000, peers, true, 200, executor).get();
    assertTrue(TestUtils.waitForCondition(() -> sameLeaders(metaStorageRaftGrpSvc1, metaStorageRaftGrpSvc2, metaStorageRaftGrpSvc3), 10_000), "Leaders: " + metaStorageRaftGrpSvc1.leader() + " " + metaStorageRaftGrpSvc2.leader() + " " + metaStorageRaftGrpSvc3.leader());
    List<Pair<RaftServer, RaftGroupService>> raftServersRaftGroups = new ArrayList<>();
    raftServersRaftGroups.add(new Pair<>(metaStorageRaftSrv1, metaStorageRaftGrpSvc1));
    raftServersRaftGroups.add(new Pair<>(metaStorageRaftSrv2, metaStorageRaftGrpSvc2));
    raftServersRaftGroups.add(new Pair<>(metaStorageRaftSrv3, metaStorageRaftGrpSvc3));
    return raftServersRaftGroups;
}
Also used : Peer(org.apache.ignite.raft.client.Peer) ArrayList(java.util.ArrayList) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) JraftServerImpl(org.apache.ignite.internal.raft.server.impl.JraftServerImpl) MetaStorageListener(org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener)

Example 3 with Peer

use of org.apache.ignite.raft.client.Peer 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 4 with Peer

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

the class ItTxDistributedTestSingleNode method getLeader.

/**
 * Returns a raft manager for a group.
 *
 * @param svc The service.
 * @return Raft manager hosting a leader for group.
 */
protected Loza getLeader(RaftGroupService svc) {
    Peer leader = svc.leader();
    assertNotNull(leader);
    return raftServers.get(svc.clusterService().topologyService().getByAddress(leader.address()));
}
Also used : Peer(org.apache.ignite.raft.client.Peer)

Example 5 with Peer

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

the class RaftGroupServiceImpl method addLearners.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<Void> addLearners(List<Peer> learners) {
    Peer leader = this.leader;
    if (leader == null)
        return refreshLeader().thenCompose(res -> addLearners(learners));
    List<String> lrns = learners.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
    AddLearnersRequest req = factory.addLearnersRequest().groupId(groupId).learnersList(lrns).build();
    CompletableFuture<LearnersOpResponse> fut = new CompletableFuture<>();
    sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
    return fut.thenApply(resp -> {
        this.learners = parsePeerList(resp.newLearnersList());
        return null;
    });
}
Also used : System.currentTimeMillis(java.lang.System.currentTimeMillis) IgniteException(org.apache.ignite.lang.IgniteException) AddPeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerRequest) S(org.apache.ignite.internal.tostring.S) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) AddPeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerResponse) TransferLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.TransferLeaderRequest) ArrayList(java.util.ArrayList) GetLeaderResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderResponse) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) RemoveLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemoveLearnersRequest) ResetLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest) RemovePeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerRequest) ActionResponse(org.apache.ignite.raft.jraft.rpc.ActionResponse) ChangePeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersResponse) ThreadLocalRandom.current(java.util.concurrent.ThreadLocalRandom.current) Collection(java.util.Collection) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) GetLeaderRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetLeaderRequest) NetworkMessage(org.apache.ignite.network.NetworkMessage) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Command(org.apache.ignite.raft.client.Command) ActionRequest(org.apache.ignite.raft.jraft.rpc.ActionRequest) GetPeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersRequest) NetworkAddress(org.apache.ignite.network.NetworkAddress) ReadCommand(org.apache.ignite.raft.client.ReadCommand) GetPeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.GetPeersResponse) TimeUnit(java.util.concurrent.TimeUnit) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) List(java.util.List) Peer(org.apache.ignite.raft.client.Peer) RemovePeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerResponse) SnapshotRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest) ClusterService(org.apache.ignite.network.ClusterService) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) ChangePeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersRequest) AddLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest) RaftError(org.apache.ignite.raft.jraft.error.RaftError) CompletableFuture(java.util.concurrent.CompletableFuture) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) Peer(org.apache.ignite.raft.client.Peer) AddLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest)

Aggregations

Peer (org.apache.ignite.raft.client.Peer)33 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)25 NetworkAddress (org.apache.ignite.network.NetworkAddress)17 ClusterService (org.apache.ignite.network.ClusterService)14 TimeoutException (java.util.concurrent.TimeoutException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 List (java.util.List)12 NotNull (org.jetbrains.annotations.NotNull)11 Collection (java.util.Collection)10 Collections (java.util.Collections)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)10 TimeUnit (java.util.concurrent.TimeUnit)10 Collectors (java.util.stream.Collectors)10 IgniteException (org.apache.ignite.lang.IgniteException)10 IgniteLogger (org.apache.ignite.lang.IgniteLogger)10 ReadCommand (org.apache.ignite.raft.client.ReadCommand)10 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)10 Test (org.junit.jupiter.api.Test)10