Thank you for your reply , i found another problem that is you have got code like below, the read part is not sychronized ,let's say if two clients doing operation, it may have got the same index ,how do you deal with this thing?
/**
* Applies the given command to the log.
*/
private void applyCommand(CommandRequest request, ServerSessionContext session, CompletableFuture<CommandResponse> future) {
final Command command = request.command();
final long term = context.getTerm();
final long timestamp = System.currentTimeMillis();
final long index;
// Create a CommandEntry and append it to the log.
try (CommandEntry entry = context.getLog().create(CommandEntry.class)) {
entry.setTerm(term)
.setSession(request.session())
.setTimestamp(timestamp)
.setSequence(request.sequence())
.setCommand(command);
index = context.getLog().append(entry);
LOGGER.debug("{} - Appended {} to log at index {}", context.getCluster().member().address(), entry, index);
}
// Replicate the command to followers.