peterxcli commented on code in PR #8311: URL: https://github.com/apache/ozone/pull/8311#discussion_r2053947825
########## hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/SafeModeEnterSubcommand.java: ########## @@ -0,0 +1,42 @@ +/* + * 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.cli; + +import java.io.IOException; +import org.apache.hadoop.hdds.cli.HddsVersionProvider; +import org.apache.hadoop.hdds.scm.client.ScmClient; +import picocli.CommandLine.Command; + +/** + * This is the handler that process safe mode enter command. + */ +@Command( Review Comment: Should add a test in `hadoop-ozone/dist/src/main/smoketest/admincli/safemode.robot`? ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/SCMSafeModeManager.java: ########## @@ -233,11 +234,32 @@ public void exitSafeMode(EventPublisher eventQueue, boolean force) { // set it to true. setPreCheckComplete(true); setInSafeMode(false); + + // Manual flag will reset only if we exit from commandline. + if (force) { + inManualSafeMode.set(false); + } setForceExitSafeMode(force); // TODO: Remove handler registration as there is no need to listen to // register events anymore. + if (inManualSafeMode.get()) { + LOG.info("SCM remains in safe mode as it was manually triggered."); + } + + emitSafeModeStatus(); + } + + /** + * Enter safe mode. It does following actions: + * <ol> + * <li>Set safe mode status to true. + * <li>Emit safe mode status. + * </ol> + */ + public void enterManualSafeMode(EventPublisher eventQueue) { + inManualSafeMode.set(true); emitSafeModeStatus(); Review Comment: Do you want to tell all the other managers on SCM to stop running? Then I think you should also modify the `emitSafeModeStatus` to be: ```java public void emitSafeModeStatus() { SafeModeStatus safeModeStatus = new SafeModeStatus(getInSafeMode(), getPreCheckComplete()); safeModeStatus.setForceExitSafeMode(isForceExitSafeMode()); // update SCMContext scmContext.updateSafeModeStatus(safeModeStatus); // notify SCMServiceManager // If safemode is on/off, then notify the delayed listeners with a delay. serviceManager.notifyStatusChanged(); if (safeModeStatus.isPreCheckComplete()) { // Only notify the delayed listeners if safemode remains on, as precheck // may have completed. serviceManager.notifyEventTriggered(Event.PRE_CHECK_COMPLETED); } } ``` This would notify those service managers to re-think whether to keep running base on their logic whenever enter/exit safemode (originally the safemode only have the transition from `in` to `out`. ########## hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestScmSafeMode.java: ########## @@ -373,4 +373,38 @@ public void testCreateRetryWhileSCMSafeMode() throws Exception { assertFalse(cluster.getStorageContainerManager().isInSafeMode()); } + + /** + * Verify that an administrator can put SCM into Safe Mode manually + * and that restricted operations are blocked until a subsequent + * {@code forceExitSafeMode()} call succeeds. + */ + @Test + void testManualEnterSafeModeAndForceExit() throws Exception { + // ‑‑ restart cluster fully healthy so SCM starts OUT of safe mode + cluster.stop(); + cluster = builder.build(); + cluster.startHddsDatanodes(); + cluster.waitForClusterToBeReady(); + cluster.waitTobeOutOfSafeMode(); Review Comment: This check can have a separate test case, and I believe there may already be existing tests that cover it. `cluster.waitForClusterToBeReady()` is enough. https://github.com/apache/ozone/blob/b91e8e732f07e220b1be6b64fb74a8d3f67dbf3c/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java#L198 -- 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: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org