| 193 | private final HashMap<Long, Long> appendingLogMap = new HashMap<>(); // <index, serial> |
| 194 | |
| 195 | public Raft(final @NotNull Env env, final int raftCount, final int selfId, final long curTime) { |
| 196 | if (raftCount < 2 || raftCount > 127) |
| 197 | throw new IllegalArgumentException("raftCount=" + raftCount + " is not in [2,127]"); |
| 198 | if (selfId < 0 || selfId >= raftCount) |
| 199 | throw new IllegalArgumentException("selfId=" + selfId + " is not in [0," + raftCount + ')'); |
| 200 | this.env = env; |
| 201 | this.raftCount = (byte)raftCount; |
| 202 | this.selfId = (byte)selfId; |
| 203 | timeout = curTime + env.random(RANDOM_TIMEOUT_MAX); |
| 204 | nextIndexes = new long[raftCount]; |
| 205 | appendingTimeouts = new long[raftCount]; |
| 206 | if (ENABLE_TRACE) |
| 207 | env.traceInfo("started: timeout=" + timeout); |
| 208 | } |
| 209 | |
| 210 | public int getLeaderId() { |
| 211 | return leaderId; |