public abstract class QuorumServiceBase<S extends HAGlue,L extends AbstractJournal> extends AbstractQuorumMember<S> implements QuorumService<S>
| Modifier and Type | Field and Description |
|---|---|
protected static org.apache.log4j.Logger |
log |
| Modifier | Constructor and Description |
|---|---|
protected |
QuorumServiceBase(String logicalServiceId,
UUID serviceId,
S service,
L localService) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort2Phase(long token)
Used by the leader to send a message to each service joined with the
quorum telling it to discard its write set, reloading all state from the
last root block.
|
static <F extends Future<T>,T> |
cancelFutures(List<F> futures)
Cancel the requests on the remote services (RMI).
|
CommitResponse |
commit2Phase(CommitRequest req)
Used by the leader to send a message to each joined service in the quorum
telling it to commit using the root block from the corresponding
prepare message. |
ExecutorService |
getExecutor()
An
ExecutorService which may be used by the QuorumMember
to run various asynchronous tasks. |
long |
getLastCommitCounter()
Return the lastCommitCounter for this service (based on its current root
block).
|
long |
getLastCommitTime()
Return the lastCommitTime for this service (based on its current root
block).
|
protected L |
getLocalService()
FIXME Return the
IResourceManager, Journal, [@link
DataService}, etc. |
long |
getPrepareTimeout()
Return the configured timeout in milliseconds that the leader will await
the other services to prepare for a 2-phase commit.
|
protected abstract long |
getRetrySendTimeoutNanos() |
S |
getService()
Return the local service implementation object (NOT the RMI proxy for
that object).
|
abstract S |
getService(UUID serviceId)
Return the remote interface used to perform HA operations on a member of
quorum.
|
UUID |
getStoreUUID()
The
UUID of the backing store. |
protected abstract void |
handleReplicatedWrite(IHASyncRequest req,
IHAWriteMessage msg,
ByteBuffer data)
Core implementation handles the message and payload when received on a
service.
|
protected abstract void |
incReceive(IHASyncRequest req,
IHAWriteMessage msg,
int nreads,
int rdlen,
int rem)
Core implementation of callback for monitoring progress of replicated
writes.
|
void |
logRootBlock(IRootBlockView rootBlock)
Log the root block for the commit point that closes the current write set
onto the
HALogWriter. |
void |
logWriteCacheBlock(IHAWriteMessage msg,
ByteBuffer data)
Log the
IHAWriteMessage and the associated data (if necessary). |
PrepareResponse |
prepare2Phase(PrepareRequest req)
Used by the leader to send a message to each joined service in the quorum
instructing it to flush all writes to the backing channel, and
acknowledge "yes" if ready to commit.
|
protected void |
processEvents()
Called from ErrorTask in HAJournalServer to ensure that events are
processed before entering SeekConsensus.
|
void |
purgeHALogs(long token)
Purge the local HA log files.
|
byte[] |
readFromQuorum(UUID storeId,
long addr)
Used by any service joined with the quorum to read a record from another
service joined with the quorum in order to work around a "bad read" as
identified by a checksum error on the local service.
|
Future<Void> |
receiveAndReplicate(IHASyncRequest req,
IHASendState snd,
IHAWriteMessage msg)
Return a
Future for a task which will replicate an NIO buffer
along the write pipeline. |
Future<Void> |
replicate(IHASyncRequest req,
IHAWriteMessage msg,
ByteBuffer b)
Return a
Future for a task which will replicate an NIO buffer
along the write pipeline. |
Future<IHAPipelineResetResponse> |
resetPipeline(IHAPipelineResetRequest req)
Reset the pipeline (blocking).
|
addListener, assertFollower, assertLeader, assertQuorum, consensus, getActor, getDownstreamServiceId, getLeader, getServiceId, isFollower, isJoinedMember, isLastInChain, isLeader, isMember, isPipelineMember, lostConsensus, memberAdd, memberRemove, pipelineAdd, pipelineChange, pipelineElectedLeader, pipelineRemove, pipelineUpstreamChange, quorumBreak, quorumMeet, removeListener, serviceJoin, serviceLeavedisconnected, getLogicalServiceZPath, getQuorum, notify, start, terminateclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdiscardWriteSet, enterErrorState, getPID, getServiceDir, installRootBlocksassertLeader, getActor, getDownstreamServiceId, getServiceId, isFollower, isJoinedMember, isLastInChain, isLeader, isMember, isPipelineMemberdisconnected, getLeader, getLogicalServiceZPath, getQuorum, start, terminatenotifyconsensus, lostConsensus, memberAdd, memberRemove, pipelineAdd, pipelineChange, pipelineElectedLeader, pipelineRemove, pipelineUpstreamChange, quorumBreak, quorumMeet, serviceJoin, serviceLeaveprotected QuorumServiceBase(String logicalServiceId, UUID serviceId, S service, L localService)
logicalServiceId - The identifier of the logical service.serviceId - The UUID for this service (a physical instance of the
logical service).service - The interface for the local service that is exposed to remote
clients (typically as a smart proxy).localService - The local service implementation.protected abstract long getRetrySendTimeoutNanos()
public S getService()
QuorumMember
A service operating as a QuorumMember has both Remote
interface and a non-remote interface. These interfaces typically define
similar methods (for example, compare HACommitGlue, which is
Remote, with QuorumCommit, which is non-remote). The
Remote interface in turn will have a local implementation object
inside of the JVM and an exported proxy for that Remote
interface. This method returns the local implementation object
for the Remote interface and is intended to facilitate operations
which the QuorumMember executes against its own Remote
interface. While the Remote interface will be exposed to other
services using a proxy, how that happens is outside of the scope of this
method.
getService in interface QuorumMember<S extends HAGlue>public abstract S getService(UUID serviceId)
getService in interface QuorumClient<S extends HAGlue>getService in interface ServiceLookup<S extends HAGlue>getService in class AbstractQuorumMember<S extends HAGlue>serviceId - The UUID associated with the service.protected L getLocalService()
IResourceManager, Journal, [@link
DataService}, etc. Probably rename to getResourceManager().public ExecutorService getExecutor()
QuorumMemberExecutorService which may be used by the QuorumMember
to run various asynchronous tasks.getExecutor in interface QuorumMember<S extends HAGlue>public Future<Void> receiveAndReplicate(IHASyncRequest req, IHASendState snd, IHAWriteMessage msg) throws IOException
QuorumPipelineFuture for a task which will replicate an NIO buffer
along the write pipeline. This method is invoked for any node except the
master, including the last node in the failover chain.receiveAndReplicate in interface QuorumPipeline<S extends HAGlue>req - A synchronization request (optional). This is only non-null
when historical WriteCache blocks are being replayed
down the write pipeline in order to synchronize a service.snd - Metadata about the state of the sender and potentially the
routing of the payload along the write replication pipeline.msg - The RMI metadata about the payload.IOExceptionpublic Future<Void> replicate(IHASyncRequest req, IHAWriteMessage msg, ByteBuffer b) throws IOException
QuorumPipelineFuture for a task which will replicate an NIO buffer
along the write pipeline. This method is only invoked by the quorum
leader. The payload is replicated to the first follower in the write
pipeline. That follower will accept the payload (and replicate it if
necessary) using #receiveAndReplicate(IHAWriteMessage).
Note: The implementation of this method should be robust to changes in
the write pipeline. Specifically, if a follower leaves the write
pipeline, it should attempt to retransmit the message and the payload
while allowing time for the write pipeline to be reconfigured in response
to the related QuorumMember events.
replicate in interface QuorumPipeline<S extends HAGlue>req - A synchronization request (optional). This is only non-null
when historical WriteCache blocks are being replayed
down the write pipeline in order to synchronize a service.msg - The RMI metadata about the payload.b - The payload. The bytes from the position to the limit will be
transmitted (note that the #of bytes remaining in the buffer
MUST agree with IHAWriteMessageBase.getSize()).IOExceptionpublic Future<IHAPipelineResetResponse> resetPipeline(IHAPipelineResetRequest req) throws IOException
QuorumPipelineHAReceiveService (including the inner HASendService). The
next message and payload relayed from the leader will cause new socket
connections to be established.resetPipeline in interface QuorumPipeline<S extends HAGlue>Future for the operation on the local service.IOExceptionprotected abstract void handleReplicatedWrite(IHASyncRequest req, IHAWriteMessage msg, ByteBuffer data) throws Exception
Note: Replication of the message and payload is handled by the caller. The implementation of this method is NOT responsible for replication.
req - The synchronization request (optional). When non-
null the message and payload are historical data.
When null they are live data.msg - Metadata about a buffer containing data replicated to this
node.data - The buffer containing the data.ExceptionQuorumPipelineImpl#handleReplicatedWrite(IHAWriteMessage,
ByteBuffer)protected abstract void incReceive(IHASyncRequest req, IHAWriteMessage msg, int nreads, int rdlen, int rem) throws Exception
req - The synchronization request (optional). When non-
null the message and payload are historical data.
When null they are live data.msg - Metadata about a buffer containing data replicated to this
node.rdlen - The number of bytes read from the socket in this read.rem - The number of bytes remaining before the payload has been
fully read.Exceptionpublic void logWriteCacheBlock(IHAWriteMessage msg, ByteBuffer data) throws IOException
IHAWriteMessage and the associated data (if necessary).
The log file for the current write set will be deleted if the quorum is
fully met at the next 2-phase commit.
Note: The default implementation is a NOP.
logWriteCacheBlock in interface QuorumPipeline<S extends HAGlue>msg - The IHAWriteMessage.data - The WriteCache block.IOExceptionpublic void purgeHALogs(long token)
Note: The open HALog file is NOT removed by this method.
Note: The default implementation is a NOP.
purgeHALogs in interface QuorumPipeline<S extends HAGlue>token - The quorum token. The quorum must remain fully met for this
token across this operation. If that invariant is violated
then the operation will terminate once this violation is
noticed.public void logRootBlock(IRootBlockView rootBlock) throws IOException
HALogWriter.
Note: This method is ONLY invoked as part of the 2-phase commit protocol. Therefore, this method ONLY applies to the live HALog file. A service is atomically either joined with the met quorum at a 2-phase commit point or not joined. The PREPARE and COMMIT messages are ONLY generated for services that were joined with the met quorum as of that atomic decision point in the commit protocol. Therefore, this method is never called for a service that was not joined as of that atomic decision point.
Note: The default implementation is a NOP.
logRootBlock in interface QuorumPipeline<S extends HAGlue>rootBlock - The root block for the commit point that was just achieved.IOExceptionpublic void abort2Phase(long token)
throws IOException,
InterruptedException
QuorumCommitabort2Phase in interface QuorumCommit<S extends HAGlue>token - The quorum token.IOExceptionInterruptedExceptionpublic CommitResponse commit2Phase(CommitRequest req) throws IOException, InterruptedException
QuorumCommitprepare message. The commit MAY
NOT go forward unless both the current quorum token and the
lastCommitTime on this message agree with the quorum token and
lastCommitTime in the root block from the last "prepare" message.commit2Phase in interface QuorumCommit<S extends HAGlue>IOExceptionInterruptedExceptionpublic PrepareResponse prepare2Phase(PrepareRequest req) throws InterruptedException, TimeoutException, IOException
QuorumCommitcommit
message.prepare2Phase in interface QuorumCommit<S extends HAGlue>InterruptedExceptionTimeoutExceptionIOExceptionpublic final UUID getStoreUUID()
QuorumPipelineUUID of the backing store.getStoreUUID in interface QuorumPipeline<S extends HAGlue>public final long getLastCommitTime()
QuorumServicegetLastCommitTime in interface QuorumPipeline<S extends HAGlue>getLastCommitTime in interface QuorumService<S extends HAGlue>public final long getLastCommitCounter()
QuorumServicegetLastCommitCounter in interface QuorumPipeline<S extends HAGlue>getLastCommitCounter in interface QuorumService<S extends HAGlue>public long getPrepareTimeout()
QuorumServicegetPrepareTimeout in interface QuorumService<S extends HAGlue>public byte[] readFromQuorum(UUID storeId, long addr) throws InterruptedException, IOException
QuorumReadNote: This is NOT the normal path for reading on a record from a service. This is used to handle bad reads (when a checksum or IO error is reported by the local disk) by reading the record from another member of the quorum.
readFromQuorum in interface QuorumRead<S extends HAGlue>storeId - The UUID of the IRawStore from which the
record should be read.addr - The address of a record on that store.InterruptedExceptionIOExceptionHAGlue#readFromDisk(UUID, long)protected void processEvents()
public static <F extends Future<T>,T> void cancelFutures(List<F> futures)
NOte: This is not being done in parallel. However, due to a DGC thread
leak issue, we now use ThickFutures. Thus, the tasks that are
being cancelled are all local tasks running on the
#executorService. If that local task is doing an RMI, then
cancelling it will cause an interrupt in the NIO request.
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.