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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ExportFileManager.java:
##########
@@ -0,0 +1,275 @@
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.commons.io.FileUtils;
+import org.apache.ratis.util.AtomicFileOutputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manages on-disk paths and artifacts for container ID export jobs.
+ *
+ * <p>The export directory ({@code exportDirectory}, typically {@code 
{scm.db.dirs}/exports})
+ * uses the layout below. The manager gzip-compresses the archive ({@code 
.tar.gz}) so operators
+ * can stream entries with {@code zcat}.
+ *
+ * <p>While a job runs, shard text files are written under {@code 
export_{jobId}/}. The archive is
+ * created only after all shards are written. The export manager writes
+ * {@code container-ids-{scope}-{timestamp}.tar.gz.tmp} and atomically renames 
it to
+ * {@code .tar.gz} on close ({@link AtomicFileOutputStream}), so a partial 
{@code .tar.gz} is
+ * never visible. {@link #lock()} is used to exclude concurrent writers.
+ *
+ * <pre>
+ * {exportDirectory}/
+ * ├── in_use.lock
+ * ├── {jobId}.in-progress

Review Comment:
   The  {jobId}.in-progress marker seems not useful.  On startup
   - Just delete all tar.gz.tmp and export_{jobId}/
   -  Load all tar.gz and rebuild the state (suppose it has the JobId.)



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ExportFileManager.java:
##########
@@ -0,0 +1,275 @@
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.commons.io.FileUtils;
+import org.apache.ratis.util.AtomicFileOutputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manages on-disk paths and artifacts for container ID export jobs.
+ *
+ * <p>The export directory ({@code exportDirectory}, typically {@code 
{scm.db.dirs}/exports})
+ * uses the layout below. The manager gzip-compresses the archive ({@code 
.tar.gz}) so operators
+ * can stream entries with {@code zcat}.
+ *
+ * <p>While a job runs, shard text files are written under {@code 
export_{jobId}/}. The archive is
+ * created only after all shards are written. The export manager writes
+ * {@code container-ids-{scope}-{timestamp}.tar.gz.tmp} and atomically renames 
it to
+ * {@code .tar.gz} on close ({@link AtomicFileOutputStream}), so a partial 
{@code .tar.gz} is
+ * never visible. {@link #lock()} is used to exclude concurrent writers.
+ *
+ * <pre>
+ * {exportDirectory}/
+ * ├── in_use.lock
+ * ├── {jobId}.in-progress
+ * ├── container-ids-{scope}-{timestamp}.tar.gz
+ * ├── container-ids-{scope}-{timestamp}.tar.gz.tmp
+ * └── export_{jobId}/
+ *     ├── container-ids-{scope}-{timestamp}-part001.txt
+ *     └── ...
+ * </pre>
+ *
+ * <p><b>When {@code export_{jobId}/} is deleted:</b> the export manager 
deletes it after the
+ * archive is committed, or during {@link #cleanupFailedArtifacts} on failure 
or cancel.
+ * On startup, {@link #start()} deletes a leftover {@code export_{jobId}/} 
when no in-progress
+ * marker remains. If the marker still exists, {@link #start()} deletes {@code 
export_{jobId}/}
+ * together with the marker and any {@code .tar.gz.tmp} for that incomplete 
job.
+ *
+ * <p><b>When {@code .tar.gz.tmp} is deleted:</b> only the temporary file is 
removed for
+ * incomplete work; a partial {@code .tar.gz} is never written. {@link 
#cleanupFailedArtifacts}
+ * deletes {@code .tar.gz.tmp} for failed or cancelled jobs. {@link #start()} 
deletes
+ * {@code .tar.gz.tmp} for jobs that still have an in-progress marker.
+ *
+ * <p><b>When completed {@code .tar.gz} is deleted:</b> completed archives 
remain on disk until
+ * the export manager evicts them ({@code maxTerminalJobs} in {@code 
ContainerExportManager}).
+ *
+ * <p><b>SCM restart:</b> in-memory job status is lost and {@code jobId} 
cannot be recovered from
+ * the archive file name. {@link #listCompletedArchivePaths()} returns 
existing {@code tarPath}

Review Comment:
   Why not just add the jobId to the name?  It is actually useful for debugging.
   - container-ids-{scope}-{timestamp}_job{jobId}.tar.gz



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