Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move away from IndexedBijections #3740

Open
wants to merge 1 commit into
base: cep-15-accord
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.cassandra.harry.SchemaSpec;
import org.apache.cassandra.harry.ValueGeneratorHelper;
import org.apache.cassandra.harry.cql.WriteHelper;
import org.apache.cassandra.harry.dsl.HistoryBuilder;
import org.apache.cassandra.harry.execution.CompiledStatement;
import org.apache.cassandra.harry.gen.Generator;
import org.apache.cassandra.harry.gen.SchemaGenerators;
Expand Down Expand Up @@ -80,11 +81,12 @@ public void writeConsistencyTest() throws Throwable
" WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};");
cluster.schemaChange(schema.compile());

for (int i = 0; i < schema.valueGenerators.pkPopulation(); i++)
HistoryBuilder.IndexedValueGenerators valueGenerators = (HistoryBuilder.IndexedValueGenerators) schema.valueGenerators;
for (int i = 0; i < valueGenerators.pkPopulation(); i++)
{
long pd = schema.valueGenerators.pkGen.descriptorAt(i);
long pd = valueGenerators.pkGen().descriptorAt(i);

ByteBuffer[] pk = ByteUtils.objectsToBytes(schema.valueGenerators.pkGen.inflate(pd));
ByteBuffer[] pk = ByteUtils.objectsToBytes(valueGenerators.pkGen().inflate(pd));
long token = TokenUtil.token(ByteUtils.compose(pk));
if (!prediction.state.get().isWriteTargetFor(token, prediction.node(6).matcher))
continue;
Expand All @@ -102,8 +104,8 @@ public void writeConsistencyTest() throws Throwable
Future<?> writeQuery = async(() -> {

CompiledStatement s = WriteHelper.inflateInsert(new Operations.WriteOp(lts, pd, 0,
ValueGeneratorHelper.randomDescriptors(rng, schema.valueGenerators.regularColumnGens),
ValueGeneratorHelper.randomDescriptors(rng, schema.valueGenerators.staticColumnGens),
ValueGeneratorHelper.randomDescriptors(rng, valueGenerators::regularColumnGen, valueGenerators.regularColumnCount()),
ValueGeneratorHelper.randomDescriptors(rng, valueGenerators::staticColumnGen, valueGenerators.staticColumnCount()),
Operations.Kind.INSERT),
schema,
lts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ public void coordinatorIsBehindTest() throws Throwable
}, "Start grep");

outer:
for (int i = 0; i < schema.valueGenerators.pkPopulation(); i++)
for (int i = 0; i < history.valueGenerators().pkPopulation(); i++)
{
long pd = schema.valueGenerators.pkGen.descriptorAt(i);
long pd = history.valueGenerators().pkGen().descriptorAt(i);
for (TokenPlacementModel.Replica replica : executor.getReplicasFor(pd))
{
if (cluster.get(1).config().broadcastAddress().toString().contains(replica.node().id()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private static CommandGen<Spec> cqlOperations(Spec spec)

for (Integer pkIdx : spec.pkGen.generated())
{
long pd = spec.schema.valueGenerators.pkGen.descriptorAt(pkIdx);
long pd = spec.harry.valueGenerators().pkGen().descriptorAt(pkIdx);
reads.add(new HarryCommand(s -> String.format("Harry Validate pd=%d%s", pd, state.commandNamePostfix()), s -> spec.harry.selectPartition(pkIdx)));

TransactionalMode transationalMode = spec.schema.options.transactionalMode();
Expand Down
13 changes: 7 additions & 6 deletions test/harry/main/org/apache/cassandra/harry/Relations.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.IntFunction;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -32,8 +32,9 @@ public class Relations
private static final Logger logger = LoggerFactory.getLogger(Relations.class);

@SuppressWarnings({ "rawtypes", "unchecked" })
public static boolean matchRange(Bijections.IndexedBijection<Object[]> ckGen,
List<Comparator<Object>> comparators,
public static boolean matchRange(Bijections.Bijection<Object[]> ckGen,
IntFunction<Comparator<Object>> comparators,
int ckCoulmnCount,
long lowBoundDescr, long highBoundDescr,
Relations.RelationKind[] lowBoundRelations, Relations.RelationKind[] highBoundRelations,
long matchDescr)
Expand All @@ -42,7 +43,7 @@ public static boolean matchRange(Bijections.IndexedBijection<Object[]> ckGen,
Object[] highBoundValue = highBoundDescr == MagicConstants.UNSET_DESCR ? null : ckGen.inflate(highBoundDescr);
Object[] matchValue = ckGen.inflate(matchDescr);
// TODO: assert that all equals + null checks
for (int i = 0; i < comparators.size(); i++)
for (int i = 0; i < ckCoulmnCount; i++)
{
Object matched = matchValue[i];

Expand All @@ -51,7 +52,7 @@ public static boolean matchRange(Bijections.IndexedBijection<Object[]> ckGen,
Object l = lowBoundValue[i];
Relations.RelationKind lr = lowBoundRelations[i];

if (lr != null && !lr.match(comparators.get(i), matched, l))
if (lr != null && !lr.match(comparators.apply(i), matched, l))
{
if (logger.isTraceEnabled())
logger.trace("Low Bound {} {} {} did match {}", lowBoundValue[i], lr, matchValue[i], i);
Expand All @@ -64,7 +65,7 @@ public static boolean matchRange(Bijections.IndexedBijection<Object[]> ckGen,
Object h = highBoundValue[i];
Relations.RelationKind hr = highBoundRelations[i];

if (hr != null && !hr.match(comparators.get(i), matched, h))
if (hr != null && !hr.match(comparators.apply(i), matched, h))
{
if (logger.isTraceEnabled())
logger.trace("High Bound {} {} {} did match {}", highBoundValue[i], hr, matchValue[i], i);
Expand Down
3 changes: 2 additions & 1 deletion test/harry/main/org/apache/cassandra/harry/SchemaSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.function.Consumer;

import org.apache.cassandra.cql3.ast.Symbol;
import org.apache.cassandra.harry.dsl.HistoryBuilder;
import org.apache.cassandra.harry.gen.Generator;
import org.apache.cassandra.harry.gen.Generators;
import org.apache.cassandra.harry.gen.ValueGenerators;
Expand Down Expand Up @@ -94,7 +95,7 @@ public SchemaSpec(long seed,
this.allColumnInSelectOrder = Collections.unmodifiableList(selectOrder);

// TODO: empty gen
this.valueGenerators = ValueGenerators.fromSchema(this, seed, populationPerColumn);
this.valueGenerators = HistoryBuilder.valueGenerators(this, seed, populationPerColumn);
}

public static /* unsigned */ long cumulativeEntropy(List<ColumnSpec<?>> columns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@

package org.apache.cassandra.harry;

import java.util.List;
import java.util.function.IntFunction;

import org.apache.cassandra.harry.gen.Bijections;
import org.apache.cassandra.harry.dsl.HistoryBuilder;
import org.apache.cassandra.harry.gen.EntropySource;

public class ValueGeneratorHelper
{
public static long[] randomDescriptors(EntropySource rng, List<Bijections.IndexedBijection<Object>> valueGens)
public static long[] randomDescriptors(EntropySource rng, IntFunction<HistoryBuilder.IndexedBijection<Object>> valueGens, int count)
{
long[] vds = new long[valueGens.size()];
for (int i = 0; i < valueGens.size(); i++)
long[] vds = new long[count];
for (int i = 0; i < count; i++)
{
if (rng.nextBoolean())
vds[i] = MagicConstants.UNSET_DESCR;
else
vds[i] = valueGens.get(i).descriptorAt(rng.nextInt(valueGens.size()));
vds[i] = valueGens.apply(i).descriptorAt(rng.nextInt(count));
}

return vds;
Expand Down
16 changes: 8 additions & 8 deletions test/harry/main/org/apache/cassandra/harry/cql/DeleteHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static CompiledStatement inflateDelete(Operations.DeletePartition delete,

List<Object> bindings = new ArrayList<>();

Object[] pk = schema.valueGenerators.pkGen.inflate(delete.pd());
Object[] pk = schema.valueGenerators.pkGen().inflate(delete.pd());

RelationWriter writer = new RelationWriter(b, bindings::add) ;

Expand Down Expand Up @@ -81,8 +81,8 @@ public static CompiledStatement inflateDelete(Operations.DeleteRow delete,

List<Object> bindings = new ArrayList<>();

Object[] pk = schema.valueGenerators.pkGen.inflate(delete.pd());
Object[] ck = schema.valueGenerators.ckGen.inflate(delete.cd());
Object[] pk = schema.valueGenerators.pkGen().inflate(delete.pd());
Object[] ck = schema.valueGenerators.ckGen().inflate(delete.cd());

RelationWriter writer = new RelationWriter(b, bindings::add);

Expand Down Expand Up @@ -139,8 +139,8 @@ public static CompiledStatement inflateDelete(Operations.DeleteColumns delete,

List<Object> bindings = new ArrayList<>();

Object[] pk = schema.valueGenerators.pkGen.inflate(delete.pd());
Object[] ck = schema.valueGenerators.ckGen.inflate(delete.cd());
Object[] pk = schema.valueGenerators.pkGen().inflate(delete.pd());
Object[] ck = schema.valueGenerators.ckGen().inflate(delete.cd());

RelationWriter writer = new RelationWriter(b, bindings::add);

Expand Down Expand Up @@ -173,9 +173,9 @@ public static CompiledStatement inflateDelete(Operations.DeleteRange delete,

List<Object> bindings = new ArrayList<>();

Object[] pk = schema.valueGenerators.pkGen.inflate(delete.pd());
Object[] lowBound = schema.valueGenerators.ckGen.inflate(delete.lowerBound());
Object[] highBound = schema.valueGenerators.ckGen.inflate(delete.upperBound());
Object[] pk = schema.valueGenerators.pkGen().inflate(delete.pd());
Object[] lowBound = schema.valueGenerators.ckGen().inflate(delete.lowerBound());
Object[] highBound = schema.valueGenerators.ckGen().inflate(delete.upperBound());

RelationWriter writer = new RelationWriter(b, bindings::add);

Expand Down
14 changes: 7 additions & 7 deletions test/harry/main/org/apache/cassandra/harry/cql/SelectHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static CompiledStatement select(Operations.SelectRow select, SchemaSpec s
{
Select.Builder builder = commmonPart(select, schema);

Object[] ck = schema.valueGenerators.ckGen.inflate(select.cd());
Object[] ck = schema.valueGenerators.ckGen().inflate(select.cd());

for (int i = 0; i < schema.clusteringKeys.size(); i++)
{
Expand All @@ -72,8 +72,8 @@ public static CompiledStatement select(Operations.SelectRange select, SchemaSpec
{
Select.Builder builder = commmonPart(select, schema);

Object[] lowBound = schema.valueGenerators.ckGen.inflate(select.lowerBound());
Object[] highBound = schema.valueGenerators.ckGen.inflate(select.upperBound());
Object[] lowBound = schema.valueGenerators.ckGen().inflate(select.lowerBound());
Object[] highBound = schema.valueGenerators.ckGen().inflate(select.upperBound());

for (int i = 0; i < schema.clusteringKeys.size(); i++)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public static CompiledStatement select(Operations.SelectCustom select, SchemaSpe
Map<Long, Object[]> cache = new HashMap<>();
for (Relations.Relation relation : select.ckRelations())
{
Object[] query = cache.computeIfAbsent(relation.descriptor, schema.valueGenerators.ckGen::inflate);
Object[] query = cache.computeIfAbsent(relation.descriptor, schema.valueGenerators.ckGen()::inflate);
ColumnSpec<?> column = schema.clusteringKeys.get(relation.column);
builder.withWhere(Reference.of(new Symbol(column.name, column.type.asServerType())),
toInequalities(relation.kind),
Expand All @@ -122,15 +122,15 @@ public static CompiledStatement select(Operations.SelectCustom select, SchemaSpe
for (Relations.Relation relation : select.regularRelations())
{
ColumnSpec<?> column = schema.regularColumns.get(relation.column);
Object query = schema.valueGenerators.regularColumnGens.get(relation.column).inflate(relation.descriptor);
Object query = schema.valueGenerators.regularColumnGen(relation.column).inflate(relation.descriptor);
builder.withWhere(Reference.of(new Symbol(column.name, column.type.asServerType())),
toInequalities(relation.kind),
new Bind(query, column.type.asServerType()));
}

for (Relations.Relation relation : select.staticRelations())
{
Object query = schema.valueGenerators.staticColumnGens.get(relation.column).inflate(relation.descriptor);
Object query = schema.valueGenerators.staticColumnGen(relation.column).inflate(relation.descriptor);
ColumnSpec<?> column = schema.staticColumns.get(relation.column);
builder.withWhere(Reference.of(new Symbol(column.name, column.type.asServerType())),
toInequalities(relation.kind),
Expand Down Expand Up @@ -191,7 +191,7 @@ public static Select.Builder commmonPart(Operations.SelectStatement select, Sche

builder.withTable(schema.keyspace, schema.table);

Object[] pk = schema.valueGenerators.pkGen.inflate(select.pd());
Object[] pk = schema.valueGenerators.pkGen().inflate(select.pd());
for (int i = 0; i < schema.partitionKeys.size(); i++)
{
ColumnSpec<?> column = schema.partitionKeys.get(i);
Expand Down
24 changes: 12 additions & 12 deletions test/harry/main/org/apache/cassandra/harry/cql/WriteHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public static CompiledStatement inflateInsert(Operations.WriteOp op,
{
assert op.vds().length == schema.regularColumns.size();
assert op.sds().length == schema.staticColumns.size();
assert op.vds().length == schema.valueGenerators.regularColumnGens.size();
assert op.sds().length == schema.valueGenerators.staticColumnGens.size();
assert op.vds().length == schema.valueGenerators.regularColumnCount();
assert op.sds().length == schema.valueGenerators.staticColumnCount();

Object[] partitionKey = schema.valueGenerators.pkGen.inflate(op.pd());
Object[] partitionKey = schema.valueGenerators.pkGen().inflate(op.pd());
assert partitionKey.length == schema.partitionKeys.size();
Object[] clusteringKey = schema.valueGenerators.ckGen.inflate(op.cd());
Object[] clusteringKey = schema.valueGenerators.ckGen().inflate(op.cd());
assert clusteringKey.length == schema.clusteringKeys.size();
Object[] regularColumns = new Object[op.vds().length];
Object[] staticColumns = new Object[op.sds().length];
Expand All @@ -51,7 +51,7 @@ public static CompiledStatement inflateInsert(Operations.WriteOp op,
if (descriptor == MagicConstants.UNSET_DESCR)
regularColumns[i] = MagicConstants.UNSET_VALUE;
else
regularColumns[i] = schema.valueGenerators.regularColumnGens.get(i).inflate(descriptor);
regularColumns[i] = schema.valueGenerators.regularColumnGen(i).inflate(descriptor);
}

for (int i = 0; i < op.sds().length; i++)
Expand All @@ -60,7 +60,7 @@ public static CompiledStatement inflateInsert(Operations.WriteOp op,
if (descriptor == MagicConstants.UNSET_DESCR)
staticColumns[i] = MagicConstants.UNSET_VALUE;
else
staticColumns[i] = schema.valueGenerators.staticColumnGens.get(i).inflate(descriptor);
staticColumns[i] = schema.valueGenerators.staticColumnGen(i).inflate(descriptor);
}

Object[] bindings = new Object[schema.allColumnInSelectOrder.size()];
Expand Down Expand Up @@ -115,21 +115,21 @@ public static CompiledStatement inflateUpdate(Operations.WriteOp op,
{
assert op.vds().length == schema.regularColumns.size();
assert op.sds().length == schema.staticColumns.size();
assert op.vds().length == schema.valueGenerators.regularColumnGens.size();
assert op.sds().length == schema.valueGenerators.staticColumnGens.size();
assert op.vds().length == schema.valueGenerators.regularColumnCount();
assert op.sds().length == schema.valueGenerators.staticColumnCount();

Object[] partitionKey = schema.valueGenerators.pkGen.inflate(op.pd);
Object[] partitionKey = schema.valueGenerators.pkGen().inflate(op.pd);
assert partitionKey.length == schema.partitionKeys.size();
Object[] clusteringKey = schema.valueGenerators.ckGen.inflate(op.cd());
Object[] clusteringKey = schema.valueGenerators.ckGen().inflate(op.cd());
assert clusteringKey.length == schema.clusteringKeys.size();
Object[] regularColumns = new Object[op.vds().length];
Object[] staticColumns = new Object[op.sds().length];

for (int i = 0; i < op.vds().length; i++)
regularColumns[i] = schema.valueGenerators.regularColumnGens.get(i).inflate(op.vds()[i]);
regularColumns[i] = schema.valueGenerators.regularColumnGen(i).inflate(op.vds()[i]);

for (int i = 0; i < op.sds().length; i++)
staticColumns[i] = schema.valueGenerators.staticColumnGens.get(i).inflate(op.sds()[i]);
staticColumns[i] = schema.valueGenerators.staticColumnGen(i).inflate(op.sds()[i]);

Object[] bindings = new Object[schema.allColumnInSelectOrder.size()];

Expand Down
Loading