dcapwell commented on code in PR #4257: URL: https://github.com/apache/cassandra/pull/4257#discussion_r2211251941
########## src/java/org/apache/cassandra/index/accord/RangeMemoryIndex.java: ########## @@ -58,13 +63,51 @@ public class RangeMemoryIndex { @GuardedBy("this") - private final Map<Group, RangeTree<byte[], Range, DecoratedKey>> map = new HashMap<>(); - @GuardedBy("this") - private final Map<Group, Metadata> groupMetadata = new HashMap<>(); + private final Map<Key, Group> map = new HashMap<>(); - private static class Metadata + private static class Group { + private RangeTree<byte[], Range, DecoratedKey> tree = createRangeTree(); public byte[] minTerm, maxTerm; + public TxnId minTimestamp = TxnId.MAX; + public TxnId maxTimestamp = TxnId.NONE; + + void add(Range range, DecoratedKey key, TxnId txnId, byte[] start, byte[] end) + { + tree.add(range, key); + minTerm = minTerm == null ? start : ByteArrayUtil.compareUnsigned(minTerm, 0, start, 0, minTerm.length) > 0 ? start : minTerm; + maxTerm = maxTerm == null ? end : ByteArrayUtil.compareUnsigned(maxTerm, 0, end, 0, maxTerm.length) < 0 ? end : maxTerm; + if (minTimestamp.compareTo(txnId) > 0) + minTimestamp = txnId; + if (maxTimestamp.compareTo(txnId) < 0) + maxTimestamp = txnId; + } + + void search(byte[] start, byte[] end, + Timestamp minTimestamp, Timestamp maxTimestamp, + Consumer<Map.Entry<RangeMemoryIndex.Range, DecoratedKey>> fn) + { + if (this.minTimestamp.compareTo(maxTimestamp) > 0 || this.maxTimestamp.compareTo(minTimestamp) < 0) + return; + tree.search(new Range(start, end), e -> { + TxnId id = AccordKeyspace.JournalColumns.getJournalKey(e.getValue()).id; Review Comment: 2 things i can do to lower this cost 1) rather than construct the full `JournalColum`, only construct the `TxnId`. This "should" be very similar CPU cost but would have slightly less memory cost 2) try to do a byte compare to avoid the memory cost. I don't believe we have this setup already so think i would have to roll my own here. For this class i don't think it matters too much (its the stuff that hasn't been flushed to sstable), but for the sstable side this "should" matter more i think -- 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