Package net.kuujo.copycat.event

Examples of net.kuujo.copycat.event.MembershipChangeEvent


   */
  protected void applyConfig(long index, ConfigurationEntry entry) {
    try {
      logger().debug("{} - Apply configuration change: {}", context.clusterManager().localNode(), entry.cluster());
      context.clusterManager().cluster().update(entry.cluster(), null);
      context.events().membershipChange().handle(new MembershipChangeEvent(entry.cluster().getMembers()));
    } catch (Exception e) {
    } finally {
      context.lastApplied(index);
    }
  }
View Full Code Here


        throw new CopycatException(e, "Failed to compact log.");
      }

      // Set the local cluster configuration according to the snapshot cluster membership.
      context.clusterManager().cluster().update(entry.cluster(), null);
      context.events().membershipChange().handle(new MembershipChangeEvent(entry.cluster().getMembers()));

      // Finally, if necessary, increment the current term.
      context.currentTerm(Math.max(context.currentTerm(), entry.term()));
      context.lastApplied(index);
    }
View Full Code Here

      // Immediately after the entry is appended to the log, apply the joint
      // configuration. Cluster membership changes do not wait for commitment.
      // Since we're using a joint consensus, it's safe to work with all members
      // of both the old and new configuration without causing split elections.
      context.clusterManager().cluster().update(jointConfig, null);
      context.events().membershipChange().handle(new MembershipChangeEvent(jointConfig.getMembers()));
      LOGGER.debug("{} - Updated internal cluster configuration {}", context.clusterManager().localNode(), context.clusterManager().cluster());

      // Once the cluster is updated, the replicator will be notified and update its
      // internal connections. Then we commit the joint configuration and allow
      // it to be replicated to all the nodes in the updated cluster.
      LOGGER.debug("{} - Committing all entries for configuration change", context.clusterManager().localNode());
      replicator.commit(configIndex).whenComplete((commitIndex2, commitError2) -> {
        // Now that we've gotten to this point, we know that the combined cluster
        // membership has been replicated to a majority of the cluster.
        // Append the new user configuration to the log and force all replicas
        // to be synchronized.
        ConfigurationEntry newConfigEntry = new ConfigurationEntry(context.currentTerm(), userConfig);
        long newConfigIndex = context.log().appendEntry(newConfigEntry);
        LOGGER.debug("{} - Appended {} to log at index {}", context.clusterManager().localNode(), newConfigEntry, newConfigIndex);

        // Again, once we've appended the new configuration to the log, update
        // the local internal configuration.
        context.clusterManager().cluster().update(userConfig, null);
        context.events().membershipChange().handle(new MembershipChangeEvent(userConfig.getMembers()));
        LOGGER.debug("{} - Updated internal cluster configuration {}", context.clusterManager().localNode(), context.clusterManager().cluster());

        // Note again that when the cluster membership changes, the replicator will
        // be notified and remove any replicas that are no longer a part of the cluster.
        // Now that the cluster and replicator have been updated, we can commit the
View Full Code Here

TOP

Related Classes of net.kuujo.copycat.event.MembershipChangeEvent

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.