From 3782accf7de5830fef1fc88d69bbe2d9259b023f Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 23 Jul 2019 13:56:52 -0700 Subject: [PATCH] ldb sometimes specify a string-append merge operator (#5607) Summary: Right now, ldb cannot scan a DB with merge operands with default ldb. There is no hard to give a general merge operator so that it can at least print out something Pull Request resolved: https://github.com/facebook/rocksdb/pull/5607 Test Plan: Run ldb against a DB with merge operands and see the outputs. Differential Revision: D16442634 fbshipit-source-id: c66c414ec07f219cfc6e6ec2cc14c783ee95df54 --- HISTORY.md | 1 + tools/ldb_cmd.cc | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 19f4ce129..04f194e92 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -18,6 +18,7 @@ * Rate limited deletion of WALs is only enabled if DBOptions::wal_dir is not set, or explicitly set to db_name passed to DB::Open and DBOptions::db_paths is empty, or same as db_paths[0].path * Overload GetAllKeyVersions() to support non-default column family. * Added new APIs ExportColumnFamily() and CreateColumnFamilyWithImport() to support export and import of a Column Family. https://github.com/facebook/rocksdb/issues/3469 +* ldb sometimes uses a string-append merge operator if no merge operator is passed in. This is to allow users to print keys from a DB with a merge operator. ### New Features * Add an option `snap_refresh_nanos` (default to 0) to periodically refresh the snapshot list in compaction jobs. Assign to 0 to disable the feature. diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index 22b2399a2..338f09fb9 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -31,6 +31,7 @@ #include "util/coding.h" #include "util/stderr_logger.h" #include "util/string_util.h" +#include "utilities/merge_operators.h" #include "utilities/ttl/db_ttl_impl.h" #include @@ -353,11 +354,24 @@ void LDBCommand::OpenDB() { stderr, "wal_dir loaded from the option file doesn't exist. Ignore it.\n"); } + + // If merge operator is not set, set a string append operator. There is + // no harm doing it. + for (auto& cf_entry : column_families_) { + if (!cf_entry.options.merge_operator) { + cf_entry.options.merge_operator = + MergeOperators::CreateStringAppendOperator(':'); + } + } } options_ = PrepareOptionsForOpenDB(); if (!exec_state_.IsNotStarted()) { return; } + if (column_families_.empty() && !options_.merge_operator) { + // No harm to add a general merge operator if it is not specified. + options_.merge_operator = MergeOperators::CreateStringAppendOperator(':'); + } // Open the DB. Status st; std::vector handles_opened;