You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "ifesdjeen (via GitHub)" <gi...@apache.org> on 2024/01/22 17:04:02 UTC
[PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
ifesdjeen opened a new pull request, #3060:
URL: https://github.com/apache/cassandra/pull/3060
…ific values for clustering, regular, and static columns
Patch by Alex Petrov; reviewed by TBD for CASSANDRA-19284
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1498088032
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
Review Comment:
nit: Can we validate after the loop, or is there something we'd miss if we didn't on every iteration?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1498129018
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, false)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.int64Type)),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.int64Type)
+ ));
+
+ Map<String, Bijections.Bijection<?>> reGenerators = new HashMap<>();
+ reGenerators.put("regular1", ColumnSpec.asciiType(4, 4).generator());
+ reGenerators.put("regular2", ColumnSpec.int64Type.generator());
+ reGenerators.put("static1", ColumnSpec.asciiType(8, 4).generator());
+ reGenerators.put("static2", ColumnSpec.int64Type.generator());
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 100;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+
+ Map<String, Set<Object>> perColumnOverrides = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
+ history.valueOverrides().override(column.name, i, override);
+ perColumnOverrides.get(column.name).add(override);
+ }
+ }
+
+ for (ColumnSpec column : schema.staticColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
+ history.valueOverrides().override(column.name, i, override);
+ perColumnOverrides.get(column.name).add(override);
+ }
+ }
+ for (int pdIdx = 0; pdIdx < 10; pdIdx++)
+ {
+ Map<String, Set<Object>> results = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ results.put(column.name, new HashSet<>());
+ for (ColumnSpec column : schema.staticColumns)
+ results.put(column.name, new HashSet<>());
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(pdIdx)
+ .insert(i,
+ new int[]{ rng.nextInt(100), rng.nextInt(100) },
+ new int[]{ rng.nextInt(100), rng.nextInt(100) });
Review Comment:
I think I made a comment about how we name these in the `SingleOperationBuilder` interface, but to confirm, we're basically asking the history builder to insert our overrides at the random row indexes?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic closed pull request #3060: Harry model that supports value overrides: an ability to provide spec…
URL: https://github.com/apache/cassandra/pull/3060
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531719380
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
+ }
+
+ @Override
+ public void overrideClusterings(Object[][] overrides)
+ {
+ assert possibleCds.length == overrides.length;
+ Arrays.sort(overrides, this::compareCds);
+ for (int i = 0; i < overrides.length; i++)
+ ckGenerator.override(possibleCds[i], overrides[i]);
+ }
+
+ @Override
+ public long pd()
+ {
+ return pd;
+ }
+
+ long getCdForOverride(Object[] ck)
+ {
+ int low = 0;
+ int high = possibleCds.length - 1;
+
+ while (low <= high)
+ {
+ int mid = (low + high) >>> 1;
+ long midEl = possibleCds[mid];
+ int cmp = compareCds(ck, midEl);
+
+ if (cmp < 0)
+ low = mid + 1;
+ else if (cmp > 0)
+ high = mid - 1;
+ else
+ throw new IllegalStateException("This value is already present");
+ }
+
+ return possibleCds[Math.min(possibleCds.length - 1, low)];
+ }
+
+ private int compareCds(Object[] v1, long cd2) {
+ Object[] v2 = schema.ckGenerator.inflate(cd2);
+ return compareCds(v1, v2);
+ }
+
+ private int compareCds(Object[] v1, Object[] v2) {
+ assert v1.length == v2.length : String.format("Values should be of same length: %d != %d\n" +
+ "%s\n" +
+ "%s",
+ v1.length, v2.length, Arrays.toString(v1), Arrays.toString(v2));
Review Comment:
To my best knowledge the `:` part is only evaluated on exception. I have removed `+` since they seem to be redundant though.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496788070
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
+ }
+
+ @Override
+ public void overrideClusterings(Object[][] overrides)
+ {
+ assert possibleCds.length == overrides.length;
+ Arrays.sort(overrides, this::compareCds);
+ for (int i = 0; i < overrides.length; i++)
+ ckGenerator.override(possibleCds[i], overrides[i]);
+ }
+
+ @Override
+ public long pd()
+ {
+ return pd;
+ }
+
+ long getCdForOverride(Object[] ck)
+ {
+ int low = 0;
+ int high = possibleCds.length - 1;
+
+ while (low <= high)
+ {
+ int mid = (low + high) >>> 1;
+ long midEl = possibleCds[mid];
+ int cmp = compareCds(ck, midEl);
+
+ if (cmp < 0)
+ low = mid + 1;
+ else if (cmp > 0)
+ high = mid - 1;
+ else
+ throw new IllegalStateException("This value is already present");
+ }
+
+ return possibleCds[Math.min(possibleCds.length - 1, low)];
+ }
+
+ private int compareCds(Object[] v1, long cd2) {
+ Object[] v2 = schema.ckGenerator.inflate(cd2);
+ return compareCds(v1, v2);
+ }
+
+ private int compareCds(Object[] v1, Object[] v2) {
+ assert v1.length == v2.length : String.format("Values should be of same length: %d != %d\n" +
+ "%s\n" +
+ "%s",
+ v1.length, v2.length, Arrays.toString(v1), Arrays.toString(v2));
Review Comment:
nit: I guess if this was a hot path, I'd be worried about the string creation.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531786680
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, false)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.int64Type)),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.int64Type)
+ ));
+
+ Map<String, Bijections.Bijection<?>> reGenerators = new HashMap<>();
+ reGenerators.put("regular1", ColumnSpec.asciiType(4, 4).generator());
+ reGenerators.put("regular2", ColumnSpec.int64Type.generator());
+ reGenerators.put("static1", ColumnSpec.asciiType(8, 4).generator());
+ reGenerators.put("static2", ColumnSpec.int64Type.generator());
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 100;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+
+ Map<String, Set<Object>> perColumnOverrides = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
Review Comment:
Added some docs!
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531779233
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, false)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.int64Type)),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.int64Type)
+ ));
+
+ Map<String, Bijections.Bijection<?>> reGenerators = new HashMap<>();
+ reGenerators.put("regular1", ColumnSpec.asciiType(4, 4).generator());
+ reGenerators.put("regular2", ColumnSpec.int64Type.generator());
+ reGenerators.put("static1", ColumnSpec.asciiType(8, 4).generator());
+ reGenerators.put("static2", ColumnSpec.int64Type.generator());
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 100;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+
+ Map<String, Set<Object>> perColumnOverrides = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
+ history.valueOverrides().override(column.name, i, override);
Review Comment:
You are right to note that using `partitionSize` here is somewhat arbitrary. In other words, there's nothing prevents us to use some other `idx` (i.e. larger than 100), and get an actually random value. I've just overriden 100 values per column, but then we're going in the loop and are simply picking one of these 100 values. In the end, there will be only 1 unique static value per partition and ~60 unique values (assuming uniform distribution, so can be more or less) per value column.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531716013
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
Review Comment:
Since it's likely to be used always in conjuntion with the existing bijection (i.e. overriding it), I think it might be fine to keep it as a class. We can always refactor it if we see more uses.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496704521
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
Review Comment:
```suggestion
public void ckOverrideSortingTest()
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1498166248
##########
test/harry/main/org/apache/cassandra/harry/dsl/SingleOperationBuilder.java:
##########
@@ -36,8 +35,8 @@ public interface SingleOperationBuilder
* Insert _specific values_ into _specific_ row. Rows are ordered by clustering key and
* numbered from 0 to maxRows
*/
- SingleOperationBuilder insert(int rowIdx, long[] vds);
- SingleOperationBuilder insert(int rowIdx, long[] vds, long[] sds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds, int[] sds);
Review Comment:
I see the right `ValueHelper#overrides` bijection getting the mapping, but then nothing accesses the overrides?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496776345
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
Review Comment:
Aside: I'm also kind of wondering now if `OverridingBijection` being an interface would have some organizational usefulness. I guess it only matters if `override()` is going to be used in contexts where we need indirection.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496800512
##########
test/harry/main/org/apache/cassandra/harry/dsl/ValueDescriptorIndexGenerator.java:
##########
@@ -37,10 +37,18 @@
*/
public class ValueDescriptorIndexGenerator implements Surjections.Surjection<Long>
{
+ public static int UNSET = Integer.MIN_VALUE;
+
private final OpSelectors.PureRng rng;
private final long columnHash;
private final long mask;
+ public ValueDescriptorIndexGenerator(ColumnSpec<?> columnSpec,
+ long seed)
Review Comment:
nit: unnecessarily breaking `seed` to a second line?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1498153826
##########
test/harry/main/org/apache/cassandra/harry/dsl/SingleOperationBuilder.java:
##########
@@ -36,8 +35,8 @@ public interface SingleOperationBuilder
* Insert _specific values_ into _specific_ row. Rows are ordered by clustering key and
* numbered from 0 to maxRows
*/
- SingleOperationBuilder insert(int rowIdx, long[] vds);
- SingleOperationBuilder insert(int rowIdx, long[] vds, long[] sds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds, int[] sds);
Review Comment:
Well, the inserts happen and the SUT matches, but `validateAll()` doesn't like it :)
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496784194
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
+ }
+
+ @Override
+ public void overrideClusterings(Object[][] overrides)
+ {
+ assert possibleCds.length == overrides.length;
+ Arrays.sort(overrides, this::compareCds);
+ for (int i = 0; i < overrides.length; i++)
+ ckGenerator.override(possibleCds[i], overrides[i]);
+ }
+
+ @Override
+ public long pd()
+ {
+ return pd;
+ }
+
+ long getCdForOverride(Object[] ck)
+ {
+ int low = 0;
+ int high = possibleCds.length - 1;
+
+ while (low <= high)
+ {
+ int mid = (low + high) >>> 1;
+ long midEl = possibleCds[mid];
+ int cmp = compareCds(ck, midEl);
+
+ if (cmp < 0)
+ low = mid + 1;
+ else if (cmp > 0)
+ high = mid - 1;
+ else
+ throw new IllegalStateException("This value is already present");
+ }
+
+ return possibleCds[Math.min(possibleCds.length - 1, low)];
+ }
+
+ private int compareCds(Object[] v1, long cd2) {
Review Comment:
nit: `{` newline
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
+ }
+
+ @Override
+ public void overrideClusterings(Object[][] overrides)
+ {
+ assert possibleCds.length == overrides.length;
+ Arrays.sort(overrides, this::compareCds);
+ for (int i = 0; i < overrides.length; i++)
+ ckGenerator.override(possibleCds[i], overrides[i]);
+ }
+
+ @Override
+ public long pd()
+ {
+ return pd;
+ }
+
+ long getCdForOverride(Object[] ck)
+ {
+ int low = 0;
+ int high = possibleCds.length - 1;
+
+ while (low <= high)
+ {
+ int mid = (low + high) >>> 1;
+ long midEl = possibleCds[mid];
+ int cmp = compareCds(ck, midEl);
+
+ if (cmp < 0)
+ low = mid + 1;
+ else if (cmp > 0)
+ high = mid - 1;
+ else
+ throw new IllegalStateException("This value is already present");
+ }
+
+ return possibleCds[Math.min(possibleCds.length - 1, low)];
+ }
+
+ private int compareCds(Object[] v1, long cd2) {
+ Object[] v2 = schema.ckGenerator.inflate(cd2);
+ return compareCds(v1, v2);
+ }
+
+ private int compareCds(Object[] v1, Object[] v2) {
Review Comment:
nit: `{` newline
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496799769
##########
test/harry/main/org/apache/cassandra/harry/dsl/SingleOperationBuilder.java:
##########
@@ -36,8 +35,8 @@ public interface SingleOperationBuilder
* Insert _specific values_ into _specific_ row. Rows are ordered by clustering key and
* numbered from 0 to maxRows
*/
- SingleOperationBuilder insert(int rowIdx, long[] vds);
- SingleOperationBuilder insert(int rowIdx, long[] vds, long[] sds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds, int[] sds);
Review Comment:
Should we be clear here in term of naming that these are indexes and no longer actual ads? `SingleOperationVisitBuilder` is a little clearer, of course...
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496760248
##########
test/harry/main/org/apache/cassandra/harry/dsl/OverridingCkGenerator.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.DataGenerators;
+
+/**
+ * A class that helps to override parts of clustering key. The tricky part about CK overrides is that Harry model makes
+ * an assumption about the ordering of clustering keys, which means clusterings have to be sorted in the same way their
+ * descriptors are. This, combined with reverse types, makes managing this state somewhat tricky at times.
+ *
+ * Additionally, Relation in delete/select query receives individual CK descriptors (i.e. after they have been sliced),
+ * while most other queries usually operate on inflated clustering key. All of this is required for efficient _stateless_
+ * validation, but makes overrides a bit less intuitive.
+ *
+ * To summarise: overrides for inflating are done for individual clustering key columns. Overrides for deflating a clustering
+ * operate on an entire key. Main reason for this is to allow having same string in several rows for the same column.
+ */
+public class OverridingCkGenerator extends DataGenerators.KeyGenerator
+{
+ private final DataGenerators.KeyGenerator delegate;
+ private final KeyPartOverride[] columnValueOverrides;
+ private final List<ColumnSpec<?>> columnSpecOverrides;
+ private final Map<ArrayWrapper, Long> valueToDescriptor;
+
+ // Had to be a static method because you can not call super after you have initialised any fields
+ public static OverridingCkGenerator make(DataGenerators.KeyGenerator delegate)
+ {
+ KeyPartOverride[] columnValueOverrides = new KeyPartOverride[delegate.columns.size()];
+ List<ColumnSpec<?>> columnSpecOverrides = new ArrayList<>();
+ for (int i = 0; i < delegate.columns.size(); i++)
+ {
+ columnValueOverrides[i] = new KeyPartOverride<>(delegate.columns.get(i).generator());
+ columnSpecOverrides.add(delegate.columns.get(i).override(columnValueOverrides[i]));
+ }
+ assert columnValueOverrides.length == columnSpecOverrides.size();
+ return new OverridingCkGenerator(delegate, columnValueOverrides, columnSpecOverrides);
+ }
+
+ private OverridingCkGenerator(DataGenerators.KeyGenerator delegate,
+ KeyPartOverride[] columnValueOverrides,
+ List<ColumnSpec<?>> columnSpecOverrides)
+ {
+ super(columnSpecOverrides);
+ this.columnValueOverrides = columnValueOverrides;
+ this.columnSpecOverrides = columnSpecOverrides;
+ this.delegate = delegate;
+ this.valueToDescriptor = new HashMap<>();
+ }
+
+ public void override(long descriptor, Object[] value)
+ {
+ long[] slices = delegate.slice(descriptor);
+ for (int i = 0; i < slices.length; i++)
+ columnValueOverrides[i].override(slices[i], value[i]);
+
+ // We _always_ deflate clustering key as a package, since we can not validate a clustering key without all components anyways.
+ valueToDescriptor.put(new ArrayWrapper(value), descriptor);
+ }
+
+ @Override
+ public Object[] inflate(long descriptor)
+ {
+ return DataGenerators.inflateKey(columnSpecOverrides, descriptor, slice(descriptor));
+ }
+
+ @Override
+ public long deflate(Object[] value)
+ {
+ Long descriptor = valueToDescriptor.get(new ArrayWrapper(value));
+ if (descriptor != null)
+ return descriptor;
+
+ return delegate.deflate(value);
+ }
+
+ @Override
+ public int byteSize()
+ {
+ return delegate.byteSize();
+ }
+
+ @Override
+ public int compare(long l, long r)
+ {
+ return delegate.byteSize();
+ }
+
+ @Override
+ public long[] slice(long descriptor)
+ {
+ return delegate.slice(descriptor);
+ }
+
+ @Override
+ public long stitch(long[] parts)
+ {
+ return delegate.stitch(parts);
+ }
+
+ @Override
+ public long minValue(int idx)
+ {
+ return delegate.minValue(idx);
+ }
+
+ @Override
+ public long maxValue(int idx)
+ {
+ return delegate.maxValue(idx);
+ }
+
+ public static class KeyPartOverride<T> implements Bijections.Bijection<T>
Review Comment:
This shares some code w/ `OverridingBijection`, but I'll let you decide whether there's enough in common to factor something out. Maybe `KeyPartOverride` could be an `OverridingBijection` that just overrides `override()` and `deflate()`...
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496704400
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
Review Comment:
```suggestion
public void ckOverrideManySortingTest()
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531710977
##########
test/harry/main/org/apache/cassandra/harry/dsl/OverridingCkGenerator.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.DataGenerators;
+
+/**
+ * A class that helps to override parts of clustering key. The tricky part about CK overrides is that Harry model makes
+ * an assumption about the ordering of clustering keys, which means clusterings have to be sorted in the same way their
+ * descriptors are. This, combined with reverse types, makes managing this state somewhat tricky at times.
+ *
+ * Additionally, Relation in delete/select query receives individual CK descriptors (i.e. after they have been sliced),
+ * while most other queries usually operate on inflated clustering key. All of this is required for efficient _stateless_
+ * validation, but makes overrides a bit less intuitive.
+ *
+ * To summarise: overrides for inflating are done for individual clustering key columns. Overrides for deflating a clustering
+ * operate on an entire key. Main reason for this is to allow having same string in several rows for the same column.
+ */
+public class OverridingCkGenerator extends DataGenerators.KeyGenerator
+{
+ private final DataGenerators.KeyGenerator delegate;
+ private final KeyPartOverride[] columnValueOverrides;
+ private final List<ColumnSpec<?>> columnSpecOverrides;
+ private final Map<ArrayWrapper, Long> valueToDescriptor;
+
+ // Had to be a static method because you can not call super after you have initialised any fields
+ public static OverridingCkGenerator make(DataGenerators.KeyGenerator delegate)
+ {
+ KeyPartOverride[] columnValueOverrides = new KeyPartOverride[delegate.columns.size()];
+ List<ColumnSpec<?>> columnSpecOverrides = new ArrayList<>();
+ for (int i = 0; i < delegate.columns.size(); i++)
+ {
+ columnValueOverrides[i] = new KeyPartOverride<>(delegate.columns.get(i).generator());
+ columnSpecOverrides.add(delegate.columns.get(i).override(columnValueOverrides[i]));
+ }
+ assert columnValueOverrides.length == columnSpecOverrides.size();
+ return new OverridingCkGenerator(delegate, columnValueOverrides, columnSpecOverrides);
+ }
+
+ private OverridingCkGenerator(DataGenerators.KeyGenerator delegate,
+ KeyPartOverride[] columnValueOverrides,
+ List<ColumnSpec<?>> columnSpecOverrides)
+ {
+ super(columnSpecOverrides);
+ this.columnValueOverrides = columnValueOverrides;
+ this.columnSpecOverrides = columnSpecOverrides;
+ this.delegate = delegate;
+ this.valueToDescriptor = new HashMap<>();
+ }
+
+ public void override(long descriptor, Object[] value)
+ {
+ long[] slices = delegate.slice(descriptor);
+ for (int i = 0; i < slices.length; i++)
+ columnValueOverrides[i].override(slices[i], value[i]);
+
+ // We _always_ deflate clustering key as a package, since we can not validate a clustering key without all components anyways.
+ valueToDescriptor.put(new ArrayWrapper(value), descriptor);
+ }
+
+ @Override
+ public Object[] inflate(long descriptor)
+ {
+ return DataGenerators.inflateKey(columnSpecOverrides, descriptor, slice(descriptor));
+ }
+
+ @Override
+ public long deflate(Object[] value)
+ {
+ Long descriptor = valueToDescriptor.get(new ArrayWrapper(value));
+ if (descriptor != null)
+ return descriptor;
+
+ return delegate.deflate(value);
+ }
+
+ @Override
+ public int byteSize()
+ {
+ return delegate.byteSize();
+ }
+
+ @Override
+ public int compare(long l, long r)
+ {
+ return delegate.byteSize();
+ }
+
+ @Override
+ public long[] slice(long descriptor)
+ {
+ return delegate.slice(descriptor);
+ }
+
+ @Override
+ public long stitch(long[] parts)
+ {
+ return delegate.stitch(parts);
+ }
+
+ @Override
+ public long minValue(int idx)
+ {
+ return delegate.minValue(idx);
+ }
+
+ @Override
+ public long maxValue(int idx)
+ {
+ return delegate.maxValue(idx);
+ }
+
+ public static class KeyPartOverride<T> implements Bijections.Bijection<T>
Review Comment:
Yeah, good point. Probably the overhead of `valueToDescriptor` is not worth custom class.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496704001
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
Review Comment:
You could also just throw `<?>` on all the problematic `DataType` and `ColumnSpec` things.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1498125966
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, false)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.int64Type)),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.int64Type)
+ ));
+
+ Map<String, Bijections.Bijection<?>> reGenerators = new HashMap<>();
+ reGenerators.put("regular1", ColumnSpec.asciiType(4, 4).generator());
+ reGenerators.put("regular2", ColumnSpec.int64Type.generator());
+ reGenerators.put("static1", ColumnSpec.asciiType(8, 4).generator());
+ reGenerators.put("static2", ColumnSpec.int64Type.generator());
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 100;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+
+ Map<String, Set<Object>> perColumnOverrides = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
+ history.valueOverrides().override(column.name, i, override);
Review Comment:
So we're overriding the value at every row of a 100-row partition?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531642247
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderIntegrationTest.java:
##########
@@ -19,46 +19,31 @@
package org.apache.cassandra.fuzz.harry.integration.dsl;
import java.util.Random;
-import java.util.function.LongSupplier;
import java.util.function.Supplier;
import org.junit.Test;
-import org.apache.cassandra.fuzz.harry.integration.model.ModelTestBase;
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
import org.apache.cassandra.harry.checker.ModelChecker;
-import org.apache.cassandra.harry.core.Configuration;
-import org.apache.cassandra.harry.core.Run;
import org.apache.cassandra.harry.ddl.SchemaGenerators;
import org.apache.cassandra.harry.ddl.SchemaSpec;
import org.apache.cassandra.harry.dsl.BatchVisitBuilder;
import org.apache.cassandra.harry.dsl.HistoryBuilder;
import org.apache.cassandra.harry.dsl.SingleOperationBuilder;
-import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
import org.apache.cassandra.harry.model.Model;
import org.apache.cassandra.harry.operations.Query;
import org.apache.cassandra.harry.sut.SystemUnderTest;
import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
import org.apache.cassandra.harry.visitors.ReplayingVisitor;
-public class HistoryBuilderIntegrationTest extends ModelTestBase
+public class HistoryBuilderIntegrationTest extends IntegrationTestBase
{
private final long seed = 1L;
private final int STEPS_PER_ITERATION = 1_000;
- private final int MAX_PARTITIONS = 100;
-
- @Override
- protected Configuration.ModelConfiguration modelConfiguration()
- {
- return new Configuration.QuiescentCheckerConfig();
- }
-
- public Configuration.ConfigurationBuilder configuration(long seed, SchemaSpec schema)
- {
- return super.configuration(seed, schema)
- .setPartitionDescriptorSelector(new Configuration.DefaultPDSelectorConfiguration(2, 2))
- .setClusteringDescriptorSelector((builder) -> builder.setOperationsPerLtsDistribution(new Configuration.ConstantDistributionConfig(100_000)));
- }
+ private final int MAX_PARTITIONS = 50;
Review Comment:
Did that for some of the fields I have found.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531774105
##########
test/harry/main/org/apache/cassandra/harry/dsl/SingleOperationBuilder.java:
##########
@@ -36,8 +35,8 @@ public interface SingleOperationBuilder
* Insert _specific values_ into _specific_ row. Rows are ordered by clustering key and
* numbered from 0 to maxRows
*/
- SingleOperationBuilder insert(int rowIdx, long[] vds);
- SingleOperationBuilder insert(int rowIdx, long[] vds, long[] sds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds, int[] sds);
Review Comment:
> Well, the inserts happen and the SUT matches, but validateAll() doesn't like it :)
Could you elaborate a bit? `history.valueOverrides().override(column.name, i, override);` is just used as a convenience method to quickly access override generator.
But we do a swap of `Schema` in `HistoryBuilder` to make sure all child generators are getting the correct (overriden) generators:
```
this.schema = schema.withCkGenerator(this.ckGenerator, this.ckGenerator.columns)
.withColumns(valueHelper.regularColumns, valueHelper.staticColumns);
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1530317815
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
Review Comment:
I thought it might be useful to validate every iteration since some problems may get shadowed by subsequent writes. it should be relatively cheap still
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531717274
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
+ }
+
+ @Override
+ public void overrideClusterings(Object[][] overrides)
+ {
+ assert possibleCds.length == overrides.length;
+ Arrays.sort(overrides, this::compareCds);
+ for (int i = 0; i < overrides.length; i++)
+ ckGenerator.override(possibleCds[i], overrides[i]);
+ }
+
+ @Override
+ public long pd()
+ {
+ return pd;
+ }
+
+ long getCdForOverride(Object[] ck)
+ {
+ int low = 0;
+ int high = possibleCds.length - 1;
+
+ while (low <= high)
+ {
+ int mid = (low + high) >>> 1;
+ long midEl = possibleCds[mid];
+ int cmp = compareCds(ck, midEl);
+
+ if (cmp < 0)
+ low = mid + 1;
+ else if (cmp > 0)
+ high = mid - 1;
+ else
+ throw new IllegalStateException("This value is already present");
+ }
+
+ return possibleCds[Math.min(possibleCds.length - 1, low)];
+ }
+
+ private int compareCds(Object[] v1, long cd2) {
Review Comment:
reformatted the whole class
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531781512
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, false)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.int64Type)),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.int64Type)
+ ));
+
+ Map<String, Bijections.Bijection<?>> reGenerators = new HashMap<>();
+ reGenerators.put("regular1", ColumnSpec.asciiType(4, 4).generator());
+ reGenerators.put("regular2", ColumnSpec.int64Type.generator());
+ reGenerators.put("static1", ColumnSpec.asciiType(8, 4).generator());
+ reGenerators.put("static2", ColumnSpec.int64Type.generator());
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 100;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+
+ Map<String, Set<Object>> perColumnOverrides = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
+ history.valueOverrides().override(column.name, i, override);
+ perColumnOverrides.get(column.name).add(override);
+ }
+ }
+
+ for (ColumnSpec column : schema.staticColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
+ history.valueOverrides().override(column.name, i, override);
+ perColumnOverrides.get(column.name).add(override);
+ }
+ }
+ for (int pdIdx = 0; pdIdx < 10; pdIdx++)
+ {
+ Map<String, Set<Object>> results = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ results.put(column.name, new HashSet<>());
+ for (ColumnSpec column : schema.staticColumns)
+ results.put(column.name, new HashSet<>());
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(pdIdx)
+ .insert(i,
+ new int[]{ rng.nextInt(100), rng.nextInt(100) },
+ new int[]{ rng.nextInt(100), rng.nextInt(100) });
Review Comment:
Right: we are simply saying "insert a value number X", where X is generated randomly. There's nothing preventing us from putting `210` as an index, it's just for the purpose of our test we ensure that _all_ the values were overriden. You can still generate arbitrary random values from the indexes you have not overriden.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531639936
##########
test/harry/main/org/apache/cassandra/harry/operations/Relation.java:
##########
@@ -97,7 +97,7 @@ public static void addEqRelation(long[] key, List<ColumnSpec<?>> columnSpecs, Li
public static void addRelation(long[] key, List<ColumnSpec<?>> columnSpecs, List<Relation> relations, RelationKind kind)
{
- assert key.length == columnSpecs.size() :
+ assert key.length == columnSpecs.size() || key.length > 4 :
Review Comment:
Good point. Added a `MAX_UNIQUE_PREFIX_COLUMNS` static field.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1497954708
##########
test/harry/main/org/apache/cassandra/harry/dsl/HistoryBuilder.java:
##########
@@ -29,15 +28,18 @@
import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
+import java.util.function.Consumer;
import java.util.function.LongSupplier;
import org.apache.cassandra.harry.clock.ApproximateClock;
import org.apache.cassandra.harry.core.Configuration;
import org.apache.cassandra.harry.core.MetricReporter;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
Review Comment:
unused `ColumnSpec` import
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496709852
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderIntegrationTest.java:
##########
@@ -19,46 +19,31 @@
package org.apache.cassandra.fuzz.harry.integration.dsl;
import java.util.Random;
-import java.util.function.LongSupplier;
import java.util.function.Supplier;
import org.junit.Test;
-import org.apache.cassandra.fuzz.harry.integration.model.ModelTestBase;
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
import org.apache.cassandra.harry.checker.ModelChecker;
-import org.apache.cassandra.harry.core.Configuration;
-import org.apache.cassandra.harry.core.Run;
import org.apache.cassandra.harry.ddl.SchemaGenerators;
import org.apache.cassandra.harry.ddl.SchemaSpec;
import org.apache.cassandra.harry.dsl.BatchVisitBuilder;
import org.apache.cassandra.harry.dsl.HistoryBuilder;
import org.apache.cassandra.harry.dsl.SingleOperationBuilder;
-import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
import org.apache.cassandra.harry.model.Model;
import org.apache.cassandra.harry.operations.Query;
import org.apache.cassandra.harry.sut.SystemUnderTest;
import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
import org.apache.cassandra.harry.visitors.ReplayingVisitor;
-public class HistoryBuilderIntegrationTest extends ModelTestBase
+public class HistoryBuilderIntegrationTest extends IntegrationTestBase
{
private final long seed = 1L;
private final int STEPS_PER_ITERATION = 1_000;
- private final int MAX_PARTITIONS = 100;
-
- @Override
- protected Configuration.ModelConfiguration modelConfiguration()
- {
- return new Configuration.QuiescentCheckerConfig();
- }
-
- public Configuration.ConfigurationBuilder configuration(long seed, SchemaSpec schema)
- {
- return super.configuration(seed, schema)
- .setPartitionDescriptorSelector(new Configuration.DefaultPDSelectorConfiguration(2, 2))
- .setClusteringDescriptorSelector((builder) -> builder.setOperationsPerLtsDistribution(new Configuration.ConstantDistributionConfig(100_000)));
- }
+ private final int MAX_PARTITIONS = 50;
Review Comment:
nit: I guess `MAX_PARTITIONS` and `STEPS_PER_ITERATION` could be static just to avoid annoying IDE warnings, but not that important...
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531725973
##########
test/harry/main/org/apache/cassandra/harry/dsl/ValueHelper.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.model.OpSelectors;
+
+/**
+ * A class responsible for value
Review Comment:
I think I was aspiring to write more :)
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531720854
##########
test/harry/main/org/apache/cassandra/harry/dsl/SingleOperationBuilder.java:
##########
@@ -36,8 +35,8 @@ public interface SingleOperationBuilder
* Insert _specific values_ into _specific_ row. Rows are ordered by clustering key and
* numbered from 0 to maxRows
*/
- SingleOperationBuilder insert(int rowIdx, long[] vds);
- SingleOperationBuilder insert(int rowIdx, long[] vds, long[] sds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds);
+ SingleOperationBuilder insert(int rowIdx, int[] vds, int[] sds);
Review Comment:
Good point, made them
```
SingleOperationBuilder insert(int rowIdx, long[] valueIdxs);
SingleOperationBuilder insert(int rowIdx, long[] valueIdxs, long[] sValueIdxs);
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1531783718
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, false)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.int64Type)),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.int64Type)
+ ));
+
+ Map<String, Bijections.Bijection<?>> reGenerators = new HashMap<>();
+ reGenerators.put("regular1", ColumnSpec.asciiType(4, 4).generator());
+ reGenerators.put("regular2", ColumnSpec.int64Type.generator());
+ reGenerators.put("static1", ColumnSpec.asciiType(8, 4).generator());
+ reGenerators.put("static2", ColumnSpec.int64Type.generator());
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 100;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+
+ Map<String, Set<Object>> perColumnOverrides = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
Review Comment:
So you simply would do
```
history.valueOverrides().override("regular1", 12345, "");
```
And then somewhere in your test you do
```
history.visitPartition(pdIdx)
.insert(i, new long[]{ 12345, 12345 });
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1530309238
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderIntegrationTest.java:
##########
@@ -129,16 +104,88 @@ public void simpleDSLTest() throws Throwable
return false;
HistoryBuilder historyBuilder = (HistoryBuilder) history;
- ReplayingVisitor visitor = historyBuilder.visitor(run.tracker, run.sut, SystemUnderTest.ConsistencyLevel.ALL);
+ ReplayingVisitor visitor = historyBuilder.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ visitor.replayAll();
+
+ if (historyBuilder.visitedPds().size() < MAX_PARTITIONS)
+ return false;
+
+ Model model = historyBuilder.quiescentChecker(tracker, sut);
+
+ for (Long pd : historyBuilder.visitedPds())
+ model.validate(Query.selectPartition(historyBuilder.schema(), pd,false));
+
+ return true;
+ })
+ .run(STEPS_PER_ITERATION, seed);
+ }
+ }
+
+ @Test
+ public void overrideCkTest() throws Throwable
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+ for (int schemaIdx = 0; schemaIdx < SchemaGenerators.DEFAULT_RUNS; schemaIdx++)
+ {
+ SchemaSpec schema = supplier.get();
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ ModelChecker<HistoryBuilder> modelChecker = new ModelChecker<>();
+ JdkRandomEntropySource rng = new JdkRandomEntropySource(new Random(seed));
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int maxPartitionSize = 10;
+ modelChecker.init(new HistoryBuilder(seed, maxPartitionSize, 10, schema, rf))
+ .beforeAll((history) -> {
+ for (int i = 0; i < MAX_PARTITIONS; i++)
+ history.forPartition(i).ensureClustering(schema.ckGenerator.inflate(rng.nextLong()));
Review Comment:
Exactly, we simply hardcode the clusterings for partition, and then let the test run.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496704972
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
Review Comment:
```suggestion
public void simpleCkOverrideTest()
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496806363
##########
test/harry/main/org/apache/cassandra/harry/dsl/ValueHelper.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.model.OpSelectors;
+
+/**
+ * A class responsible for value
Review Comment:
I'd probably just get rid of the JavaDoc here, given it doesn't really say much more than the name of the class does. Do we anticipate any other implementations of `ValueOverrides` in the near future? I guess we could just get rid of the interface and call this `ValueOverrides` if not...
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1498149987
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, false)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.int64Type)),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(2, 2)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.int64Type)
+ ));
+
+ Map<String, Bijections.Bijection<?>> reGenerators = new HashMap<>();
+ reGenerators.put("regular1", ColumnSpec.asciiType(4, 4).generator());
+ reGenerators.put("regular2", ColumnSpec.int64Type.generator());
+ reGenerators.put("static1", ColumnSpec.asciiType(8, 4).generator());
+ reGenerators.put("static2", ColumnSpec.int64Type.generator());
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 100;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+
+ Map<String, Set<Object>> perColumnOverrides = new HashMap<>();
+ for (ColumnSpec column : schema.regularColumns)
+ {
+ perColumnOverrides.put(column.name, new HashSet<>());
+ for (int i = 0; i < partitionSize; i++)
+ {
+ Object override = reGenerators.get(column.name).inflate(rng.next());
Review Comment:
Say I was testing SAI here and I wanted to try something like an empty string...
```
Object override = column.name.equals("regular1") ? "" : reGenerators.get(column.name).inflate(rng.next());
```
This doesn't seem to quite work when I try it...
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496707384
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
Review Comment:
If I comment out lines 86-93, the test still seems to pass. Dead code from a previous iteration of the test?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496781769
##########
test/harry/main/org/apache/cassandra/harry/dsl/PartitionVisitStateImpl.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.harry.dsl;
+
+import java.util.Arrays;
+import java.util.NavigableSet;
+
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+
+public class PartitionVisitStateImpl implements PartitionVisitState
+{
+ final long pd;
+ final long[] possibleCds;
+ final NavigableSet<Long> visitedLts;
+ final SchemaSpec schema;
+ private final OverridingCkGenerator ckGenerator;
+
+ PartitionVisitStateImpl(long pd, long[] possibleCds, NavigableSet<Long> visitedLts, SchemaSpec schema)
+ {
+ this.pd = pd;
+ this.possibleCds = possibleCds;
+ this.visitedLts = visitedLts;
+ this.schema = schema;
+ this.ckGenerator = (OverridingCkGenerator) schema.ckGenerator;
+ }
+
+
+ /**
+ * Ensures that exactly one of the clustering keys will have given values.
+ */
+ @Override
+ public void ensureClustering(Object[] overrides)
+ {
+ long cd = getCdForOverride(overrides);
+ ckGenerator.override(cd, overrides);
+ }
+
+ @Override
+ public void overrideClusterings(Object[][] overrides)
+ {
+ assert possibleCds.length == overrides.length;
+ Arrays.sort(overrides, this::compareCds);
+ for (int i = 0; i < overrides.length; i++)
+ ckGenerator.override(possibleCds[i], overrides[i]);
+ }
+
+ @Override
+ public long pd()
+ {
+ return pd;
+ }
+
+ long getCdForOverride(Object[] ck)
Review Comment:
```suggestion
long findCdForOverride(Object[] ck)
```
Not a big deal, but feels appropriate given the binary search?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496554179
##########
test/harry/main/org/apache/cassandra/harry/operations/Relation.java:
##########
@@ -97,7 +97,7 @@ public static void addEqRelation(long[] key, List<ColumnSpec<?>> columnSpecs, Li
public static void addRelation(long[] key, List<ColumnSpec<?>> columnSpecs, List<Relation> relations, RelationKind kind)
{
- assert key.length == columnSpecs.size() :
+ assert key.length == columnSpecs.size() || key.length > 4 :
Review Comment:
Do we want to keep the hard-coded "4" here?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1496704186
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, 5, 10, schema, rf);
+ Object[] override = new Object[]{ "", "b", -1L, "c", "d" };
+ history.forPartition(1).ensureClustering(override);
+ for (int i = 0; i < 5; i++)
+ history.visitPartition(1).insert(i);
+
+ history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL).replayAll();
+
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), history.visitedPds().get(0), false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+ int found = 0;
+ for (Object[] row : res)
+ {
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 4, 9)))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+
+ history.validateAll(tracker, sut);
+ }
+
+ @Test
+ public void ckOverrideSortingTest() throws Throwable
+ {
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (reverse ? "_reverse" : ""),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0), reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ Set<Integer> foundAt = new HashSet<>();
+ for (int pdIdx = 0; pdIdx < 128; pdIdx++)
+ {
+ Object[] override = new Object[]{ Character.toString(pdIdx) };
+ history.forPartition(pdIdx).ensureClustering(override);
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ if (Arrays.equals(override, Arrays.copyOfRange(row, 1, 2)))
+ {
+ found++;
+ foundAt.add(i);
+ }
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, 1);
+ }
+ history.validateAll(tracker, sut);
+ }
+ Assert.assertEquals(10, foundAt.size());
+ }
+ }
+
+ @Test
+ public void ckOverrideManySortingTest() throws Throwable
+ {
+ int counter = 0;
+ for (boolean reverse : new boolean[]{ true, false })
+ {
+ for (ColumnSpec.DataType type : new ColumnSpec.DataType[]{ ColumnSpec.asciiType(2, 0), ColumnSpec.int64Type })
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides" + (counter++),
+ Arrays.asList(ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10))),
+ Arrays.asList(ColumnSpec.ck("ck1", type, reverse)),
+ Arrays.asList(ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100))),
+ Arrays.asList(ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100))));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int partitionSize = 10;
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 10, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int pdIdx = 0; pdIdx < 100; pdIdx++)
+ {
+ Set<Object> overrides = new HashSet<>();
+ for (int i = 0; i < 5; i++)
+ {
+ Object override = schema.clusteringKeys.get(0).generator().inflate(rng.next());
+ try
+ {
+ history.forPartition(pdIdx).ensureClustering(new Object[]{ override });
+ overrides.add(override);
+ }
+ catch (IllegalStateException t)
+ {
+ // could not override twice
+ }
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ history.visitPartition(pdIdx).insert(i);
+
+ visitor.replayAll();
+ long visitedPd = history.forPartition(pdIdx).pd();
+ {
+ Object[][] res = sut.execute(Query.selectPartition(history.schema(), visitedPd, false).toSelectStatement(),
+ SystemUnderTest.ConsistencyLevel.ALL);
+
+ int found = 0;
+ for (int i = 0; i < res.length; i++)
+ {
+ Object[] row = res[i];
+ Object v = row[1];
+ if (overrides.contains(v))
+ found++;
+ }
+ Assert.assertEquals("Should have mutated exactly one CK", found, overrides.size());
+ }
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void ckOverrideWithDeleteTestSingleColumn()
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+
+ int partitionSize = 5;
+ for (int cnt = 0; cnt < SchemaGenerators.DEFAULT_RUNS; cnt++)
+ {
+ SchemaSpec schema = supplier.get();
+ beforeEach();
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ HistoryBuilder history = new HistoryBuilder(seed, partitionSize, 1, schema, rf);
+ ReplayingVisitor visitor = history.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+
+ EntropySource rng = new JdkRandomEntropySource(seed);
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1,
+ (e) -> schema.ckGenerator.inflate(rng.next()))
+ .insert(i);
+ }
+
+ for (int i = 0; i < partitionSize; i++)
+ {
+ history.visitPartition(1)
+ .deleteRow(i);
+
+ visitor.replayAll();
+ history.validateAll(tracker, sut);
+ }
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("rawtypes")
+ public void regularAndStaticOverrideTest() throws Throwable
Review Comment:
```suggestion
public void regularAndStaticOverrideTest()
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "ifesdjeen (via GitHub)" <gi...@apache.org>.
ifesdjeen commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1530314892
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderOverridesTest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.fuzz.harry.integration.dsl;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.fuzz.harry.integration.model.IntegrationTestBase;
+import org.apache.cassandra.harry.ddl.ColumnSpec;
+import org.apache.cassandra.harry.ddl.SchemaGenerators;
+import org.apache.cassandra.harry.ddl.SchemaSpec;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.dsl.ValueDescriptorIndexGenerator;
+import org.apache.cassandra.harry.gen.Bijections;
+import org.apache.cassandra.harry.gen.EntropySource;
+import org.apache.cassandra.harry.gen.rng.JdkRandomEntropySource;
+import org.apache.cassandra.harry.operations.Query;
+import org.apache.cassandra.harry.sut.SystemUnderTest;
+import org.apache.cassandra.harry.sut.TokenPlacementModel;
+import org.apache.cassandra.harry.tracker.DataTracker;
+import org.apache.cassandra.harry.tracker.DefaultDataTracker;
+import org.apache.cassandra.harry.visitors.ReplayingVisitor;
+
+public class HistoryBuilderOverridesTest extends IntegrationTestBase
+{
+ private final long seed = 1L;
+
+ @Test
+ public void simpleCkOverrideTest() throws Throwable
+ {
+ SchemaSpec schema = new SchemaSpec("harry",
+ "test_overrides",
+ Arrays.asList(
+ ColumnSpec.pk("pk1", ColumnSpec.asciiType(4, 10)),
+ ColumnSpec.pk("pk2", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk3", ColumnSpec.int64Type),
+ ColumnSpec.pk("pk4", ColumnSpec.asciiType(2, 10))
+ ),
+ Arrays.asList(
+ ColumnSpec.ck("ck1", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck2", ColumnSpec.asciiType(2, 0)),
+ ColumnSpec.ck("ck3", ColumnSpec.int64Type),
+ ColumnSpec.ck("ck4", ColumnSpec.asciiType(4, 100)),
+ ColumnSpec.ck("ck5", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.regularColumn("regular1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.regularColumn("regular3", ColumnSpec.asciiType(8, 100))
+ ),
+ Arrays.asList(
+ ColumnSpec.staticColumn("static1", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static2", ColumnSpec.asciiType(8, 100)),
+ ColumnSpec.staticColumn("static3", ColumnSpec.asciiType(8, 100))
+ ));
+
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ JdkRandomEntropySource entropySource = new JdkRandomEntropySource(new Random(seed));
+
+ LongSupplier[] valueGenerators = new LongSupplier[schema.regularColumns.size()];
+ for (int j = 0; j < valueGenerators.length; j++)
+ {
+ valueGenerators[j] = new ValueDescriptorIndexGenerator(schema.regularColumns.get(j), seed)
+ .toSupplier(entropySource.derive(), 20, 0.2f);
+ }
Review Comment:
yes, sorry: this is just a remainder from the previous test
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Harry model that supports value overrides: an ability to provide spec… [cassandra]
Posted by "maedhroz (via GitHub)" <gi...@apache.org>.
maedhroz commented on code in PR #3060:
URL: https://github.com/apache/cassandra/pull/3060#discussion_r1497949880
##########
test/distributed/org/apache/cassandra/fuzz/harry/integration/dsl/HistoryBuilderIntegrationTest.java:
##########
@@ -129,16 +104,88 @@ public void simpleDSLTest() throws Throwable
return false;
HistoryBuilder historyBuilder = (HistoryBuilder) history;
- ReplayingVisitor visitor = historyBuilder.visitor(run.tracker, run.sut, SystemUnderTest.ConsistencyLevel.ALL);
+ ReplayingVisitor visitor = historyBuilder.visitor(tracker, sut, SystemUnderTest.ConsistencyLevel.ALL);
+ visitor.replayAll();
+
+ if (historyBuilder.visitedPds().size() < MAX_PARTITIONS)
+ return false;
+
+ Model model = historyBuilder.quiescentChecker(tracker, sut);
+
+ for (Long pd : historyBuilder.visitedPds())
+ model.validate(Query.selectPartition(historyBuilder.schema(), pd,false));
+
+ return true;
+ })
+ .run(STEPS_PER_ITERATION, seed);
+ }
+ }
+
+ @Test
+ public void overrideCkTest() throws Throwable
+ {
+ Supplier<SchemaSpec> supplier = SchemaGenerators.progression(SchemaGenerators.DEFAULT_SWITCH_AFTER);
+ for (int schemaIdx = 0; schemaIdx < SchemaGenerators.DEFAULT_RUNS; schemaIdx++)
+ {
+ SchemaSpec schema = supplier.get();
+ DataTracker tracker = new DefaultDataTracker();
+ beforeEach();
+ sut.schemaChange(schema.compile().cql());
+
+ ModelChecker<HistoryBuilder> modelChecker = new ModelChecker<>();
+ JdkRandomEntropySource rng = new JdkRandomEntropySource(new Random(seed));
+
+ TokenPlacementModel.ReplicationFactor rf = new TokenPlacementModel.SimpleReplicationFactor(1);
+
+ int maxPartitionSize = 10;
+ modelChecker.init(new HistoryBuilder(seed, maxPartitionSize, 10, schema, rf))
+ .beforeAll((history) -> {
+ for (int i = 0; i < MAX_PARTITIONS; i++)
+ history.forPartition(i).ensureClustering(schema.ckGenerator.inflate(rng.nextLong()));
Review Comment:
So this is the crux of the test? i.e. Make sure every partition has the provided clustering key inflated from the underlying `KeyPartOverride`, then do normal validation?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org