Package org.jgroups.protocols.pbcast
Class GMS
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.pbcast.GMS
-
- All Implemented Interfaces:
DiagnosticsHandler.ProbeHandler
public class GMS extends Protocol implements DiagnosticsHandler.ProbeHandler
Group membership protocol. Handles joins/leaves/crashes (suspicions) and emits new views accordingly. Use VIEW_ENFORCER on top of this layer to make sure new members don't receive any messages until they are members- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GMS.DefaultMembershipPolicy
static class
GMS.GmsHeader
-
Field Summary
Fields Modifier and Type Field Description protected AckCollector
ack_collector
To collect VIEW_ACKs from all membersprotected int
all_clients_retry_timeout
protected static java.lang.String
CLIENT
protected static java.lang.String
COORD
static short
DELTA_VIEW
static short
DIGEST_PRESENT
protected boolean
first_view_sent
protected boolean
flushProtocolInStack
protected GmsImpl
impl
protected java.util.concurrent.locks.Lock
impl_lock
protected java.util.Map<java.lang.String,GmsImpl>
impls
protected boolean
install_view_locally_first
Deprecated.true by defaultprotected long
join_timeout
protected java.util.List<Address>
joining
Members joined but for which no view has been received yetprotected long
leave_timeout
protected Leaver
leaver
protected java.util.List<Address>
leaving
Members excluded from group, but for which no view has been received yetprotected Address
local_addr
protected boolean
log_collect_msgs
protected boolean
log_view_warnings
protected long
ltime
protected long
max_bundling_time
Deprecated.protected int
max_join_attempts
protected int
max_leave_attempts
protected Membership
members
protected MembershipChangePolicy
membership_change_policy
protected AckCollector
merge_ack_collector
protected long
merge_timeout
static short
MERGE_VIEW
protected Merger
merger
protected int
num_prev_mbrs
protected int
num_prev_views
protected int
num_views
protected static java.lang.String
PART
protected BoundedList<Address>
prev_members
Keeps track of old members (up to num_prev_mbrs)protected BoundedList<java.lang.String>
prev_views
Stores the last 20 viewsprotected boolean
print_local_addr
protected boolean
print_physical_addrs
protected boolean
print_view_details
static short
READ_ADDRS
protected TimeScheduler
timer
protected Membership
tmp_members
protected boolean
use_delta_views
protected boolean
use_flush_if_present
protected View
view
protected long
view_ack_collection_timeout
protected boolean
view_bundling
Deprecated.protected ViewHandler<GmsImpl.Request>
view_handler
Class to process JOIN, LEAVE and MERGE requestsstatic short
VIEW_PRESENT
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description GMS()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MergeId
_getMergeId()
static Tuple<View,Digest>
_readViewAndDigest(byte[] buffer, int offset, int length)
protected boolean
_startFlush(View new_view, int maxAttempts, boolean resumeIfFailed, long randomFloor, long randomCeiling)
void
becomeClient()
void
becomeCoordinator()
void
becomeParticipant()
void
cancelMerge()
void
castViewChangeAndSendJoinRsps(View new_view, Digest digest, java.util.Collection<Address> expected_acks, java.util.Collection<Address> joiners, JoinRsp jr)
Broadcasts the new view and digest as VIEW messages, possibly sends JOIN-RSP messages to joiners and then waits for acks from expected_acksprotected java.util.List<Address>
computeNewMembership(java.util.Collection<java.util.Collection<Address>> subviews)
Computes a merge membershipprotected java.util.List<Address>
computeNewMembership(java.util.List<Address> current_members, java.util.Collection<Address> joiners, java.util.Collection<Address> leavers, java.util.Collection<Address> suspects)
Computes the regular membershipprotected static View
createDeltaView(View current_view, View next_view)
protected View
createViewFromDeltaView(View current_view, DeltaView delta_view)
protected Address
determineCoordinator()
protected static short
determineFlags(View view, Digest digest)
protected Address
determineNextCoordinator()
Returns the second-in-linejava.lang.Object
down(Event evt)
An event is to be sent down the stack.java.lang.String
dumpViewHandlerHistory()
java.lang.String
dumpViewHandlerQueue()
void
fixDigests()
protected Address
getCoord()
Digest
getDigest()
Grabs the current digest from NAKACK{2}GmsImpl
getImpl()
java.lang.String
getImplementation()
long
getJoinTimeout()
java.lang.String
getLocalAddress()
boolean
getLogCollectMessages()
int
getMaxJoinAttempts()
int
getMaxLeaveAttempts()
java.lang.String
getMembers()
MembershipChangePolicy
getMembershipChangePolicy()
java.lang.String
getMergeId()
Merger
getMerger()
Only used for internal testing, don't use this method !long
getMergeTimeout()
View
getNextView(java.util.Collection<Address> joiners, java.util.Collection<Address> leavers, java.util.Collection<Address> suspected_mbrs)
Computes the next view.int
getNumberOfViews()
int
getNumMembers()
java.lang.String
getView()
long
getViewAckCollectionTimeout()
Tuple<View,Digest>
getViewAndDigest()
Returns the current view and digest.ViewHandler
getViewHandler()
int
getViewHandlerSize()
ViewId
getViewId()
java.util.Map<java.lang.String,java.lang.String>
handleProbe(java.lang.String... keys)
Handles a probe.void
init()
Called after instance has been created (null constructor) and before protocol is started.protected void
initState()
void
installView(View new_view)
void
installView(View new_view, Digest digest)
Sets the new view and sends a VIEW_CHANGE event up and down the stack.boolean
isCoord()
boolean
isLeaving()
boolean
isMergeInProgress()
boolean
isMergeKillerRunning()
boolean
isMergeTaskRunning()
boolean
isViewHandlerSuspended()
GMS
joinTimeout(long timeout)
GMS
leaveTimeout(long timeout)
protected static Buffer
marshal(java.util.Collection<? extends Address> mbrs)
static Buffer
marshal(JoinRsp join_rsp)
protected static Buffer
marshal(ViewId view_id)
protected static Buffer
marshal(View view, Digest digest)
void
mergeDigest(Digest d)
Send down a MERGE_DIGEST eventGMS
printLocalAddress(boolean flag)
java.lang.String
printMergeIdHistory()
java.lang.String
printPreviousMembers()
java.lang.String
printPreviousViews()
boolean
printViewDetails()
GMS
printViewDetails(boolean p)
protected void
process(java.util.Collection<GmsImpl.Request> requests)
java.util.List<java.lang.Integer>
providedDownServices()
List of events that are provided to layers below (they will be handled when sent from down below)protected JoinRsp
readJoinRsp(byte[] buffer, int offset, int length)
protected java.util.Collection<? extends Address>
readMembers(byte[] buffer, int offset, int length)
protected Tuple<View,Digest>
readViewAndDigest(byte[] buffer, int offset, int length)
protected ViewId
readViewId(byte[] buffer, int offset, int length)
java.util.List<java.lang.Integer>
requiredDownServices()
List of events that are required to be answered by some layer belowvoid
resetStats()
void
resumeViewHandler()
void
sendJoinResponse(JoinRsp rsp, Address dest)
protected void
sendJoinResponse(Buffer marshalled_rsp, Address dest)
protected void
sendJoinResponses(JoinRsp jr, java.util.Collection<Address> joiners)
protected void
sendViewAck(Address dest)
void
setDigest(Digest d)
Send down a SET_DIGEST eventvoid
setImpl(GmsImpl new_impl)
GMS
setJoinTimeout(long t)
GMS
setLeaveTimeout(long t)
GMS
setLogCollectMessages(boolean flag)
GMS
setMaxJoinAttempts(int t)
GMS
setMaxLeaveAttempts(int t)
GMS
setMembershipChangePolicy(java.lang.String classname)
GMS
setMembershipChangePolicy(MembershipChangePolicy membership_change_policy)
GMS
setMergeTimeout(long timeout)
GMS
setPrintLocalAddr(boolean flag)
GMS
setPrintLocalAddress(boolean flag)
GMS
setViewAckCollectionTimeout(long view_ack_collection_timeout)
void
start()
This method is called on aJChannel.connect(String)
.void
stop()
This method is called on aJChannel.disconnect()
.java.lang.String[]
supportedKeys()
Returns a list of supported keysvoid
suspect(java.lang.String suspected_member)
void
suspendViewHandler()
java.lang.Object
up(Event evt)
An event was received from the protocol below.java.lang.Object
up(Message msg)
A single message was received.View
view()
GMS
viewAckCollectionTimeout(long view_ack_collection_timeout)
protected boolean
wouldBeNewCoordinator(Address potential_new_coord)
Checks whether the potential_new_coord would be the new coordinator (2nd in line)protected static boolean
writeAddresses(View view, Digest digest)
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, destroy, down, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedUpServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, up
-
-
-
-
Field Detail
-
CLIENT
protected static final java.lang.String CLIENT
- See Also:
- Constant Field Values
-
COORD
protected static final java.lang.String COORD
- See Also:
- Constant Field Values
-
PART
protected static final java.lang.String PART
- See Also:
- Constant Field Values
-
VIEW_PRESENT
public static final short VIEW_PRESENT
- See Also:
- Constant Field Values
-
DIGEST_PRESENT
public static final short DIGEST_PRESENT
- See Also:
- Constant Field Values
-
MERGE_VIEW
public static final short MERGE_VIEW
- See Also:
- Constant Field Values
-
DELTA_VIEW
public static final short DELTA_VIEW
- See Also:
- Constant Field Values
-
READ_ADDRS
public static final short READ_ADDRS
- See Also:
- Constant Field Values
-
join_timeout
protected long join_timeout
-
max_join_attempts
protected int max_join_attempts
-
all_clients_retry_timeout
protected int all_clients_retry_timeout
-
leave_timeout
protected long leave_timeout
-
max_leave_attempts
protected int max_leave_attempts
-
merge_timeout
protected long merge_timeout
-
print_local_addr
protected boolean print_local_addr
-
print_physical_addrs
protected boolean print_physical_addrs
-
view_bundling
@Deprecated protected boolean view_bundling
Deprecated.Whether view bundling (http://jira.jboss.com/jira/browse/JGRP-144) should be enabled or not. Setting this to false forces each JOIN/LEAVE/SUPSECT request to be handled separately. By default these requests are processed together if they are queued at approximately the same time
-
use_delta_views
protected boolean use_delta_views
-
max_bundling_time
@Deprecated protected long max_bundling_time
Deprecated.
-
num_prev_mbrs
protected int num_prev_mbrs
-
num_prev_views
protected int num_prev_views
-
view_ack_collection_timeout
protected long view_ack_collection_timeout
-
use_flush_if_present
protected boolean use_flush_if_present
-
log_collect_msgs
protected boolean log_collect_msgs
-
log_view_warnings
protected boolean log_view_warnings
-
install_view_locally_first
@Deprecated protected boolean install_view_locally_first
Deprecated.true by default
-
print_view_details
protected boolean print_view_details
-
num_views
protected int num_views
-
prev_views
protected BoundedList<java.lang.String> prev_views
Stores the last 20 views
-
impl
protected GmsImpl impl
-
impl_lock
protected final java.util.concurrent.locks.Lock impl_lock
-
impls
protected final java.util.Map<java.lang.String,GmsImpl> impls
-
merger
protected Merger merger
-
leaver
protected final Leaver leaver
-
local_addr
protected Address local_addr
-
members
protected final Membership members
-
tmp_members
protected final Membership tmp_members
-
membership_change_policy
protected MembershipChangePolicy membership_change_policy
-
joining
protected final java.util.List<Address> joining
Members joined but for which no view has been received yet
-
leaving
protected final java.util.List<Address> leaving
Members excluded from group, but for which no view has been received yet
-
prev_members
protected BoundedList<Address> prev_members
Keeps track of old members (up to num_prev_mbrs)
-
view
protected volatile View view
-
ltime
protected long ltime
-
timer
protected TimeScheduler timer
-
view_handler
protected final ViewHandler<GmsImpl.Request> view_handler
Class to process JOIN, LEAVE and MERGE requests
-
ack_collector
protected final AckCollector ack_collector
To collect VIEW_ACKs from all members
-
merge_ack_collector
protected final AckCollector merge_ack_collector
-
flushProtocolInStack
protected boolean flushProtocolInStack
-
first_view_sent
protected boolean first_view_sent
-
-
Method Detail
-
getViewId
public ViewId getViewId()
-
view
public View view()
-
getViewAndDigest
public Tuple<View,Digest> getViewAndDigest()
Returns the current view and digest. Try to find a matching digest twice (if not found on the first try)
-
getView
public java.lang.String getView()
-
getNumberOfViews
public int getNumberOfViews()
-
getLocalAddress
public java.lang.String getLocalAddress()
-
getMembers
public java.lang.String getMembers()
-
getNumMembers
public int getNumMembers()
-
getJoinTimeout
public long getJoinTimeout()
-
setJoinTimeout
public GMS setJoinTimeout(long t)
-
joinTimeout
public GMS joinTimeout(long timeout)
-
leaveTimeout
public GMS leaveTimeout(long timeout)
-
setLeaveTimeout
public GMS setLeaveTimeout(long t)
-
getMergeTimeout
public long getMergeTimeout()
-
setMergeTimeout
public GMS setMergeTimeout(long timeout)
-
getMaxJoinAttempts
public int getMaxJoinAttempts()
-
setMaxJoinAttempts
public GMS setMaxJoinAttempts(int t)
-
getMaxLeaveAttempts
public int getMaxLeaveAttempts()
-
setMaxLeaveAttempts
public GMS setMaxLeaveAttempts(int t)
-
printViewDetails
public boolean printViewDetails()
-
printViewDetails
public GMS printViewDetails(boolean p)
-
getImplementation
public java.lang.String getImplementation()
-
isCoord
public boolean isCoord()
-
isLeaving
public boolean isLeaving()
-
getMembershipChangePolicy
public MembershipChangePolicy getMembershipChangePolicy()
-
setMembershipChangePolicy
public GMS setMembershipChangePolicy(MembershipChangePolicy membership_change_policy)
-
getMergeId
public java.lang.String getMergeId()
-
isMergeInProgress
public boolean isMergeInProgress()
-
getMerger
public Merger getMerger()
Only used for internal testing, don't use this method !
-
setMembershipChangePolicy
public GMS setMembershipChangePolicy(java.lang.String classname)
-
printMergeIdHistory
public java.lang.String printMergeIdHistory()
-
printPreviousMembers
public java.lang.String printPreviousMembers()
-
setPrintLocalAddress
public GMS setPrintLocalAddress(boolean flag)
-
setPrintLocalAddr
public GMS setPrintLocalAddr(boolean flag)
-
printLocalAddress
public GMS printLocalAddress(boolean flag)
-
getViewAckCollectionTimeout
public long getViewAckCollectionTimeout()
-
setViewAckCollectionTimeout
public GMS setViewAckCollectionTimeout(long view_ack_collection_timeout)
-
viewAckCollectionTimeout
public GMS viewAckCollectionTimeout(long view_ack_collection_timeout)
-
getViewHandlerSize
public int getViewHandlerSize()
-
isViewHandlerSuspended
public boolean isViewHandlerSuspended()
-
dumpViewHandlerQueue
public java.lang.String dumpViewHandlerQueue()
-
dumpViewHandlerHistory
public java.lang.String dumpViewHandlerHistory()
-
suspendViewHandler
public void suspendViewHandler()
-
resumeViewHandler
public void resumeViewHandler()
-
getViewHandler
public ViewHandler getViewHandler()
-
printPreviousViews
public java.lang.String printPreviousViews()
-
suspect
public void suspect(java.lang.String suspected_member)
-
_getMergeId
public MergeId _getMergeId()
-
setLogCollectMessages
public GMS setLogCollectMessages(boolean flag)
-
getLogCollectMessages
public boolean getLogCollectMessages()
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classProtocol
-
requiredDownServices
public java.util.List<java.lang.Integer> requiredDownServices()
Description copied from class:Protocol
List of events that are required to be answered by some layer below- Overrides:
requiredDownServices
in classProtocol
-
providedDownServices
public java.util.List<java.lang.Integer> providedDownServices()
Description copied from class:Protocol
List of events that are provided to layers below (they will be handled when sent from down below)- Overrides:
providedDownServices
in classProtocol
-
setImpl
public void setImpl(GmsImpl new_impl)
-
getImpl
public GmsImpl getImpl()
-
init
public void init() throws java.lang.Exception
Description copied from class:Protocol
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.
-
start
public void start() throws java.lang.Exception
Description copied from class:Protocol
This method is called on aJChannel.connect(String)
. Starts work. Protocols are connected and queues are ready to receive events. Will be called from bottom to top. This call will replace the START and START_OK events.- Overrides:
start
in classProtocol
- Throws:
java.lang.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soJChannel.connect(String)
will throw an exception
-
stop
public void stop()
Description copied from class:Protocol
This method is called on aJChannel.disconnect()
. Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed
-
becomeCoordinator
public void becomeCoordinator()
-
becomeParticipant
public void becomeParticipant()
-
becomeClient
public void becomeClient()
-
fixDigests
public void fixDigests()
-
cancelMerge
public void cancelMerge()
-
isMergeTaskRunning
public boolean isMergeTaskRunning()
-
isMergeKillerRunning
public boolean isMergeKillerRunning()
-
getNextView
public View getNextView(java.util.Collection<Address> joiners, java.util.Collection<Address> leavers, java.util.Collection<Address> suspected_mbrs)
Computes the next view. Returns a copy that hasleavers
andsuspected_mbrs
removed andjoiners
added.
-
computeNewMembership
protected java.util.List<Address> computeNewMembership(java.util.List<Address> current_members, java.util.Collection<Address> joiners, java.util.Collection<Address> leavers, java.util.Collection<Address> suspects)
Computes the regular membership
-
computeNewMembership
protected java.util.List<Address> computeNewMembership(java.util.Collection<java.util.Collection<Address>> subviews)
Computes a merge membership
-
castViewChangeAndSendJoinRsps
public void castViewChangeAndSendJoinRsps(View new_view, Digest digest, java.util.Collection<Address> expected_acks, java.util.Collection<Address> joiners, JoinRsp jr)
Broadcasts the new view and digest as VIEW messages, possibly sends JOIN-RSP messages to joiners and then waits for acks from expected_acks- Parameters:
new_view
- the new view (View
orMergeView
)digest
- the digest, can be null if new_view is not a MergeViewexpected_acks
- the members from which to wait for VIEW_ACKs (self will be excluded)joiners
- the list of members to which to send the join response (jr). If null, no JOIN_RSPs will be sentjr
- theJoinRsp
. If null (or joiners is null), no JOIN_RSPs will be sent
-
sendJoinResponses
protected void sendJoinResponses(JoinRsp jr, java.util.Collection<Address> joiners)
-
installView
public void installView(View new_view)
-
installView
public void installView(View new_view, Digest digest)
Sets the new view and sends a VIEW_CHANGE event up and down the stack. If the view is a MergeView (subclass of View), then digest will be non-null and has to be set before installing the view.
-
getCoord
protected Address getCoord()
-
determineCoordinator
protected Address determineCoordinator()
-
determineNextCoordinator
protected Address determineNextCoordinator()
Returns the second-in-line
-
wouldBeNewCoordinator
protected boolean wouldBeNewCoordinator(Address potential_new_coord)
Checks whether the potential_new_coord would be the new coordinator (2nd in line)
-
setDigest
public void setDigest(Digest d)
Send down a SET_DIGEST event
-
mergeDigest
public void mergeDigest(Digest d)
Send down a MERGE_DIGEST event
-
getDigest
public Digest getDigest()
Grabs the current digest from NAKACK{2}
-
_startFlush
protected boolean _startFlush(View new_view, int maxAttempts, boolean resumeIfFailed, long randomFloor, long randomCeiling)
-
up
public java.lang.Object up(Event evt)
Description copied from class:Protocol
An event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally the event is either a) discarded, or b) an event is sent down the stack usingdown_prot.down()
or c) the event (or another event) is sent up the stack usingup_prot.up()
.
-
up
public java.lang.Object up(Message msg)
Description copied from class:Protocol
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
down
public java.lang.Object down(Event evt)
Description copied from class:Protocol
An event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down()
.
-
handleProbe
public java.util.Map<java.lang.String,java.lang.String> handleProbe(java.lang.String... keys)
Description copied from interface:DiagnosticsHandler.ProbeHandler
Handles a probe. For each key that is handled, the key and its result should be in the returned map.- Specified by:
handleProbe
in interfaceDiagnosticsHandler.ProbeHandler
- Returns:
- Map
. A map of keys and values. A null return value is permissible.
-
supportedKeys
public java.lang.String[] supportedKeys()
Description copied from interface:DiagnosticsHandler.ProbeHandler
Returns a list of supported keys- Specified by:
supportedKeys
in interfaceDiagnosticsHandler.ProbeHandler
-
initState
protected void initState()
-
sendViewAck
protected void sendViewAck(Address dest)
-
createViewFromDeltaView
protected View createViewFromDeltaView(View current_view, DeltaView delta_view)
-
readJoinRsp
protected JoinRsp readJoinRsp(byte[] buffer, int offset, int length)
-
readMembers
protected java.util.Collection<? extends Address> readMembers(byte[] buffer, int offset, int length)
-
readViewAndDigest
protected Tuple<View,Digest> readViewAndDigest(byte[] buffer, int offset, int length)
-
_readViewAndDigest
public static Tuple<View,Digest> _readViewAndDigest(byte[] buffer, int offset, int length) throws java.lang.Exception
- Throws:
java.lang.Exception
-
readViewId
protected ViewId readViewId(byte[] buffer, int offset, int length)
-
process
protected void process(java.util.Collection<GmsImpl.Request> requests)
-
-