szetszwo commented on code in PR #10813:
URL: https://github.com/apache/ozone/pull/10813#discussion_r3780711458


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ContainerExportManager.java:
##########
@@ -0,0 +1,363 @@
+/*
+ * 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.hadoop.hdds.scm.container.export;
+
+import static 
org.apache.hadoop.hdds.scm.container.export.ExportLimits.DEFAULT_PAGE_SIZE;
+import static 
org.apache.hadoop.hdds.scm.container.export.ExportLimits.DEFAULT_SHARD_SIZE;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayDeque;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BooleanSupplier;
+import java.util.stream.Collectors;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
+import org.apache.hadoop.hdds.scm.container.ContainerHealthState;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manages asynchronous container ID export jobs on the SCM leader.
+ *
+ * <p>Health filters read {@link 
org.apache.hadoop.hdds.scm.container.ContainerInfo#getHealthState()}
+ * as last written by Replication Manager; they are not recomputed during 
export and may be stale
+ * if RM has not yet evaluated a container.
+ *
+ * <p>Job status is kept in memory only. On SCM restart or leader failover, 
in-flight jobs are lost
+ * and the operator must re-submit on the new leader. {@link 
ExportFileManager} owns on-disk layout,
+ * locking, shard files, and completed archives; this class tracks {@link 
ExportJob} state,
+ * schedules work, and applies {@code maxTerminalJobs} eviction.
+ */
+public class ContainerExportManager {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ContainerExportManager.class);
+
+  //TODO: make ozone.scm.container.export.max.terminal.jobs configurable.
+  private static final int DEFAULT_MAX_TERMINAL_JOBS = 10;
+  private static final long SHUTDOWN_TIMEOUT_MS = 5_000;
+
+  private final Map<ExportJob.Id, ExportJob> jobMap = new 
ConcurrentHashMap<>();
+  private final Deque<String> completedArchivePaths = new ArrayDeque<>();
+  private final AtomicReference<ExportJob.Id> runningJobId = new 
AtomicReference<>();
+  private final ExecutorService workerPool;
+  private final ContainerManager containerManager;
+  private final ExportFileManager fileManager;
+  private final ExportMetrics metrics;
+  private final BooleanSupplier isLeaderReady;
+  private final int defaultShardSize;
+  private final int defaultPageSize;
+  private final int maxTerminalJobs;
+  /** SCM node id, used in the export worker thread name. */
+  private final String scmId;
+
+  public ContainerExportManager(ContainerManager containerManager, 
BooleanSupplier isLeaderReady,
+      OzoneConfiguration conf, String scmId) {
+    this.containerManager = Objects.requireNonNull(containerManager, 
"containerManager == null");
+    this.isLeaderReady = Objects.requireNonNull(isLeaderReady, "isLeaderReady 
== null");
+    this.fileManager = new ExportFileManager(
+        Objects.requireNonNull(ExportFileManager.resolveExportDirectory(conf), 
"exportDirectory == null"));
+    this.scmId = Objects.requireNonNull(scmId, "scmId == null");
+    this.defaultShardSize = DEFAULT_SHARD_SIZE;
+    this.defaultPageSize = DEFAULT_PAGE_SIZE;
+    this.maxTerminalJobs = DEFAULT_MAX_TERMINAL_JOBS;
+    this.metrics = ExportMetrics.create();
+    this.workerPool = newWorkerPool(this.scmId);
+  }
+
+  ContainerExportManager(ContainerManager containerManager, BooleanSupplier 
isLeaderReady,
+      String exportDirectory, int defaultShardSize, int defaultPageSize, int 
maxTerminalJobs,
+      String scmId) {
+    this.containerManager = Objects.requireNonNull(containerManager, 
"containerManager == null");
+    this.isLeaderReady = Objects.requireNonNull(isLeaderReady, "isLeaderReady 
== null");
+    this.fileManager = new 
ExportFileManager(Objects.requireNonNull(exportDirectory, "exportDirectory == 
null"));
+    this.scmId = Objects.requireNonNull(scmId, "scmId == null");
+    this.defaultShardSize = defaultShardSize;
+    this.defaultPageSize = defaultPageSize;
+    this.maxTerminalJobs = maxTerminalJobs;
+    this.metrics = null;
+    this.workerPool = newWorkerPool(this.scmId);
+  }
+
+  private static ExecutorService newWorkerPool(String scmId) {
+    return Executors.newSingleThreadExecutor(r -> {
+      Thread t = new Thread(r, scmId + "-ContainerExportWorker");
+      t.setDaemon(true);
+      return t;
+    });
+  }
+
+  /**
+   * Initializes the export directory. Must be called once before submitting 
jobs.
+   */
+  public void start() throws IOException {
+    fileManager.start();
+    reloadCompletedArchives();
+    LOG.info("ContainerExportManager started (dir={}, defaultShardSize={}, 
defaultPageSize={}, maxTerminalJobs={})",
+        fileManager.getExportDirectory(), defaultShardSize, defaultPageSize, 
maxTerminalJobs);
+  }
+
+  /**
+   * Submit a container ID export job on the SCM leader.
+   * Batch sizing is described by {@link ExportSizing}.
+   *
+   * @return job id, or {@code null} if not leader or another export is 
already running
+   */
+  public ExportJob.Id submitJob(ContainerID start, LifeCycleState 
lifeCycleState,
+      ContainerHealthState healthState, long maxRows, int pageSize, int 
shardSize) {
+    if (!isLeaderReady.getAsBoolean()) {
+      return null;
+    }
+    if (lifeCycleState == null && healthState == null) {
+      throw new IllegalArgumentException("At least one of healthState or 
lifecycleState filter is required.");
+    }
+    validateRequest(start);

Review Comment:
   Move lifeCycleState == null && healthState inside validateRequest(..).



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ContainerExportManager.java:
##########
@@ -0,0 +1,363 @@
+/*
+ * 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.hadoop.hdds.scm.container.export;
+
+import static 
org.apache.hadoop.hdds.scm.container.export.ExportLimits.DEFAULT_PAGE_SIZE;
+import static 
org.apache.hadoop.hdds.scm.container.export.ExportLimits.DEFAULT_SHARD_SIZE;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayDeque;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BooleanSupplier;
+import java.util.stream.Collectors;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
+import org.apache.hadoop.hdds.scm.container.ContainerHealthState;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manages asynchronous container ID export jobs on the SCM leader.
+ *
+ * <p>Health filters read {@link 
org.apache.hadoop.hdds.scm.container.ContainerInfo#getHealthState()}
+ * as last written by Replication Manager; they are not recomputed during 
export and may be stale
+ * if RM has not yet evaluated a container.
+ *
+ * <p>Job status is kept in memory only. On SCM restart or leader failover, 
in-flight jobs are lost
+ * and the operator must re-submit on the new leader. {@link 
ExportFileManager} owns on-disk layout,
+ * locking, shard files, and completed archives; this class tracks {@link 
ExportJob} state,
+ * schedules work, and applies {@code maxTerminalJobs} eviction.
+ */
+public class ContainerExportManager {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ContainerExportManager.class);
+
+  //TODO: make ozone.scm.container.export.max.terminal.jobs configurable.
+  private static final int DEFAULT_MAX_TERMINAL_JOBS = 10;
+  private static final long SHUTDOWN_TIMEOUT_MS = 5_000;
+
+  private final Map<ExportJob.Id, ExportJob> jobMap = new 
ConcurrentHashMap<>();
+  private final Deque<String> completedArchivePaths = new ArrayDeque<>();
+  private final AtomicReference<ExportJob.Id> runningJobId = new 
AtomicReference<>();
+  private final ExecutorService workerPool;
+  private final ContainerManager containerManager;
+  private final ExportFileManager fileManager;
+  private final ExportMetrics metrics;
+  private final BooleanSupplier isLeaderReady;
+  private final int defaultShardSize;
+  private final int defaultPageSize;

Review Comment:
   Remove "default".



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