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


##########
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()) {
+                break;
+            }
+
+            updateHeartbeat();
 
-        assert !queue.isEmpty();
+            int threads = threadPoolExecutor == null ? 1 : 
threadPoolExecutor.getMaximumPoolSize();
 
-        updateHeartbeat();
+            CompletableFuture<?>[] futures = new CompletableFuture[threads];
 
-        int threads = threadPoolExecutor == null ? 1 : 
threadPoolExecutor.getMaximumPoolSize();
+            for (int i = 0; i < threads; i++) {
+                CompletableFuture<?> future = futures[i] = new 
CompletableFuture<>();
 
-        CompletableFuture<?>[] futures = new CompletableFuture[threads];
+                Runnable merger = () -> {
+                    DeltaFileToCompaction toMerge;
 
-        for (int i = 0; i < threads; i++) {
-            CompletableFuture<?> future = futures[i] = new 
CompletableFuture<>();
+                    try {
+                        while ((toMerge = queue.poll()) != null) {

Review Comment:
   I tried to fix it.



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