dombizita commented on code in PR #10678:
URL: https://github.com/apache/ozone/pull/10678#discussion_r3639048051
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/upgrade/FinalizeSubCommand.java:
##########
@@ -51,11 +65,70 @@ public Integer call() throws Exception {
}
client.finalizeUpgrade();
out().println("Cluster finalization has been started. Monitor progress
with `ozone admin upgrade status`");
+
+ if (wait) {
+ return waitForFinalization(client);
+ }
}
return 0;
}
+ /**
+ * Polls the cluster status until OM, SCM and all healthy datanodes report
finalized, the operator
+ * interrupts the command, or an RPC fails. {@code --wait} is safe to
re-run: if the cluster is already
+ * finalized, the first poll returns done and the command exits 0.
+ */
+ private int waitForFinalization(OzoneManagerProtocol client) {
+ while (true) {
+ QueryUpgradeStatusResponse status;
+ try {
+ status = client.queryUpgradeStatus();
+ } catch (Exception e) {
+ err().println("Failed to query upgrade status: " + e.getMessage()
+ + ". Use `ozone admin upgrade status` to monitor progress.");
+ return 1;
+ }
+
+ // Check if cluster is already finalized
+ if (isClusterFinalized(status)) {
+ out().println("Finalization complete.");
+ return 0;
+ }
+
+ if (isVerbose()) {
+ StatusSubCommand.printVerbose(status, out());
+ } else {
+ HddsProtos.UpgradeStatus hdds = status.getHddsStatus();
+ out().printf("Waiting for finalization: OM=%s, SCM=%s,
datanodes=%d/%d%n",
+ status.getOmFinalized(), hdds.getScmFinalized(),
+ hdds.getNumDatanodesFinalized(), hdds.getNumDatanodesTotal());
+ }
+ out().flush();
+
+ // Finalization checks before sleeping, so an already-finalized cluster
returns without waiting a poll interval.
+ try {
+ Thread.sleep(pollIntervalMillis);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ out().println("Waiting interrupted. Use `ozone admin upgrade status`
to monitor progress.");
+ return 0;
+ }
+ }
+ }
+
+ static boolean isClusterFinalized(QueryUpgradeStatusResponse status) {
+ HddsProtos.UpgradeStatus hdds = status.getHddsStatus();
+ return status.getOmFinalized()
+ && hdds.getScmFinalized()
+ && hdds.getNumDatanodesFinalized() == hdds.getNumDatanodesTotal();
+ }
Review Comment:
I added `clusterFinalized` to the proto, it makes sense to go with this way
--
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]