swamirishi commented on code in PR #7957: URL: https://github.com/apache/ozone/pull/7957#discussion_r1972639464
########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/RocksDBManualCompaction.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.repair; + +import jakarta.annotation.Nonnull; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.hadoop.hdds.cli.HddsVersionProvider; +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; +import org.apache.hadoop.ozone.debug.RocksDBUtils; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Tool to perform compaction on a table. + */ [email protected]( + name = "compact", + description = "CLI to compact a table in the DB.", + mixinStandardHelpOptions = true, + versionProvider = HddsVersionProvider.class +) +public class RocksDBManualCompaction extends RepairTool { + + @CommandLine.Option(names = {"--db"}, + required = true, + description = "Database File Path") + private String dbPath; + + @CommandLine.Option(names = {"--column_family", "--column-family", "--cf"}, + required = true, + description = "Table name") + private String columnFamilyName; + + @Override + public void execute() throws Exception { + List<ColumnFamilyHandle> cfHandleList = new ArrayList<>(); + List<ColumnFamilyDescriptor> cfDescList = RocksDBUtils.getColumnFamilyDescriptors( + dbPath); + + try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, cfHandleList)) { + ColumnFamilyHandle cfh = RocksDBUtils.getColumnFamilyHandle(columnFamilyName, cfHandleList); + if (cfh == null) { + throw new IllegalArgumentException(columnFamilyName + + " is not in a column family in DB for the given path."); + } + + info("Running compaction on " + (columnFamilyName == null ? "entire DB" : columnFamilyName)); + + if (!isDryRun()) { + db.get().compactRange(cfh); Review Comment: Let us also support initializing Compaction with CompactRangeOptions that is a much needed thing. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/RocksDBManualCompaction.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.repair; + +import jakarta.annotation.Nonnull; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.hadoop.hdds.cli.HddsVersionProvider; +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; +import org.apache.hadoop.ozone.debug.RocksDBUtils; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Tool to perform compaction on a table. + */ [email protected]( + name = "compact", + description = "CLI to compact a table in the DB.", + mixinStandardHelpOptions = true, + versionProvider = HddsVersionProvider.class +) +public class RocksDBManualCompaction extends RepairTool { + + @CommandLine.Option(names = {"--db"}, + required = true, + description = "Database File Path") + private String dbPath; + + @CommandLine.Option(names = {"--column_family", "--column-family", "--cf"}, + required = true, + description = "Table name") + private String columnFamilyName; + + @Override + public void execute() throws Exception { + List<ColumnFamilyHandle> cfHandleList = new ArrayList<>(); + List<ColumnFamilyDescriptor> cfDescList = RocksDBUtils.getColumnFamilyDescriptors( + dbPath); + + try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, cfHandleList)) { + ColumnFamilyHandle cfh = RocksDBUtils.getColumnFamilyHandle(columnFamilyName, cfHandleList); + if (cfh == null) { + throw new IllegalArgumentException(columnFamilyName + + " is not in a column family in DB for the given path."); + } + + info("Running compaction on " + (columnFamilyName == null ? "entire DB" : columnFamilyName)); Review Comment: Let us not have an option to compact the entire DB. We can do it on a column family level basis. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/RocksDBManualCompaction.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.repair; + +import jakarta.annotation.Nonnull; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.hadoop.hdds.cli.HddsVersionProvider; +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; +import org.apache.hadoop.ozone.debug.RocksDBUtils; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Tool to perform compaction on a table. + */ [email protected]( + name = "compact", + description = "CLI to compact a table in the DB.", + mixinStandardHelpOptions = true, + versionProvider = HddsVersionProvider.class +) +public class RocksDBManualCompaction extends RepairTool { + + @CommandLine.Option(names = {"--db"}, + required = true, + description = "Database File Path") + private String dbPath; + + @CommandLine.Option(names = {"--column_family", "--column-family", "--cf"}, + required = true, + description = "Table name") + private String columnFamilyName; + + @Override + public void execute() throws Exception { + List<ColumnFamilyHandle> cfHandleList = new ArrayList<>(); + List<ColumnFamilyDescriptor> cfDescList = RocksDBUtils.getColumnFamilyDescriptors( + dbPath); + + try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, cfHandleList)) { + ColumnFamilyHandle cfh = RocksDBUtils.getColumnFamilyHandle(columnFamilyName, cfHandleList); + if (cfh == null) { + throw new IllegalArgumentException(columnFamilyName + + " is not in a column family in DB for the given path."); + } + + info("Running compaction on " + (columnFamilyName == null ? "entire DB" : columnFamilyName)); + + if (!isDryRun()) { + db.get().compactRange(cfh); + info("Compaction completed."); + } + } catch (RocksDBException exception) { + error("Failed to compact the RocksDB for the given path: %s, column-family:%s", dbPath, columnFamilyName); + error("Exception: " + exception); + throw new IOException("Failed to compact RocksDB.", exception); + } finally { + IOUtils.closeQuietly(cfHandleList); + } + } + + @Override + @Nonnull + protected Component serviceToBeOffline() { Review Comment: I dont really like the idea of opening a rocksdb directly and performing operations on it. It would be great if all the repair commands open the DB via DBStoreBuilder class. Eventually we can work on initilializing the DBStoreBuilder based on some ini file or json file directly creating an object(setting parameters) based on an input file. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/RocksDBManualCompaction.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.repair; + +import jakarta.annotation.Nonnull; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.hadoop.hdds.cli.HddsVersionProvider; +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; +import org.apache.hadoop.ozone.debug.RocksDBUtils; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Tool to perform compaction on a table. + */ [email protected]( + name = "compact", + description = "CLI to compact a table in the DB.", + mixinStandardHelpOptions = true, + versionProvider = HddsVersionProvider.class +) +public class RocksDBManualCompaction extends RepairTool { + + @CommandLine.Option(names = {"--db"}, + required = true, + description = "Database File Path") + private String dbPath; + + @CommandLine.Option(names = {"--column_family", "--column-family", "--cf"}, + required = true, + description = "Table name") + private String columnFamilyName; + + @Override + public void execute() throws Exception { + List<ColumnFamilyHandle> cfHandleList = new ArrayList<>(); + List<ColumnFamilyDescriptor> cfDescList = RocksDBUtils.getColumnFamilyDescriptors( + dbPath); + + try (ManagedRocksDB db = ManagedRocksDB.open(dbPath, cfDescList, cfHandleList)) { + ColumnFamilyHandle cfh = RocksDBUtils.getColumnFamilyHandle(columnFamilyName, cfHandleList); + if (cfh == null) { + throw new IllegalArgumentException(columnFamilyName + + " is not in a column family in DB for the given path."); + } + + info("Running compaction on " + (columnFamilyName == null ? "entire DB" : columnFamilyName)); + + if (!isDryRun()) { + db.get().compactRange(cfh); + info("Compaction completed."); + } + } catch (RocksDBException exception) { + error("Failed to compact the RocksDB for the given path: %s, column-family:%s", dbPath, columnFamilyName); + error("Exception: " + exception); + throw new IOException("Failed to compact RocksDB.", exception); + } finally { + IOUtils.closeQuietly(cfHandleList); + } + } + + @Override + @Nonnull + protected Component serviceToBeOffline() { Review Comment: One question I have is why are we not directly providing a wrapper on top of the rocksdb ldb tool and doing it via java? Given that the cli command is also gonna do the same thing. What is the additional feature are we going to provide here. We are not even initializing the compaction listeners that is needed for Snapshot diff. If we want to go that route we should do this via the DBStoreBuilder class and have a proper ozone wrapper for rocksdb. -- 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]
