com.sleepycat.je.rep.impl
Class RepGroupDB

java.lang.Object
  extended by com.sleepycat.je.rep.impl.RepGroupDB

public class RepGroupDB
extends Object

This class is used to encapsulate all access to the rep group data that is present in every replicated JE environment. The rep group data exists primarily to support dynamic group membership. Both read and update access must be done through the APIs provided by this class. The database is simply a representation of the RepGroup. Each entry in the database represents a node in RepGroup; the key is the String node name, and the data is the serialized ReplicationNode. There is a special entry keyed by GROUP_KEY that holds the contents of the RepGroup (excluding the nodes) itself. The database may be modified concurrently by multiple transactions as a master processes requests to update it. It may also be accessed by multiple overlapping transactions as a Replica replays the rep stream. These updates need to be interleaved with operations like getGroup() that create copies of the RepGroup instance. To avoid deadlocks, entries in the database are accessed in order of ascending key. GROUP_KEY in particular is associated with the lowest key value so that it's locked first implicitly as part of any iteration and any other modifications to the database must first lock it before making changes to the group itself. An instance of this class is created as part of a replication node and is retained for the entire lifetime of that node.


Nested Class Summary
static class RepGroupDB.GroupBinding
           
static class RepGroupDB.NodeBinding
          Supports the serialization/deserialization of node info into and out of the database.
 
Field Summary
static int DB_ID
           
 RepGroupImpl emptyGroup
           
static String GROUP_KEY
           
static DatabaseEntry groupKeyEntry
           
(package private) static TransactionConfig READ_ONLY
           
 
Constructor Summary
RepGroupDB(RepImpl repImpl)
          Create an instance.
 
Method Summary
 void addFirstNode()
          Ensures that information about this node, the current master is in the member database.
 void ensureMember(Protocol.NodeGroupInfo membershipInfo)
          Ensures that the membership info for the replica is in the database.
(package private)  void ensureMember(RepNodeImpl ensureNode)
           
static RepGroupImpl getGroup(File envDir)
          An internal API used to obtain group information by opening a stand alone environment handle and reading the RepGroupDB.
static RepGroupImpl getGroup(RepImpl rImpl, String groupName, ReplicaConsistencyPolicy policy)
          Returns all the members that are currently part of the replication group.
 RepGroupImpl getGroup(ReplicaConsistencyPolicy policy)
           
 void reinitFirstNode(VLSN lastOldVLSN)
          Deletes all the current members from the rep group database and creates a new group, with just the member supplied via the configuration.
 void removeMember(RepNodeImpl removeNode)
          Deletes a node from the replication group by marking it as such in the rep group db.
 boolean updateLocalCBVLSN(NameIdPair nameIdPair, VLSN newCBVLSN)
          Updates the database entry associated with the node with the new local CBVLSN, if it can do so without encountering lock contention.
 void updateMember(RepNodeImpl node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emptyGroup

public final RepGroupImpl emptyGroup

GROUP_KEY

public static final String GROUP_KEY
See Also:
Constant Field Values

groupKeyEntry

public static final DatabaseEntry groupKeyEntry

DB_ID

public static final int DB_ID
See Also:
Constant Field Values

READ_ONLY

static final TransactionConfig READ_ONLY
Constructor Detail

RepGroupDB

public RepGroupDB(RepImpl repImpl)
           throws DatabaseException,
                  IOException
Create an instance. Note that the database handle is not initialized at this time, since the state of the node master/replica is not known at the time the replication node (and consequently this instance) is created.

Throws:
IOException
DatabaseException
Method Detail

getGroup

public static RepGroupImpl getGroup(RepImpl rImpl,
                                    String groupName,
                                    ReplicaConsistencyPolicy policy)
                             throws DatabaseException
Returns all the members that are currently part of the replication group. This method can read the database directly, and can be used when the replicated environment is detached and the RepNode is null. It's for the latter reason that the method reads uncommitted data. In detached mode, there may be transactions on the database that were in progress when the node was last shutdown. These transactions may have locks which will not be released until after the node is re-attached and the replication stream is resumed. Using uncommitted reads avoids use of locks in this circumstance. It's safe to read these records, since the database will eventually be updated with these changes.

Parameters:
policy - determines how current the information must be if it's invoked on a Replica.
Returns:
the group object
Throws:
DatabaseException - if the object could not be obtained

getGroup

public RepGroupImpl getGroup(ReplicaConsistencyPolicy policy)
                      throws DatabaseException
Throws:
DatabaseException

addFirstNode

public void addFirstNode()
                  throws DatabaseException
Ensures that information about this node, the current master is in the member database. If it isn't, enter it into the database. If the database does not exist, create it as well. Note that this overloading is only used by a node that is the master.

Throws:
DatabaseException

ensureMember

public void ensureMember(Protocol.NodeGroupInfo membershipInfo)
                  throws InsufficientReplicasException,
                         InsufficientAcksException,
                         DatabaseException
Ensures that the membership info for the replica is in the database. A call to this method is initiated by the master as part of the feeder/replica handshake, where the replica provides membership information as part of the handshake protocol. The membership database must already exist, with the master in it, when this method is invoked.

Parameters:
membershipInfo - provided by the replica
Throws:
InsufficientReplicasException - upon failure of 2p member update
DatabaseException - when the membership info could not be entered into the membership database.
InsufficientAcksException

ensureMember

void ensureMember(RepNodeImpl ensureNode)
            throws DatabaseException
Throws:
DatabaseException

removeMember

public void removeMember(RepNodeImpl removeNode)
Deletes a node from the replication group by marking it as such in the rep group db.


updateMember

public void updateMember(RepNodeImpl node)
                  throws InsufficientReplicasException,
                         InsufficientAcksException,
                         DatabaseException
Throws:
InsufficientReplicasException
InsufficientAcksException
DatabaseException

updateLocalCBVLSN

public boolean updateLocalCBVLSN(NameIdPair nameIdPair,
                                 VLSN newCBVLSN)
                          throws DatabaseException
Updates the database entry associated with the node with the new local CBVLSN, if it can do so without encountering lock contention. If it encounters contention, it returns false, and the caller must retry at some later point in time. Note that changes to the local CBVLSN do not update the group version number since they do not impact group membership.

Parameters:
nameIdPair - identifies the node being updated
newCBVLSN - the new local CBVLSN to be associated with the node.
Returns:
true if the update succeeded.
Throws:
DatabaseException

getGroup

public static RepGroupImpl getGroup(File envDir)
An internal API used to obtain group information by opening a stand alone environment handle and reading the RepGroupDB. Used for debugging and utilities.

Parameters:
envDir - the directory containing the environment log files
Returns:
the group as currently defined by the environment

reinitFirstNode

public void reinitFirstNode(VLSN lastOldVLSN)
Deletes all the current members from the rep group database and creates a new group, with just the member supplied via the configuration. This method exists to support the utility DbResetRepGroup

The changes proceed in three steps: 1) Determine the node id sequence number. This is to ensure that rep node ids are not reused. Old rep node ids are present in the logs as commit records. 2) A new group object, with the node id sequence number determined in step 1), is created and all existing nodes are deleted. 3) The first node is added to the rep group.

Parameters:
lastOldVLSN - the VLSN used to associate the new barrier wrt this node.


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