Search in sources :

Example 16 with Configuration

use of org.apache.ignite.raft.jraft.conf.Configuration in project ignite-3 by apache.

the class NodeImpl method addPeer.

@Override
public void addPeer(final PeerId peer, final Closure done) {
    Requires.requireNonNull(peer, "Null peer");
    this.writeLock.lock();
    try {
        Requires.requireTrue(!this.conf.getConf().contains(peer), "Peer already exists in current configuration");
        final Configuration newConf = new Configuration(this.conf.getConf());
        newConf.addPeer(peer);
        unsafeRegisterConfChange(this.conf.getConf(), newConf, done);
    } finally {
        this.writeLock.unlock();
    }
}
Also used : Configuration(org.apache.ignite.raft.jraft.conf.Configuration)

Example 17 with Configuration

use of org.apache.ignite.raft.jraft.conf.Configuration in project ignite-3 by apache.

the class ResetPeerRequestProcessor method processRequest0.

@Override
protected Message processRequest0(final CliRequestContext ctx, final ResetPeerRequest request, final IgniteCliRpcRequestClosure done) {
    final Configuration newConf = new Configuration();
    for (final String peerIdStr : request.newPeersList()) {
        final PeerId peer = new PeerId();
        if (peer.parse(peerIdStr)) {
            newConf.addPeer(peer);
        } else {
            return // 
            RaftRpcFactory.DEFAULT.newResponse(msgFactory(), RaftError.EINVAL, "Fail to parse peer id %s", peerIdStr);
        }
    }
    LOG.info("Receive ResetPeerRequest to {} from {}, new conf is {}", ctx.node.getNodeId(), done.getRpcCtx().getRemoteAddress(), newConf);
    final Status st = ctx.node.resetPeers(newConf);
    return // 
    RaftRpcFactory.DEFAULT.newResponse(msgFactory(), st);
}
Also used : Status(org.apache.ignite.raft.jraft.Status) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 18 with Configuration

use of org.apache.ignite.raft.jraft.conf.Configuration in project ignite-3 by apache.

the class ReplicatorGroupTest method testFindTheNextCandidateWithPriority1.

@Test
public void testFindTheNextCandidateWithPriority1() {
    final PeerId p1 = new PeerId("localhost", 18881, 0, 60);
    final PeerId p2 = new PeerId("localhost", 18882, 0, 80);
    final PeerId p3 = new PeerId("localhost", 18883, 0, 100);
    Mockito.when(this.rpcService.connect(p1.getEndpoint())).thenReturn(true);
    Mockito.when(this.rpcService.connect(p2.getEndpoint())).thenReturn(true);
    Mockito.when(this.rpcService.connect(p3.getEndpoint())).thenReturn(true);
    this.replicatorGroup.resetTerm(1);
    this.replicatorGroup.addReplicator(p1);
    this.replicatorGroup.addReplicator(p2);
    this.replicatorGroup.addReplicator(p3);
    final ConfigurationEntry conf = new ConfigurationEntry();
    conf.setConf(new Configuration(Arrays.asList(p1, p2, p3)));
    final PeerId p = this.replicatorGroup.findTheNextCandidate(conf);
    assertEquals(p3, p);
}
Also used : Configuration(org.apache.ignite.raft.jraft.conf.Configuration) ConfigurationEntry(org.apache.ignite.raft.jraft.conf.ConfigurationEntry) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 19 with Configuration

use of org.apache.ignite.raft.jraft.conf.Configuration in project ignite-3 by apache.

the class ReplicatorGroupTest method testFindTheNextCandidateWithPriority2.

