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


##########
src/java/org/apache/cassandra/index/sai/StorageAttachedIndex.java:
##########
@@ -709,15 +524,164 @@ public IndexBuildingSupport getBuildTaskSupport()
         return INDEX_BUILDER_SUPPORT;
     }
 
-    public IndexContext getIndexContext()
+    /**
+     * Splits SSTables into groups of similar overall size.
+     *
+     * @param toRebuild a list of SSTables to split (Note that this list will 
be sorted in place!)
+     * @param parallelism an upper bound on the number of groups
+     *
+     * @return a {@link List} of SSTable groups, each represented as a {@link 
List} of {@link SSTableReader}
+     */
+    @VisibleForTesting
+    public static List<List<SSTableReader>> groupBySize(List<SSTableReader> 
toRebuild, int parallelism)
     {
-        return indexContext;
+        List<List<SSTableReader>> groups = new ArrayList<>();
+
+        
toRebuild.sort(Comparator.comparingLong(SSTableReader::onDiskLength).reversed());
+        Iterator<SSTableReader> sortedSSTables = toRebuild.iterator();
+        double dataPerCompactor = 
toRebuild.stream().mapToLong(SSTableReader::onDiskLength).sum() * 1.0 / 
parallelism;
+
+        while (sortedSSTables.hasNext())
+        {
+            long sum = 0;
+            List<SSTableReader> current = new ArrayList<>();
+
+            while (sortedSSTables.hasNext() && sum < dataPerCompactor)
+            {
+                SSTableReader sstable = sortedSSTables.next();
+                sum += sstable.onDiskLength();
+                current.add(sstable);
+            }
+
+            assert !current.isEmpty();
+            groups.add(current);
+        }
+
+        return groups;
     }
 
-    @Override
-    public String toString()
+    /**
+     * @return A set of SSTables which have attached to them invalid index 
components.
+     */
+    public Collection<SSTableContext> 
onSSTableChanged(Collection<SSTableReader> oldSSTables, 
Collection<SSTableContext> newSSTables, IndexValidation validation)
+    {
+        return viewManager.update(oldSSTables, newSSTables, validation);
+    }
+
+    public void drop(Collection<SSTableReader> sstablesToRebuild)
+    {
+        viewManager.drop(sstablesToRebuild);
+    }
+
+    public MemtableIndexManager memtableIndexManager()
+    {
+        return memtableIndexManager;
+    }
+
+    public View view()
+    {
+        return viewManager.view();
+    }
+
+    public IndexTermType indexTermType()
+    {
+        return this.indexTermType;
+    }
+
+    public IndexIdentifier indexIdentifier()

Review Comment:
   ```suggestion
       public IndexIdentifier identifier()
   ```
   nit: This might look nicer when we have usages like `index.identifier()` 
rather than `index.indexIdentifier()`...



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