k-rus commented on code in PR #4683:
URL: https://github.com/apache/cassandra/pull/4683#discussion_r3116034746
##########
test/microbench/org/apache/cassandra/test/microbench/sai/KeyLookupBench.java:
##########
@@ -170,36 +160,87 @@ public long advanceToKey()
return primaryKeyMap.rowIdFromPrimaryKey(primaryKey);
}
- private static DecoratedKey makeKey(TableMetadata table,
Object...partitionKeys)
+ private static DecoratedKey makeKey(TableMetadata table, Object...
partitionKeys)
{
ByteBuffer key;
if (table.partitionKeyType instanceof CompositeType)
- key =
((CompositeType)table.partitionKeyType).decompose(partitionKeys);
+ key = ((CompositeType)
table.partitionKeyType).decompose(partitionKeys);
else
- key = table.partitionKeyType.fromString((String)partitionKeys[0]);
+ key = table.partitionKeyType.decomposeUntyped(partitionKeys[0]);
return table.partitioner.decorateKey(key);
}
- private Clustering<?> makeClustering(TableMetadata table)
+ private PrimaryKey[] generatePrimaryKeys(PrimaryKey.Factory factory)
{
- Clustering<?> clustering;
- if (table.comparator.size() == 0)
- clustering = Clustering.EMPTY;
- else
+ PrimaryKey[] primaryKeys = new PrimaryKey[rows];
+ int partition = 0;
+ int partitionRowCounter = 0;
+
+ ClusteringStringGenerator clusteringStringGenerator = new
ClusteringStringGenerator(metadata);
+ for (int index = 0; index < rows; index++)
{
- ByteBuffer[] values = new ByteBuffer[table.comparator.size()];
- for (int index = 0; index < table.comparator.size(); index++)
- values[index] =
table.comparator.subtype(index).fromString(makeClusteringString());
- clustering = Clustering.make(values);
+ primaryKeys[index] = factory.create(makeKey(metadata, (long)
partition, (long) partition),
+
clusteringStringGenerator.makeClustering());
+ partitionRowCounter++;
+ if (partitionRowCounter == partitionSize)
+ {
+ partition++;
+ partitionRowCounter = 0;
+ clusteringStringGenerator = new
ClusteringStringGenerator(metadata);
+ }
}
- return clustering;
+ return primaryKeys;
}
- private String makeClusteringString()
+
+ /**
+ * Generates a sorted list of unique clustering strings during
initialization,
+ * then returns them in lexicographical order on each call to
makeClustering().
+ */
+ private class ClusteringStringGenerator
{
- if (randomClustering)
- return getRandom().nextTextString(10, 100);
- else
- return String.format("%08d", getRandom().nextIntBetween(0,
partitionSize));
+ private final List<String> sortedStrings;
+ private final TableMetadata table;
+ private int currentIndex;
+
+ ClusteringStringGenerator(TableMetadata table)
+ {
+ // Use TreeSet to maintain sorted order and ensure uniqueness
+ TreeSet<String> uniqueStrings = new TreeSet<>();
+ this.table = table;
+ this.currentIndex = 0;
+
+ sortedStrings = generateUniqueSortedStrings(uniqueStrings);
+ }
+
+ private List<String> generateUniqueSortedStrings(TreeSet<String>
uniqueStrings)
+ {
+ while (uniqueStrings.size() < partitionSize)
+ {
+ String candidate = makeClusteringString();
+ uniqueStrings.add(candidate);
+ }
+ return new ArrayList<>(uniqueStrings);
+ }
+
+ Clustering<?> makeClustering()
+ {
+ if (table.comparator.size() == 0)
+ return Clustering.EMPTY;
+
+ ByteBuffer[] values = new ByteBuffer[table.comparator.size()];
+ String nextString = sortedStrings.get(currentIndex++);
+ for (int index = 0; index < table.comparator.size(); index++)
+ values[index] =
table.comparator.subtype(index).fromString(nextString);
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]