From f942446291f5bd0c3fd868156663caf9c05dea49 Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Wed, 8 Jan 2025 12:39:18 +0530 Subject: [PATCH 1/8] HDDS-11775. Allow Ozone debug tools that need to read RocksDB to automatically create a checkpoint --- .../hadoop/ozone/debug/ldb/DBScanner.java | 21 +++++++++++++++++-- .../hadoop/ozone/debug/ldb/RDBParser.java | 8 +++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java index 6fbbd1a3083..abd167373e6 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java @@ -36,6 +36,7 @@ import org.apache.hadoop.hdds.utils.db.FixedLengthStringCodec; import org.apache.hadoop.hdds.utils.db.LongCodec; import org.apache.hadoop.hdds.utils.db.RocksDatabase; +import org.apache.hadoop.hdds.utils.db.managed.ManagedCheckpoint; import org.apache.hadoop.hdds.utils.db.managed.ManagedReadOptions; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator; @@ -46,6 +47,7 @@ import org.apache.hadoop.ozone.debug.DBDefinitionFactory; import org.apache.hadoop.ozone.debug.RocksDBUtils; import org.apache.hadoop.ozone.utils.Filter; +import org.jooq.meta.derby.sys.Sys; import org.rocksdb.ColumnFamilyDescriptor; import org.rocksdb.ColumnFamilyHandle; import org.rocksdb.RocksDBException; @@ -65,6 +67,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -199,9 +202,23 @@ public Void call() throws Exception { parent.getDbPath().contains(OzoneConsts.CONTAINER_DB_NAME); boolean success; + String dbPath = parent.getDbPath(); + + if (parent.getCheckpoint()) { + String checkpointDir = parent.getDbPath() + "/checkpoint-ldb-" + (new Random()).nextInt(100); + try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( + parent.getDbPath(), cfDescList, cfHandleList)) { + ManagedCheckpoint cp = ManagedCheckpoint.create(db); + cp.get().createCheckpoint(checkpointDir); + out().println("tej Created checkpoint at " + checkpointDir); + dbPath = checkpointDir; + } + } + try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( - parent.getDbPath(), cfDescList, cfHandleList)) { - success = printTable(cfHandleList, db, parent.getDbPath(), schemaV3); + dbPath, cfDescList, cfHandleList)) { + out().println("tej opened checkpoint"); + success = printTable(cfHandleList, db, dbPath, schemaV3); } if (!success) { diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java index f07e8f35fba..ec75a72591a 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java @@ -43,10 +43,18 @@ public class RDBParser implements DebugSubcommand { description = "Database File Path") private String dbPath; + @CommandLine.Option(names = {"--checkpoint"}, + description = "Create a checkpoint on the DB passed to use for the operations.") + private boolean checkpoint; + public String getDbPath() { return dbPath; } + public boolean getCheckpoint() { + return checkpoint; + } + public void setDbPath(String dbPath) { this.dbPath = dbPath; } From 820cca088bbc0a94ab880452c99b93b02b588d65 Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Wed, 8 Jan 2025 13:14:12 +0530 Subject: [PATCH 2/8] remove unused import --- .../main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java | 1 - 1 file changed, 1 deletion(-) diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java index abd167373e6..26d25101a27 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java @@ -47,7 +47,6 @@ import org.apache.hadoop.ozone.debug.DBDefinitionFactory; import org.apache.hadoop.ozone.debug.RocksDBUtils; import org.apache.hadoop.ozone.utils.Filter; -import org.jooq.meta.derby.sys.Sys; import org.rocksdb.ColumnFamilyDescriptor; import org.rocksdb.ColumnFamilyHandle; import org.rocksdb.RocksDBException; From 951553b05c6ef06cafbd1861eba7a123a1cd9ed0 Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Wed, 8 Jan 2025 13:51:16 +0530 Subject: [PATCH 3/8] HDDS-11775. Allow Ozone debug tools that need to read RocksDB to automatically create a checkpoint --- .../hadoop/ozone/debug/ldb/DBScanner.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java index 26d25101a27..0ba918eda97 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java @@ -201,23 +201,28 @@ public Void call() throws Exception { parent.getDbPath().contains(OzoneConsts.CONTAINER_DB_NAME); boolean success; - String dbPath = parent.getDbPath(); - if (parent.getCheckpoint()) { String checkpointDir = parent.getDbPath() + "/checkpoint-ldb-" + (new Random()).nextInt(100); + // Create checkpoint try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( parent.getDbPath(), cfDescList, cfHandleList)) { ManagedCheckpoint cp = ManagedCheckpoint.create(db); cp.get().createCheckpoint(checkpointDir); out().println("tej Created checkpoint at " + checkpointDir); - dbPath = checkpointDir; } - } - - try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( - dbPath, cfDescList, cfHandleList)) { - out().println("tej opened checkpoint"); - success = printTable(cfHandleList, db, dbPath, schemaV3); + //Use the checkpoint for ldb operations + List cfDescListForCheckpoint = + RocksDBUtils.getColumnFamilyDescriptors(checkpointDir); + final List cfHandleListForCheckpoint = new ArrayList<>(); + try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( + checkpointDir, cfDescListForCheckpoint, cfHandleListForCheckpoint)) { + success = printTable(cfHandleListForCheckpoint, db, parent.getDbPath(), schemaV3); + } + } else { + try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( + parent.getDbPath(), cfDescList, cfHandleList)) { + success = printTable(cfHandleList, db, parent.getDbPath(), schemaV3); + } } if (!success) { From 397ae90ddec5af48886439106b653ed5aab30520 Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Wed, 8 Jan 2025 13:56:14 +0530 Subject: [PATCH 4/8] Change checkpoint message from out() to err() --- .../main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java index 0ba918eda97..b3f6a90addf 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java @@ -208,7 +208,7 @@ public Void call() throws Exception { parent.getDbPath(), cfDescList, cfHandleList)) { ManagedCheckpoint cp = ManagedCheckpoint.create(db); cp.get().createCheckpoint(checkpointDir); - out().println("tej Created checkpoint at " + checkpointDir); + err().println("Created checkpoint at " + checkpointDir); } //Use the checkpoint for ldb operations List cfDescListForCheckpoint = From 3024fa22b26b8e16c7c97054093da5753f5c122c Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Fri, 10 Jan 2025 14:00:53 +0530 Subject: [PATCH 5/8] Introduce checkpoint command for ldb --- .../hadoop/ozone/debug/ldb/Checkpoint.java | 71 +++++++++++++++++++ .../hadoop/ozone/debug/ldb/DBScanner.java | 27 +------ .../hadoop/ozone/debug/ldb/RDBParser.java | 9 +-- 3 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java new file mode 100644 index 00000000000..10874ee7763 --- /dev/null +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java @@ -0,0 +1,71 @@ +/* + * 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.ldb; + +import org.apache.hadoop.hdds.utils.db.managed.ManagedCheckpoint; +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 picocli.CommandLine; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +/** + * Create a checkpoint for a rocksDB. + */ +@CommandLine.Command( + name = "checkpoint", + description = "Create checkpoint for specified db" +) +public class Checkpoint implements Callable { + @CommandLine.Option(names = {"--output"}, + required = true, + description = "Path to output directory for the checkpoint.") + private String outputPath; + + @CommandLine.ParentCommand + private RDBParser parent; + + @CommandLine.Spec + private static CommandLine.Model.CommandSpec spec; + + @Override + public Void call() throws Exception { + List cfDescList = + RocksDBUtils.getColumnFamilyDescriptors(parent.getDbPath()); + final List cfHandleList = new ArrayList<>(); + + // Create checkpoint + try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( + parent.getDbPath(), cfDescList, cfHandleList)) { + ManagedCheckpoint cp = ManagedCheckpoint.create(db); + cp.get().createCheckpoint(outputPath); + out().println("Created checkpoint at " + outputPath); + } + return null; + } + + private static PrintWriter out() { + return spec.commandLine().getOut(); + } + +} diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java index b3f6a90addf..6fbbd1a3083 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/DBScanner.java @@ -36,7 +36,6 @@ import org.apache.hadoop.hdds.utils.db.FixedLengthStringCodec; import org.apache.hadoop.hdds.utils.db.LongCodec; import org.apache.hadoop.hdds.utils.db.RocksDatabase; -import org.apache.hadoop.hdds.utils.db.managed.ManagedCheckpoint; import org.apache.hadoop.hdds.utils.db.managed.ManagedReadOptions; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator; @@ -66,7 +65,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -201,28 +199,9 @@ public Void call() throws Exception { parent.getDbPath().contains(OzoneConsts.CONTAINER_DB_NAME); boolean success; - if (parent.getCheckpoint()) { - String checkpointDir = parent.getDbPath() + "/checkpoint-ldb-" + (new Random()).nextInt(100); - // Create checkpoint - try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( - parent.getDbPath(), cfDescList, cfHandleList)) { - ManagedCheckpoint cp = ManagedCheckpoint.create(db); - cp.get().createCheckpoint(checkpointDir); - err().println("Created checkpoint at " + checkpointDir); - } - //Use the checkpoint for ldb operations - List cfDescListForCheckpoint = - RocksDBUtils.getColumnFamilyDescriptors(checkpointDir); - final List cfHandleListForCheckpoint = new ArrayList<>(); - try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( - checkpointDir, cfDescListForCheckpoint, cfHandleListForCheckpoint)) { - success = printTable(cfHandleListForCheckpoint, db, parent.getDbPath(), schemaV3); - } - } else { - try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( - parent.getDbPath(), cfDescList, cfHandleList)) { - success = printTable(cfHandleList, db, parent.getDbPath(), schemaV3); - } + try (ManagedRocksDB db = ManagedRocksDB.openReadOnly( + parent.getDbPath(), cfDescList, cfHandleList)) { + success = printTable(cfHandleList, db, parent.getDbPath(), schemaV3); } if (!success) { diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java index ec75a72591a..ba58b05ac54 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/RDBParser.java @@ -33,6 +33,7 @@ DropTable.class, ListTables.class, ValueSchema.class, + Checkpoint.class, }, description = "Parse rocksdb file content") @MetaInfServices(DebugSubcommand.class) @@ -43,18 +44,10 @@ public class RDBParser implements DebugSubcommand { description = "Database File Path") private String dbPath; - @CommandLine.Option(names = {"--checkpoint"}, - description = "Create a checkpoint on the DB passed to use for the operations.") - private boolean checkpoint; - public String getDbPath() { return dbPath; } - public boolean getCheckpoint() { - return checkpoint; - } - public void setDbPath(String dbPath) { this.dbPath = dbPath; } From ae96feeb66dd85d9af4cd1f4ed508e9284657028 Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Wed, 15 Jan 2025 12:15:33 +0530 Subject: [PATCH 6/8] Add robot test --- .../dist/src/main/smoketest/debug/ozone-debug-ldb.robot | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot b/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot index 4380a3cf94d..d5effac7f0b 100644 --- a/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot +++ b/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot @@ -144,3 +144,9 @@ Test ozone debug ldb scan with filter option failure # test filter option for lesser/greater operator on non-numeric field ${output} = Execute And Ignore Error ozone debug ldb --db=/data/metadata/om.db scan --cf=keyTable --filter="keyName:lesser:k1" Should contain ${output} only on numeric values + +Test ozone debug ldb checkpoint command + ${output} = Execute ozone debug ldb --db=/data/metadata/om.db checkpoint --output=/data/metadata/checkpoint1.db + Should contain ${output} Created checkpoint at + ${output} = Execute ls /data/metadata/checkpoint1.db + Should contain ${output} .sst From 56bd8af53dea0f5fa25a0596e847063e174a5659 Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Wed, 15 Jan 2025 22:53:49 +0530 Subject: [PATCH 7/8] Reuse abstractSubcommand code --- .../apache/hadoop/ozone/debug/ldb/Checkpoint.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java index 10874ee7763..76e3db4aa45 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.ozone.debug.ldb; +import org.apache.hadoop.hdds.cli.AbstractSubcommand; import org.apache.hadoop.hdds.utils.db.managed.ManagedCheckpoint; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB; import org.apache.hadoop.ozone.debug.RocksDBUtils; @@ -24,7 +25,6 @@ import org.rocksdb.ColumnFamilyHandle; import picocli.CommandLine; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -36,7 +36,7 @@ name = "checkpoint", description = "Create checkpoint for specified db" ) -public class Checkpoint implements Callable { +public class Checkpoint extends AbstractSubcommand implements Callable { @CommandLine.Option(names = {"--output"}, required = true, description = "Path to output directory for the checkpoint.") @@ -45,9 +45,6 @@ public class Checkpoint implements Callable { @CommandLine.ParentCommand private RDBParser parent; - @CommandLine.Spec - private static CommandLine.Model.CommandSpec spec; - @Override public Void call() throws Exception { List cfDescList = @@ -59,13 +56,8 @@ public Void call() throws Exception { parent.getDbPath(), cfDescList, cfHandleList)) { ManagedCheckpoint cp = ManagedCheckpoint.create(db); cp.get().createCheckpoint(outputPath); - out().println("Created checkpoint at " + outputPath); + spec().commandLine().getOut().println("Created checkpoint at " + outputPath); } return null; } - - private static PrintWriter out() { - return spec.commandLine().getOut(); - } - } From f7e5b092e69d7eaf225d8c896e016caf43ae1a96 Mon Sep 17 00:00:00 2001 From: tejaskriya Date: Wed, 15 Jan 2025 23:05:07 +0530 Subject: [PATCH 8/8] reduce code duplication --- .../main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java index 76e3db4aa45..d12cf479336 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ldb/Checkpoint.java @@ -56,7 +56,7 @@ public Void call() throws Exception { parent.getDbPath(), cfDescList, cfHandleList)) { ManagedCheckpoint cp = ManagedCheckpoint.create(db); cp.get().createCheckpoint(outputPath); - spec().commandLine().getOut().println("Created checkpoint at " + outputPath); + out().println("Created checkpoint at " + outputPath); } return null; }