You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/02/04 16:27:37 UTC

[GitHub] [ozone] rakeshadr commented on a change in pull request #1891: HDDS-4790. Add a tool to parse entries in the prefix format

rakeshadr commented on a change in pull request #1891:
URL: https://github.com/apache/ozone/pull/1891#discussion_r570351420



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/PrefixParser.java
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.debug;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import java.nio.file.Path;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.Table.KeyValue;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
+import org.apache.hadoop.ozone.om.helpers.WithParentObjectId;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils;
+import org.kohsuke.MetaInfServices;
+import picocli.CommandLine;
+import picocli.CommandLine.Model.CommandSpec;
+import picocli.CommandLine.Spec;
+
+/**
+ * Tool that parses OM db file for prefix table.
+ */
+@CommandLine.Command(
+    name = "prefix",
+    description = "Parse prefix contents")
+@MetaInfServices(SubcommandWithParent.class)
+public class PrefixParser implements Callable<Void>, SubcommandWithParent {
+
+  @Spec
+  private CommandSpec spec;
+
+  @CommandLine.Option(names = {"--db"},
+      required = true,
+      description = "Database File Path")
+  private String dbPath;
+
+  @CommandLine.Option(names = {"--path"},
+      required = true,
+      description = "prefixFile Path")
+  private String filePath;
+
+  @CommandLine.Option(names = {"--bucket"},
+      required = true,
+      description = "bucket in /vol/bucket format")
+  private String bucket;
+
+  @CommandLine.Option(names = {"--volume"},
+      required = true,
+      description = "volume in /vol/bucket format")
+  private String volume;
+
+  public enum Type {
+    BUCKET,
+    INTERMEDIATE_DIR,
+    TERMINAL_FILE,
+    TERMINAL_DIR
+  }
+
+  private long[] numOps;
+
+  public PrefixParser() {
+    this.numOps = new long[Type.values().length];
+  }
+
+  public String getDbPath() {
+    return dbPath;
+  }
+
+  public void setDbPath(String dbPath) {
+    this.dbPath = dbPath;
+  }
+
+  public void setVolume(String volume) {
+    this.volume = volume;
+  }
+
+  public void setBucket(String bucket) {
+    this.bucket = bucket;
+  }
+
+  public void setFilePath(String filePath) {
+    this.filePath = filePath;
+  }
+
+  @Override
+  public Class<?> getParentType() {
+    return OzoneDebug.class;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    parse();
+    return null;
+  }
+
+  public static void main(String[] args) throws Exception {
+    new PrefixParser().call();
+  }
+
+  public void parse() throws Exception {
+    System.out.println("FilePath is:" + filePath);
+    System.out.println("Db Path is:" + dbPath);
+
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, dbPath);
+    OzoneManagerRatisUtils.setBucketFSOptimized(true);
+
+    OmMetadataManagerImpl metadataManager = new OmMetadataManagerImpl(conf);
+    metadataManager.start(conf);
+
+    org.apache.hadoop.fs.Path effectivePath =
+        new org.apache.hadoop.fs.Path("/");
+
+    Path p = Paths.get(filePath);
+
+    // First get the info about the bucket
+    String bucketKey = metadataManager.getBucketKey(volume, bucket);
+    OmBucketInfo info = metadataManager.getBucketTable().get(bucketKey);
+    long lastObjectId = info.getObjectID();
+    WithParentObjectId objectBucketId = new WithParentObjectId();
+    objectBucketId.setObjectID(lastObjectId);
+    dumpInfo(Type.BUCKET, effectivePath, objectBucketId, bucketKey);
+
+    Iterator<Path> pathIterator =  p.iterator();
+    while(pathIterator.hasNext()) {
+      Path elem = pathIterator.next();
+      String dbKey =
+          metadataManager.getOzonePathKey(lastObjectId, elem.toString());
+      OmDirectoryInfo directoryInfo =
+          metadataManager.getDirectoryTable().get(dbKey);
+      effectivePath = getEffectivePath(effectivePath, elem.toString());
+
+      dumpInfo(Type.INTERMEDIATE_DIR, effectivePath, directoryInfo, dbKey);

Review comment:
       Please add a test case if filePath=/a/b/c/file1. Can you get the path from FileTable if the given path is a **File Type**, here the directoryInfo will return null for the leaf node.

##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/PrefixParser.java
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.debug;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import java.nio.file.Path;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.Table.KeyValue;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
+import org.apache.hadoop.ozone.om.helpers.WithParentObjectId;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils;
+import org.kohsuke.MetaInfServices;
+import picocli.CommandLine;
+import picocli.CommandLine.Model.CommandSpec;
+import picocli.CommandLine.Spec;
+
+/**
+ * Tool that parses OM db file for prefix table.
+ */
+@CommandLine.Command(
+    name = "prefix",
+    description = "Parse prefix contents")
+@MetaInfServices(SubcommandWithParent.class)
+public class PrefixParser implements Callable<Void>, SubcommandWithParent {
+
+  @Spec
+  private CommandSpec spec;
+
+  @CommandLine.Option(names = {"--db"},
+      required = true,
+      description = "Database File Path")
+  private String dbPath;
+
+  @CommandLine.Option(names = {"--path"},
+      required = true,
+      description = "prefixFile Path")
+  private String filePath;
+
+  @CommandLine.Option(names = {"--bucket"},
+      required = true,
+      description = "bucket in /vol/bucket format")
+  private String bucket;
+
+  @CommandLine.Option(names = {"--volume"},
+      required = true,
+      description = "volume in /vol/bucket format")
+  private String volume;
+
+  public enum Type {
+    BUCKET,
+    INTERMEDIATE_DIR,
+    TERMINAL_FILE,
+    TERMINAL_DIR
+  }
+
+  private long[] numOps;
+
+  public PrefixParser() {
+    this.numOps = new long[Type.values().length];
+  }
+
+  public String getDbPath() {
+    return dbPath;
+  }
+
+  public void setDbPath(String dbPath) {
+    this.dbPath = dbPath;
+  }
+
+  public void setVolume(String volume) {
+    this.volume = volume;
+  }
+
+  public void setBucket(String bucket) {
+    this.bucket = bucket;
+  }
+
+  public void setFilePath(String filePath) {
+    this.filePath = filePath;
+  }
+
+  @Override
+  public Class<?> getParentType() {
+    return OzoneDebug.class;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    parse();
+    return null;
+  }
+
+  public static void main(String[] args) throws Exception {
+    new PrefixParser().call();
+  }
+
+  public void parse() throws Exception {
+    System.out.println("FilePath is:" + filePath);
+    System.out.println("Db Path is:" + dbPath);

Review comment:
       Can you add DB path validation like,
   
   ```
   if (!Files.exists(dbPath)) {
         LOG.error("DB path not exist:{}", dbPath);
         return;
   }
   ```

##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/PrefixParser.java
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.debug;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import java.nio.file.Path;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.Table.KeyValue;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
+import org.apache.hadoop.ozone.om.helpers.WithParentObjectId;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils;
+import org.kohsuke.MetaInfServices;
+import picocli.CommandLine;
+import picocli.CommandLine.Model.CommandSpec;
+import picocli.CommandLine.Spec;
+
+/**
+ * Tool that parses OM db file for prefix table.
+ */
+@CommandLine.Command(
+    name = "prefix",
+    description = "Parse prefix contents")
+@MetaInfServices(SubcommandWithParent.class)
+public class PrefixParser implements Callable<Void>, SubcommandWithParent {
+
+  @Spec
+  private CommandSpec spec;
+
+  @CommandLine.Option(names = {"--db"},
+      required = true,
+      description = "Database File Path")
+  private String dbPath;
+
+  @CommandLine.Option(names = {"--path"},
+      required = true,
+      description = "prefixFile Path")
+  private String filePath;
+
+  @CommandLine.Option(names = {"--bucket"},
+      required = true,
+      description = "bucket in /vol/bucket format")
+  private String bucket;
+
+  @CommandLine.Option(names = {"--volume"},
+      required = true,
+      description = "volume in /vol/bucket format")
+  private String volume;
+
+  public enum Type {
+    BUCKET,
+    INTERMEDIATE_DIR,
+    TERMINAL_FILE,
+    TERMINAL_DIR
+  }
+
+  private long[] numOps;
+
+  public PrefixParser() {
+    this.numOps = new long[Type.values().length];
+  }
+
+  public String getDbPath() {
+    return dbPath;
+  }
+
+  public void setDbPath(String dbPath) {
+    this.dbPath = dbPath;
+  }
+
+  public void setVolume(String volume) {
+    this.volume = volume;
+  }
+
+  public void setBucket(String bucket) {
+    this.bucket = bucket;
+  }
+
+  public void setFilePath(String filePath) {
+    this.filePath = filePath;
+  }
+
+  @Override
+  public Class<?> getParentType() {
+    return OzoneDebug.class;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    parse();
+    return null;
+  }
+
+  public static void main(String[] args) throws Exception {
+    new PrefixParser().call();
+  }
+
+  public void parse() throws Exception {
+    System.out.println("FilePath is:" + filePath);
+    System.out.println("Db Path is:" + dbPath);
+
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, dbPath);
+    OzoneManagerRatisUtils.setBucketFSOptimized(true);
+
+    OmMetadataManagerImpl metadataManager = new OmMetadataManagerImpl(conf);
+    metadataManager.start(conf);
+
+    org.apache.hadoop.fs.Path effectivePath =
+        new org.apache.hadoop.fs.Path("/");
+
+    Path p = Paths.get(filePath);
+
+    // First get the info about the bucket
+    String bucketKey = metadataManager.getBucketKey(volume, bucket);
+    OmBucketInfo info = metadataManager.getBucketTable().get(bucketKey);
+    long lastObjectId = info.getObjectID();
+    WithParentObjectId objectBucketId = new WithParentObjectId();
+    objectBucketId.setObjectID(lastObjectId);
+    dumpInfo(Type.BUCKET, effectivePath, objectBucketId, bucketKey);
+
+    Iterator<Path> pathIterator =  p.iterator();
+    while(pathIterator.hasNext()) {
+      Path elem = pathIterator.next();
+      String dbKey =
+          metadataManager.getOzonePathKey(lastObjectId, elem.toString());
+      OmDirectoryInfo directoryInfo =

Review comment:
       Can you add null check for a non-existent path instead of throwing NPE?

##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemPrefixParser.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.fs.ozone;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.TestDataUtil;
+import org.apache.hadoop.ozone.debug.PrefixParser;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMStorage;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * Test Ozone Prefix Parser.
+ */
+public class TestOzoneFileSystemPrefixParser {
+
+  private MiniOzoneCluster cluster = null;
+
+  private FileSystem fs;
+
+  private String volumeName;
+
+  private String bucketName;
+
+  private OzoneConfiguration configuration;
+
+  @Before
+  public void init() throws Exception {
+    volumeName = RandomStringUtils.randomAlphabetic(10).toLowerCase();
+    bucketName = RandomStringUtils.randomAlphabetic(10).toLowerCase();
+
+    configuration = new OzoneConfiguration();
+    configuration.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,

Review comment:
       Please remove `configuration.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS`, which is already sets in 
   
   `TestOMRequestUtils.configureFSOptimizedPaths(configuration, true...
   `




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org