ibessonov commented on code in PR #1325:
URL: https://github.com/apache/ignite-3/pull/1325#discussion_r1032119674


##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/compaction/Compactor.java:
##########
@@ -164,77 +170,90 @@ void waitDeltaFiles() {
     }
 
     /**
-     * Adds the number of delta files to compact.
-     *
-     * @param count Number of delta files.
+     * Callback on adding delta files so we can start compacting them.
      */
-    public void addDeltaFiles(int count) {
-        assert count >= 0;
-
-        if (count > 0) {
-            deltaFileCount.addAndGet(count);
+    public void onAddingDeltaFiles() {
+        synchronized (mux) {
+            addedDeltaFiles = true;
 
-            synchronized (mux) {
-                mux.notifyAll();
-            }
+            mux.notifyAll();
         }
     }
 
     /**
      * Merges delta files with partition files.
      */
     void doCompaction() {
-        // Let's collect one delta file for each partition.
-        Queue<IgniteBiTuple<FilePageStore, DeltaFilePageStoreIo>> queue = 
filePageStoreManager.allPageStores().stream()
-                .flatMap(List::stream)
-                .map(filePageStore -> {
+        while (true) {
+            // Let's collect one delta file for each partition.
+            ConcurrentLinkedQueue<DeltaFileToCompaction> queue = new 
ConcurrentLinkedQueue<>();
+
+            for (GroupPageStores<FilePageStore> groupPageStores : 
filePageStoreManager.allPageStores()) {
+                for (PartitionPageStore<FilePageStore> partitionPageStore : 
groupPageStores.getAll()) {
+                    FilePageStore filePageStore = 
partitionPageStore.pageStore();
+
                     DeltaFilePageStoreIo deltaFileToCompaction = 
filePageStore.getDeltaFileToCompaction();
 
-                    return deltaFileToCompaction == null ? null : new 
IgniteBiTuple<>(filePageStore, deltaFileToCompaction);
-                })
-                .filter(Objects::nonNull)
-                .collect(toCollection(ConcurrentLinkedQueue::new));
+                    if (!filePageStore.isMarkedToDestroy() && 
deltaFileToCompaction != null) {
+                        queue.add(new DeltaFileToCompaction(
+                                groupPageStores.groupId(),
+                                partitionPageStore.partitionId(),
+                                filePageStore,
+                                deltaFileToCompaction
+                        ));
+                    }
+                }
+            }
+
+            if (queue.isEmpty()) {

Review Comment:
   > All threads must wait until the last thread finishes its delta file, and 
only then the next batch is created.
   
   This is probably the most important sentence in my comment. Threads in 
thread-pool will wait until the last delta file is merged, and only then the 
next portion of delta files will be presented to the thread-pool.
   Is that intentionally planned? What was the reasoning?



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

Reply via email to