Package org.apache.cassandra.service
Class AbstractWriteResponseHandler<T>
- java.lang.Object
-
- org.apache.cassandra.service.AbstractWriteResponseHandler<T>
-
- All Implemented Interfaces:
RequestCallback<T>
- Direct Known Subclasses:
BatchlogResponseHandler
,DatacenterSyncWriteResponseHandler
,WriteResponseHandler
public abstract class AbstractWriteResponseHandler<T> extends java.lang.Object implements RequestCallback<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Runnable
callback
protected static org.slf4j.Logger
logger
protected ReplicaPlan.ForWrite
replicaPlan
protected WriteType
writeType
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, java.lang.Runnable callback, WriteType writeType, java.util.function.Supplier<Mutation> hintOnFailure, Dispatcher.RequestTime requestTime)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract int
ackCount()
protected int
blockFor()
protected int
candidateReplicaCount()
TODO: this method is brittle for its purpose of deciding when we should fail a query; this needs to be aware of which nodes are live/downConsistencyLevel
consistencyLevel()
long
currentTimeoutNanos()
void
expired()
void
get()
boolean
invokeOnFailure()
Returns true if the callback handles failure reporting - in which case the remove host will be asked to report failures to us in the event of a problem processing the request.protected void
logResponseToIdealCLDelegate(Message<T> m)
This logs the response but doesn't do any further processing related to this write response handler on whether the CL was achieved.void
maybeTryAdditionalReplicas(IMutation mutation, StorageProxy.WritePerformer writePerformer, java.lang.String localDC)
Cheap Quorum backup.void
onFailure(InetAddressAndPort from, RequestFailureReason failureReason)
Called when there is an exception on the remote node or timeout happensabstract void
onResponse(Message<T> msg)
null message means "response from local write"void
setIdealCLResponseHandler(AbstractWriteResponseHandler handler)
Set a delegate ideal CL write response handler.protected void
signal()
protected boolean
waitingFor(InetAddressAndPort from)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.net.RequestCallback
trackLatencyForSnitch
-
-
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
replicaPlan
protected final ReplicaPlan.ForWrite replicaPlan
-
callback
protected final java.lang.Runnable callback
-
writeType
protected final WriteType writeType
-
-
Constructor Detail
-
AbstractWriteResponseHandler
protected AbstractWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, java.lang.Runnable callback, WriteType writeType, java.util.function.Supplier<Mutation> hintOnFailure, Dispatcher.RequestTime requestTime)
- Parameters:
callback
- A callback to be called when the write is successful.hintOnFailure
-requestTime
-
-
-
Method Detail
-
get
public void get() throws WriteTimeoutException, WriteFailureException
-
currentTimeoutNanos
public final long currentTimeoutNanos()
-
setIdealCLResponseHandler
public void setIdealCLResponseHandler(AbstractWriteResponseHandler handler)
Set a delegate ideal CL write response handler. Note that this could be the same as this if the ideal CL and requested CL are the same.
-
logResponseToIdealCLDelegate
protected final void logResponseToIdealCLDelegate(Message<T> m)
This logs the response but doesn't do any further processing related to this write response handler on whether the CL was achieved. Only call this after the subclass has completed all it's processing since the subclass instance may be queried to find out if the CL was achieved.
-
expired
public final void expired()
-
blockFor
protected int blockFor()
- Returns:
- the minimum number of endpoints that must respond.
-
candidateReplicaCount
protected int candidateReplicaCount()
TODO: this method is brittle for its purpose of deciding when we should fail a query; this needs to be aware of which nodes are live/down- Returns:
- the total number of endpoints the request can send to.
-
consistencyLevel
public ConsistencyLevel consistencyLevel()
-
waitingFor
protected boolean waitingFor(InetAddressAndPort from)
- Returns:
- true if the message counts towards the blockFor() threshold
-
ackCount
protected abstract int ackCount()
- Returns:
- number of responses received
-
onResponse
public abstract void onResponse(Message<T> msg)
null message means "response from local write"- Specified by:
onResponse
in interfaceRequestCallback<T>
- Parameters:
msg
- response received.
-
signal
protected void signal()
-
onFailure
public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason)
Description copied from interface:RequestCallback
Called when there is an exception on the remote node or timeout happens- Specified by:
onFailure
in interfaceRequestCallback<T>
-
invokeOnFailure
public boolean invokeOnFailure()
Description copied from interface:RequestCallback
Returns true if the callback handles failure reporting - in which case the remove host will be asked to report failures to us in the event of a problem processing the request. TODO: this is an error prone method, and we should be handling failures everywhere so we should probably just start doing that, and remove this method- Specified by:
invokeOnFailure
in interfaceRequestCallback<T>
- Returns:
- true if the callback should be invoked on failure
-
maybeTryAdditionalReplicas
public void maybeTryAdditionalReplicas(IMutation mutation, StorageProxy.WritePerformer writePerformer, java.lang.String localDC)
Cheap Quorum backup. If we failed to reach quorum with our initial (full) nodes, reach out to other nodes.
-
-