public String getNodeState() { if (_state.get() != State.OPEN) { return ReplicatedEnvironment.State.UNKNOWN.name(); } try { ReplicatedEnvironment.State state = getEnvironment().getState(); return state.toString(); } catch (RuntimeException e) { throw handleDatabaseException("Cannot get environment state", e); } }
if ((envImpl == null) || !((RepImpl) envImpl).getState().isActive()) {
("Parameter 'replicas' cannot be null or empty"); if (!nodeState.getRepEnvState().isMaster()) { throw new IllegalStateException("Not currently master");
return (state != null) && state.isMaster(); } catch (Exception e) { LoggerUtils.info(logger, repImpl,
(nodeState.getRepEnvState().isMaster())) {
if (nodeState.getRepEnvState().isDetached()) { nodeState.changeAndNotify(UNKNOWN, NameIdPair.NULL);
if ((updates == 0) || ! repEnv.getState().isMaster()) { return;
return (state != null) && state.isMaster(); } catch (Exception e) { LoggerUtils.info(logger, repImpl,
throws MemberNotFoundException { if (!nodeState.getRepEnvState().isMaster()) { throw EnvironmentFailureException.unexpectedState ("Not currently a master. " + actionName + " must be " +
/** * Utility method used here and by ReplicaThreadLocker. */ static void checkConsistency(final RepImpl repImpl, final ReplicaConsistencyPolicy policy) { if (State.DETACHED.equals(repImpl.getState()) || State.MASTER.equals(repImpl.getState())) { /* Detached state, permit read-only access to the environment. */ return; } assert (policy != null) : "Missing default consistency policy"; try { policy.ensureConsistency(repImpl); } catch (InterruptedException e) { throw new ThreadInterruptedException(repImpl, e); } catch (MasterStateException e) { /* * Transitioned to master, while waiting for consistency, so the * txn is free to go ahead on the master. */ return; } } }
/** * Wait on the given countdown latch and generate the appropriate * exception upon timeout. * * @throws InterruptedException */ private void await(ExceptionAwareCountDownLatch consistencyLatch, ReplicaConsistencyPolicy consistencyPolicy) throws ReplicaConsistencyException, DatabaseException, InterruptedException { if (!consistencyLatch.awaitOrException (consistencyPolicy.getTimeout(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)) { /* Timed out. */ final RepImpl rimpl = repNode.getRepImpl(); final boolean inactive = !rimpl.getState().isActive(); final String rnName = rimpl.getNameIdPair().getName(); throw new ReplicaConsistencyException(consistencyPolicy, rnName, inactive); } }
/** * Prevent this MasterTxn from taking locks if the node becomes a * replica. The application has a reference to this Txn, and may * attempt to use it well after the node has transitioned from master * to replica. */ @Override public LockResult lockInternal(long lsn, LockType lockType, boolean noWait, boolean jumpAheadOfWaiters, DatabaseImpl database) throws LockNotAvailableException, LockConflictException, DatabaseException { ReplicatedEnvironment.State nodeState = ((RepImpl)envImpl).getState(); if (nodeState.isMaster()) { return super.lockInternal (lsn, lockType, noWait, jumpAheadOfWaiters, database); } throwNotMaster(nodeState); return null; /* not reached */ }
/** * Must be invoked on the Master via the last open handle. * * Note that the method itself does not shutdown the group. It merely * sets replicaCloseCatchupMs, indicating that the ensuing handle close * should shutdown the Replicas. The actual coordination with the closing * of the handle is implemented by ReplicatedEnvironment.shutdownGroup(). * * @see ReplicatedEnvironment#shutdownGroup(long, TimeUnit) */ public void shutdownGroupOnClose(long timeoutMs) throws IllegalStateException { if (!nodeState.getRepEnvState().isMaster()) { throw new IllegalStateException ("Node state must be " + MASTER + ", not " + nodeState.getRepEnvState()); } replicaCloseCatchupMs = (timeoutMs < 0) ? 0 : timeoutMs; }
public boolean isMaster() { return ReplicatedEnvironment.State.MASTER.name().equals(getNodeState()); }
private void throwNotMaster(ReplicatedEnvironment.State nodeState) { if (nodeState.isReplica()) { throw new ReplicaWriteException (this, ((RepImpl)envImpl).getStateChangeEvent()); } throw new UnknownMasterException ("Transaction " + getId() + " cannot execute write operations because this node is" + " no longer a master"); }
@Override public String wireFormat() { return wireFormatPrefix() + SEPARATOR + nodeName + SEPARATOR + masterName + SEPARATOR + Long.toString(joinTime) + SEPARATOR + nodeState.toString(); } }
public NodeStateResponse(String line, String[] tokens) throws InvalidMessageException { super(line, tokens); nodeName = nextPayloadToken(); masterName = nextPayloadToken(); joinTime = Long.parseLong(nextPayloadToken()); nodeState = State.valueOf(nextPayloadToken()); }
@Override public boolean getIsMaster() { return getState().isMaster(); }