com.sleepycat.je.rep.impl.node
Class Replica

java.lang.Object
  extended by com.sleepycat.je.rep.impl.node.Replica

public class Replica
extends Object

The Replica class is the locus of the replay operations and replica transaction consistency tracking and management operations at a replica node. A single instance of this class is created when the replication node is created and exists for the lifetime of the replication node, although it is only really used when the node is operating as a Replica. Note that the Replica (like the FeederManager) does not have its own independent thread of control; it runs in the RepNode's thread.


Nested Class Summary
(package private) static class Replica.ConnectRetryException
           
 class Replica.ConsistencyTracker
          Tracks the consistency of this replica wrt the Master.
static class Replica.HardRecoveryElectionException
          Indicates that an election is needed before the hard recovery can proceed.
(package private)  class Replica.ReplayThread
          The thread responsible for the replay of messages delivered over the replication stream.
(package private) static class Replica.RetryException
          Thrown to indicate that the Replica must retry connecting to the same master, after some period of time.
 
Constructor Summary
Replica(RepNode repNode, Replay replay)
           
 
Method Summary
(package private)  void clearDbTreeCache()
           
protected  void doRunReplicaLoopInternalWork()
           
 Replica.ConsistencyTracker getConsistencyTracker()
           
 DbCache getDbCache()
           
 long getMasterTxnEndVLSN()
          Returns the last commit VLSN at the master, as known at the replica.
(package private)  Protocol getProtocol()
           
 StatGroup getProtocolStats(StatsConfig config)
           
 StatGroup getReplayStats(StatsConfig config)
          Returns the replay statistics associated with the Replica.
(package private)  SocketChannel getReplicaFeederChannel()
           
 ReplicaFeederSyncup.TestHook<Object> getReplicaFeederSyncupHook()
           
 StatGroup getTrackerStats(StatsConfig config)
           
(package private)  void masterTransitionCleanup()
          Invoked when this node transitions to the master state.
 Replay replay()
           
 void resetStats()
           
(package private)  void runReplicaLoop()
          The core control loop when the node is serving as a Replica.
 void setDontProcessStream()
          For unit testing only!
static void setInitialReplayHook(TestHook<BinaryProtocol.Message> hook)
          Sets a test hook for installation into Replica class instances to be created in the future.
 void setReplayHook(TestHook<BinaryProtocol.Message> hook)
          Sets a test hook which is executed in the reply loop.
 void setReplicaFeederSyncupHook(ReplicaFeederSyncup.TestHook<Object> syncupHook)
          Set a test hook which is executed when the ReplicaFeederSyncup finishes.
 void setTestDelayMs(int testDelayMs)
          For unit testing only!
 void shutdown()
          Shutdown the Replica, free any threads that may have been waiting for the replica to reach some degree of consistency.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Replica

Replica(RepNode repNode,
        Replay replay)
Method Detail

shutdown

public void shutdown()
Shutdown the Replica, free any threads that may have been waiting for the replica to reach some degree of consistency. This method is only invoked as part of the repnode shutdown. If the shutdown is being executed from a different thread, it attempts to interrupt the thread by first shutting down the channel it may be waiting on for input from the feeder. The replica thread should notice the channel shutdown and/or the shutdown state of the rep node itself. The caller will use harsher methods, like an interrupt, if the rep node thread (Replica or Feeder) is still active.


setTestDelayMs

public void setTestDelayMs(int testDelayMs)
For unit testing only!


setDontProcessStream

public void setDontProcessStream()
For unit testing only!


replay

public Replay replay()

getDbCache

public DbCache getDbCache()

getConsistencyTracker

public Replica.ConsistencyTracker getConsistencyTracker()

getReplicaFeederChannel

SocketChannel getReplicaFeederChannel()

getProtocol

Protocol getProtocol()

getMasterTxnEndVLSN

public long getMasterTxnEndVLSN()
Returns the last commit VLSN at the master, as known at the replica.

Returns:
the commit VLSN

runReplicaLoop

void runReplicaLoop()
              throws InterruptedException,
                     DatabaseException,
                     GroupShutdownException
The core control loop when the node is serving as a Replica. Note that if a Replica is also serving the role of a feeder, it will run additional feeder loops in separate threads. The loop exits when it encounters one of the following possible conditions: 1) The connection to the master can no longer be maintained, due to connectivity issues, or because the master has explicitly shutdown its connections due to an election. 2) The node becomes aware of a change in master, that is, assertSync() fails. 3) The loop is interrupted, which is interpreted as a request to shutdown the replication node as a whole. 4) It fails to establish its node information in the master as it attempts to join the replication group for the first time. Normal exit from this run loop results in the rep node retrying an election and continuing in its new role as determined by the outcome of the election. A thrown exception, on the other hand, results in the rep node as a whole terminating its operation and no longer participating in the replication group, that is, it enters the DETACHED state. Note that the in/out streams are handled synchronously on the replica, while they are handled asynchronously by the Feeder.

Throws:
InterruptedException
RestoreFailedException
DatabaseException - if the environment cannot be closed/for a re-init
GroupShutdownException

doRunReplicaLoopInternalWork

protected void doRunReplicaLoopInternalWork()
                                     throws Exception
Throws:
Exception

clearDbTreeCache

void clearDbTreeCache()

masterTransitionCleanup

void masterTransitionCleanup()
                       throws DatabaseException
Invoked when this node transitions to the master state. Aborts all inflight replay transactions outstanding from a previous state as a Replica, because they were initiated by a different master and will never complete. Also, release any Replica transactions that were waiting on consistency policy requirements.

Throws:
DatabaseException

getReplayStats

public StatGroup getReplayStats(StatsConfig config)
Returns the replay statistics associated with the Replica.

Returns:
the statistics.

getProtocolStats

public StatGroup getProtocolStats(StatsConfig config)

getTrackerStats

public StatGroup getTrackerStats(StatsConfig config)

resetStats

public void resetStats()

setReplayHook

public void setReplayHook(TestHook<BinaryProtocol.Message> hook)
Sets a test hook which is executed in the reply loop.


setInitialReplayHook

public static void setInitialReplayHook(TestHook<BinaryProtocol.Message> hook)
Sets a test hook for installation into Replica class instances to be created in the future. This is needed when the test hook must be installed before the ReplicatedEnvironment handle constructor returns, so that a test may influence the replay of the sync-up transaction backlog.


setReplicaFeederSyncupHook

public void setReplicaFeederSyncupHook(ReplicaFeederSyncup.TestHook<Object> syncupHook)
Set a test hook which is executed when the ReplicaFeederSyncup finishes. This differs from the static method ReplicaFeederSyncup.setGlobalSyncupHook in that it sets the hook for a specific node, whereas the other method is static and sets it globally. This method is required when a test is trying to set the hook for only one node, and the node already exists. The other method is useful when a test is trying to set the hook before a node exists.


getReplicaFeederSyncupHook

public ReplicaFeederSyncup.TestHook<Object> getReplicaFeederSyncupHook()


Copyright (c) 2004-2012 Oracle. All rights reserved.