This is an automated email from the ASF dual-hosted git repository.
marcuse pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new f53c051118 Accord: Minor serialization changes
f53c051118 is described below
commit f53c0511184cdbae7bbed1aaa68ec955f8f8f27a
Author: Marcus Eriksson <[email protected]>
AuthorDate: Fri Aug 15 08:54:32 2025 +0200
Accord: Minor serialization changes
Patch by marcuse; reviewed by David Capwell and Benedict Elliott Smith for
CASSANDRA-20840
---
.../apache/cassandra/schema/ColumnMetadata.java | 7 ++--
.../org/apache/cassandra/schema/TableParams.java | 13 ++++----
.../cassandra/service/accord/AccordFastPath.java | 6 ++--
.../fastpath/ParameterizedFastPathStrategy.java | 5 ++-
.../accord/AccordFastpathConfigurationTest.java | 39 ++++++++++++++++++++++
.../cassandra/utils/CassandraGenerators.java | 6 ++--
6 files changed, 59 insertions(+), 17 deletions(-)
diff --git a/src/java/org/apache/cassandra/schema/ColumnMetadata.java
b/src/java/org/apache/cassandra/schema/ColumnMetadata.java
index d5e7b23e40..817c99327b 100644
--- a/src/java/org/apache/cassandra/schema/ColumnMetadata.java
+++ b/src/java/org/apache/cassandra/schema/ColumnMetadata.java
@@ -65,6 +65,7 @@ import org.apache.cassandra.utils.ByteBufferUtil;
import static org.apache.cassandra.db.TypeSizes.BOOL_SIZE;
import static org.apache.cassandra.db.TypeSizes.sizeof;
+import static org.apache.cassandra.db.TypeSizes.sizeofVInt;
@Unmetered
public final class ColumnMetadata extends ColumnSpecification implements
Selectable, Comparable<ColumnMetadata>
@@ -737,7 +738,7 @@ public final class ColumnMetadata extends
ColumnSpecification implements Selecta
ColumnConstraints.serializer.serialize(t.columnConstraints, out, version);
}
if (version.isAtLeast(Version.V7))
- out.writeInt(t.uniqueId);
+ out.writeVInt32(t.uniqueId);
}
public ColumnMetadata deserialize(DataInputPlus in, Types types,
UserFunctions functions, Version version) throws IOException
@@ -763,7 +764,7 @@ public final class ColumnMetadata extends
ColumnSpecification implements Selecta
constraints = ColumnConstraints.NO_OP;
int uniqueId = NO_UNIQUE_ID;
if (version.isAtLeast(Version.V7))
- uniqueId = in.readInt();
+ uniqueId = in.readVInt32();
return new ColumnMetadata(ksName, tableName, new
ColumnIdentifier(nameBB, name), type, uniqueId, position, kind, mask,
constraints);
}
@@ -787,7 +788,7 @@ public final class ColumnMetadata extends
ColumnSpecification implements Selecta
BOOL_SIZE +
((t.mask == null) ? 0 :
ColumnMask.serializer.serializedSize(t.mask, version)) +
constraintsSize +
- (version.isAtLeast(Version.V7) ? 4 : 0);
+ (version.isAtLeast(Version.V7) ? sizeofVInt(t.uniqueId) :
0);
}
}
}
diff --git a/src/java/org/apache/cassandra/schema/TableParams.java
b/src/java/org/apache/cassandra/schema/TableParams.java
index fa8a2ac44c..fe0e13adf5 100644
--- a/src/java/org/apache/cassandra/schema/TableParams.java
+++ b/src/java/org/apache/cassandra/schema/TableParams.java
@@ -49,6 +49,7 @@ import static java.lang.String.format;
import static java.util.stream.Collectors.toMap;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.cassandra.db.TypeSizes.sizeof;
+import static org.apache.cassandra.db.TypeSizes.sizeofUnsignedVInt;
import static
org.apache.cassandra.schema.TableParams.Option.ADDITIONAL_WRITE_POLICY;
import static
org.apache.cassandra.schema.TableParams.Option.ALLOW_AUTO_SNAPSHOT;
import static
org.apache.cassandra.schema.TableParams.Option.BLOOM_FILTER_FP_CHANCE;
@@ -638,8 +639,8 @@ public final class TableParams
if (version.isAtLeast(Version.MIN_ACCORD_VERSION))
{
FastPathStrategy.serializer.serialize(t.fastPath, out,
version);
- out.writeInt(t.transactionalMode.ordinal());
- out.writeInt(t.transactionalMigrationFrom.ordinal());
+ out.writeUnsignedVInt32(t.transactionalMode.ordinal());
+
out.writeUnsignedVInt32(t.transactionalMigrationFrom.ordinal());
out.writeBoolean(t.pendingDrop);
}
}
@@ -669,8 +670,8 @@ public final class TableParams
if (version.isAtLeast(Version.MIN_ACCORD_VERSION))
{
builder.fastPath(FastPathStrategy.serializer.deserialize(in,
version))
-
.transactionalMode(TransactionalMode.fromOrdinal(in.readInt()))
-
.transactionalMigrationFrom(TransactionalMigrationFromMode.fromOrdinal(in.readInt()))
+
.transactionalMode(TransactionalMode.fromOrdinal(in.readUnsignedVInt32()))
+
.transactionalMigrationFrom(TransactionalMigrationFromMode.fromOrdinal(in.readUnsignedVInt32()))
.pendingDrop(in.readBoolean());
}
return builder.build();
@@ -700,8 +701,8 @@ public final class TableParams
if (version.isAtLeast(Version.MIN_ACCORD_VERSION))
{
size += FastPathStrategy.serializer.serializedSize(t.fastPath,
version) +
- sizeof(t.transactionalMode.ordinal()) +
- sizeof(t.transactionalMigrationFrom.ordinal()) +
+ sizeofUnsignedVInt(t.transactionalMode.ordinal()) +
+
sizeofUnsignedVInt(t.transactionalMigrationFrom.ordinal()) +
sizeof(t.pendingDrop);
}
return size;
diff --git a/src/java/org/apache/cassandra/service/accord/AccordFastPath.java
b/src/java/org/apache/cassandra/service/accord/AccordFastPath.java
index 71150355dd..2afc16f9fe 100644
--- a/src/java/org/apache/cassandra/service/accord/AccordFastPath.java
+++ b/src/java/org/apache/cassandra/service/accord/AccordFastPath.java
@@ -249,7 +249,7 @@ public class AccordFastPath implements
MetadataValue<AccordFastPath>
{
private void serializeMap(Map<Node.Id, NodeInfo> map, DataOutputPlus
out, Version version) throws IOException
{
- out.writeInt(map.size());
+ out.writeUnsignedVInt32(map.size());
for (Map.Entry<Node.Id, NodeInfo> entry : map.entrySet())
{
TopologySerializers.nodeId.serialize(entry.getKey(), out);
@@ -265,7 +265,7 @@ public class AccordFastPath implements
MetadataValue<AccordFastPath>
private ImmutableMap<Node.Id, NodeInfo> deserializeMap(DataInputPlus
in, Version version) throws IOException
{
- int size = in.readInt();
+ int size = in.readUnsignedVInt32();
if (size == 0)
return ImmutableMap.of();
@@ -284,7 +284,7 @@ public class AccordFastPath implements
MetadataValue<AccordFastPath>
private long serializedMapSize(Map<Node.Id, NodeInfo> map, Version
version)
{
- long size = TypeSizes.INT_SIZE;
+ long size = TypeSizes.sizeofUnsignedVInt(map.size());
for (Map.Entry<Node.Id, NodeInfo> entry : map.entrySet())
{
size +=
TopologySerializers.nodeId.serializedSize(entry.getKey());
diff --git
a/src/java/org/apache/cassandra/service/accord/fastpath/ParameterizedFastPathStrategy.java
b/src/java/org/apache/cassandra/service/accord/fastpath/ParameterizedFastPathStrategy.java
index 858c15b64d..9ad04ebbfa 100644
---
a/src/java/org/apache/cassandra/service/accord/fastpath/ParameterizedFastPathStrategy.java
+++
b/src/java/org/apache/cassandra/service/accord/fastpath/ParameterizedFastPathStrategy.java
@@ -221,7 +221,7 @@ public class ParameterizedFastPathStrategy implements
FastPathStrategy
sorters.sort(Comparator.naturalOrder());
int slowQuorum = Shard.slowQuorumSize(nodes.size());
- int fpSize = Math.max(size, slowQuorum);
+ int fpSize = Math.max(Math.min(size, nodes.size()), slowQuorum);
Node.Id[] array = new Node.Id[fpSize];
for (int i=0; i<fpSize; i++)
array[i] = sorters.get(i).id;
@@ -256,9 +256,8 @@ public class ParameterizedFastPathStrategy implements
FastPathStrategy
throw cfe("%s must be greater than zero", SIZE);
ImmutableMap<String, WeightedDc> dcMap;
- if (map.containsKey(DCS))
+ if (map.containsKey(DCS) && !map.get(DCS).isEmpty())
{
-
Map<String, WeightedDc> mutableDcs = new HashMap<>();
String dcsString = map.get(DCS);
if (dcsString.trim().isEmpty())
diff --git
a/test/distributed/org/apache/cassandra/distributed/test/accord/AccordFastpathConfigurationTest.java
b/test/distributed/org/apache/cassandra/distributed/test/accord/AccordFastpathConfigurationTest.java
new file mode 100644
index 0000000000..25598e58f9
--- /dev/null
+++
b/test/distributed/org/apache/cassandra/distributed/test/accord/AccordFastpathConfigurationTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.distributed.test.accord;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.test.TestBaseImpl;
+
+public class AccordFastpathConfigurationTest extends TestBaseImpl
+{
+ @Test
+ public void testParameterized() throws IOException
+ {
+ try (Cluster cluster = init(Cluster.build(1)
+ .start()))
+ {
+ cluster.schemaChange(withKeyspace("create table %s.tbl (id int
primary key) with transactional_mode='full' and fast_path={'size':55}"));
+ }
+ }
+}
diff --git a/test/unit/org/apache/cassandra/utils/CassandraGenerators.java
b/test/unit/org/apache/cassandra/utils/CassandraGenerators.java
index 08b06c0730..efbc3cabb6 100644
--- a/test/unit/org/apache/cassandra/utils/CassandraGenerators.java
+++ b/test/unit/org/apache/cassandra/utils/CassandraGenerators.java
@@ -861,7 +861,8 @@ public final class CassandraGenerators
// Names are used for
DCs and those are seperated by ,
.map(s ->
s.replace(",", "_"))
.assuming(s ->
!s.trim().isEmpty());
- int numNames = SourceDSL.integers().between(1,
10).generate(rnd);
+ // DCs is optional, allow 0 dcs:
+ int numNames = SourceDSL.integers().between(0,
10).generate(rnd);
for (int i = 0; i < numNames; i++)
{
while (!names.add(nameGen.generate(rnd)))
@@ -888,7 +889,8 @@ public final class CassandraGenerators
// dcFormat: name | weight
// weight: int: >= 0
// note: can't mix auto and user defined weight;
need one or the other. Names must be unique
- map.put(ParameterizedFastPathStrategy.DCS,
String.join(",", dcs));
+ if (!dcs.isEmpty())
+ map.put(ParameterizedFastPathStrategy.DCS,
String.join(",", dcs));
return ParameterizedFastPathStrategy.fromMap(map);
}
default:
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]