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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ExportFileManager.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.commons.io.FileUtils;
+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}
+ * 
+ * <pre>
+ * {exportDirectory}/
+ * ├── {jobId}.in-progress
+ * ├── container-ids-{scope}-{timestamp}-{jobId}.tar.gz
+ * └── export_{jobId}/
+ *     ├── container-ids-{scope}-{timestamp}-part001.txt
+ *     └── ...
+ * </pre>
+ *
+ * <p>{@code export_{jobId}/} holds shard text files while the job appends 
them into the archive.
+ *
+ * <p><b>When {@code export_{jobId}/} is deleted:</b> the export manager 
deletes it after the
+ * archive closes successfully, 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 partial archive for that job id.
+ *
+ * <p><b>When {@code .tar.gz} is deleted:</b> {@link #cleanupFailedArtifacts} 
deletes partial
+ * archives for failed or cancelled jobs. {@link #start()} deletes partial 
archives for jobs that
+ * still have an in-progress marker. Completed archives remain on disk until 
the export manager
+ * evicts the job from memory ({@code maxTerminalJobs} in {@code 
ContainerExportManager}) or an
+ * operator deletes them manually. After SCM restart, in-memory eviction state 
is lost, so
+ * completed archives persist until manual cleanup.
+ *
+ * <p><b>SCM restart while a job runs:</b> the in-progress marker and {@code 
export_{jobId}/}
+ * remain on disk, but in-memory job status is lost. {@link #start()} treats 
the job as incomplete,
+ * removes the marker, workspace, and any partial {@code .tar.gz} for that job 
id, and the

Review Comment:
   We should not allow a partial {@code .tar.gz}.
   
   1. When the job is running, it writes to export_{jobId}/
   2. When the job is completed, it creates gz for export_{jobId}/
   
   Step 2 should be:
   - create .tar.gz.tmp
   - atomic rename tar.gz.tmp to tar.gz.
   
   We may use AtomicFileOutputStream.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ExportFileManager.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.commons.io.FileUtils;
+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}
+ * 
+ * <pre>
+ * {exportDirectory}/
+ * ├── {jobId}.in-progress

Review Comment:
   It should not include {jobId}.  If different jobs write to a different file, 
we cannot make it atomic.   We should use FileLock.  For example, see 
https://github.com/apache/ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageDirectoryImpl.java#L191,L204



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ExportFileManager.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.commons.io.FileUtils;
+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}
+ * 
+ * <pre>
+ * {exportDirectory}/
+ * ├── {jobId}.in-progress
+ * ├── container-ids-{scope}-{timestamp}-{jobId}.tar.gz
+ * └── export_{jobId}/
+ *     ├── container-ids-{scope}-{timestamp}-part001.txt
+ *     └── ...
+ * </pre>
+ *
+ * <p>{@code export_{jobId}/} holds shard text files while the job appends 
them into the archive.
+ *
+ * <p><b>When {@code export_{jobId}/} is deleted:</b> the export manager 
deletes it after the
+ * archive closes successfully, 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 partial archive for that job id.
+ *
+ * <p><b>When {@code .tar.gz} is deleted:</b> {@link #cleanupFailedArtifacts} 
deletes partial
+ * archives for failed or cancelled jobs. {@link #start()} deletes partial 
archives for jobs that
+ * still have an in-progress marker. Completed archives remain on disk until 
the export manager
+ * evicts the job from memory ({@code maxTerminalJobs} in {@code 
ContainerExportManager}) or an
+ * operator deletes them manually. After SCM restart, in-memory eviction state 
is lost, so
+ * completed archives persist until manual cleanup.

Review Comment:
   When SCM restart, could it count the number of gz files and rebuild the 
in-memory eviction state?



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