ifesdjeen commented on code in PR #4738:
URL: https://github.com/apache/cassandra/pull/4738#discussion_r3208907970
##########
src/java/org/apache/cassandra/service/accord/serializers/CommandStoreSerializers.java:
##########
@@ -236,6 +353,502 @@ public long serializedSize(NavigableMap<T, Ranges> map)
}
}
- public static final UnversionedSerializer<NavigableMap<TxnId, Ranges>>
bootstrapBeganAt = new TimestampToRangesSerializer<>(CommandSerializers.txnId);
- public static final UnversionedSerializer<NavigableMap<Timestamp, Ranges>>
safeToRead = new TimestampToRangesSerializer<>(CommandSerializers.timestamp);
+ private static abstract class BTreeReducingRangeMapSerializer<E extends
ReducingBTree.Entry<E>, Map extends BTreeReducingRangeMap<E>> implements
UnversionedSerializer<Map>
+ {
+ private static final int RESERVED_MAP_MASK = 0x3;
+
+ private static final int DISCONTIGUOUS = 1;
+ private static final int NEW_PREFIX = 2;
+
+ public BTreeReducingRangeMapSerializer()
+ {
+ }
+
+ abstract Map empty();
+ abstract BTreeReducingRangeMap.Builder<E, Map> builder();
+ abstract void serializeWithoutRange(E e, DataOutputPlus out) throws
IOException;
+ abstract long serializedSizeWithoutRange(E e);
+ abstract E deserialize(RoutingKey start, RoutingKey end, DataInputPlus
in, int mapFlags) throws IOException;
+ abstract E deserializeArrayModeWithoutRange(DataInputPlus in) throws
IOException;
+
+ protected int mapFlags() { return 0; }
+
+ @Override
+ public void serialize(Map map, DataOutputPlus out) throws IOException
+ {
+ // for upgrading non-tree structures
+ int mapFlags = mapFlags();
+ Invariants.require((mapFlags & RESERVED_MAP_MASK) == 0);
+ mapFlags |= REDUCING_BTREE_MODE;
+ int mapSize = map.size();
+ out.writeUnsignedVInt32(mapFlags);
+ out.writeUnsignedVInt32(mapSize);
+
+ if (mapSize == 0)
+ return;
+
+ E prev = null;
+ int fixedLength = 0;
+ for (E e : map)
+ {
+ int flags = 0;
+ if (prev == null)
+ {
+ flags = NEW_PREFIX | DISCONTIGUOUS;
+ }
+ else
+ {
+ int c = prev.end().compareTo(e.start());
+ if (c > 0)
+ throw illegalState("Not well-formed: %s overlaps %s in
%s", prev, e, map);
+
+ if (c < 0)
+ {
+ flags = DISCONTIGUOUS;
+ if (!prev.prefix().equals(e.prefix()))
+ flags |= NEW_PREFIX;
+ }
+ out.writeByte(flags);
+ }
+
+ if ((flags & DISCONTIGUOUS) != 0)
+ {
+ if ((flags & NEW_PREFIX) != 0)
+ {
+ KeySerializers.routingKey.serializePrefix(e.prefix(),
out);
+ fixedLength =
KeySerializers.routingKey.fixedKeyLengthForPrefix(e.prefix());
+ }
+ if (fixedLength < 0)
+
out.writeUnsignedVInt32(KeySerializers.routingKey.serializedSizeWithoutPrefixOrLength(e.start()));
+
KeySerializers.routingKey.serializeWithoutPrefixOrLength(e.start(), out);
+ }
+ if (fixedLength < 0)
+
out.writeUnsignedVInt32(KeySerializers.routingKey.serializedSizeWithoutPrefixOrLength(e.end()));
+
KeySerializers.routingKey.serializeWithoutPrefixOrLength(e.end(), out);
+ serializeWithoutRange(e, out);
+ prev = e;
+ }
+ }
+
+ @Override
+ public Map deserialize(DataInputPlus in) throws IOException
+ {
+ int mapFlags = in.readUnsignedVInt32();
+ int mapSize = in.readUnsignedVInt32();
+
+ if (mapSize == 0)
+ return empty();
+
+ try (BTreeReducingRangeMap.Builder<E, Map> builder = builder())
+ {
+ if ((mapFlags & REDUCING_MODE_BIT) == REDUCING_BTREE_MODE)
+ {
+ Object prefix = null;
+ RoutingKey prevEnd = null;
+ E prev = null;
+ int fixedLength = 0;
+ while (mapSize-- > 0)
+ {
+ int flags;
+ if (prefix == null) flags = NEW_PREFIX | DISCONTIGUOUS;
+ else flags = in.readByte();
+
+ RoutingKey start;
+ if ((flags & DISCONTIGUOUS) == 0)
+ {
+ start = prevEnd;
+ }
+ else
+ {
+ if ((flags & NEW_PREFIX) != 0)
+ {
+ prefix =
KeySerializers.routingKey.deserializePrefix(in);
+ fixedLength =
KeySerializers.routingKey.fixedKeyLengthForPrefix(in);
Review Comment:
should be `prefix` instead of `in`
--
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]