Package org.jgroups.protocols.pbcast
Class GMS
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.pbcast.GMS
-
- All Implemented Interfaces:
Lifecycle,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 classGMS.DefaultMembershipPolicystatic classGMS.GmsHeader
-
Field Summary
Fields Modifier and Type Field Description protected AckCollectorack_collectorTo collect VIEW_ACKs from all membersprotected intall_clients_retry_timeoutprotected static java.lang.StringCLIENTprotected static java.lang.StringCOORDstatic shortDELTA_VIEWstatic shortDIGEST_PRESENTprotected booleanfirst_view_sentprotected GmsImplimplprotected java.util.Map<java.lang.String,GmsImpl>implsprotected longjoin_timeoutprotected java.util.List<Address>joiningMembers joined but for which no view has been received yetprotected longleave_timeoutprotected Leaverleaverprotected java.util.List<Address>leavingMembers excluded from group, but for which no view has been received yetprotected java.util.concurrent.locks.Locklockprotected booleanlog_collect_msgsprotected booleanlog_view_warningsprotected longltimeprotected intmax_join_attemptsprotected intmax_leave_attemptsDeprecated.protected Membershipmembersprotected MembershipChangePolicymembership_change_policyprotected longmerge_timeoutstatic shortMERGE_VIEWprotected Mergermergerprotected intnum_prev_mbrsprotected intnum_prev_viewsprotected intnum_viewsprotected static java.lang.StringPARTprotected BoundedList<Address>prev_membersKeeps track of old members (up to num_prev_mbrs)protected BoundedList<java.lang.String>prev_viewsprotected booleanprint_local_addrprotected booleanprint_physical_addrsprotected booleanprint_view_detailsstatic shortREAD_ADDRSprotected Membershipsuspected_mbrsprotected ThreadPoolthread_poolprotected TimeSchedulertimerprotected Membershiptmp_membersprotected booleanuse_delta_viewsprotected Viewviewprotected longview_ack_collection_timeoutprotected ViewHandler<GmsImpl.Request>view_handlerClass to process JOIN, LEAVE and MERGE requestsstatic shortVIEW_PRESENT-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, 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)voidbecomeClient()voidbecomeCoordinator()voidbecomeParticipant()voidcancelMerge()voidcastViewChangeAndSendJoinRsps(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 ViewcreateDeltaView(View current_view, View next_view)protected ViewcreateViewFromDeltaView(View current_view, DeltaView delta_view)protected AddressdetermineCoordinator()protected static shortdetermineFlags(View view, Digest digest)protected AddressdetermineNextCoordinator()Returns the second-in-linejava.lang.Objectdown(Event evt)An event is to be sent down the stack.java.lang.StringdumpViewHandlerHistory()java.lang.StringdumpViewHandlerQueue()voidfixDigests()protected AddressgetCoord()DigestgetDigest()Grabs the current digest from NAKACK{2}GmsImplgetImpl()java.lang.StringgetImplementation()longgetJoinTimeout()longgetLeaveTimeout()booleangetLogCollectMessages()intgetMaxJoinAttempts()MembershipChangePolicygetMembershipChangePolicy()java.lang.StringgetMergeId()MergergetMerger()Only used for internal testing, don't use this method !longgetMergeTimeout()ViewgetNextView(java.util.Collection<Address> joiners, java.util.Collection<Address> leavers, java.util.Collection<Address> suspected_mbrs)Computes the next view.java.lang.StringgetView()longgetViewAckCollectionTimeout()Tuple<View,Digest>getViewAndDigest()Returns the current view and digest.ViewHandler<GmsImpl.Request>getViewHandler()intgetViewHandlerSize()ViewIdgetViewId()protected java.lang.Objecthandle(GMS.GmsHeader hdr, Message msg)java.util.Map<java.lang.String,java.lang.String>handleProbe(java.lang.String... keys)Handles a probe.voidinit()Called after a protocol has been created and before the protocol is started.protected voidinitState()voidinstallView(View new_view)voidinstallView(View new_view, Digest digest)Sets the new view and sends a VIEW_CHANGE event up and down the stack.booleanisCoord()booleanisLeaving()booleanisMergeInProgress()booleanisMergeKillerRunning()booleanisMergeTaskRunning()booleanisViewHandlerSuspended()booleanlogCollectMessages()GMSlogCollectMessages(boolean b)booleanlogViewWarnings()GMSlogViewWarnings(boolean b)protected static ByteArraymarshal(java.util.Collection<? extends Address> mbrs)static ByteArraymarshal(JoinRsp join_rsp)protected static ByteArraymarshal(ViewId view_id)protected static ByteArraymarshal(View view, Digest digest)voidmergeDigest(Digest d)Send down a MERGE_DIGEST eventbooleanprintLocalAddress()GMSprintLocalAddress(boolean p)java.lang.StringprintMergeIdHistory()booleanprintPhysicalAddress()GMSprintPhysicalAddress(boolean p)java.lang.StringprintPreviousMembers()java.lang.StringprintPreviousViews()booleanprintViewDetails()GMSprintViewDetails(boolean p)protected voidprocess(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 JoinRspreadJoinRsp(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 ViewIdreadViewId(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 belowvoidresetStats()voidresumeViewHandler()voidsendJoinResponse(JoinRsp rsp, Address dest)protected voidsendJoinResponse(ByteArray marshalled_rsp, Address dest)protected voidsendJoinResponses(JoinRsp jr, java.util.Collection<Address> joiners)protected voidsendViewAck(Address dest)protected voidsendViewChangeAndJoinResponse(Message view_change_msg, JoinRsp jr, java.util.Collection<Address> joiners)voidsetDigest(Digest d)Send down a SET_DIGEST eventvoidsetImpl(GmsImpl new_impl)GMSsetJoinTimeout(long t)GMSsetLeaveTimeout(long t)GMSsetLogCollectMessages(boolean flag)GMSsetMaxJoinAttempts(int t)GMSsetMembershipChangePolicy(java.lang.String classname)GMSsetMembershipChangePolicy(MembershipChangePolicy membership_change_policy)GMSsetMergeTimeout(long t)GMSsetViewAckCollectionTimeout(long v)voidstart()This method is called on aJChannel.connect(String); starts work.voidstop()Called on aJChannel.disconnect(); stops work (e.g.java.lang.String[]supportedKeys()Returns a list of supported keysvoidsuspect(java.lang.String suspected_member)voidsuspendViewHandler()java.lang.Objectup(Event evt)An event was received from the protocol below.java.lang.Objectup(Message msg)A single message was received.voidup(MessageBatch batch)Sends up a multiple messages in aMessageBatch.booleanuseDeltaViews()GMSuseDeltaViews(boolean b)Viewview()protected booleanwouldBeNewCoordinator(Address potential_new_coord)Checks whether the potential_new_coord would be the new coordinator (2nd in line)protected static booleanwriteAddresses(View view, Digest digest)-
Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedUpServices, removePolicy, requiredUpServices, resetStatistics, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, toString
-
-
-
-
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
@Deprecated protected int max_leave_attempts
Deprecated.
-
merge_timeout
protected long merge_timeout
-
print_local_addr
protected boolean print_local_addr
-
print_physical_addrs
protected boolean print_physical_addrs
-
use_delta_views
protected boolean use_delta_views
-
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
-
log_collect_msgs
protected boolean log_collect_msgs
-
log_view_warnings
protected boolean log_view_warnings
-
print_view_details
protected boolean print_view_details
-
members
protected final Membership members
-
num_views
protected int num_views
-
prev_views
protected BoundedList<java.lang.String> prev_views
-
impl
protected GmsImpl impl
-
lock
protected final java.util.concurrent.locks.Lock lock
-
impls
protected final java.util.Map<java.lang.String,GmsImpl> impls
-
merger
protected Merger merger
-
leaver
protected final Leaver leaver
-
tmp_members
protected final Membership tmp_members
-
suspected_mbrs
protected final Membership suspected_mbrs
-
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
-
thread_pool
protected ThreadPool thread_pool
-
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
-
first_view_sent
protected boolean first_view_sent
-
-
Method Detail
-
getJoinTimeout
public long getJoinTimeout()
-
setJoinTimeout
public GMS setJoinTimeout(long t)
-
getLeaveTimeout
public long getLeaveTimeout()
-
setLeaveTimeout
public GMS setLeaveTimeout(long t)
-
getMergeTimeout
public long getMergeTimeout()
-
setMergeTimeout
public GMS setMergeTimeout(long t)
-
getMaxJoinAttempts
public int getMaxJoinAttempts()
-
setMaxJoinAttempts
public GMS setMaxJoinAttempts(int t)
-
printLocalAddress
public boolean printLocalAddress()
-
printLocalAddress
public GMS printLocalAddress(boolean p)
-
printPhysicalAddress
public boolean printPhysicalAddress()
-
printPhysicalAddress
public GMS printPhysicalAddress(boolean p)
-
useDeltaViews
public boolean useDeltaViews()
-
useDeltaViews
public GMS useDeltaViews(boolean b)
-
getViewAckCollectionTimeout
public long getViewAckCollectionTimeout()
-
setViewAckCollectionTimeout
public GMS setViewAckCollectionTimeout(long v)
-
logCollectMessages
public boolean logCollectMessages()
-
logCollectMessages
public GMS logCollectMessages(boolean b)
-
logViewWarnings
public boolean logViewWarnings()
-
logViewWarnings
public GMS logViewWarnings(boolean b)
-
printViewDetails
public boolean printViewDetails()
-
printViewDetails
public GMS printViewDetails(boolean p)
-
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()
-
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()
-
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<GmsImpl.Request> 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:
resetStatsin classProtocol
-
requiredDownServices
public java.util.List<java.lang.Integer> requiredDownServices()
Description copied from class:ProtocolList of events that are required to be answered by some layer below- Overrides:
requiredDownServicesin classProtocol
-
providedDownServices
public java.util.List<java.lang.Integer> providedDownServices()
Description copied from class:ProtocolList of events that are provided to layers below (they will be handled when sent from down below)- Overrides:
providedDownServicesin classProtocol
-
setImpl
public void setImpl(GmsImpl new_impl)
-
getImpl
public GmsImpl getImpl()
-
init
public void init() throws java.lang.ExceptionDescription copied from class:ProtocolCalled after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent.
-
start
public void start() throws java.lang.ExceptionDescription copied from class:ProtocolThis method is called on aJChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top.- Specified by:
startin interfaceLifecycle- Overrides:
startin 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:ProtocolCalled on aJChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom.
-
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 hasleaversandsuspected_mbrsremoved andjoinersadded.
-
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 (VieworMergeView)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
-
sendViewChangeAndJoinResponse
protected void sendViewChangeAndJoinResponse(Message view_change_msg, JoinRsp jr, java.util.Collection<Address> joiners)
-
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}
-
up
public java.lang.Object up(Event evt)
Description copied from class:ProtocolAn 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:ProtocolA single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
up
public void up(MessageBatch batch)
Description copied from class:ProtocolSends up a multiple messages in aMessageBatch. The sender of the batch is always the same, and so is the destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed messages, although the transport itself will create initial MessageBatches that contain only either OOB or regular messages. The default processing below sends messages up the stack individually, based on a matching criteria (callingProtocol.accept(Message)), and - if true - callsProtocol.up(org.jgroups.Event)for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped. Subclasses should check if there are any messages destined for them (e.g. usingMessageBatch.iterator(Predicate)), then possibly remove and process them and finally pass the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all encrypted messages in the batch, not remove them, and pass the batch up when done.
-
down
public java.lang.Object down(Event evt)
Description copied from class:ProtocolAn 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.ProbeHandlerHandles a probe. For each key that is handled, the key and its result should be in the returned map.- Specified by:
handleProbein 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.ProbeHandlerReturns a list of supported keys- Specified by:
supportedKeysin interfaceDiagnosticsHandler.ProbeHandler
-
handle
protected java.lang.Object handle(GMS.GmsHeader hdr, Message msg)
-
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)
-
-