belliottsmith commented on code in PR #2056:
URL: https://github.com/apache/cassandra/pull/2056#discussion_r1082369095
##########
test/simulator/main/org/apache/cassandra/simulator/paxos/PairOfSequencesAccordSimulation.java:
##########
@@ -281,21 +157,152 @@ protected String preInsertStmt()
}
@Override
- Operation verifying(int operationId, IInvokableInstance instance, int
primaryKey, HistoryChecker historyChecker)
+ boolean allowMultiplePartitions() { return true; }
+
+ @Override
+ BiFunction<SimulatedSystems, int[], Supplier<Action>> actionFactory()
{
- return new VerifyingOperation(operationId, instance,
serialConsistency, primaryKey, historyChecker);
+ AtomicInteger id = new AtomicInteger(0);
+
+ return (simulated, primaryKeyIndex) -> {
+ int[] primaryKeys = IntStream.of(primaryKeyIndex).map(i ->
this.primaryKeys[i]).toArray();
+ return () -> accordAction(id.getAndIncrement(), simulated,
primaryKeys);
+ };
}
- @Override
- Operation nonVerifying(int operationId, IInvokableInstance instance, int
primaryKey, HistoryChecker historyChecker)
+ public class ReadWriteOperation extends Operation
{
- return new NonVerifyingOperation(operationId, instance,
serialConsistency, primaryKey, historyChecker);
+ private final IntHashSet reads, writes;
+
+ public ReadWriteOperation(int id, int[] primaryKeys, IntHashSet reads,
IntHashSet writes, IInvokableInstance instance)
+ {
+ super(primaryKeys, id, instance, "Accord", createQuery(id, reads,
writes));
+ this.reads = reads;
+ this.writes = writes;
+ }
+
+ @Override
+ void verify(Observation outcome)
+ {
+ SimpleQueryResult result = outcome.result;
+ (result != null ? successfulWrites :
failedWrites).incrementAndGet();
+ if (result != null)
+ {
+ IntHashSet seen = new IntHashSet();
+ //TODO if there isn't a value then we get empty read, which
then doesn't make it into the QueryResult
+ // given the fact that we always run with the partitions
defined this should be fine
+ try (HistoryValidator.Checker checker =
validator.witness(outcome.start, outcome.end))
+ {
+ while (result.hasNext())
+ {
+ org.apache.cassandra.distributed.api.Row row =
result.next();
+
+ int pk = row.getInteger("pk");
+ int count = row.getInteger("count", 0);
+ int[] seq = Arrays.stream(row.getString("seq",
"").split(","))
+ .filter(s -> !s.isEmpty())
+ .mapToInt(Integer::parseInt)
+ .toArray();
+
+ if (!seen.add(pk))
+ throw new IllegalStateException("Duplicate
partition key " + pk);
+ // every partition was read, but not all were written
to... need to verify each partition
+ if (seq.length != count)
+ throw fail(pk, "%d != #%s", count, seq);
+
+ checker.read(pk, outcome.id, count, seq);
+
+ if (writes.contains(pk))
Review Comment:
Can just leave this to the write loop?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]