Package net.kuujo.copycat

Examples of net.kuujo.copycat.CopycatException


      // If the log is compactable then compact it at the snapshot index.
      try {
        context.log().compact(index, entry);
      } catch (IOException e) {
        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()));
View Full Code Here


        final SnapshotEntry snapshot = createSnapshot();
        if (snapshot != null) {
          try {
            context.log().compact(lastApplied, snapshot);
          } catch (IOException e) {
            throw new CopycatException(e, "Failed to compact log.");
          }
        } else {
          logger().warn("{} - Failed to compact log: no snapshot data provided", context.clusterManager().localNode());
        }
      }
View Full Code Here

    // Find the named operation.
    StateMachineExecutor.Operation operation = context.stateMachineExecutor().getOperation(request.operation());

    // If the operation is unknown the immediately return a failure.
    if (operation == null) {
      future.completeExceptionally(new CopycatException("Invalid operation"));
    }
    // Depending on the operation type, read or write operations may or may not be replicated
    // to a quorum based on configuration options. For write operations, if a quorum is
    // required then the operation will be replicated. For read operations, if a quorum is
    // required then we simply ping a quorum of the cluster to ensure that data is not stale.
View Full Code Here

            try {
              LOGGER.debug("{} calling {} with arguments: {}", stateMachine, method.getName(), args);
              return method.invoke(stateMachine, args.toArray());
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
              throw new CopycatException(e);
            }
          }
        }
      throw new CopycatException("Invalid command");
    }
View Full Code Here

    checkConfiguration();
    return clusterManager.localNode().server().listen().whenComplete((result, error) -> {
      try {
        log.open();
      } catch (Exception e) {
        throw new CopycatException(e);
      }
      transition(FollowerController.class);
      events.start().handle(new StartEvent());
    });
  }
View Full Code Here

    LOGGER.info("{} - Stopping context", clusterManager.localNode());
    return clusterManager.localNode().server().close().whenComplete((result, error) -> {
      try {
        log.close();
      } catch (Exception e) {
        throw new CopycatException(e);
      }
      transition(NoneController.class);
      events.stop().handle(new StopEvent());
    });
  }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public <R> CompletableFuture<R> submit(final String operation, final Object... args) {
    final CompletableFuture<R> future = new CompletableFuture<>();
    if (currentState == null) {
      future.completeExceptionally(new CopycatException("Invalid copycat state"));
      return future;
    }

    currentState.submit(new SubmitRequest(nextCorrelationId(), operation, Arrays.asList(args))).whenComplete((response, error) -> {
      if (error != null) {
View Full Code Here

    // requirement, the future will succeed.
    final Quorum quorum = new Quorum(writeQuorum, succeeded -> {
      if (succeeded) {
        future.complete(index);
      } else {
        future.completeExceptionally(new CopycatException("Failed to obtain quorum"));
      }
    }).countSelf();

    // Iterate through replicas and commit all entries up to the given index.
    for (NodeReplicator replica : replicaMap.values()) {
View Full Code Here

    // contacted the quorum will succeed.
    final Quorum quorum = new Quorum(readQuorum, succeeded -> {
      if (succeeded) {
        future.complete(index);
      } else {
        future.completeExceptionally(new CopycatException("Failed to obtain quorum"));
      }
    }).countSelf();

    // Iterate through replicas and ping each replica. Internally, this
    // should cause the replica to send any remaining entries if necessary.
View Full Code Here

   * Pings the replica.
   */
  synchronized CompletableFuture<Long> ping(long index) {
    if (!open) {
      CompletableFuture<Long> future = new CompletableFuture<>();
      future.completeExceptionally(new CopycatException("Connection not open"));
      return future;
    }

    if (index > matchIndex) {
      return replicate(index);
    }

    CompletableFuture<Long> future = new CompletableFuture<>();
    if (!pingFutures.isEmpty() && pingFutures.lastKey() >= index) {
      return pingFutures.lastEntry().getValue();
    }

    pingFutures.put(index, future);

    PingRequest request = new PingRequest(state.nextCorrelationId(), state.currentTerm(), state.cluster().localMember().id(), index, log.containsEntry(index) ? log.<CopycatEntry>getEntry(index).term() : 0, state.commitIndex());
    LOGGER.debug("{} - Sent {} to {}", state.clusterManager().localNode(), request, node);
    node.client().ping(request).whenComplete((response, error) -> {
      if (error != null) {
        triggerPingFutures(index, error);
      } else {
        LOGGER.debug("{} - Received {} from {}", state.clusterManager().localNode(), response, node);
        if (response.status().equals(Response.Status.OK)) {
          if (response.term() > state.currentTerm()) {
            state.currentTerm(response.term());
            state.currentLeader(null);
            state.transition(FollowerController.class);
            triggerPingFutures(index, new CopycatException("Not the leader"));
          } else if (!response.succeeded()) {
            triggerPingFutures(index, new ProtocolException("Replica not in sync"));
          } else {
            triggerPingFutures(index);
          }
View Full Code Here

TOP

Related Classes of net.kuujo.copycat.CopycatException

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.