mirror of https://github.com/apache/cassandra
CEP-15: (Accord) Migrate Accord away from JDK random to a new interface RandomSource
patch by David Capwell; reviewed by Blake Eggleston for CASSANDRA-18213
This commit is contained in:
parent
6c62cc4ffa
commit
f092461114
|
|
@ -1 +1 @@
|
|||
Subproject commit f607a05b76df32b39c97a6e49068ae35057be98a
|
||||
Subproject commit bc81f81c75f93c73989a30bbc51b5c241a893c1a
|
||||
|
|
@ -19,7 +19,6 @@
|
|||
package org.apache.cassandra.service.accord;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
|
@ -40,6 +39,7 @@ import accord.messages.Request;
|
|||
import accord.primitives.Txn;
|
||||
import accord.primitives.TxnId;
|
||||
import accord.topology.TopologyManager;
|
||||
import accord.utils.DefaultRandom;
|
||||
import accord.utils.async.AsyncChains;
|
||||
import org.apache.cassandra.concurrent.Shutdownable;
|
||||
import accord.utils.async.AsyncResult;
|
||||
|
|
@ -144,7 +144,7 @@ public class AccordService implements IAccordService, Shutdownable
|
|||
() -> null,
|
||||
new KeyspaceSplitter(new EvenSplit<>(getConcurrentAccordOps(), getPartitioner().accordSplitter())),
|
||||
new AccordAgent(),
|
||||
new Random(),
|
||||
new DefaultRandom(),
|
||||
scheduler,
|
||||
SizeOfIntersectionSorter.SUPPLIER,
|
||||
SimpleProgressLog::new,
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ import accord.primitives.TxnId;
|
|||
import accord.primitives.Writes;
|
||||
import accord.utils.Gen;
|
||||
import accord.utils.Gens;
|
||||
import accord.utils.RandomSource;
|
||||
import accord.utils.async.AsyncChains;
|
||||
import accord.utils.async.AsyncResult;
|
||||
import org.apache.cassandra.SchemaLoader;
|
||||
|
|
@ -481,7 +482,7 @@ public class AsyncOperationTest
|
|||
});
|
||||
}
|
||||
|
||||
private static void createCommand(AccordCommandStore commandStore, Gen.Random rs, List<TxnId> ids)
|
||||
private static void createCommand(AccordCommandStore commandStore, RandomSource rs, List<TxnId> ids)
|
||||
{
|
||||
// to simulate CommandsForKey not being found, use createCommittedAndPersist periodically as it does not update
|
||||
if (rs.nextBoolean()) ids.forEach(id -> createCommittedAndPersist(commandStore, id));
|
||||
|
|
@ -489,7 +490,7 @@ public class AsyncOperationTest
|
|||
commandStore.clearCache();
|
||||
}
|
||||
|
||||
private static Map<TxnId, Boolean> selectFailedTxn(Gen.Random rs, List<TxnId> ids)
|
||||
private static Map<TxnId, Boolean> selectFailedTxn(RandomSource rs, List<TxnId> ids)
|
||||
{
|
||||
Map<TxnId, Boolean> failed = Maps.newHashMapWithExpectedSize(ids.size());
|
||||
for (TxnId id : ids)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.junit.Test;
|
|||
|
||||
import accord.impl.CommandsForKey;
|
||||
import accord.primitives.TxnId;
|
||||
import accord.utils.AccordGens;
|
||||
import accord.utils.Gens;
|
||||
import org.apache.cassandra.SchemaLoader;
|
||||
import org.apache.cassandra.io.util.DataInputBuffer;
|
||||
|
|
@ -56,7 +57,7 @@ public class CommandsForKeySerializerTest
|
|||
{
|
||||
DataOutputBuffer buffer = new DataOutputBuffer();
|
||||
int version = MessagingService.Version.VERSION_40.value;
|
||||
qt().forAll(Gens.lists(AccordGenerators.ids()).ofSizeBetween(0, 10)).check(ids -> {
|
||||
qt().forAll(Gens.lists(AccordGens.txnIds()).ofSizeBetween(0, 10)).check(ids -> {
|
||||
buffer.clear();
|
||||
|
||||
long expectedSize = CommandsForKeySerializer.depsIdSerializer.serializedSize(ids, version);
|
||||
|
|
|
|||
|
|
@ -18,48 +18,26 @@
|
|||
|
||||
package org.apache.cassandra.utils;
|
||||
|
||||
import java.util.function.ToIntFunction;
|
||||
import java.util.function.ToLongFunction;
|
||||
|
||||
import accord.local.Command;
|
||||
import accord.local.Node;
|
||||
import accord.primitives.PartialTxn;
|
||||
import accord.primitives.Routable;
|
||||
import accord.primitives.Timestamp;
|
||||
import accord.primitives.Txn;
|
||||
import accord.primitives.TxnId;
|
||||
import accord.utils.Gen;
|
||||
import accord.utils.Gens;
|
||||
import org.apache.cassandra.service.accord.AccordTestUtils;
|
||||
|
||||
import static accord.utils.AccordGens.txnIds;
|
||||
import static org.apache.cassandra.service.accord.AccordTestUtils.createPartialTxn;
|
||||
|
||||
public class AccordGenerators
|
||||
{
|
||||
private AccordGenerators() {}
|
||||
|
||||
public static Gen.LongGen epochs()
|
||||
{
|
||||
return Gens.longs().between(0, Timestamp.MAX_EPOCH);
|
||||
}
|
||||
|
||||
public static Gen<TxnId> ids()
|
||||
{
|
||||
return ids(epochs()::nextLong, Gen.Random::nextLong, Gen.Random::nextInt);
|
||||
}
|
||||
|
||||
public static Gen<TxnId> ids(ToLongFunction<Gen.Random> epochs, ToLongFunction<Gen.Random> hlcs, ToIntFunction<Gen.Random> nodes)
|
||||
{
|
||||
Gen<Txn.Kind> kinds = Gens.enums().all(Txn.Kind.class);
|
||||
Gen<Routable.Domain> domains = Gens.enums().all(Routable.Domain.class);
|
||||
return rs -> new TxnId(epochs.applyAsLong(rs), hlcs.applyAsLong(rs), kinds.next(rs), domains.next(rs), new Node.Id(nodes.applyAsInt(rs)));
|
||||
}
|
||||
|
||||
private enum SupportedCommandTypes { notWitnessed, preaccepted, committed }
|
||||
|
||||
public static Gen<Command> commands()
|
||||
{
|
||||
Gen<TxnId> ids = ids();
|
||||
Gen<TxnId> ids = txnIds();
|
||||
//TODO switch to Status once all types are supported
|
||||
Gen<SupportedCommandTypes> supportedTypes = Gens.enums().all(SupportedCommandTypes.class);
|
||||
//TODO goes against fuzz testing, and also limits to a very specific table existing...
|
||||
|
|
|
|||
Loading…
Reference in New Issue