maedhroz commented on code in PR #2498:
URL: https://github.com/apache/cassandra/pull/2498#discussion_r1270153486


##########
src/java/org/apache/cassandra/index/sai/disk/v1/sortedterms/SortedTermsWriter.java:
##########
@@ -124,26 +146,61 @@ public void add(final @Nonnull ByteComparable term) 
throws IOException
         copyBytes(term, tempTerm);
 
         BytesRef termRef = tempTerm.get();
-        BytesRef prevTermRef = this.prevTerm.get();
 
-        Preconditions.checkArgument(prevTermRef.length == 0 || 
prevTermRef.compareTo(termRef) < 0,
-                                    "Terms must be added in lexicographic 
ascending order.");
         writeTermData(termRef);
-        writeTermToTrie(term);
 
-        maxLength = Math.max(maxLength, termRef.length);
-        swapTempWithPrevious();
-        pointId++;
+        maxTermLength = Math.max(maxTermLength, termRef.length);
+
+        BytesRefBuilder temp = this.tempTerm;
+        this.tempTerm = this.prevTerm;
+        this.prevTerm = temp;
+
+        if (trieOutputWriter != null)
+        {
+            if (trieSegment == null)
+                trieSegment = new TrieSegment();
+            else if 
(SegmentMemoryLimiter.usageExceedsLimit(trieSegment.totalBytesAllocated))
+            {
+                segments.add(trieSegment.flush());
+                trieSegment = new TrieSegment();
+            }
+            trieSegment.add(term);
+        }

Review Comment:
   Just a code organization nit, but it might be nice to have something like a 
`TrieWriter` interface in here that we can implement w/ a no-op singleton and 
the real implementation. That way, I imagine we could avoid all the `if 
(trieOutputWriter != null)` checking stuff and keep all the trie writing 
state/header writing there.
   
   For example, this whole block of code reverts back to something like 
`trieWriter.add(term, rowID);`



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