|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.quorum.AbstractQuorum<S,C>
public abstract class AbstractQuorum<S extends Remote,C extends QuorumClient<S>>
Abstract base class handles much of the logic for the distribution of RMI calls from the leader to the follower and for the HA write pipeline.
| Nested Class Summary | |
|---|---|
protected static class |
AbstractQuorum.E
Simple event impl. |
protected class |
AbstractQuorum.QuorumActorBase
Base class for QuorumActor implementations. |
protected class |
AbstractQuorum.QuorumWatcherBase
Base class for QuorumWatcher implementations. |
| Field Summary | |
|---|---|
protected static String |
ERR_BAD_TOKEN
Text when an operation is not permitted because the new value for the lastValidToken is not strictly greater than the current value. |
protected static String |
ERR_CAN_NOT_MEET
Text when an operation is not permitted because the quorum can not meet. |
protected static String |
ERR_NOT_IN_CONSENSUS
Text when an operation is not permitted because the service has not cast its vote for a lastCommitTime around which there is a consensus of (k+1)/2 quorum members. |
protected static String |
ERR_NOT_MEMBER
Text when an operation is not permitted because the service is not a quorum member. |
protected static String |
ERR_NOT_PIPELINE
Text when an operation is not permitted because the service is not part of the write pipeline. |
protected static String |
ERR_QUORUM_MET
Text when an operation is not permitted while the quorum is met. |
protected ReentrantLock |
lock
The lock protecting state changes in the remaining fields and used to provide Conditions used to await various states. |
protected static org.apache.log4j.Logger |
log
|
| Fields inherited from interface com.bigdata.quorum.Quorum |
|---|
NO_QUORUM |
| Constructor Summary | |
|---|---|
protected |
AbstractQuorum(int k)
Constructor, which MUST be followed by #start() to begin
operations. |
| Method Summary | |
|---|---|
void |
addListener(QuorumListener listener)
Add a listener |
void |
assertLeader(long token)
Assert that the token is still valid and that the Quorum.getClient() is
the quorum leader. |
void |
assertQuorum(long token)
Assert that the quorum associated with the token is still valid. |
void |
awaitBreak()
Await a met break (blocking). |
void |
awaitBreak(long timeout,
TimeUnit units)
Await a met break (blocking). |
long |
awaitQuorum()
Await a met quorum (blocking). |
long |
awaitQuorum(long timeout,
TimeUnit units)
Await a met quorum (blocking). |
protected void |
finalize()
|
QuorumActor<S,C> |
getActor()
The object used to effect changes in distributed quorum state on the behalf of the QuorumMember. |
Long |
getCastVote(UUID serviceId)
Return the vote cast by the service. |
C |
getClient()
Return the QuorumClient iff the quorum is running. |
UUID[] |
getJoined()
Return the identifiers for the member services joined with this quorum. |
UUID |
getLastInPipeline()
Return the UUID of the service which is the last service in the
write pipeline. |
UUID |
getLeaderId()
The UUID of the leader Quorum leader (non-blocking). |
QuorumMember<S> |
getMember()
Return the QuorumMember iff the quorum is running. |
UUID[] |
getMembers()
Return the identifiers for the member services (all known physical services for the logical service). |
UUID[] |
getPipeline()
Return the service identifiers for the services in the write pipeline in the order in which they will accept and relay writes. |
UUID[] |
getPipelinePriorAndNext(UUID serviceId)
Return the UUIDof the service in the pipeline which is
immediately upstream from (prior to) and downstream from (next to) the
specified service. |
Map<Long,UUID[]> |
getVotes()
Return an immutable snapshot of the votes cast by the quorum members. |
protected QuorumWatcher<S,C> |
getWatcher()
The QuorumWatcher which informs this AbstactQuorum of
changes occurring in the distributed state of the quorum. |
boolean |
isHighlyAvailable()
Return true if Quorum.replicationFactor() is GT ONE (1). |
boolean |
isQuorumMet()
Return true iff the #of services joined with the quorum is GTE (k + 1). |
long |
lastValidToken()
The quorum token which was assigned the last time a leader was elected. |
protected abstract AbstractQuorum.QuorumActorBase |
newActor(String logicalServiceId,
UUID serviceId)
Factory method invoked by start(QuorumClient) iff the
QuorumClient is a QuorumMember. |
protected abstract AbstractQuorum.QuorumWatcherBase |
newWatcher(String logicalServiceId)
Factory method invoked by start(QuorumClient). |
void |
removeListener(QuorumListener listener)
Remove a listener (the quorum's client is always a listener). |
int |
replicationFactor()
Return k, the target replication factor. |
void |
start(C client)
Begin asynchronous processing. |
void |
terminate()
Terminate any asynchronous processing associated with maintaining the Quorum state. |
long |
token()
The current token for the quorum. |
String |
toString()
Return a human readable representation of the local copy of the distributed quorum state (non-blocking). |
String |
toStringAtomic()
Return a human readable representation of an atomic snapshot of the local copy of the distributed quorum state. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final transient org.apache.log4j.Logger log
protected static final transient String ERR_NOT_MEMBER
protected static final transient String ERR_NOT_PIPELINE
protected static final transient String ERR_NOT_IN_CONSENSUS
protected static final transient String ERR_BAD_TOKEN
protected static final transient String ERR_QUORUM_MET
protected static final transient String ERR_CAN_NOT_MEET
protected final ReentrantLock lock
Conditions used to await various states. This is exposed
to concrete implementations of the AbstractQuorum.QuorumWatcherBase.
| Constructor Detail |
|---|
protected AbstractQuorum(int k)
#start() to begin
operations.
| Method Detail |
|---|
protected void finalize()
throws Throwable
finalize in class ObjectThrowablepublic void start(C client)
QuorumListener, the QuorumActor
and QuorumWatcher are created, and asynchronous discovery is
initialized for the QuorumWatcher.
start in interface Quorum<S extends Remote,C extends QuorumClient<S>>public void terminate()
QuorumQuorum state.
terminate in interface Quorum<S extends Remote,C extends QuorumClient<S>>
protected abstract AbstractQuorum.QuorumActorBase newActor(String logicalServiceId,
UUID serviceId)
start(QuorumClient) iff the
QuorumClient is a QuorumMember.
logicalServiceId - The identifier of the logical service corresponding to the
highly available quorum.serviceId - The UUID of the service on whose behalf the actor will
act.
QuorumActor which will effect changes in the
distributed state of the quorum.protected abstract AbstractQuorum.QuorumWatcherBase newWatcher(String logicalServiceId)
start(QuorumClient).
Note: Additional information can be passed to the watcher factor by
derived classes. For example, the UUID of the logical service to
logicalServiceId - The identifier of the logical service whose quorum state
will be watched.
QuorumWatcher which will inform this
AbstactQuorum of changes occurring in the distributed
state of the quorum.public String toString()
toString in class Objectpublic String toStringAtomic()
public C getClient()
QuorumQuorumClient iff the quorum is running.
getClient in interface Quorum<S extends Remote,C extends QuorumClient<S>>QuorumClient.public QuorumMember<S> getMember()
QuorumQuorumMember iff the quorum is running.
getMember in interface Quorum<S extends Remote,C extends QuorumClient<S>>QuorumMember.public QuorumActor<S,C> getActor()
QuorumMember.
getActor in interface Quorum<S extends Remote,C extends QuorumClient<S>>QuorumActor which will effect changes in the
distributed state of the quorum -or- null if the
client is not a QuorumMember (only quorum members can
take actions which effect the distributed quorum state).
IllegalStateException - if the quorum is not running.protected QuorumWatcher<S,C> getWatcher()
QuorumWatcher which informs this AbstactQuorum of
changes occurring in the distributed state of the quorum.
IllegalStateException - if the quorum is not running.public void addListener(QuorumListener listener)
Quorum
addListener in interface Quorum<S extends Remote,C extends QuorumClient<S>>listener - The listener.public void removeListener(QuorumListener listener)
Quorum
removeListener in interface Quorum<S extends Remote,C extends QuorumClient<S>>listener - The listener.public int replicationFactor()
Quorum(k + 1)/2 physical services for the same logical
service have an agreement on state. A single service with
k := 1 is the degenerate case and has a minimum quorum size
of ONE (1). High availability is only possible when k is GT
ONE (1). Thus k := 3 is the minimum value for which services
can be highly available and has a minimum quorum size of 2.
replicationFactor in interface Quorum<S extends Remote,C extends QuorumClient<S>>public final boolean isHighlyAvailable()
Quorumtrue if Quorum.replicationFactor() is GT ONE (1).
High availability exists (in principle) when the
Quorum.replicationFactor() k is greater than one. High
availability exists (in practice) when the Quorum
is met for a Quorum that is
configured for high availability.
isHighlyAvailable in interface Quorum<S extends Remote,C extends QuorumClient<S>>true if this Quorum is highly available
in principlepublic long lastValidToken()
Quorum
lastValidToken in interface Quorum<S extends Remote,C extends QuorumClient<S>>public UUID[] getMembers()
Quorum
getMembers in interface Quorum<S extends Remote,C extends QuorumClient<S>>UUIDs of the member services.public Map<Long,UUID[]> getVotes()
Quorum
getVotes in interface Quorum<S extends Remote,C extends QuorumClient<S>>public Long getCastVote(UUID serviceId)
Quorum
getCastVote in interface Quorum<S extends Remote,C extends QuorumClient<S>>serviceId - The service.
null if the
service has not cast a vote.public UUID[] getJoined()
Quorum
getJoined in interface Quorum<S extends Remote,C extends QuorumClient<S>>UUIDs of the member services joined with this quorum.public UUID[] getPipeline()
Quorum
getPipeline in interface Quorum<S extends Remote,C extends QuorumClient<S>>UUIDs of the ordered services in the write pipeline.public UUID getLastInPipeline()
QuorumUUID of the service which is the last service in the
write pipeline.
getLastInPipeline in interface Quorum<S extends Remote,C extends QuorumClient<S>>UUID of the last service in the write pipeline or
null if there are no services in the write pipeline.public UUID[] getPipelinePriorAndNext(UUID serviceId)
QuorumUUIDof the service in the pipeline which is
immediately upstream from (prior to) and downstream from (next to) the
specified service. These are, respectively, the service from which it
receives data (upstream) and to which it sends data (downstream).
getPipelinePriorAndNext in interface Quorum<S extends Remote,C extends QuorumClient<S>>serviceId - The service id.
null if the serviceId does not appear
in the write pipeline -or- an array of two elements whose values
are: [0] The upstream serviceId in the write pipeline, which will
be null iff serviceId is the first service in
the write pipeline; and [1] The downstream service in the write
pipeline, which will be null iff serviceId is
the last service in the write pipeline.public UUID getLeaderId()
QuorumUUID of the leader Quorum leader (non-blocking).
getLeaderId in interface Quorum<S extends Remote,C extends QuorumClient<S>>UUID of the leader Quorum leader -or-
null if the quorum is not met.public final long token()
QuorumQuorum.NO_QUORUM. When a leader is elected, it sets the current
token as token := lastValidToken() + 1. The current token is
cleared to Quorum.NO_QUORUM if the leader leaves the met quorum. It is
cleared Quorum.NO_QUORUM if the quorum breaks. While a leader may be
elected many times for the same lastCommitTime, a new quorum
token is assigned each time a leader is elected.
token in interface Quorum<S extends Remote,C extends QuorumClient<S>>public final void assertQuorum(long token)
QuorumQuorum.token() somewhere.
This method may then be invoked to verify that the saved token is still
valid and, hence, that the quorum is still met.
assertQuorum in interface Quorum<S extends Remote,C extends QuorumClient<S>>token - The token for the quorum.public final void assertLeader(long token)
QuorumQuorum.getClient() is
the quorum leader.
assertLeader in interface Quorum<S extends Remote,C extends QuorumClient<S>>token - A quorum token.public final boolean isQuorumMet()
Quorum
isQuorumMet in interface Quorum<S extends Remote,C extends QuorumClient<S>>
public long awaitQuorum()
throws InterruptedException,
AsynchronousQuorumCloseException
Quorumis not met, then this
will block until the Quorum meets.
This watches the current token and will return as soon as the token is valid.
awaitQuorum in interface Quorum<S extends Remote,C extends QuorumClient<S>>AsynchronousQuorumCloseException - if Quorum.terminate() is invoked while awaiting a quorum
meet.
InterruptedException
public long awaitQuorum(long timeout,
TimeUnit units)
throws InterruptedException,
TimeoutException,
AsynchronousQuorumCloseException
QuorumQuorumis not met, then this
will block until the Quorum meets.
awaitQuorum in interface Quorum<S extends Remote,C extends QuorumClient<S>>timeout - The timeout.units - The timeout units.
TimeoutException - if the timeout expired before the quorum met.
AsynchronousQuorumCloseException - if Quorum.terminate() is invoked while awaiting a quorum
meet.
InterruptedException
public void awaitBreak()
throws InterruptedException,
AsynchronousQuorumCloseException
Quorum is met, then this
will block until the Quorum breaks.
awaitBreak in interface Quorum<S extends Remote,C extends QuorumClient<S>>AsynchronousQuorumCloseException - if Quorum.terminate() is invoked while awaiting a quorum
break.
InterruptedExceptionAre these the desired semantics for this public method?
public void awaitBreak(long timeout,
TimeUnit units)
throws InterruptedException,
TimeoutException,
AsynchronousQuorumCloseException
QuorumQuorum is met, then this
will block until the Quorum breaks.
awaitBreak in interface Quorum<S extends Remote,C extends QuorumClient<S>>timeout - The timeout.units - The timeout units.
TimeoutException - if the timeout expired before the quorum breaks.
AsynchronousQuorumCloseException - if Quorum.terminate() is invoked while awaiting a quorum
break.
InterruptedException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||