belliottsmith commented on code in PR #4078:
URL: https://github.com/apache/cassandra/pull/4078#discussion_r2040596597


##########
src/java/org/apache/cassandra/service/accord/serializers/TableMetadatasAndKeys.java:
##########
@@ -0,0 +1,270 @@
+/*
+ * 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.service.accord.serializers;
+
+import java.io.IOException;
+import java.util.Comparator;
+
+import accord.api.Key;
+import accord.api.Sliceable;
+import accord.primitives.AbstractRanges;
+import accord.primitives.Keys;
+import accord.primitives.Participants;
+import accord.primitives.Ranges;
+import accord.primitives.Routable;
+import accord.primitives.Seekable;
+import accord.primitives.Seekables;
+import accord.utils.Invariants;
+import accord.utils.VIntCoding;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.io.UnversionedSerializer;
+import org.apache.cassandra.io.util.DataInputPlus;
+import org.apache.cassandra.io.util.DataOutputPlus;
+import org.apache.cassandra.schema.TableId;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.service.accord.api.PartitionKey;
+import org.apache.cassandra.service.accord.serializers.TableMetadatas.Multi;
+import org.apache.cassandra.utils.btree.BTreeSet;
+
+import static accord.primitives.Routable.Domain.Range;
+import static accord.primitives.Routables.Slice.Minimal;
+
+public class TableMetadatasAndKeys extends 
IVersionedWithKeysSerializer.AbstractWithKeysSerializer implements 
Sliceable<TableMetadatasAndKeys>
+{
+    public static class KeyCollector extends 
AbstractSortedCollector<PartitionKey, Keys>
+    {
+        private static final Comparator<Object> comparator = 
Comparator.comparing(v -> ((PartitionKey) v));
+
+        public final TableMetadatas tables;
+
+        public KeyCollector(TableMetadatas tables)
+        {
+            this.tables = tables;
+        }
+
+        public TableMetadatasAndKeys buildTablesAndKeys()
+        {
+            return new TableMetadatasAndKeys(tables, build());
+        }
+
+        @Override
+        Comparator<Object> comparator()
+        {
+            return comparator;
+        }
+
+        public PartitionKey collect(TableMetadata table, DecoratedKey key)
+        {
+            TableId tableId = tables.get(table.id).id;
+            if (count == 1)
+            {
+                PartitionKey one = (PartitionKey) buffer;
+                if (one.prefix() == table && one.partitionKey().equals(key))

Review Comment:
   Either way, the line that interns it is directly above. At most this needs a 
comment. If we can’t trust ourselves to maintain an invariant like this with 
reasonable certainty (no worse than any other invariant) we should probably 
stop developing software IMO.
   
   I get the concern if the imposition of this invariant is distant and 
fragile, just not here where it’s enforced hyper locally. Note your reference 
about the intern “race” was not the issue you think, as it was never relied 
upon for object identity testing, its goal was only reducing the memory burden 
of RoutingKey, which occupy a large amount of space in the accord cache given 
all the different copies of keys we have. Really we want to pass this object 
through to the RoutingKey serializers for that reason, since you plan to remove 
intern (a version like this was also my ultimate plan for those places). But, 
they are also likely improved by some other recent serialisation improvements, 
so it may be unnecessary.



-- 
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]

Reply via email to