com.sleepycat.je.rep.impl
Class RepGroupImpl

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

public class RepGroupImpl
extends Object

Represents a snapshot of the Replication Group as a whole. Note that membership associated with a group is dynamic and its constituents can change at any time. It's useful to keep in mind that due to the distributed nature of the Replication Group all the nodes in a replication group may not have the same consistent picture of the replication group at a single point in time, but will converge to become consistent eventually.


Nested Class Summary
static class RepGroupImpl.BarrierState
          Encapsulates the last known syncup state associated with a node.
static class RepGroupImpl.NodeConflictException
           
(package private)  class RepGroupImpl.Predicate
           
 
Constructor Summary
RepGroupImpl(String groupName)
          Constructor to create a new empty repGroup, typically as part of environment initialization.
RepGroupImpl(String groupName, boolean unknownUUID)
           
RepGroupImpl(String groupName, UUID uuid, int version, int changeVersion, int nodeIdSequence, Map<Integer,RepNodeImpl> nodes)
          Constructor used to recreate an existing RepGroup, typically as part of a deserialization operation.
 
Method Summary
 void checkForConflicts(RepNodeImpl node)
          Checks for whether a new node definition is in conflict with the current members of the group.
static RepGroupImpl deserializeHex(String[] tokens, int start)
          De-serializes an array of tokens into a Rep group object and its nodes.
static RepNodeImpl deserializeNode(byte[] bytes)
          Deserialize the mode from its byte representation.
 boolean equals(Object obj)
           
 Set<InetSocketAddress> getAcceptorSockets()
          Returns the sockets used by nodes running Acceptor agents, that is, just nodes which participate in elections and can become Masters.
 Set<RepNodeImpl> getAllElectableMembers()
          Returns the subset of Electable nodes in the group.
 Set<Integer> getAllMemberIds()
          Returns the nodes ids associated with all the nodes that are members of the group.
 Set<RepNodeImpl> getAllMembers(RepGroupImpl.Predicate p)
           
 int getChangeVersion()
          Returns the version of the instance as represented by changes to the members constituting the group.
 int getElectableGroupSize()
          Note that even unACKed nodes are considered part of the group for group size/durability considerations.
 Set<RepNodeImpl> getElectableNodes()
           
static int getFirstNodeId()
          Returns the node id that is associated with the very first node in the replication group.
 Set<InetSocketAddress> getLearnerSockets()
          Return all learner sockets.
 RepNodeImpl getMember(int nodeId)
           
 RepNodeImpl getMember(String name)
          Lookup for existing members.
 Set<RepNodeImpl> getMonitorNodes()
          Returns the monitor nodes that are members of the group.
 Set<InetSocketAddress> getMonitorSockets()
          Returns the sockets used by just the Monitor nodes in the group
 String getName()
           
 int getNextNodeId()
          Increments the node id sequence and returns it.
 RepNodeImpl getNode(int nodeId)
          Get the node, if it's present, regardless of its membership state.
 RepNodeImpl getNode(String name)
          Get the node, if it's present, regardless of its membership state.
 int getNodeIdSequence()
          Returns the current highest node id currently in use by the group.
 UUID getUUID()
          returns the unique UUID associated with the replicated environment.
 int getVersion()
          Returns the version of the representation (the schema) in use by this group instance in the database.
 int hashCode()
           
 boolean hasUnknownUUID()
           
static RepNodeImpl hexDeserializeNode(String hex)
          Deserializes the object serialized by serializeHex()
 int incrementChangeVersion()
          Increments the object change version.
static boolean isUnknownUUID(UUID uuid)
          Predicate to help determine whether the UUID is the canonical unknown UUID.
 void makeConsistent()
          Used to ensure that the ReplicationGroup value is consistent after it has been fetched via a readUncommitted access to the rep group database.
(package private) static
<T> String
objectToHex(TupleBinding<T> binding, T object)
          Serializes an object by converting its TupleBinding byte based representation into the hex characters deonoting the bytes.
 RepNodeImpl removeMember(String nodeName)
          Removes a member transiently from the rep group by marking it as being deleted.
