github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/cmd/rocksdb/trace_rocksdb.cpp (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  
    21  #include "common/configuration.h"
    22  #include "common/version.h"
    23  #include "fs/ir_manager/api/ir_api.h"
    24  #include "fs/ir_manager/ir_manager.h"
    25  #include "fs/proto/block.pb.h"
    26  #include "fs/proto/ir.pb.h"
    27  #include "fs/rocksdb_storage.h"
    28  #include "fs/util.h"
    29  #include <boost/program_options.hpp>
    30  
    31  namespace po = boost::program_options;
    32  
    33  void display_ir_versions(neb::fs::rocksdb_storage &rs) {
    34    auto ir_list_ptr = neb::fs::ir_api::get_ir_list(&rs);
    35    for (auto &name : *ir_list_ptr) {
    36      auto ir_versions_ptr = neb::fs::ir_api::get_ir_versions(name, &rs);
    37      std::cout << name;
    38      for (auto &version : *ir_versions_ptr) {
    39        std::cout << ' ' << version;
    40      }
    41      std::cout << std::endl;
    42    }
    43  }
    44  
    45  int main(int argc, char *argv[]) {
    46  
    47    po::options_description desc("Rocksdb read and write");
    48    desc.add_options()("help", "show help message")(
    49        "db_path", po::value<std::string>(), "Database file directory");
    50  
    51    po::variables_map vm;
    52    po::store(po::parse_command_line(argc, argv, desc), vm);
    53    po::notify(vm);
    54  
    55    if (vm.count("help")) {
    56      std::cout << desc << "\n";
    57      return 1;
    58    }
    59  
    60    if (!vm.count("db_path")) {
    61      std::cout << "You must specify \"db_path\"!" << std::endl;
    62      return 1;
    63    }
    64  
    65    std::string db_path = vm["db_path"].as<std::string>();
    66    neb::fs::rocksdb_storage rs;
    67    rs.open_database(db_path, neb::fs::storage_open_for_readonly);
    68  
    69    auto f_keys = [](rocksdb::Iterator *it) {
    70      for (it->SeekToFirst(); it->Valid(); it->Next()) {
    71        LOG(INFO) << it->key().ToString();
    72      }
    73    };
    74    rs.display(f_keys);
    75  
    76    display_ir_versions(rs);
    77  
    78    rs.close_database();
    79    return 0;
    80  }