copy cat codes problem

33 views
Skip to first unread message

Terry Tan

unread,
Aug 7, 2016, 2:46:34 AM8/7/16
to raft-dev
Hey ,

anyone can explain for me why copycat do so ,like below , the red part can not garantee thread safety ,which means the log index might be duplicated,
while index is really important in raft ,and can not be duplicated

  /**
   * 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);
    }

Reply all
Reply to author
Forward
0 new messages