dcapwell commented on code in PR #4202: URL: https://github.com/apache/cassandra/pull/4202#discussion_r2191021211
########## 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; + ImmutableUniqueList<TokenRange> ranges; + { + ImmutableUniqueList.Builder<TableId> tablesBuilder = ImmutableUniqueList.builder(); + ImmutableUniqueList.Builder<TokenRange> rangesBuilder = ImmutableUniqueList.builder(); + for (Shard shard : shards) + { + TokenRange range = (TokenRange) shard.range; + tablesBuilder.add(range.table()); + rangesBuilder.add(range.withTable(TableId.UNDEFINED)); + } + tables = tablesBuilder.buildAndClear(); + ranges = rangesBuilder.buildAndClear(); + } + + CollectionSerializers.serializeList(tables, out, TableId.compactComparableSerializer); + CollectionSerializers.serializeList(ranges, out, TokenRange.noTableSerializer); + + out.writeUnsignedVInt32(shards.size()); + for (Shard shard : shards) + { + TokenRange range = (TokenRange) shard.range; + int tableIdx = tables.indexOf(range.table()); + int rangeIdx = ranges.indexOf(range.withTable(TableId.UNDEFINED)); + out.writeUnsignedVInt32(tableIdx); + out.writeUnsignedVInt32(rangeIdx); + + CollectionSerializers.serializeList(shard.nodes, out, TopologySerializers.nodeId); + BitSet notInFastPath = SortedArrays.toBitSet(shard.nodes, shard.notInFastPath); + BitSetSerializer.instance.serialize(notInFastPath, out); + BitSet joining = SortedArrays.toBitSet(shard.nodes, shard.joining); + BitSetSerializer.instance.serialize(joining, out); Review Comment: sorry, i wasn't clear. This specific line isn't what i am talking about, but the node ids are. joining is 1 byte in the common case now which should be in-line with previous version. But when something is joining its now 2 bytes vs 5. Same happens in the `notInFastPath`. This logic is the most repeated so got the largest savings -- 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