private NotCurrentLeaderException notCurrentLeaderException(String message, @Nullable Throwable cause) { Optional<HostAndPort> maybeLeader = leaderElectionService.getSuspectedLeaderInMemory(); if (maybeLeader.isPresent()) { HostAndPort leaderHint = maybeLeader.get(); return new NotCurrentLeaderException(message + "; hinting suspected leader host " + leaderHint, cause, leaderHint); } else { return new NotCurrentLeaderException(message, cause); } }
@VisibleForTesting LeadershipToken getLeadershipToken() { LeadershipToken leadershipToken = leadershipTokenRef.get(); if (leadershipToken == null) { NotCurrentLeaderException notCurrentLeaderException = notCurrentLeaderException( "method invoked on a non-leader"); if (notCurrentLeaderException.getServiceHint().isPresent()) { // There's a chance that we can gain leadership while generating this exception. // In this case, we should be able to get a leadership token after all leadershipToken = leadershipTokenRef.get(); // If leadershipToken is still null, then someone's the leader, but it isn't us. } if (leadershipToken == null) { throw notCurrentLeaderException; } } return leadershipToken; }
public void failAllOutstandingRequestsWithNotCurrentLeaderException() { NotCurrentLeaderException ex = new NotCurrentLeaderException("This lock service has been closed"); heldLocksById.values().forEach(result -> result.failIfNotCompleted(ex)); }
@VisibleForTesting LeadershipToken getLeadershipToken() { LeadershipToken leadershipToken = leadershipTokenRef.get(); if (leadershipToken == null) { NotCurrentLeaderException notCurrentLeaderException = notCurrentLeaderException( "method invoked on a non-leader"); if (notCurrentLeaderException.getServiceHint().isPresent()) { // There's a chance that we can gain leadership while generating this exception. // In this case, we should be able to get a leadership token after all leadershipToken = leadershipTokenRef.get(); // If leadershipToken is still null, then someone's the leader, but it isn't us. } if (leadershipToken == null) { throw notCurrentLeaderException; } } return leadershipToken; }
@Test public void throwsDependencyUnavailableWhenDelegateIsNotCurrentLeader() { Throwable cause = new NotCurrentLeaderException("No TimeLock node appears to be the leader"); assertDependencyUnavailableIsThrownWhenWeCatch(cause); }
/** * Checks that the PaxosValue agreed upon by a quorum of nodes in our cluster was proposed by us. * * @param limit the limit our node has proposed * @param newSeq the sequence number for which our node has proposed the limit * @param value PaxosValue agreed upon by a quorum of nodes, for sequence number newSeq * @throws NotCurrentLeaderException if the agreed timestamp bound (PaxosValue) changed under us */ private void checkAgreedBoundIsOurs(long limit, long newSeq, PaxosValue value) throws NotCurrentLeaderException { if (!value.getLeaderUUID().equals(proposer.getUuid())) { String errorMsg = String.format( "Timestamp limit changed from under us for sequence '%s' (proposer with UUID '%s' changed" + " it, our UUID is '%s'). This suggests that we have lost leadership, and another timelock" + " server has gained leadership and updated the timestamp bound." + " The offending bound was '%s'; we tried to propose" + " a bound of '%s'. (The offending Paxos value was '%s'.)", newSeq, value.getLeaderUUID(), proposer.getUuid(), PtBytes.toLong(value.getData()), limit, value); throw new NotCurrentLeaderException(errorMsg); } DebugLogger.logger.info("Trying to store limit '{}' for sequence '{}' yielded consensus on the value '{}'.", SafeArg.of("limit", limit), SafeArg.of("paxosSequenceNumber", newSeq), SafeArg.of("paxosValue", value)); }
SafeArg.of("newLimit", newLimit), SafeArg.of("target", limit)); throw new NotCurrentLeaderException(String.format( "We updated the timestamp limit to %s, which was less than our target %s.", newLimit,
private NotCurrentLeaderException notCurrentLeaderException(String message, @Nullable Throwable cause) { Optional<HostAndPort> maybeLeader = leaderElectionService.getSuspectedLeaderInMemory(); if (maybeLeader.isPresent()) { HostAndPort leaderHint = maybeLeader.get(); return new NotCurrentLeaderException(message + "; hinting suspected leader host " + leaderHint, cause, leaderHint); } else { return new NotCurrentLeaderException(message, cause); } }
public void failAllOutstandingRequestsWithNotCurrentLeaderException() { NotCurrentLeaderException ex = new NotCurrentLeaderException("This lock service has been closed"); heldLocksById.values().forEach(result -> result.failIfNotCompleted(ex)); }
/** * Checks that the PaxosValue agreed upon by a quorum of nodes in our cluster was proposed by us. * * @param limit the limit our node has proposed * @param newSeq the sequence number for which our node has proposed the limit * @param value PaxosValue agreed upon by a quorum of nodes, for sequence number newSeq * @throws NotCurrentLeaderException if the agreed timestamp bound (PaxosValue) changed under us */ private void checkAgreedBoundIsOurs(long limit, long newSeq, PaxosValue value) throws NotCurrentLeaderException { if (!value.getLeaderUUID().equals(proposer.getUuid())) { String errorMsg = String.format( "Timestamp limit changed from under us for sequence '%s' (proposer with UUID '%s' changed" + " it, our UUID is '%s'). This suggests that we have lost leadership, and another timelock" + " server has gained leadership and updated the timestamp bound." + " The offending bound was '%s'; we tried to propose" + " a bound of '%s'. (The offending Paxos value was '%s'.)", newSeq, value.getLeaderUUID(), proposer.getUuid(), PtBytes.toLong(value.getData()), limit, value); throw new NotCurrentLeaderException(errorMsg); } DebugLogger.logger.info("Trying to store limit '{}' for sequence '{}' yielded consensus on the value '{}'.", SafeArg.of("limit", limit), SafeArg.of("paxosSequenceNumber", newSeq), SafeArg.of("paxosValue", value)); }
SafeArg.of("newLimit", newLimit), SafeArg.of("target", limit)); throw new NotCurrentLeaderException(String.format( "We updated the timestamp limit to %s, which was less than our target %s.", newLimit,