You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "szehon-ho (via GitHub)" <gi...@apache.org> on 2023/04/18 16:58:09 UTC

[GitHub] [iceberg] szehon-ho commented on a diff in pull request #7343: Core: Parameterize RewriteDataFile's CommitService

szehon-ho commented on code in PR #7343:
URL: https://github.com/apache/iceberg/pull/7343#discussion_r1170329259


##########
core/src/main/java/org/apache/iceberg/actions/BaseCommitService.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * 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.iceberg.actions;
+
+import java.io.Closeable;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Queues;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An async service which allows for committing multiple file groups as their rewrites complete. The
+ * service also allows for partial-progress since commits can fail. Once the service has been closed
+ * no new file groups should not be offered.
+ *
+ * <p>Specific implementations provide implementations for {@link #commitOrClean(Set)} and {@link
+ * #abortFileGroup(Object)}
+ *
+ * @param <T> abstract type of file group
+ */
+abstract class BaseCommitService<T> implements Closeable {
+  private static final Logger LOG = LoggerFactory.getLogger(BaseCommitService.class);
+
+  private final Table table;
+  private final ExecutorService committerService;
+  private final ConcurrentLinkedQueue<T> completedRewrites;
+  private final ConcurrentLinkedQueue<String> inProgressCommits;
+  private final List<T> committedRewrites;
+  private final int rewritesPerCommit;
+  private final AtomicBoolean running = new AtomicBoolean(false);
+
+  /**
+   * Constructs a {@link BaseCommitService}
+   *
+   * @param table table to perform commit on
+   * @param rewritesPerCommit number of file groups to include in a commit
+   */
+  BaseCommitService(Table table, int rewritesPerCommit) {
+    this.table = table;
+    LOG.info(
+        "Creating commit service for table {} with {} groups per commit", table, rewritesPerCommit);
+    this.rewritesPerCommit = rewritesPerCommit;
+
+    committerService =
+        Executors.newSingleThreadExecutor(
+            new ThreadFactoryBuilder().setNameFormat("Committer-Service").build());
+
+    completedRewrites = Queues.newConcurrentLinkedQueue();
+    committedRewrites = Lists.newArrayList();
+    inProgressCommits = Queues.newConcurrentLinkedQueue();
+  }
+
+  /**
+   * Perform a commit operation on the table for the set of file groups, should cleanup failed file
+   * groups.
+   *
+   * @param batch set of file groups
+   */
+  abstract void commitOrClean(Set<T> batch);
+
+  /**
+   * Clean up a specified file set by removing any files created for that operation, should not
+   * throw any exceptions
+   *
+   * @param group group of files which are not yet committed
+   */
+  abstract void abortFileGroup(T group);
+
+  /** Starts a single threaded executor service for handling file group commits. */
+  public void start() {
+    Preconditions.checkState(
+        running.compareAndSet(false, true), "Rewrite Commit service already started");
+    LOG.info("Starting commit service for {}", table);
+    // Partial progress commit service

Review Comment:
   Removed



-- 
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@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org