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();
}
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations