errose28 commented on code in PR #4995: URL: https://github.com/apache/ozone/pull/4995#discussion_r1257742145
########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/utils/ContainerLogger.java: ########## @@ -0,0 +1,162 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common.utils; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.ozone.container.common.impl.ContainerData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.hadoop.ozone.container.common.interfaces.Container.ScanResult; + +/** + * Utility class defining methods to write to the datanode container log. + * + * The container log contains brief messages about container replica level + * events like state changes or replication/reconstruction. Messages in this + * log are minimal, so it can be used to track the history of every container + * on a datanode for a long period of time without rolling off. + * + * All messages should be logged after their corresponding event succeeds, to + * prevent misleading state changes or logs filling with retries on errors. + * Errors and retries belong in the main datanode application log. + */ +public final class ContainerLogger { + + @VisibleForTesting + public static final String LOG_NAME = "ContainerLog"; + private static final Logger LOG = LoggerFactory.getLogger(LOG_NAME); + private static final String FIELD_SEPARATOR = " | "; + + private ContainerLogger() { } + + /** + * Logged when an open container is first created. + * + * @param containerData The container that was created and opened. + */ + public static void logOpen(ContainerData containerData) { + LOG.info(getMessage(containerData)); + } + + /** + * Logged when a container is moved to the closing state. + * + * @param containerData The container that was marked as closing. + */ + public static void logClosing(ContainerData containerData) { + LOG.info(getMessage(containerData)); + } + + /** + * Logged when a Ratis container is moved to the quasi-closed state. + * + * @param containerData The container that was quasi-closed. + * @param message The reason the container was quasi-closed, if known. + */ + public static void logQuasiClosed(ContainerData containerData, + String message) { + LOG.warn(getMessage(containerData, message)); + } + + /** + * Logged when a container is moved to the closed state. + * + * @param containerData The container that was closed. + */ + public static void logClosed(ContainerData containerData) { + LOG.info(getMessage(containerData)); + } + + /** + * Logged when a container is moved to the unhealthy state. + * + * @param containerData The container that was marked unhealthy. + * @param reason The reason the container was marked unhealthy. + */ + public static void logUnhealthy(ContainerData containerData, + ScanResult reason) { + String message = reason.getFailureType() + " for file " + Review Comment: I think the exception message is redundant. Here are the container log messages and exception messages for every container scan failure taken from `TestBackgroundContainerDataScannerIntegration` for reference. In most cases it contains the same info as the container log. In some cases it contains less. In some cases it has more information like the specific checksums computed, but those are not useful IMO. - Missing chunks directory - **Container Log**: 2023-07-09 22:16:28,923 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=1 | Index=0 | BCSID=4 | State=UNHEALTHY | MISSING_CHUNKS_DIR for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/1/chunks. - **Exception Message**: Chunks directory /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/1/chunks not found. - Missing metadata directory - **Container Log**: 2023-07-09 22:36:22,165 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-2ac050f5-ec11-42ec-ae1f-1755cf95dc40/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=1 | Index=0 | BCSID=4 | State=UNHEALTHY | MISSING_METADATA_DIR for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-2ac050f5-ec11-42ec-ae1f-1755cf95dc40/datanode-0/data-0/containers/hdds/2ac050f5-ec11-42ec-ae1f-1755cf95dc40/current/containerDir0/1/metadata. - **Exception Message**: Metadata directory /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-2ac050f5-ec11-42ec-ae1f-1755cf95dc40/datanode-0/data-0/containers/hdds/2ac050f5-ec11-42ec-ae1f-1755cf95dc40/current/containerDir0/1/metadata not found. - Missing container file - **Container Log**: 2023-07-09 22:16:48,947 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=3 | Index=0 | BCSID=4 | State=UNHEALTHY | MISSING_CONTAINER_FILE for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/3/metadata/3.container. - **Exception Message**: /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/3/metadata/3.container (No such file or directory) - Missing container directory - **Container Log**: 2023-07-09 22:16:53,967 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=4 | Index=0 | BCSID=11 | State=UNHEALTHY | MISSING_CONTAINER_DIR for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/4. - **Exception Message**: Container directory /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/4 not found. - Missing block - **Container Log**: 2023-07-09 22:16:58,984 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=5 | Index=0 | BCSID=18 | State=UNHEALTHY | MISSING_CHUNK_FILE for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/5/chunks/111677748019200005.block. - **Exception Message**: Missing chunk file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/5/chunks/111677748019200005.block - Corrupt container file - **Container Log**: 2023-07-09 22:17:03,007 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=6 | Index=0 | BCSID=25 | State=UNHEALTHY | CORRUPT_CONTAINER_FILE for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/6/metadata/6.container. - **Exception Message**: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1 - Truncated container file - **Container Log**: 2023-07-09 22:17:07,017 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=7 | Index=0 | BCSID=32 | State=UNHEALTHY | CORRUPT_CONTAINER_FILE for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/7/metadata/7.container. - **Exception Message**: Failed to load container file. File is empty. - Corrupt block - **Container Log**: 2023-07-09 22:17:12,042 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=8 | Index=0 | BCSID=39 | State=UNHEALTHY | CORRUPT_CHUNK for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/8/chunks/111677748019200008.block. - **Exception Message**: Inconsistent read for chunk=ChunkInfo{chunkName='111677748019200008_chunk_1, offset=0, len=1048576} checksum item 0 expected checksum [-15, 3, 2, -89] actual checksum [13, 36, -20, -78] for block conID: 8 locID: 111677748019200008 bcsId: 39 - Truncated block - **Container Log**: 2023-07-09 22:17:16,045 [ContainerDataScanner(/Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds)] ERROR ContainerLog (ContainerLogger.java:logUnhealthy(96)) - ID=9 | Index=0 | BCSID=46 | State=UNHEALTHY | INCONSISTENT_CHUNK_LENGTH for file /Users/erose/Repos/apache/ozone/hadoop-ozone/integration-test/target/test-dir/MiniOzoneClusterImpl-d4385882-e6c0-4101-b1fd-8db2eecc2539/datanode-0/data-0/containers/hdds/d4385882-e6c0-4101-b1fd-8db2eecc2539/current/containerDir0/9/chunks/111677748019200009.block. - **Exception Message**: Inconsistent read for chunk=111677748019200009_chunk_1 expected length=1048576 actual length=0 for block conID: 9 locID: 111677748019200009 bcsId: 46 -- 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]