static byte[] serializeBytes(RepNodeImpl node)
          Serialize the node into its byte representation.
 String serializeHex()
          Returns a serialized character based form of the group suitable for use in subclasses of SimpleProtocol.
static String serializeHex(RepNodeImpl node)
          Returns the serialized form of the node as a sequence of hex characters suitable for use by the text based protocols.
 void setNodes(Map<Integer,RepNodeImpl> nodes)
          Sets the nodes associated with the Rep group.
 void setUUID(UUID uuid)
          Sets the UUID.
 String toString()
          Return information to the user, format nicely for ease of reading.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RepGroupImpl

public RepGroupImpl(String groupName)
Constructor to create a new empty repGroup, typically as part of environment initialization.

Parameters:
groupName -

RepGroupImpl

public RepGroupImpl(String groupName,
                    boolean unknownUUID)

RepGroupImpl

public RepGroupImpl(String groupName,
                    UUID uuid,
                    int version,
                    int changeVersion,
                    int nodeIdSequence,
                    Map<Integer,RepNodeImpl> nodes)
Constructor used to recreate an existing RepGroup, typically as part of a deserialization operation.

Parameters:
groupName -
uuid -
version -
changeVersion -
nodes -
Method Detail

hasUnknownUUID

public boolean hasUnknownUUID()

isUnknownUUID

public static boolean isUnknownUUID(UUID uuid)
Predicate to help determine whether the UUID is the canonical unknown UUID.


setUUID

public void setUUID(UUID uuid)
Sets the UUID. The UUID can only be set if it's currently unknown.


removeMember

public RepNodeImpl removeMember(String nodeName)
Removes a member transiently from the rep group by marking it as being deleted. This action is usually a precursor to making the change persistent on disk. Note that the node is simply marked as being removed it's not actually deleted from the representation.

Parameters:
nodeName - identifies the node being removed
Returns:
the node that was removed
Throws:
EnvironmentFailureException - if the node is not part of the group

checkForConflicts

public void checkForConflicts(RepNodeImpl node)
                       throws DatabaseException,
                              RepGroupImpl.NodeConflictException
Checks for whether a new node definition is in conflict with the current members of the group. This check must be done before adding a new member to the group and must be done with the rep group entry in the database locked for write to prevent race conditions.

Parameters:
node - the new node that is being checked for conflicts
Throws:
RepGroupImpl.NodeConflictException - if there is a conflict
DatabaseException

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

setNodes

public void setNodes(Map<Integer,RepNodeImpl> nodes)
Sets the nodes associated with the Rep group. Note that both nodesById and nodesByIndex are initialized.


getUUID

public UUID getUUID()
returns the unique UUID associated with the replicated environment.

Returns:
the UUID

getVersion

public int getVersion()
Returns the version of the representation (the schema) in use by this group instance in the database.

Returns:
the representation version number

getChangeVersion

public int getChangeVersion()
Returns the version of the instance as represented by changes to the members constituting the group.

Returns:
the object change version

incrementChangeVersion

public int incrementChangeVersion()
Increments the object change version. It must be called with the group entry locked in the group database.

Returns:
the incremented change version

getNodeIdSequence

public int getNodeIdSequence()
Returns the current highest node id currently in use by the group.

Returns:
the highest node id in use

getNextNodeId

public int getNextNodeId()
Increments the node id sequence and returns it.

Returns:
the next node id for use in a new node

getFirstNodeId

public static int getFirstNodeId()
Returns the node id that is associated with the very first node in the replication group.


makeConsistent

public void makeConsistent()
Used to ensure that the ReplicationGroup value is consistent after it has been fetched via a readUncommitted access to the rep group database. It does so by ensuring that the summarized values match the nodes that were actually read.


objectToHex

static <T> String objectToHex(TupleBinding<T> binding,
                              T object)
Serializes an object by converting its TupleBinding byte based representation into the hex characters deonoting the bytes.

Type Parameters:
T - the type of the object being serialized
Parameters:
binding - the tuble binding used to convert it into its byte form
object - the object being serialized
Returns:
the hex string containing the serialized hex form of the object

