steveloughran commented on a change in pull request #1208: HADOOP-16423. 
S3Guard fsck: Check metadata consistency between S3 and metadatastore (log)
URL: https://github.com/apache/hadoop/pull/1208#discussion_r321803937
 
 

 ##########
 File path: 
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardFsckViolationHandler.java
 ##########
 @@ -0,0 +1,315 @@
+/*
+ * 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.fs.s3a.s3guard;
+
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.s3a.S3AFileStatus;
+import org.apache.hadoop.fs.s3a.S3AFileSystem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Violation handler for the S3Guard's fsck.
+ */
+public class S3GuardFsckViolationHandler {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      S3GuardFsckViolationHandler.class);
+
+  // The rawFS and metadataStore are here to prepare when the ViolationHandlers
+  // will not just log, but fix the violations, so they will have access.
+  private S3AFileSystem rawFs;
+  private DynamoDBMetadataStore metadataStore;
+
+  private static String newLine = System.getProperty("line.separator");
+
+  public S3GuardFsckViolationHandler(S3AFileSystem fs,
+      DynamoDBMetadataStore ddbms) {
+
+    this.metadataStore = ddbms;
+    this.rawFs = fs;
+  }
+
+  public void handle(S3GuardFsck.ComparePair comparePair) {
+    if (!comparePair.containsViolation()) {
+      LOG.debug("There is no violation in the compare pair: " + toString());
+      return;
+    }
+
+    StringBuilder sB = new StringBuilder();
+    sB.append(newLine)
+        .append("On path: ").append(comparePair.getPath()).append(newLine);
+
+    // Create a new instance of the handler and use it.
+    for (S3GuardFsck.Violation violation : comparePair.getViolations()) {
+      try {
+        ViolationHandler handler = violation.getHandler()
+            .getDeclaredConstructor(S3GuardFsck.ComparePair.class)
+            .newInstance(comparePair);
+        final String errorStr = handler.getError();
+        sB.append(errorStr);
+      } catch (NoSuchMethodException e) {
+        LOG.error("Can not find declared constructor for handler: {}",
+            violation.getHandler());
+      } catch (IllegalAccessException | InstantiationException | 
InvocationTargetException e) {
+        LOG.error("Can not instantiate handler: {}",
+            violation.getHandler());
+      }
+      sB.append(newLine);
+    }
+    LOG.error(sB.toString());
 
 Review comment:
   I think we should change the log level based on the severity. This matters 
for those of us who have their log4j settings set to log different levels in 
different colours, and it will help people interpret the output

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to