Package net.kuujo.copycat.internal.log

Examples of net.kuujo.copycat.internal.log.CopycatEntry


    }).countSelf();

    // First, load the last log entry to get its term. We load the entry
    // by its index since the index is required by the protocol.
    final long lastIndex = context.log().lastIndex();
    CopycatEntry lastEntry = context.log().getEntry(lastIndex);

    // Once we got the last log term, iterate through each current member
    // of the cluster and poll each member for a vote.
    LOGGER.info("{} - Polling members {}", context.clusterManager().localNode(), context.clusterManager().cluster().remoteMembers());
    final long lastTerm = lastEntry != null ? lastEntry.term() : 0;
    for (RemoteNode<?> node : (Set<RemoteNode<?>>) context.clusterManager().remoteNodes()) {
      final ProtocolClient client = node.client();
      client.connect().whenComplete((result1, error1) -> {
        if (error1 != null) {
          quorum.fail();
View Full Code Here


    // If the last log entry's term is not the same as the given
    // prevLogTerm then return false. This will cause the leader to
    // decrement this node's nextIndex and ultimately retry with the
    // leader's previous log entry so that the inconsistent entry
    // can be overwritten.
    CopycatEntry entry = context.log().getEntry(request.logIndex());
    if (entry == null) {
      logger().warn("{} - Rejected {}: request entry not found in local log", context.clusterManager().localNode(), request);
      return new PingResponse(request.id(), context.currentTerm(), false);
    } else if (entry.term() != request.logTerm()) {
      logger().warn("{} - Rejected {}: request entry term does not match local log", context.clusterManager().localNode(), request);
      return new PingResponse(request.id(), context.currentTerm(), false);
    } else {
      doApplyCommits(request.commitIndex());
      return new PingResponse(request.id(), context.currentTerm(), true);
View Full Code Here

    // If the last log entry's term is not the same as the given
    // prevLogTerm then return false. This will cause the leader to
    // decrement this node's nextIndex and ultimately retry with the
    // leader's previous log entry so that the inconsistent entry
    // can be overwritten.
    CopycatEntry entry = context.log().getEntry(request.prevLogIndex());
    if (entry == null) {
      logger().warn("{} - Rejected {}: request entry not found in local log", context.clusterManager().localNode(), request);
      return new SyncResponse(request.id(), context.currentTerm(), false, context.log().lastIndex());
    } else if (entry.term() != request.prevLogTerm()) {
      logger().warn("{} - Rejected {}: request entry term does not match local log", context.clusterManager().localNode(), request);
      return new SyncResponse(request.id(), context.currentTerm(), false, context.log().lastIndex());
    } else {
      return doAppendEntries(request);
    }
View Full Code Here

          // since snapshots are only taken of committed state machine state. This will cause all previous
          // entries to be removed from the log.
          if (entry instanceof SnapshotEntry) {
            installSnapshot(index, (SnapshotEntry) entry);
          } else {
            CopycatEntry match = context.log().getEntry(index);
            if (match != null) {
              if (entry.term() != match.term()) {
                logger().warn("{} - Synced entry does not match local log, removing incorrect entries", context.clusterManager().localNode());
                context.log().removeAfter(index - 1);
                context.log().appendEntry(entry);
                logger().debug("{} - Appended {} to log at index {}", context.clusterManager().localNode(), entry, index);
              }
View Full Code Here

      } else {
        // Otherwise, load the last entry in the log. The last entry should be
        // at least as up to date as the candidates entry and term.
        synchronized (context.log()) {
          long lastIndex = context.log().lastIndex();
          CopycatEntry entry = context.log().getEntry(lastIndex);
          if (entry == null) {
            context.lastVotedFor(request.candidate());
            context.events()
              .voteCast()
              .handle(new VoteCastEvent(context.currentTerm(), context.clusterManager()
                .node(request.candidate())
                .member()));
            logger().debug("{} - Accepted {}: candidate's log is up-to-date", context.clusterManager().localNode(), request);
            return new PollResponse(request.id(), context.currentTerm(), true);
          }

          long lastTerm = entry.term();
          if (request.lastLogIndex() >= lastIndex) {
            if (request.lastLogTerm() >= lastTerm) {
              context.lastVotedFor(request.candidate());
              context.events()
                .voteCast()
View Full Code Here

  /**
   * Performs a commit operation.
   */
  private synchronized void replicate() {
    final long prevIndex = sendIndex - 1;
    final CopycatEntry prevEntry = log.getEntry(prevIndex);

    // Create a list of up to ten entries to send to the follower.
    // We can only send one snapshot entry in any given request. So, if any of
    // the entries are snapshot entries, send all entries up to the snapshot and
    // then send snapshot entries individually.
    List<CopycatEntry> entries = new ArrayList<>(BATCH_SIZE);
    long lastIndex = Math.min(sendIndex + BATCH_SIZE - 1, log.lastIndex());
    for (long i = sendIndex; i <= lastIndex; i++) {
      CopycatEntry entry = log.getEntry(i);
      if (entry instanceof SnapshotEntry) {
        if (entries.isEmpty()) {
          doSync(prevIndex, prevEntry, Collections.singletonList(entry));
        } else {
          doSync(prevIndex, prevEntry, entries);
View Full Code Here

TOP

Related Classes of net.kuujo.copycat.internal.log.CopycatEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.