Copilot commented on code in PR #10214:
URL: https://github.com/apache/ozone/pull/10214#discussion_r3218569900
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerScanHelper.java:
##########
@@ -115,7 +115,14 @@ public void scanMetadata(Container<?> container)
logScanCompleted(containerData, now);
}
+ /**
+ * Marks container UNHEALTHY when the scan reports real errors.
+ * If every scan error is related to file-descriptor exhaustion, return
without marking container unhealthy.
+ */
public void handleUnhealthyScanResult(ContainerData containerData,
ScanResult result) throws IOException {
+ if (ScanTransientIOUtil.scanErrorsAreOnlyTooManyOpenFiles(result)) {
+ return;
+ }
long containerID = containerData.getContainerID();
Review Comment:
This early-return suppresses any visibility into repeated scan failures
caused by FD exhaustion (no log, no metric, no backoff signal). Consider
logging at least once per container/iteration (eg. warn/debug) that the scan is
being treated as transient due to 'Too many open files', so operators can
diagnose FD pressure without incorrectly marking containers as corrupt.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ScanTransientIOUtil.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.ozone.container.ozoneimpl;
+
+import java.util.Locale;
+import org.apache.hadoop.ozone.container.common.interfaces.ScanResult;
+
+/**
+ * Utility to catch transient scan failures (typically related to
file-descriptor exhaustion)
+ * that should not be treated as container data corruption.
+ */
+public final class ScanTransientIOUtil {
+
+ private static final String TOO_MANY_OPEN_FILES = "too many open files";
+
+ private ScanTransientIOUtil() {
+ }
+
+ /**
+ * Returns true when every scan error is related to file-descriptor
exhaustion.
+ * Each error's exception chain is checked via {@link
#isTooManyOpenFiles(Throwable)}.
+ */
+ public static boolean scanErrorsAreOnlyTooManyOpenFiles(ScanResult
scanResult) {
+ if (!scanResult.hasErrors()) {
+ return false;
+ }
+ return scanResult.getErrors().stream()
+ .allMatch(scanError -> isTooManyOpenFiles(scanError.getException()));
+ }
+
+ public static boolean isTooManyOpenFiles(Throwable throwable) {
+ for (Throwable cause = throwable; cause != null; cause = cause.getCause())
{
+ String message = cause.getMessage();
+ if (message != null && containsTooManyOpenFiles(message)) {
+ return true;
+ }
+ }
+ return false;
+ }
Review Comment:
Iterating the cause chain without cycle protection can lead to an infinite
loop if a cyclic cause chain is ever encountered (possible with manually
constructed exceptions). To make this robust, track visited Throwables (eg.
identity set) or enforce a reasonable maximum depth and break if exceeded.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ScanTransientIOUtil.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.ozone.container.ozoneimpl;
+
+import java.util.Locale;
+import org.apache.hadoop.ozone.container.common.interfaces.ScanResult;
+
+/**
+ * Utility to catch transient scan failures (typically related to
file-descriptor exhaustion)
+ * that should not be treated as container data corruption.
+ */
+public final class ScanTransientIOUtil {
+
+ private static final String TOO_MANY_OPEN_FILES = "too many open files";
+
+ private ScanTransientIOUtil() {
+ }
+
+ /**
+ * Returns true when every scan error is related to file-descriptor
exhaustion.
+ * Each error's exception chain is checked via {@link
#isTooManyOpenFiles(Throwable)}.
+ */
+ public static boolean scanErrorsAreOnlyTooManyOpenFiles(ScanResult
scanResult) {
+ if (!scanResult.hasErrors()) {
+ return false;
+ }
+ return scanResult.getErrors().stream()
+ .allMatch(scanError -> isTooManyOpenFiles(scanError.getException()));
+ }
+
+ public static boolean isTooManyOpenFiles(Throwable throwable) {
+ for (Throwable cause = throwable; cause != null; cause = cause.getCause())
{
+ String message = cause.getMessage();
+ if (message != null && containsTooManyOpenFiles(message)) {
+ return true;
Review Comment:
Relying exclusively on Throwable.getMessage() string matching is brittle and
can increase false positives (path + message formatting) and false negatives
(localized messages). For FileSystemException, consider preferring getReason()
(and/or checking known exception types) before falling back to message-based
matching; this keeps detection more stable across platforms and message formats.
--
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]