Include correct consistencyLevel in LWT timeout

patch by Sankalp Kohli; reviewed by jbellis for CASSANDRA-6884
This commit is contained in:
Jonathan Ellis 2014-03-19 00:15:19 -05:00
parent 9269cb83ce
commit f5e1cbca87
5 changed files with 19 additions and 14 deletions

View File

@ -1,4 +1,5 @@
2.0.7 2.0.7
* Include correct consistencyLevel in LWT timeout (CASSANDRA-6884)
* Lower chances for losing new SSTables during nodetool refresh and * Lower chances for losing new SSTables during nodetool refresh and
ColumnFamilyStore.loadNewSSTables (CASSANDRA-6514) ColumnFamilyStore.loadNewSSTables (CASSANDRA-6514)
* Add support for DELETE ... IF EXISTS to CQL3 (CASSANDRA-5708) * Add support for DELETE ... IF EXISTS to CQL3 (CASSANDRA-5708)

View File

@ -246,7 +246,7 @@ public class StorageProxy implements StorageProxyMBean
Commit proposal = Commit.newProposal(key, ballot, updates); Commit proposal = Commit.newProposal(key, ballot, updates);
Tracing.trace("CAS precondition is met; proposing client-requested updates for {}", ballot); Tracing.trace("CAS precondition is met; proposing client-requested updates for {}", ballot);
if (proposePaxos(proposal, liveEndpoints, requiredParticipants, true)) if (proposePaxos(proposal, liveEndpoints, requiredParticipants, true, consistencyForPaxos))
{ {
if (consistencyForCommit == ConsistencyLevel.ANY) if (consistencyForCommit == ConsistencyLevel.ANY)
sendCommit(proposal, liveEndpoints); sendCommit(proposal, liveEndpoints);
@ -318,7 +318,7 @@ public class StorageProxy implements StorageProxyMBean
// prepare // prepare
Tracing.trace("Preparing {}", ballot); Tracing.trace("Preparing {}", ballot);
Commit toPrepare = Commit.newPrepare(key, metadata, ballot); Commit toPrepare = Commit.newPrepare(key, metadata, ballot);
summary = preparePaxos(toPrepare, liveEndpoints, requiredParticipants); summary = preparePaxos(toPrepare, liveEndpoints, requiredParticipants, consistencyForPaxos);
if (!summary.promised) if (!summary.promised)
{ {
Tracing.trace("Some replicas have already promised a higher ballot than ours; aborting"); Tracing.trace("Some replicas have already promised a higher ballot than ours; aborting");
@ -336,7 +336,7 @@ public class StorageProxy implements StorageProxyMBean
{ {
Tracing.trace("Finishing incomplete paxos round {}", inProgress); Tracing.trace("Finishing incomplete paxos round {}", inProgress);
Commit refreshedInProgress = Commit.newProposal(inProgress.key, ballot, inProgress.update); Commit refreshedInProgress = Commit.newProposal(inProgress.key, ballot, inProgress.update);
if (proposePaxos(refreshedInProgress, liveEndpoints, requiredParticipants, false)) if (proposePaxos(refreshedInProgress, liveEndpoints, requiredParticipants, false, consistencyForPaxos))
{ {
commitPaxos(refreshedInProgress, ConsistencyLevel.QUORUM); commitPaxos(refreshedInProgress, ConsistencyLevel.QUORUM);
} }
@ -381,10 +381,10 @@ public class StorageProxy implements StorageProxyMBean
MessagingService.instance().sendOneWay(message, target); MessagingService.instance().sendOneWay(message, target);
} }
private static PrepareCallback preparePaxos(Commit toPrepare, List<InetAddress> endpoints, int requiredParticipants) private static PrepareCallback preparePaxos(Commit toPrepare, List<InetAddress> endpoints, int requiredParticipants, ConsistencyLevel consistencyForPaxos)
throws WriteTimeoutException throws WriteTimeoutException
{ {
PrepareCallback callback = new PrepareCallback(toPrepare.key, toPrepare.update.metadata(), requiredParticipants); PrepareCallback callback = new PrepareCallback(toPrepare.key, toPrepare.update.metadata(), requiredParticipants, consistencyForPaxos);
MessageOut<Commit> message = new MessageOut<Commit>(MessagingService.Verb.PAXOS_PREPARE, toPrepare, Commit.serializer); MessageOut<Commit> message = new MessageOut<Commit>(MessagingService.Verb.PAXOS_PREPARE, toPrepare, Commit.serializer);
for (InetAddress target : endpoints) for (InetAddress target : endpoints)
MessagingService.instance().sendRR(message, target, callback); MessagingService.instance().sendRR(message, target, callback);
@ -392,10 +392,10 @@ public class StorageProxy implements StorageProxyMBean
return callback; return callback;
} }
private static boolean proposePaxos(Commit proposal, List<InetAddress> endpoints, int requiredParticipants, boolean timeoutIfPartial) private static boolean proposePaxos(Commit proposal, List<InetAddress> endpoints, int requiredParticipants, boolean timeoutIfPartial, ConsistencyLevel consistencyLevel)
throws WriteTimeoutException throws WriteTimeoutException
{ {
ProposeCallback callback = new ProposeCallback(endpoints.size(), requiredParticipants, !timeoutIfPartial); ProposeCallback callback = new ProposeCallback(endpoints.size(), requiredParticipants, !timeoutIfPartial, consistencyLevel);
MessageOut<Commit> message = new MessageOut<Commit>(MessagingService.Verb.PAXOS_PROPOSE, proposal, Commit.serializer); MessageOut<Commit> message = new MessageOut<Commit>(MessagingService.Verb.PAXOS_PROPOSE, proposal, Commit.serializer);
for (InetAddress target : endpoints) for (InetAddress target : endpoints)
MessagingService.instance().sendRR(message, target, callback); MessagingService.instance().sendRR(message, target, callback);
@ -406,7 +406,7 @@ public class StorageProxy implements StorageProxyMBean
return true; return true;
if (timeoutIfPartial && !callback.isFullyRefused()) if (timeoutIfPartial && !callback.isFullyRefused())
throw new WriteTimeoutException(WriteType.CAS, ConsistencyLevel.SERIAL, callback.getAcceptCount(), requiredParticipants); throw new WriteTimeoutException(WriteType.CAS, consistencyLevel, callback.getAcceptCount(), requiredParticipants);
return false; return false;
} }

View File

@ -34,10 +34,12 @@ public abstract class AbstractPaxosCallback<T> implements IAsyncCallback<T>
{ {
protected final CountDownLatch latch; protected final CountDownLatch latch;
protected final int targets; protected final int targets;
private final ConsistencyLevel consistency;
public AbstractPaxosCallback(int targets) public AbstractPaxosCallback(int targets, ConsistencyLevel consistency)
{ {
this.targets = targets; this.targets = targets;
this.consistency = consistency;
latch = new CountDownLatch(targets); latch = new CountDownLatch(targets);
} }
@ -56,7 +58,7 @@ public abstract class AbstractPaxosCallback<T> implements IAsyncCallback<T>
try try
{ {
if (!latch.await(DatabaseDescriptor.getWriteRpcTimeout(), TimeUnit.MILLISECONDS)) if (!latch.await(DatabaseDescriptor.getWriteRpcTimeout(), TimeUnit.MILLISECONDS))
throw new WriteTimeoutException(WriteType.CAS, ConsistencyLevel.SERIAL, getResponseCount(), targets); throw new WriteTimeoutException(WriteType.CAS, consistency, getResponseCount(), targets);
} }
catch (InterruptedException ex) catch (InterruptedException ex)
{ {

View File

@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import org.apache.cassandra.db.ConsistencyLevel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -45,9 +46,9 @@ public class PrepareCallback extends AbstractPaxosCallback<PrepareResponse>
private final Map<InetAddress, Commit> commitsByReplica = new ConcurrentHashMap<InetAddress, Commit>(); private final Map<InetAddress, Commit> commitsByReplica = new ConcurrentHashMap<InetAddress, Commit>();
public PrepareCallback(ByteBuffer key, CFMetaData metadata, int targets) public PrepareCallback(ByteBuffer key, CFMetaData metadata, int targets, ConsistencyLevel consistency)
{ {
super(targets); super(targets, consistency);
// need to inject the right key in the empty commit so comparing with empty commits in the reply works as expected // need to inject the right key in the empty commit so comparing with empty commits in the reply works as expected
mostRecentCommit = Commit.emptyCommit(key, metadata); mostRecentCommit = Commit.emptyCommit(key, metadata);
mostRecentInProgressCommit = Commit.emptyCommit(key, metadata); mostRecentInProgressCommit = Commit.emptyCommit(key, metadata);

View File

@ -23,6 +23,7 @@ package org.apache.cassandra.service.paxos;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.apache.cassandra.db.ConsistencyLevel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -49,9 +50,9 @@ public class ProposeCallback extends AbstractPaxosCallback<Boolean>
private final int requiredAccepts; private final int requiredAccepts;
private final boolean failFast; private final boolean failFast;
public ProposeCallback(int totalTargets, int requiredTargets, boolean failFast) public ProposeCallback(int totalTargets, int requiredTargets, boolean failFast, ConsistencyLevel consistency)
{ {
super(totalTargets); super(totalTargets, consistency);
this.requiredAccepts = requiredTargets; this.requiredAccepts = requiredTargets;
this.failFast = failFast; this.failFast = failFast;
} }