Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The parameter column_families in the LDBTool::Run function did not take effect. #11581

Closed
dongdongwcpp opened this issue Jun 30, 2023 · 4 comments
Assignees
Labels
bug Confirmed RocksDB bugs

Comments

@dongdongwcpp
Copy link

The parameter column_families in the LDBTool::Run function did not take effect while using a custom Comparator or other custom scenarios:

void LDBTool::Run(int argc, char** argv, Options options,
                  const LDBOptions& ldb_options,
                  const std::vector<ColumnFamilyDescriptor>* column_families) 
LDBTool tool;
tool.Run(argc, argv, rocksdb::Options(), LDBOptions(), &column_families);

which seems to be a problem. This issue still exists in the latest version of RocksDB.

Expected behavior

when using a custom Comparator to open rocksdb,The function LDBTool::run should set std::vector column_families to ldb tool, and should work fine to admin the database.

Actual behavior

root$ ../build/tools/ldb   --db=./testdb drop_column_family new_cf
Failed: Invalid argument: leveldb.BytewiseComparator: does not match existing comparator my_comparator

Steps to reproduce the behavior

#include <rocksdb/db.h>
#include <rocksdb/options.h>
#include "rocksdb/ldb_tool.h"

using namespace rocksdb;
class MyComparator : public rocksdb::Comparator {
 public:
  int Compare(const rocksdb::Slice& a, const rocksdb::Slice& b) const override {
    return a.compare(b);
  }
  virtual void FindShortSuccessor(std::string* key) const {}
  virtual void FindShortestSeparator(std::string* start, const Slice& limit) const {}
  const char* Name() const override { return "my_comparator"; }
};

int main(int argc, char** argv) {
  rocksdb::DB* db;
  rocksdb::Options options;
  options.create_if_missing = true;
  options.create_missing_column_families = true;
  rocksdb::ColumnFamilyOptions cf_options;

  cf_options.comparator = new MyComparator;
  // create column family with custom comparator
  std::vector<rocksdb::ColumnFamilyDescriptor> column_families = {
      rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName,cf_options),
      rocksdb::ColumnFamilyDescriptor("new_cf", cf_options),
  };

  if (argc > 2) {
    LDBTool tool;
    tool.Run(argc, argv, rocksdb::Options(), LDBOptions(), &column_families);
    return 0;
  }

  std::vector<ColumnFamilyHandle*> handles;
  rocksdb::DB::Open(options, "./testdb", column_families, &handles, &db);
  db->Put(rocksdb::WriteOptions(), "key1", "value1");
  delete db;
  return 0;
}

compile and run:

g++ --std=c++11 my_comparator.cc -o ldb_test  -I ../include ../build_release/librocksdb.a -lpthread 
#run to create db with two cf
./ldb_test
#run to drop new_cf and got failed
./ldb_test --db=./testdb drop_column_family new_cf
Failed: Invalid argument: leveldb.BytewiseComparator: does not match existing comparator my_comparator

how to fix

set column_families for command here:

command->SetLDBOptions(ldb_options);

I may try to fix it if it's a real issue.

@ajkr ajkr added bug Confirmed RocksDB bugs up-for-grabs Up for grabs labels Aug 10, 2023
@ajkr
Copy link
Contributor

ajkr commented Aug 10, 2023

I may try to fix it if it's a real issue.

Looks like a real issue to me

@cz2h
Copy link
Contributor

cz2h commented Nov 26, 2023

Hi @dongdongwcpp, @ajkr , may I take this issue if you are not currently working on it?

@ajkr
Copy link
Contributor

ajkr commented Nov 27, 2023

I think it has been long enough since the last update to assume nobody is working on it. Just make sure to confirm the provided instructions still repro the bug, as there's a chance somebody fixed it without closing the issue.

@ajkr
Copy link
Contributor

ajkr commented Jan 24, 2024

Fixed by #12261

@ajkr ajkr closed this as completed Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed RocksDB bugs
Projects
None yet
Development

No branches or pull requests

3 participants