@Test
public void testFindTheNextCandidateWithPriority2() {
    final PeerId p1 = new PeerId("localhost", 18881, 0, 0);
    final PeerId p2 = new PeerId("localhost", 18882, 0, 0);
    final PeerId p3 = new PeerId("localhost", 18883, 0, -1);
    Mockito.when(this.rpcService.connect(p1.getEndpoint())).thenReturn(true);
    Mockito.when(this.rpcService.connect(p2.getEndpoint())).thenReturn(true);
    Mockito.when(this.rpcService.connect(p3.getEndpoint())).thenReturn(true);
    this.replicatorGroup.resetTerm(1);
    this.replicatorGroup.addReplicator(p1);
    this.replicatorGroup.addReplicator(p2);
    this.replicatorGroup.addReplicator(p3);
    final ConfigurationEntry conf = new ConfigurationEntry();
    conf.setConf(new Configuration(Arrays.asList(p1, p2, p3)));
    final PeerId p = this.replicatorGroup.findTheNextCandidate(conf);
    assertEquals(p3, p);
}
Also used : Configuration(org.apache.ignite.raft.jraft.conf.Configuration) ConfigurationEntry(org.apache.ignite.raft.jraft.conf.ConfigurationEntry) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 20 with Configuration

use of org.apache.ignite.raft.jraft.conf.Configuration in project ignite-3 by apache.

the class LogManagerImpl method setSnapshot.

@Override
public void setSnapshot(final SnapshotMeta meta) {
    LOG.debug("set snapshot: {}.", meta);
    this.writeLock.lock();
    try {
        if (meta.lastIncludedIndex() <= this.lastSnapshotId.getIndex()) {
            return;
        }
        final Configuration conf = confFromMeta(meta);
        final Configuration oldConf = oldConfFromMeta(meta);
        final ConfigurationEntry entry = new ConfigurationEntry(new LogId(meta.lastIncludedIndex(), meta.lastIncludedTerm()), conf, oldConf);
        this.configManager.setSnapshot(entry);
        final long term = unsafeGetTerm(meta.lastIncludedIndex());
        final long savedLastSnapshotIndex = this.lastSnapshotId.getIndex();
        this.lastSnapshotId.setIndex(meta.lastIncludedIndex());
        this.lastSnapshotId.setTerm(meta.lastIncludedTerm());
        if (this.lastSnapshotId.compareTo(this.appliedId) > 0) {
            this.appliedId = this.lastSnapshotId.copy();
        }
        if (term == 0) {
            // last_included_index is larger than last_index
            // FIXME: what if last_included_index is less than first_index?
            truncatePrefix(meta.lastIncludedIndex() + 1);
        } else if (term == meta.lastIncludedTerm()) {
            // TODO if there are still be need? TODO asch
            if (savedLastSnapshotIndex > 0) {
                truncatePrefix(savedLastSnapshotIndex + 1);
            }
        } else {
            if (!reset(meta.lastIncludedIndex() + 1)) {
                LOG.warn("Reset log manager failed, nextLogIndex={}.", meta.lastIncludedIndex() + 1);
            }
        }
    } finally {
        this.writeLock.unlock();
    }
}
Also used : Configuration(org.apache.ignite.raft.jraft.conf.Configuration) ConfigurationEntry(org.apache.ignite.raft.jraft.conf.ConfigurationEntry) LogId(org.apache.ignite.raft.jraft.entity.LogId)

Aggregations

Configuration (org.apache.ignite.raft.jraft.conf.Configuration)45 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)37 Test (org.junit.jupiter.api.Test)20 Node (org.apache.ignite.raft.jraft.Node)17 Status (org.apache.ignite.raft.jraft.Status)16 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)13 ArrayList (java.util.ArrayList)9 RaftGroupService (org.apache.ignite.raft.jraft.RaftGroupService)9 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)9 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)8 CountDownLatch (java.util.concurrent.CountDownLatch)5 ExecutorService (java.util.concurrent.ExecutorService)5 NetworkAddress (org.apache.ignite.network.NetworkAddress)5 ConfigurationEntry (org.apache.ignite.raft.jraft.conf.ConfigurationEntry)5 LogId (org.apache.ignite.raft.jraft.entity.LogId)5 Task (org.apache.ignite.raft.jraft.entity.Task)5 IgniteRpcClient (org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcClient)5 HashMap (java.util.HashMap)4 ClusterService (org.apache.ignite.network.ClusterService)4 StaticNodeFinder (org.apache.ignite.network.StaticNodeFinder)4