belliottsmith commented on code in PR #4202: URL: https://github.com/apache/cassandra/pull/4202#discussion_r2191566496
########## src/java/org/apache/cassandra/service/accord/serializers/TopologySerializers.java: ########## @@ -159,4 +167,127 @@ public long serializedSize(Topology topology) return size; } }; + + public static final UnversionedSerializer<Topology> compactTopology = new UnversionedSerializer<>() + { + @Override + public void serialize(Topology topology, DataOutputPlus out) throws IOException + { + out.writeLong(topology.epoch()); + CollectionSerializers.serializeList(topology.staleIds(), out, TopologySerializers.nodeId); + + List<Shard> shards = topology.shards(); + + // need to loop twice; once to collect tables/ranges, and another to save shards + ImmutableUniqueList<TableId> tables; Review Comment: It is new to src, which to me is new to the PR. The expectations of src are different, and we will need to at least haggle about naming etc. But, even if it were already in src it is not a suitable data structure here as it imposes unnecessary costs in at least one but likely both directions. For deserialisation, the object->int mapping is unused, so this is a costly waste of effort to construct. For serialisation I don’t see why you need to sort the values? The normal approach here is to simply write them in the order they come, and ensure they are inserted into the hash map in that same order, so that the hash map contains their index. That is, on deserialization you simply build the original array/list and lookup by index, and on serialisation you serialise the array/list and build a lookup for finding the index to encode. This pattern is used extensively throughout the code base. -- 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