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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/export/ExportJob.java:
##########
@@ -69,6 +87,190 @@ public int hashCode() {
     }
   }
 
-  private ExportJob() {
+  /**
+   * Snapshot of export progress returned to callers. Reads live fields from 
the enclosing job.
+   */
+  public final class Status {
+    private Status() {
+    }
+
+    public Id getId() {
+      return id;
+    }
+
+    public ExecutionState getExecutionState() {
+      return ExportJob.this.getExecutionState();
+    }
+
+    public long getTotalRows() {
+      return ExportJob.this.getTotalRows();
+    }
+
+    public long getElapsedMs() {
+      return ExportJob.this.getElapsedMs();
+    }
+
+    public String getTarPath() {
+      return ExportJob.this.getTarPath();
+    }
+
+    public String getErrorMessage() {
+      return ExportJob.this.getErrorMessage();
+    }
+  }
+
+  /**
+   * Job execution state.
+   */
+  public enum ExecutionState {
+    RUNNING(false),
+    SUCCEEDED(true),
+    FAILED(true);
+
+    private final boolean terminal;
+
+    ExecutionState(boolean terminal) {
+      this.terminal = terminal;
+    }
+
+    public boolean isTerminal() {
+      return terminal;
+    }
+  }
+
+  ExportJob(Id id, ExportScope scope, String timestamp, String tarPath, 
ContainerID startContainerId,
+      ExportSizing sizing) {
+    this.id = id;
+    this.scope = scope;
+    this.timestamp = timestamp;
+    this.tarPath = tarPath;
+    this.startContainerId = startContainerId != null ? startContainerId : 
ContainerID.valueOf(0);
+    this.sizing = sizing;
+  }
+
+  Id getId() {
+    return id;
+  }
+
+  String getTimestamp() {
+    return timestamp;
+  }
+
+  ContainerID getStartContainerId() {
+    return startContainerId;
+  }
+
+  LifeCycleState getLifeCycleState() {
+    return scope.getLifeCycleState();
+  }
+
+  ContainerHealthState getHealthState() {
+    return scope.getHealthState();
+  }
+
+  long getMaxRows() {
+    return sizing.getMaxRows();
+  }
+
+  int getPageSize() {
+    return sizing.getPageSize();
+  }
+
+  int getShardSize() {
+    return sizing.getShardSize();
+  }
+
+  synchronized String getTarPath() {
+    return tarPath;
+  }
+
+  synchronized ExecutionState getExecutionState() {
+    return executionState;
+  }
+
+  synchronized long getEndTimeNs() {
+    return endTimeNs;
+  }
+
+  synchronized long getTotalRows() {
+    return totalRows;
+  }
+
+  synchronized long getElapsedMs() {
+    if (startTimeNs <= 0) {
+      return 0;
+    }
+    long endNs = endTimeNs > 0 ? endTimeNs : System.nanoTime();
+    return TimeUnit.NANOSECONDS.toMillis(endNs - startTimeNs);
+  }
+
+  synchronized String getErrorMessage() {
+    return errorMessage;
+  }
+
+  synchronized void startExecution() {
+    if (executionState.isTerminal()) {
+      throw new IllegalStateException("Export job " + id + " is already 
terminal: " + executionState);
+    }
+    startTimeNs = System.nanoTime();
+  }
+
+  synchronized void updateTotalRows(long rows) {
+    totalRows = rows;
+  }
+
+  synchronized void completeWithNoMatches() {
+    tarPath = null;
+    transitionToTerminal(ExecutionState.SUCCEEDED);
+  }
+
+  synchronized void completeWithArchive(String archivePath) {
+    tarPath = archivePath;
+    transitionToTerminal(ExecutionState.SUCCEEDED);
+  }
+
+  synchronized void fail(String message) {
+    errorMessage = message;
+    transitionToTerminal(ExecutionState.FAILED);
+  }
+
+  private synchronized void transitionToTerminal(ExecutionState terminalState) 
{
+    if (executionState.isTerminal()) {
+      throw new IllegalStateException("Export job " + id + " is already 
terminal: " + executionState);
+    }
+    executionState = terminalState;
+    endTimeNs = System.nanoTime();
+  }
+
+  Status toStatus() {
+    return new Status();
+  }
+
+  String shardFileName(int partIndex) {
+    return String.format("container-ids_%s_%s_part%03d.txt",
+        scope.getValue(), timestamp, partIndex);

Review Comment:
   - timestamp has METADATA_TIMESTAMP_FORMAT which has ":".  We should never 
use ":" in a file name.
   - timestamp is a bad name.  Something like jobStartTime is better.



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