use of org.apache.ratis.protocol.RaftPeerId in project incubator-ratis by apache.
the class TestPeerProxyMap method testCloseDeadLock.
@Test(timeout = 10_000)
public void testCloseDeadLock() throws Exception {
final PeerProxyMap<DummyProxy> map = new PeerProxyMap<>("test", DummyProxy::new);
final RaftPeerId id = RaftPeerId.valueOf("s0");
final RaftPeer peer = RaftPeer.newBuilder().setId(id).build();
map.computeIfAbsent(peer);
final DummyProxy proxy = map.getProxy(id);
final Thread t = new Thread(() -> {
// hold proxy lock and then getProxy(..) which requires resetLock
synchronized (proxy) {
LOG.info("Acquired lock");
try {
HUNDRED_MILLIS.sleep();
LOG.info("Try getProxy");
final DummyProxy newProxy = map.getProxy(id);
Assert.assertNotSame(proxy, newProxy);
} catch (Exception e) {
setFirstException(e);
}
LOG.info("Will release lock");
}
});
t.start();
// hold resetLock and then call close() with requires proxy lock
map.resetProxy(id);
t.join();
}
use of org.apache.ratis.protocol.RaftPeerId in project incubator-ratis by apache.
the class Server method run.
@Override
public void run() throws Exception {
RaftPeerId peerId = RaftPeerId.valueOf(id);
RaftProperties properties = new RaftProperties();
final int port = NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort();
GrpcConfigKeys.Server.setPort(properties, port);
Optional.ofNullable(getPeer(peerId).getClientAddress()).ifPresent(address -> GrpcConfigKeys.Client.setPort(properties, NetUtils.createSocketAddr(address).getPort()));
Optional.ofNullable(getPeer(peerId).getAdminAddress()).ifPresent(address -> GrpcConfigKeys.Admin.setPort(properties, NetUtils.createSocketAddr(address).getPort()));
RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir));
StateMachine stateMachine = new ArithmeticStateMachine();
final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers());
RaftServer raftServer = RaftServer.newBuilder().setServerId(RaftPeerId.valueOf(id)).setStateMachine(stateMachine).setProperties(properties).setGroup(raftGroup).build();
raftServer.start();
for (; raftServer.getLifeCycleState() != LifeCycle.State.CLOSED; ) {
TimeUnit.SECONDS.sleep(1);
}
}
use of org.apache.ratis.protocol.RaftPeerId in project incubator-ratis by apache.
the class LeaderStateImpl method newAppendEntriesRequestProto.
@Override
public AppendEntriesRequestProto newAppendEntriesRequestProto(FollowerInfo follower, List<LogEntryProto> entries, TermIndex previous, long callId) {
final boolean initializing = isAttendingVote(follower);
final RaftPeerId targetId = follower.getPeer().getId();
return ServerProtoUtils.toAppendEntriesRequestProto(server.getMemberId(), targetId, currentTerm, entries, ServerImplUtils.effectiveCommitIndex(raftLog.getLastCommittedIndex(), previous, entries.size()), initializing, previous, server.getCommitInfos(), callId);
}
use of org.apache.ratis.protocol.RaftPeerId in project incubator-ratis by apache.
the class LeaderStateImpl method getMajorityMin.
private Optional<MinMajorityMax> getMajorityMin(ToLongFunction<FollowerInfo> followerIndex, LongSupplier logIndex, long gapThreshold) {
final RaftPeerId selfId = server.getId();
final RaftConfigurationImpl conf = server.getRaftConf();
final List<RaftPeerId> followers = voterLists.get(0);
final boolean includeSelf = conf.containsInConf(selfId);
if (followers.isEmpty() && !includeSelf) {
return Optional.empty();
}
final long[] indicesInNewConf = getSorted(followers, includeSelf, followerIndex, logIndex);
final MinMajorityMax newConf = MinMajorityMax.valueOf(indicesInNewConf, gapThreshold);
if (!conf.isTransitional()) {
return Optional.of(newConf);
} else {
// configuration is in transitional state
final List<RaftPeerId> oldFollowers = voterLists.get(1);
final boolean includeSelfInOldConf = conf.containsInOldConf(selfId);
if (oldFollowers.isEmpty() && !includeSelfInOldConf) {
return Optional.empty();
}
final long[] indicesInOldConf = getSorted(oldFollowers, includeSelfInOldConf, followerIndex, logIndex);
final MinMajorityMax oldConf = MinMajorityMax.valueOf(indicesInOldConf, followerMaxGapThreshold);
return Optional.of(newConf.combine(oldConf));
}
}
use of org.apache.ratis.protocol.RaftPeerId in project incubator-ratis by apache.
the class LeaderStateImpl method checkHealth.
@Override
public void checkHealth(FollowerInfo follower) {
final TimeDuration elapsedTime = follower.getLastRpcResponseTime().elapsedTime();
if (elapsedTime.compareTo(server.properties().rpcSlownessTimeout()) > 0) {
server.getStateMachine().leaderEvent().notifyFollowerSlowness(server.getInfo().getRoleInfoProto());
}
final RaftPeerId followerId = follower.getPeer().getId();
raftServerMetrics.recordFollowerHeartbeatElapsedTime(followerId, elapsedTime.toLong(TimeUnit.NANOSECONDS));
}
Aggregations