dcapwell commented on code in PR #3789:
URL: https://github.com/apache/cassandra/pull/3789#discussion_r1915859177


##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -279,7 +302,7 @@ public static <I extends IInstance> I 
replaceHostAndStart(AbstractCluster<I> clu
     {
         IInstanceConfig toReplaceConf = toReplace.config();
         I inst = addInstance(cluster, toReplaceConf, c -> 
c.set("auto_bootstrap", true)
-                                                           
.set("progress_barrier_min_consistency_level", ConsistencyLevel.ONE));
+                .set("progress_barrier_min_consistency_level", 
ConsistencyLevel.ONE));

Review Comment:
   formatting bug



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -689,18 +738,18 @@ public static Map<String, Epoch> 
getPeerEpochs(IInvokableInstance requester)
             return epochs;
         });
         return map.entrySet()
-                  .stream()
-                  .collect(Collectors.toMap(Map.Entry::getKey, e -> 
decode(e.getValue())));
+                .stream()
+                .collect(Collectors.toMap(Map.Entry::getKey, e -> 
decode(e.getValue())));
     }
 
     public static Set<String> getCMSMembers(IInvokableInstance inst)
     {
         return inst.callOnInstance(() -> ClusterMetadata.current()
-                                                        .fullCMSMembers()
-                                                        .stream()
-                                                        
.map(InetSocketAddress::getAddress)
-                                                        .map(Object::toString)
-                                                        
.collect(Collectors.toSet()));
+                .fullCMSMembers()

Review Comment:
   formatting bug?



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -921,10 +982,10 @@ private static List<RingInstanceDetails> 
awaitInstanceMatching(IInstance instanc
                                                                    String 
errorMessage)
     {
         return awaitRing(instance,
-                         errorMessage,
-                         ring -> ring.stream()
-                                     .filter(d -> 
d.address.equals(getBroadcastAddressHostString(expectedInRing)))
-                                     .anyMatch(predicate));
+                errorMessage,

Review Comment:
   formatting bug?



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -1085,9 +1146,9 @@ public static void awaitGossipStateMatch(ICluster<? 
extends  IInstance> cluster,
         for (int i = 0; i < 100; i++)
         {
             matches = cluster.stream().map(ClusterUtils::gossipInfo)
-                             .map(gi -> 
Objects.requireNonNull(gi.get(getBroadcastAddressString(expectedInGossip))))
-                             .map(m -> m.get(key.name()))
-                             .collect(Collectors.toSet());
+                    .map(gi -> 
Objects.requireNonNull(gi.get(getBroadcastAddressString(expectedInGossip))))

Review Comment:
   formatting bug?



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -898,7 +959,7 @@ public static List<RingInstanceDetails> 
awaitRingHealthy(IInstance src)
     public static List<RingInstanceDetails> awaitRingStatus(IInstance 
instance, IInstance expectedInRing, String status)
     {
         return awaitInstanceMatching(instance, expectedInRing, d -> 
d.status.equals(status),
-                                     "Timeout waiting for " + expectedInRing + 
" to have status " + status);
+                "Timeout waiting for " + expectedInRing + " to have status " + 
status);

Review Comment:
   formatting bug?



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -802,12 +851,12 @@ public static List<RingInstanceDetails> 
assertRingState(IInstance instance, IIns
         String targetAddress = getBroadcastAddressHostString(expectedInRing);
         List<RingInstanceDetails> ring = ring(instance);
         List<RingInstanceDetails> match = ring.stream()
-                                              .filter(d -> 
d.address.equals(targetAddress))
-                                              .collect(Collectors.toList());
+                .filter(d -> d.address.equals(targetAddress))

Review Comment:
   formatting bug?



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -317,10 +340,10 @@ public static <I extends IInstance> I 
startHostReplacement(I toReplace, I inst,
     public static List<String> getTokenMetadataTokens(IInvokableInstance inst)
     {
         return inst.callOnInstance(() ->
-                                   ClusterMetadata.current().tokenMap.tokens()
-                                                                     .stream()
-                                                                     
.map(Object::toString)
-                                                                     
.collect(Collectors.toList()));
+                ClusterMetadata.current().tokenMap.tokens()

Review Comment:
   formatting bug... shouldn't this get reverted?



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -912,7 +973,7 @@ public static List<RingInstanceDetails> 
awaitRingStatus(IInstance instance, IIns
     public static List<RingInstanceDetails> awaitRingState(IInstance instance, 
IInstance expectedInRing, String state)
     {
         return awaitInstanceMatching(instance, expectedInRing, d -> 
d.state.equals(state),
-                                     "Timeout waiting for " + expectedInRing + 
" to have state " + state);
+                "Timeout waiting for " + expectedInRing + " to have state " + 
state);

Review Comment:
   formatting bug?



##########
test/unit/org/apache/cassandra/cql3/ast/Select.java:
##########
@@ -303,6 +303,7 @@ public OrderBy build()
 
     public static class Builder implements 
Conditional.ConditionalBuilder<Builder>
     {
+        private boolean filtering = false;

Review Comment:
   you can remove this.  the ast rewrite fixed a style issue with this field, 
the fields try to use the same thing as the CQL so became `allowFiltering`, and 
the logic from harry v2 just got renamed (its why this is dead code)



##########
test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java:
##########
@@ -951,8 +1012,8 @@ public static List<RingInstanceDetails> 
assertRingIs(IInstance instance, IInstan
     public static List<RingInstanceDetails> assertRingIs(IInstance instance, 
Collection<? extends IInstance> expectedInRing)
     {
         Set<String> expectedRingAddresses = expectedInRing.stream()
-                                                         .map(i -> 
i.config().broadcastAddress().getAddress().getHostAddress())
-                                                         
.collect(Collectors.toSet());
+                .map(i -> 
i.config().broadcastAddress().getAddress().getHostAddress())

Review Comment:
   formatting bug?



##########
test/harry/main/org/apache/cassandra/harry/SchemaSpec.java:
##########
@@ -0,0 +1,440 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Consumer;
+
+import org.apache.cassandra.cql3.ast.Symbol;
+import org.apache.cassandra.harry.dsl.HistoryBuilder;
+import org.apache.cassandra.harry.gen.Generator;
+import org.apache.cassandra.harry.gen.Generators;
+import org.apache.cassandra.harry.gen.ValueGenerators;
+import org.apache.cassandra.harry.util.IteratorsUtil;
+import org.apache.cassandra.utils.ByteArrayUtil;
+
+import static org.apache.cassandra.harry.gen.InvertibleGenerator.MAX_ENTROPY;
+
+public class SchemaSpec
+{
+    public final String keyspace;
+    public final String table;
+
+    public final List<ColumnSpec<?>> partitionKeys;
+    public final List<ColumnSpec<?>> clusteringKeys;
+    public final List<ColumnSpec<?>> regularColumns;
+    public final List<ColumnSpec<?>> staticColumns;
+
+    public final List<ColumnSpec<?>> allColumnInSelectOrder;
+    public final ValueGenerators valueGenerators;
+    public final Options options;
+
+    public SchemaSpec(long seed,
+                      int populationPerColumn,
+                      String keyspace,
+                      String table,
+                      List<ColumnSpec<?>> partitionKeys,
+                      List<ColumnSpec<?>> clusteringKeys,
+                      List<ColumnSpec<?>> regularColumns,
+                      List<ColumnSpec<?>> staticColumns)
+    {
+        this(seed, populationPerColumn, keyspace, table, partitionKeys, 
clusteringKeys, regularColumns, staticColumns, optionsBuilder());
+    }
+
+    @SuppressWarnings({ "unchecked" })
+    public SchemaSpec(long seed,
+                      int populationPerColumn,
+                      String keyspace,
+                      String table,
+                      List<ColumnSpec<?>> partitionKeys,
+                      List<ColumnSpec<?>> clusteringKeys,
+                      List<ColumnSpec<?>> regularColumns,
+                      List<ColumnSpec<?>> staticColumns,
+                      Options options)
+    {
+        this.keyspace = keyspace;
+        this.table = table;
+        this.options = options;
+
+        this.partitionKeys = Collections.unmodifiableList(new 
ArrayList<>(partitionKeys));
+        this.clusteringKeys = Collections.unmodifiableList(new 
ArrayList<>(clusteringKeys));
+        this.staticColumns = Collections.unmodifiableList(new 
ArrayList<>(staticColumns));
+        this.regularColumns = Collections.unmodifiableList(new 
ArrayList<>(regularColumns));
+
+        List<ColumnSpec<?>> staticSelectOrder = new ArrayList<>(staticColumns);
+        staticSelectOrder.sort((s1, s2) -> 
ByteArrayUtil.compareUnsigned(s1.name.getBytes(), s2.name.getBytes()));
+        List<ColumnSpec<?>> regularSelectOrder = new 
ArrayList<>(regularColumns);
+        regularSelectOrder.sort((s1, s2) -> 
ByteArrayUtil.compareUnsigned(s1.name.getBytes(), s2.name.getBytes()));
+
+        List<ColumnSpec<?>> selectOrder = new ArrayList<>();
+        for (ColumnSpec<?> column : IteratorsUtil.concat(partitionKeys,
+                                                         clusteringKeys,
+                                                         staticSelectOrder,
+                                                         regularSelectOrder))
+            selectOrder.add(column);
+        this.allColumnInSelectOrder = 
Collections.unmodifiableList(selectOrder);
+
+        // TODO: empty gen
+        this.valueGenerators = HistoryBuilder.valueGenerators(this, seed, 
populationPerColumn);
+    }
+
+    public static /* unsigned */ long cumulativeEntropy(List<ColumnSpec<?>> 
columns)
+    {
+        if (columns.isEmpty())
+            return 0;
+
+        long entropy = 1;
+        for (ColumnSpec<?> column : columns)
+        {
+            if (Long.compareUnsigned(column.type.typeEntropy(), MAX_ENTROPY) 
== 0)
+                return MAX_ENTROPY;
+
+            long next = entropy * column.type.typeEntropy();
+            if (Long.compareUnsigned(next, entropy) < 0 || 
Long.compareUnsigned(next, column.type.typeEntropy()) < 0)
+                return MAX_ENTROPY;
+
+            entropy = next;
+        }
+
+        return entropy;
+    }
+
+    public static Generator<Object[]> forKeys(List<ColumnSpec<?>> columns)
+    {
+        Generator<?>[] gens = new Generator[columns.size()];
+        for (int i = 0; i < gens.length; i++)
+            gens[i] = columns.get(i).gen;
+        return Generators.zipArray(gens);
+    }
+
+    public String compile()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append("CREATE TABLE ");
+        if (options.ifNotExists())
+            sb.append("IF NOT EXISTS ");
+
+        sb.append(Symbol.maybeQuote(keyspace))
+          .append(".")
+          .append(Symbol.maybeQuote(table))
+          .append(" (");
+
+        SeparatorAppender commaAppender = new SeparatorAppender();
+        for (ColumnSpec<?> cd : partitionKeys)
+        {
+            commaAppender.accept(sb);
+            sb.append(cd.toCQL());
+            if (partitionKeys.size() == 1 && clusteringKeys.isEmpty())
+                sb.append(" PRIMARY KEY");
+        }
+
+        for (ColumnSpec<?> cd : IteratorsUtil.concat(clusteringKeys,
+                                                     staticColumns,
+                                                     regularColumns))
+        {
+            commaAppender.accept(sb);
+            sb.append(cd.toCQL());
+        }
+
+        if (!clusteringKeys.isEmpty() || partitionKeys.size() > 1)
+        {
+            sb.append(", ").append(getPrimaryKeyCql());
+        }
+
+        // TODO: test
+        if (options.trackLts())
+            sb.append(", ").append("visited_lts list<bigint> static");
+
+        sb.append(')');
+
+        Runnable appendWith = doOnce(() -> sb.append(" WITH"));
+        boolean shouldAppendAnd = false;
+
+        if (options.compactStorage())
+        {
+            appendWith.run();
+            sb.append(" COMPACT STORAGE");
+            shouldAppendAnd = true;
+        }
+
+        if (options.disableReadRepair())
+        {
+            appendWith.run();
+            if (shouldAppendAnd)
+                sb.append(" AND");
+            sb.append(" read_repair = 'NONE' ");
+            shouldAppendAnd = true;
+        }
+
+        if (options.compactionStrategy() != null)
+        {
+            appendWith.run();
+            if (shouldAppendAnd)
+                sb.append(" AND");
+            sb.append(" compaction = {'class': 
'").append(options.compactionStrategy()).append("'}");
+            shouldAppendAnd = true;
+        }
+
+        if (!clusteringKeys.isEmpty())
+        {
+            appendWith.run();
+            if (shouldAppendAnd)
+            {
+                sb.append(" AND");
+                shouldAppendAnd = false;
+            }
+            sb.append(getClusteringOrderCql());
+        }
+
+        if (shouldAppendAnd)
+        {
+            sb.append(" AND");
+            shouldAppendAnd = false;
+        }
+
+        sb.append(';');
+        return sb.toString();
+    }
+
+    private String getClusteringOrderCql()
+    {
+        StringBuilder sb = new StringBuilder();
+        if (!clusteringKeys.isEmpty())
+        {
+            sb.append(" CLUSTERING ORDER BY (");
+
+            SeparatorAppender commaAppender = new SeparatorAppender();
+            for (ColumnSpec<?> column : clusteringKeys)
+            {
+                commaAppender.accept(sb);
+                sb.append(column.name).append(' ').append(column.isReversed() 
? "DESC" : "ASC");
+            }
+
+            sb.append(')');
+        }
+
+        return sb.toString();
+    }
+
+    private String getPrimaryKeyCql()
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append("PRIMARY KEY (");
+        if (partitionKeys.size() > 1)
+        {
+            sb.append('(');
+            SeparatorAppender commaAppender = new SeparatorAppender();
+            for (ColumnSpec<?> cd : partitionKeys)
+            {
+                commaAppender.accept(sb);
+                sb.append(cd.name);
+            }
+            sb.append(')');
+        }
+        else
+        {
+            sb.append(partitionKeys.get(0).name);
+        }
+
+        for (ColumnSpec<?> cd : clusteringKeys)
+            sb.append(", ").append(cd.name);
+
+        return sb.append(')').toString();
+    }
+
+    public String toString()
+    {
+        return String.format("schema {cql=%s}", compile());
+    }
+
+    private static Runnable doOnce(Runnable r)
+    {
+        return new Runnable()
+        {
+            boolean executed = false;
+
+            public void run()
+            {
+                if (executed)
+                    return;
+
+                executed = true;
+                r.run();
+            }
+        };
+    }
+
+    public static class SeparatorAppender implements Consumer<StringBuilder>
+    {
+        boolean isFirst = true;
+        private final String separator;
+
+        public SeparatorAppender()
+        {
+            this(",");
+        }
+
+        public SeparatorAppender(String separator)
+        {
+            this.separator = separator;
+        }
+
+        public void accept(StringBuilder stringBuilder)
+        {
+            if (isFirst)
+                isFirst = false;
+            else
+                stringBuilder.append(separator);
+        }
+
+        public void accept(StringBuilder stringBuilder, String s)
+        {
+            accept(stringBuilder);
+            stringBuilder.append(s);
+        }
+
+
+        public void reset()
+        {
+            isFirst = true;
+        }
+    }
+
+    public boolean equals(Object o)
+    {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        SchemaSpec that = (SchemaSpec) o;
+        return Objects.equals(keyspace, that.keyspace) &&
+               Objects.equals(table, that.table) &&
+               Objects.equals(partitionKeys, that.partitionKeys) &&
+               Objects.equals(clusteringKeys, that.clusteringKeys) &&
+               Objects.equals(regularColumns, that.regularColumns);
+    }
+
+    public int hashCode()
+    {
+        return Objects.hash(keyspace, table, partitionKeys, clusteringKeys, 
regularColumns);
+    }
+
+    public interface Options
+    {
+        boolean addWriteTimestamps();

Review Comment:
   this was for accord but it doesn't have to be... so still makes sense to 
keep...



-- 
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-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to