github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/ldb.cc (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  #include <rocksdb/ldb_tool.h>
    12  #include "db.h"
    13  #include "options.h"
    14  
    15  extern "C" {
    16  char* prettyPrintKey(DBKey);
    17  }  // extern "C"
    18  
    19  using namespace cockroach;
    20  
    21  namespace {
    22  
    23  class KeyFormatter : public rocksdb::SliceFormatter {
    24    std::string Format(const rocksdb::Slice& s) const {
    25      char* p = prettyPrintKey(ToDBKey(s));
    26      std::string ret(p);
    27      free(static_cast<void*>(p));
    28      return ret;
    29    }
    30  };
    31  
    32  }  // namespace
    33  
    34  void DBRunLDB(int argc, char** argv) {
    35    rocksdb::Options options = DBMakeOptions(DBOptions());
    36    rocksdb::LDBOptions ldb_options;
    37    ldb_options.key_formatter.reset(new KeyFormatter);
    38    rocksdb::LDBTool tool;
    39    tool.Run(argc, argv, options, ldb_options);
    40  }