dcapwell commented on code in PR #4257:
URL: https://github.com/apache/cassandra/pull/4257#discussion_r2211273200


##########
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:
   FYI given how we do things today, we don't ever touch this object... journal 
directly creates SSTables and ignores memtable, so it really doesn't matter too 
much what we do here...
   
   2i *requires* we have memory indexes and its mostly here just to be 
"correct" if we ever do rely on memtable for some reason (such as to patch a 
journal entry?)...



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