serializeHex

public String serializeHex()
Returns a serialized character based form of the group suitable for use in subclasses of SimpleProtocol. The serialized form is a multi-token string. The first token represents the RepGroup object itself with each subsequent node representing a node in the group. Tokens are separated by '|', the protocol separator character. The number of tokens is thus equal to the number of nodes in the group + 1. Each token is itself a hex character based representation of the binding used to serialize a RepGroup and store it into the database.

Returns:
the string encoded as above.

serializeHex

public static String serializeHex(RepNodeImpl node)
Returns the serialized form of the node as a sequence of hex characters suitable for use by the text based protocols.

Parameters:
node - the node to be serialized.
Returns:
the string containing the serialized form of the node.

serializeBytes

public static byte[] serializeBytes(RepNodeImpl node)
Serialize the node into its byte representation.

Parameters:
node - the node to be serialized
Returns:
the serailized byte array

hexDeserializeNode

public static RepNodeImpl hexDeserializeNode(String hex)
Deserializes the object serialized by serializeHex()

Parameters:
hex - the string containing the serialized form of the node
Returns:
the de-serialized object

deserializeNode

public static RepNodeImpl deserializeNode(byte[] bytes)
Deserialize the mode from its byte representation.

Parameters:
bytes - the byte representation of the node.
Returns:
the deserialized object

deserializeHex

public static RepGroupImpl deserializeHex(String[] tokens,
                                          int start)
De-serializes an array of tokens into a Rep group object and its nodes. the token at startrepresents the group object and each subsequent token represents a node in the group.

Parameters:
tokens - the array representing the group and its nodes
start - the position in the array at which to start the de-serialization.
Returns:
the de-serialized RepGroup

getAllMemberIds

public Set<Integer> getAllMemberIds()
Returns the nodes ids associated with all the nodes that are members of the group.


getAllMembers

public Set<RepNodeImpl> getAllMembers(RepGroupImpl.Predicate p)

getAllElectableMembers

public Set<RepNodeImpl> getAllElectableMembers()
Returns the subset of Electable nodes in the group. Includes nodes that may not yet have been acknowledged.


getElectableNodes

public Set<RepNodeImpl> getElectableNodes()

getMonitorNodes

public Set<RepNodeImpl> getMonitorNodes()
Returns the monitor nodes that are members of the group.

Returns:
the set of monitor nodes

getLearnerSockets

public Set<InetSocketAddress> getLearnerSockets()
Return all learner sockets. Every node electable, non-electable and peer has a learner socket so it can track elections. All nodes in the group have Learner agents associated with them.

Returns:
set of learner sockets for the group

getMonitorSockets

public Set<InetSocketAddress> getMonitorSockets()
Returns the sockets used by just the Monitor nodes in the group

Returns:
the set of Monitor sockets

getAcceptorSockets

public Set<InetSocketAddress> getAcceptorSockets()
Returns the sockets used by nodes running Acceptor agents, that is, just nodes which participate in elections and can become Masters.

Returns:
the set of Monitor sockets

getMember

public RepNodeImpl getMember(int nodeId)

getMember

public RepNodeImpl getMember(String name)
                      throws MemberNotFoundException
Lookup for existing members. Nodes that are no longer members are not returned.

Throws:
MemberNotFoundException

getNode

public RepNodeImpl getNode(int nodeId)
Get the node, if it's present, regardless of its membership state. Use getMember() to retrieve a current member.

Returns:
the node if it's still present in the group, null otherwise.

getNode

public RepNodeImpl getNode(String name)
Get the node, if it's present, regardless of its membership state. Use getMember() to retrieve a current member.

Returns:
the node if it's still present in the group, null otherwise.

getElectableGroupSize

public int getElectableGroupSize()
Note that even unACKed nodes are considered part of the group for group size/durability considerations.

Returns:
the size of the group for durability considerations

getName

public String getName()

toString

public String toString()
Return information to the user, format nicely for ease of reading.

Overrides:
toString in class Object


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