adoroszlai commented on code in PR #7465: URL: https://github.com/apache/ozone/pull/7465#discussion_r1867291548
########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/KeyPathRetriever.java: ########## @@ -0,0 +1,301 @@ +/* + * 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.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.stream.Stream; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hadoop.hdds.cli.SubcommandWithParent; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition; +import org.apache.hadoop.hdds.utils.db.DBStore; +import org.apache.hadoop.hdds.utils.db.DBStoreBuilder; +import org.apache.hadoop.hdds.utils.db.LongCodec; +import org.apache.hadoop.hdds.utils.db.StringCodec; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.hdds.utils.db.Table.KeyValue; +import org.apache.hadoop.hdds.utils.db.TableIterator; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.kohsuke.MetaInfServices; +import picocli.CommandLine; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX; + +/** + * Tool that retrieve key full path from OM db file table with pattern match. + */ [email protected]( + name = "retrieve-key-fullpath", + description = "retrieve full key path with matching criteria") +@MetaInfServices(SubcommandWithParent.class) +public class KeyPathRetriever implements Callable<Void>, SubcommandWithParent { + private static final String DIRTREEDBNAME = "omdirtree.db"; + private static final DBColumnFamilyDefinition<Long, String> DIRTREE_COLUMN_FAMILY + = new DBColumnFamilyDefinition<>("dirTreeTable", LongCodec.get(), StringCodec.get()); + + @CommandLine.Spec + private static CommandLine.Model.CommandSpec spec; + + @CommandLine.Option(names = {"--db"}, + required = true, + description = "Database File") + private String dbFile; + + @CommandLine.Option(names = {"--containers"}, + required = false, + description = "Comma separated Container Ids") + private String strContainerIds; + + @CommandLine.Option(names = {"--container-file"}, + required = false, + description = "file with container id in new line") + private String containerFileName; + + @CommandLine.Option(names = {"--out", "-o"}, + required = false, + description = "out file name") + private String fileName; Review Comment: How about always writing to stdout and using `>` for redirection to file? We don't need to reimplement write to file for all commands. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/KeyPathRetriever.java: ########## @@ -0,0 +1,301 @@ +/* + * 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.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.stream.Stream; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hadoop.hdds.cli.SubcommandWithParent; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition; +import org.apache.hadoop.hdds.utils.db.DBStore; +import org.apache.hadoop.hdds.utils.db.DBStoreBuilder; +import org.apache.hadoop.hdds.utils.db.LongCodec; +import org.apache.hadoop.hdds.utils.db.StringCodec; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.hdds.utils.db.Table.KeyValue; +import org.apache.hadoop.hdds.utils.db.TableIterator; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.kohsuke.MetaInfServices; +import picocli.CommandLine; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX; + +/** + * Tool that retrieve key full path from OM db file table with pattern match. + */ [email protected]( + name = "retrieve-key-fullpath", + description = "retrieve full key path with matching criteria") +@MetaInfServices(SubcommandWithParent.class) +public class KeyPathRetriever implements Callable<Void>, SubcommandWithParent { + private static final String DIRTREEDBNAME = "omdirtree.db"; + private static final DBColumnFamilyDefinition<Long, String> DIRTREE_COLUMN_FAMILY + = new DBColumnFamilyDefinition<>("dirTreeTable", LongCodec.get(), StringCodec.get()); + + @CommandLine.Spec + private static CommandLine.Model.CommandSpec spec; + + @CommandLine.Option(names = {"--db"}, + required = true, + description = "Database File") + private String dbFile; + + @CommandLine.Option(names = {"--containers"}, + required = false, + description = "Comma separated Container Ids") + private String strContainerIds; + + @CommandLine.Option(names = {"--container-file"}, + required = false, + description = "file with container id in new line") + private String containerFileName; Review Comment: Two separate options, the command requires one of them (otherwise `No containers to be filtered`), but help does not indicate that. Also no mention of what happens if both are provided (error, or one of them takes precedence?). I suggest simplifying this: - Drop both options and accept one or more container ID as parameter, not option. - Read container IDs from stdin if argument is `-`. Use `container info` command as example for implementation: https://github.com/apache/ozone/blob/9b619373b666b9fc4054ad73a5abba05e5ed7e3e/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/container/InfoSubcommand.java#L72-L77 Extract logic if necessary, avoid copying. (I see @errose28 made [similar suggestion](https://github.com/apache/ozone/pull/7465#issuecomment-2491648586), but keeping both options and merging container IDs from all 3 sources.) ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/KeyPathRetriever.java: ########## @@ -0,0 +1,301 @@ +/* + * 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.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.stream.Stream; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hadoop.hdds.cli.SubcommandWithParent; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition; +import org.apache.hadoop.hdds.utils.db.DBStore; +import org.apache.hadoop.hdds.utils.db.DBStoreBuilder; +import org.apache.hadoop.hdds.utils.db.LongCodec; +import org.apache.hadoop.hdds.utils.db.StringCodec; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.hdds.utils.db.Table.KeyValue; +import org.apache.hadoop.hdds.utils.db.TableIterator; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.kohsuke.MetaInfServices; +import picocli.CommandLine; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX; + +/** + * Tool that retrieve key full path from OM db file table with pattern match. + */ [email protected]( + name = "retrieve-key-fullpath", + description = "retrieve full key path with matching criteria") +@MetaInfServices(SubcommandWithParent.class) +public class KeyPathRetriever implements Callable<Void>, SubcommandWithParent { + private static final String DIRTREEDBNAME = "omdirtree.db"; + private static final DBColumnFamilyDefinition<Long, String> DIRTREE_COLUMN_FAMILY + = new DBColumnFamilyDefinition<>("dirTreeTable", LongCodec.get(), StringCodec.get()); + + @CommandLine.Spec + private static CommandLine.Model.CommandSpec spec; + + @CommandLine.Option(names = {"--db"}, + required = true, + description = "Database File") + private String dbFile; + + @CommandLine.Option(names = {"--containers"}, + required = false, + description = "Comma separated Container Ids") + private String strContainerIds; + + @CommandLine.Option(names = {"--container-file"}, + required = false, + description = "file with container id in new line") + private String containerFileName; + + @CommandLine.Option(names = {"--out", "-o"}, + required = false, + description = "out file name") + private String fileName; + + private DBStore dirTreeDbStore = null; + private Table<Long, String> dirTreeTable = null; + + @Override + public Class<?> getParentType() { + return OzoneDebug.class; + } + + public void setDirTreeTable(Table<Long, String> table) { + this.dirTreeTable = table; + } + + @Override + public Void call() throws Exception { + // get containerIds filter + Set<Long> containerIds = new HashSet<>(); + if (!StringUtils.isEmpty(strContainerIds)) { + if (!StringUtils.isEmpty(strContainerIds)) { Review Comment: double-check for extra safety? :) -- 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]
