errose28 commented on code in PR #10678:
URL: https://github.com/apache/ozone/pull/10678#discussion_r3641225809
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/upgrade/FinalizeSubCommand.java:
##########
@@ -50,12 +63,63 @@ public Integer call() throws Exception {
return 1;
}
client.finalizeUpgrade();
+ if (wait) {
+ out().println("Cluster finalization has been started. Waiting for the
cluster to finalize; "
+ + "interrupt with Ctrl-C to stop waiting (finalization continues
on the server).");
+ return waitForFinalization(client);
+ }
out().println("Cluster finalization has been started. Monitor progress
with `ozone admin upgrade status`");
}
return 0;
}
+ /**
+ * Polls the cluster status until OM, SCM and all healthy datanodes report
finalized, or the operator
+ * interrupts the command. A failed status query is reported to stderr and
retried on the next poll,
+ * so transient RPC errors do not abort the wait. {@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 = null;
+ try {
+ status = client.queryUpgradeStatus();
+ } catch (Exception e) {
+ err().println("Failed to query upgrade status: " + e.getMessage()
+ + ". Retrying, or use `ozone admin upgrade status` to monitor
progress.");
+ }
+
+ if (status != null) {
+ // Finalization checks before sleeping, so an already-finalized
cluster returns without waiting.
+ if (status.getClusterFinalized()) {
+ out().println("Finalization complete.");
+ return 0;
+ }
+
+ if (isVerbose()) {
+ StatusSubCommand.printVerbose(status, out());
+ } else {
+ StatusSubCommand.printBasic(status, out());
+ }
+ out().flush();
+ }
+
+ try {
+ Thread.sleep(pollIntervalMillis);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ out().println("Waiting interrupted. Use `ozone admin upgrade status`
to monitor progress.");
+ return 0;
Review Comment:
This should return 1. We should only return 0 with `--wait` if finalization
was known to be successful.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -3664,11 +3665,27 @@ public void finalizeUpgrade() throws IOException {
@Override
public QueryUpgradeStatusResponse queryUpgradeStatus() throws IOException {
- HddsProtos.UpgradeStatus scmStatus =
scmClient.getContainerClient().queryUpgradeStatus();
+ HddsProtos.UpgradeStatus scmStatus;
+ try {
+ scmStatus = scmClient.getContainerClient().queryUpgradeStatus();
+ } catch (SCMException e) {
+ // SCM refuses the query while in safe mode
+ if (e.getResult() == SCMException.ResultCodes.SAFE_MODE_EXCEPTION) {
+ throw new OMException(e.getMessage(), e, NOT_SUPPORTED_OPERATION);
+ }
Review Comment:
We need a similar check in the OM background service, otherwise we will get
a full stack trace on every bg run when SCM is in safemode. Just one line
indicating SCM is in safemode is enough.
--
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]