Beispiel #1
0
  private void handleReadyLocalTransaction(final ReadyLocalTransaction message) {
    LOG.debug(
        "{}: handleReadyLocalTransaction for {}", persistenceId(), message.getTransactionID());

    boolean isLeaderActive = isLeaderActive();
    if (isLeader() && isLeaderActive) {
      try {
        commitCoordinator.handleReadyLocalTransaction(message, getSender(), this);
      } catch (Exception e) {
        LOG.error(
            "{}: Error handling ReadyLocalTransaction for Tx {}",
            persistenceId(),
            message.getTransactionID(),
            e);
        getSender().tell(new akka.actor.Status.Failure(e), getSelf());
      }
    } else {
      ActorSelection leader = getLeader();
      if (!isLeaderActive || leader == null) {
        messageRetrySupport.addMessageToRetry(
            message, getSender(), "Could not commit transaction " + message.getTransactionID());
      } else {
        LOG.debug("{}: Forwarding ReadyLocalTransaction to leader {}", persistenceId(), leader);
        message.setRemoteVersion(getCurrentBehavior().getLeaderPayloadVersion());
        leader.forward(message, getContext());
      }
    }
  }
Beispiel #2
0
  private void handleForwardedReadyTransaction(ForwardedReadyTransaction forwardedReady) {
    LOG.debug(
        "{}: handleForwardedReadyTransaction for {}",
        persistenceId(),
        forwardedReady.getTransactionID());

    boolean isLeaderActive = isLeaderActive();
    if (isLeader() && isLeaderActive) {
      commitCoordinator.handleForwardedReadyTransaction(forwardedReady, getSender(), this);
    } else {
      ActorSelection leader = getLeader();
      if (!isLeaderActive || leader == null) {
        messageRetrySupport.addMessageToRetry(
            forwardedReady,
            getSender(),
            "Could not commit transaction " + forwardedReady.getTransactionID());
      } else {
        LOG.debug("{}: Forwarding ForwardedReadyTransaction to leader {}", persistenceId(), leader);

        ReadyLocalTransaction readyLocal =
            new ReadyLocalTransaction(
                forwardedReady.getTransactionID(),
                forwardedReady.getTransaction().getSnapshot(),
                forwardedReady.isDoImmediateCommit());
        readyLocal.setRemoteVersion(getCurrentBehavior().getLeaderPayloadVersion());
        leader.forward(readyLocal, getContext());
      }
    }
  }
Beispiel #3
0
  private void handleBatchedModifications(BatchedModifications batched) {
    // This message is sent to prepare the modifications transaction directly on the Shard as an
    // optimization to avoid the extra overhead of a separate ShardTransaction actor. On the last
    // BatchedModifications message, the caller sets the ready flag in the message indicating
    // modifications are complete. The reply contains the cohort actor path (this actor) for the
    // caller
    // to initiate the 3-phase commit. This also avoids the overhead of sending an additional
    // ReadyTransaction message.

    // If we're not the leader then forward to the leader. This is a safety measure - we shouldn't
    // normally get here if we're not the leader as the front-end (TransactionProxy) should
    // determine
    // the primary/leader shard. However with timing and caching on the front-end, there's a small
    // window where it could have a stale leader during leadership transitions.
    //
    boolean isLeaderActive = isLeaderActive();
    if (isLeader() && isLeaderActive) {
      handleBatchedModificationsLocal(batched, getSender());
    } else {
      ActorSelection leader = getLeader();
      if (!isLeaderActive || leader == null) {
        messageRetrySupport.addMessageToRetry(
            batched, getSender(), "Could not commit transaction " + batched.getTransactionID());
      } else {
        // TODO: what if this is not the first batch and leadership changed in between batched
        // messages?
        // We could check if the commitCoordinator already has a cached entry and forward all the
        // previous
        // batched modifications.
        LOG.debug("{}: Forwarding BatchedModifications to leader {}", persistenceId(), leader);
        leader.forward(batched, getContext());
      }
    }
  }