Skip to content

Commit

Permalink
Merge branch 'apache:master' into HDDS-9124
Browse files Browse the repository at this point in the history
  • Loading branch information
devabhishekpal authored Aug 7, 2023
2 parents 253fe28 + d6af04f commit 1166c7f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@
import org.apache.hadoop.ozone.TestDataUtil;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.client.OzoneSnapshot;
import org.apache.hadoop.ozone.debug.DBScanner;
import org.apache.hadoop.ozone.debug.OzoneDebug;
import org.apache.hadoop.ozone.debug.RDBParser;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.OMStorage;
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.Duration;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand All @@ -52,6 +61,9 @@
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_PIPELINE_REPORT_INTERVAL;
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_COMMAND_STATUS_REPORT_INTERVAL;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL;
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_CHECKPOINT_DIR;
import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;

/**
* Test Ozone Debug shell.
Expand Down Expand Up @@ -118,6 +130,44 @@ public void testChunkInfoCmdBeforeAfterCloseContainer() throws Exception {
Assertions.assertEquals(0, exitCode);
}

@Test
public void testLdbCliForOzoneSnapshot() throws Exception {
StringWriter stdout = new StringWriter();
PrintWriter pstdout = new PrintWriter(stdout);
CommandLine cmd = new CommandLine(new RDBParser())
.addSubcommand(new DBScanner())
.setOut(pstdout);
final String volumeName = UUID.randomUUID().toString();
final String bucketName = UUID.randomUUID().toString();
final String keyName = UUID.randomUUID().toString();

writeKey(volumeName, bucketName, keyName);

String snapshotName =
client.getObjectStore().createSnapshot(volumeName, bucketName, "snap1");
OzoneSnapshot snapshot =
client.getObjectStore().listSnapshot(volumeName, bucketName, null, null)
.next();
Assertions.assertEquals(snapshotName, snapshot.getName());
String dbPath = getSnapshotDBPath(snapshot.getCheckpointDir());
String snapshotCurrent = dbPath + OM_KEY_PREFIX + "CURRENT";
GenericTestUtils
.waitFor(() -> new File(snapshotCurrent).exists(), 1000, 120000);
String[] args =
new String[] {"--db=" + dbPath, "scan", "--cf", "keyTable"};
int exitCode = cmd.execute(args);
Assertions.assertEquals(0, exitCode);
String cmdOut = stdout.toString();
Assertions.assertTrue(cmdOut.contains(keyName));
}

private static String getSnapshotDBPath(String checkPointDir) {
return OMStorage.getOmDbDir(conf) +
OM_KEY_PREFIX + OM_SNAPSHOT_CHECKPOINT_DIR + OM_KEY_PREFIX +
OM_DB_NAME + checkPointDir;
}


private static void writeKey(String volumeName, String bucketName,
String keyName) throws IOException {
try (OzoneClient client = OzoneClientFactory.getRpcClient(conf)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import com.amazonaws.services.kms.model.InvalidArnException;
import com.google.common.base.Preconditions;

import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
import static org.apache.hadoop.ozone.recon.ReconConstants.RECON_CONTAINER_KEY_DB;
import static org.apache.hadoop.ozone.recon.ReconConstants.RECON_OM_SNAPSHOT_DB;

Expand All @@ -60,6 +62,10 @@ private DBDefinitionFactory() {
}

public static DBDefinition getDefinition(String dbName) {
// OM snapshot DB name starts with this prefix.
if (!dbName.equals(OM_DB_NAME) && dbName.startsWith(OM_DB_NAME)) {
dbName = OM_DB_NAME;
}
if (dbMap.containsKey(dbName)) {
return dbMap.get(dbName);
}
Expand Down

0 comments on commit 1166c7f

Please sign in to comment.