You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "leaves12138 (via GitHub)" <gi...@apache.org> on 2023/07/31 08:21:20 UTC

[GitHub] [incubator-paimon] leaves12138 opened a new pull request, #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

leaves12138 opened a new pull request, #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690

   
   Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.
   
   Cause compaction may stock the checkpoint acknowledgement, but we actually don't need wait for all the compaction tasks finished to complete the checkpoint.
   
   Use the ExecutorService with max 100 tasks queue running background to execute compaction tasks.
   
   
   Worker Task    <---------    ResultQueue
        |                                                      /\
        |                  (   o     o    )                  |
        |                          -                           |
        |                                                       |
        |                                                       |
       \/                                                       |
   Task Queue  ---------------> ExecutorService


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690#discussion_r1280019250


##########
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/FileStoreTableTestBase.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.flink;
+
+import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.CatalogContext;
+import org.apache.paimon.catalog.CatalogFactory;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.options.CatalogOptions;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.table.Table;
+import org.apache.paimon.table.sink.CommitMessage;
+import org.apache.paimon.table.sink.StreamTableWrite;
+import org.apache.paimon.table.sink.StreamWriteBuilder;
+
+import org.junit.jupiter.api.io.TempDir;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+
+/** Test base for create table more conveniently. */
+public abstract class FileStoreTableTestBase {

Review Comment:
   Use `TableTestBase`?



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-paimon] JingsongLi merged pull request #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690#discussion_r1278965816


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/AppendOnlyTableCompactionWorkerOperator.java:
##########
@@ -54,14 +65,27 @@ public AppendOnlyTableCompactionWorkerOperator(
     public void open() throws Exception {
         this.worker = new AppendOnlyTableCompactionWorker(table, commitUser);
         this.result = new ArrayList<>();
+        executor =
+                new ThreadPoolExecutor(
+                        1,
+                        1,
+                        0L,
+                        TimeUnit.MILLISECONDS,
+                        new LinkedBlockingQueue<>(
+                                100)); // most 100 tasks in queue to avoid memory collapse
+        lock = new Object();
     }
 

Review Comment:
   Uncommit files should be deleted in close.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690#discussion_r1278963818


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/AppendOnlyTableCompactionWorkerOperator.java:
##########
@@ -54,14 +65,27 @@ public AppendOnlyTableCompactionWorkerOperator(
     public void open() throws Exception {
         this.worker = new AppendOnlyTableCompactionWorker(table, commitUser);
         this.result = new ArrayList<>();
+        executor =
+                new ThreadPoolExecutor(

Review Comment:
   See `AbstractFileStoreWrite`, how to new an executor and close executor.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690#discussion_r1280254879


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/AppendOnlyTableCompactionWorkerOperator.java:
##########
@@ -52,25 +70,105 @@ public AppendOnlyTableCompactionWorkerOperator(
 
     @Override
     public void open() throws Exception {
+        LOG.debug("Opened a append-only table compaction worker.");
         this.worker = new AppendOnlyTableCompactionWorker(table, commitUser);
-        this.result = new ArrayList<>();
+        this.result = new LinkedList<>();
     }
 
     @Override
     protected List<Committable> prepareCommit(boolean waitCompaction, long checkpointId)
             throws IOException {
-        // ignore waitCompaction tag
-        ArrayList<CommitMessage> tempList = new ArrayList<>(result);
-        result.clear();
-        return tempList.stream()
-                .map(s -> new Committable(checkpointId, Committable.Kind.FILE, s))
-                .collect(Collectors.toList());
+        List<CommitMessage> tempList = new ArrayList<>();
+        try {
+            while (!result.isEmpty()) {
+                Future<List<CommitMessage>> future = result.peek();
+                if (!future.isDone()) {

Review Comment:
   ```
   if (!future.isDone() && !waitCompaction) {
       break;
   }
   ....
   ```



##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/AppendOnlyTableCompactionWorkerOperator.java:
##########
@@ -52,25 +70,105 @@ public AppendOnlyTableCompactionWorkerOperator(
 
     @Override
     public void open() throws Exception {
+        LOG.debug("Opened a append-only table compaction worker.");
         this.worker = new AppendOnlyTableCompactionWorker(table, commitUser);
-        this.result = new ArrayList<>();
+        this.result = new LinkedList<>();
     }
 
     @Override
     protected List<Committable> prepareCommit(boolean waitCompaction, long checkpointId)
             throws IOException {
-        // ignore waitCompaction tag
-        ArrayList<CommitMessage> tempList = new ArrayList<>(result);
-        result.clear();
-        return tempList.stream()
-                .map(s -> new Committable(checkpointId, Committable.Kind.FILE, s))
-                .collect(Collectors.toList());
+        List<CommitMessage> tempList = new ArrayList<>();
+        try {
+            while (!result.isEmpty()) {
+                Future<List<CommitMessage>> future = result.peek();
+                if (!future.isDone()) {
+                    if (waitCompaction) {
+                        while (!future.isDone()) {
+                            Thread.sleep(1000L);
+                        }
+                    } else {
+                        break;
+                    }
+                }
+
+                result.poll();
+                tempList.addAll(future.get());
+            }
+            return tempList.stream()
+                    .map(s -> new Committable(checkpointId, Committable.Kind.FILE, s))
+                    .collect(Collectors.toList());
+        } catch (InterruptedException e) {
+            throw new RuntimeException("Interrupted while waiting tasks done.", e);
+        } catch (Exception e) {
+            throw new RuntimeException("Encountered an error while do compaction", e);
+        }
     }
 
     @Override
     public void processElement(StreamRecord<AppendOnlyCompactionTask> element) throws Exception {
         AppendOnlyCompactionTask task = element.getValue();
-        worker.accept(task);
-        result.addAll(worker.doCompact());
+        result.add(
+                workerExecutor()
+                        .submit(
+                                () -> {
+                                    worker.accept(task);

Review Comment:
   Can we refine the `AppendOnlyTableCompactionWorker`?
   Actually, we don't need `AppendOnlyTableCompactionWorker`?



##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/AppendOnlyTableCompactionWorkerOperator.java:
##########
@@ -52,25 +70,105 @@ public AppendOnlyTableCompactionWorkerOperator(
 
     @Override
     public void open() throws Exception {
+        LOG.debug("Opened a append-only table compaction worker.");
         this.worker = new AppendOnlyTableCompactionWorker(table, commitUser);
-        this.result = new ArrayList<>();
+        this.result = new LinkedList<>();
     }
 
     @Override
     protected List<Committable> prepareCommit(boolean waitCompaction, long checkpointId)
             throws IOException {
-        // ignore waitCompaction tag
-        ArrayList<CommitMessage> tempList = new ArrayList<>(result);
-        result.clear();
-        return tempList.stream()
-                .map(s -> new Committable(checkpointId, Committable.Kind.FILE, s))
-                .collect(Collectors.toList());
+        List<CommitMessage> tempList = new ArrayList<>();
+        try {
+            while (!result.isEmpty()) {
+                Future<List<CommitMessage>> future = result.peek();
+                if (!future.isDone()) {
+                    if (waitCompaction) {
+                        while (!future.isDone()) {
+                            Thread.sleep(1000L);
+                        }
+                    } else {
+                        break;
+                    }
+                }
+
+                result.poll();
+                tempList.addAll(future.get());
+            }
+            return tempList.stream()
+                    .map(s -> new Committable(checkpointId, Committable.Kind.FILE, s))
+                    .collect(Collectors.toList());
+        } catch (InterruptedException e) {
+            throw new RuntimeException("Interrupted while waiting tasks done.", e);
+        } catch (Exception e) {
+            throw new RuntimeException("Encountered an error while do compaction", e);
+        }
     }
 
     @Override
     public void processElement(StreamRecord<AppendOnlyCompactionTask> element) throws Exception {
         AppendOnlyCompactionTask task = element.getValue();
-        worker.accept(task);
-        result.addAll(worker.doCompact());
+        result.add(
+                workerExecutor()
+                        .submit(
+                                () -> {
+                                    worker.accept(task);
+                                    return worker.doCompact();
+                                }));
+    }
+
+    private ExecutorService workerExecutor() {
+        if (lazyCompactExecutor == null) {
+            lazyCompactExecutor =
+                    Executors.newSingleThreadScheduledExecutor(
+                            new ExecutorThreadFactory(
+                                    Thread.currentThread().getName()
+                                            + "-append-only-compact-worker"));
+        }
+        return lazyCompactExecutor;
+    }
+
+    @Override
+    public void close() throws Exception {
+        shutdown();
+    }
+
+    @VisibleForTesting
+    void shutdown() {
+        if (lazyCompactExecutor != null) {
+            // ignore runnable tasks in queue
+            lazyCompactExecutor.shutdownNow();
+
+            // remove the file already written
+            FileIO fileIO = table.fileIO();
+
+            for (Future<List<CommitMessage>> resultFuture : result) {
+                if (!resultFuture.isDone()) {
+                    // the later tasks should be stopped running
+                    break;
+                }
+                List<CommitMessage> messages;
+                try {
+                    messages = resultFuture.get();
+                } catch (Exception exception) {
+                    // exception should already be handled
+                    continue;
+                }
+                for (CommitMessage uncommitMessage : messages) {
+                    CommitMessageImpl uncommitMessageImpl = (CommitMessageImpl) uncommitMessage;
+                    List<DataFileMeta> fileMetas =

Review Comment:
   See `TableCommit.abort`?



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-paimon] leaves12138 commented on a diff in pull request #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

Posted by "leaves12138 (via GitHub)" <gi...@apache.org>.
leaves12138 commented on code in PR #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690#discussion_r1280267352


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/AppendOnlyTableCompactionWorkerOperator.java:
##########
@@ -52,25 +70,105 @@ public AppendOnlyTableCompactionWorkerOperator(
 
     @Override
     public void open() throws Exception {
+        LOG.debug("Opened a append-only table compaction worker.");
         this.worker = new AppendOnlyTableCompactionWorker(table, commitUser);
-        this.result = new ArrayList<>();
+        this.result = new LinkedList<>();
     }
 
     @Override
     protected List<Committable> prepareCommit(boolean waitCompaction, long checkpointId)
             throws IOException {
-        // ignore waitCompaction tag
-        ArrayList<CommitMessage> tempList = new ArrayList<>(result);
-        result.clear();
-        return tempList.stream()
-                .map(s -> new Committable(checkpointId, Committable.Kind.FILE, s))
-                .collect(Collectors.toList());
+        List<CommitMessage> tempList = new ArrayList<>();
+        try {
+            while (!result.isEmpty()) {
+                Future<List<CommitMessage>> future = result.peek();
+                if (!future.isDone()) {

Review Comment:
   reasonable
   



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-paimon] JingsongLi commented on a diff in pull request #1690: [improve] Unaware-bucket table do compaction async, uncoupled with CheckpointBarrier.

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #1690:
URL: https://github.com/apache/incubator-paimon/pull/1690#discussion_r1278967459


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/AppendOnlyTableCompactionWorkerOperator.java:
##########
@@ -38,10 +44,15 @@
  */
 public class AppendOnlyTableCompactionWorkerOperator
         extends PrepareCommitOperator<AppendOnlyCompactionTask, Committable> {
+    private static final Logger LOG =
+            LoggerFactory.getLogger(AppendOnlyTableCompactionWorkerOperator.class);
     private final AppendOnlyFileStoreTable table;
-    private transient AppendOnlyTableCompactionWorker worker;
     private final String commitUser;
+    private transient AppendOnlyTableCompactionWorker worker;
     private transient List<CommitMessage> result;

Review Comment:
   You can just change this to `LinkedBlockingQueue` and avoid lock.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org