Search code examples
c++bulkinsertrocksdb

Insert 1 hundred millions of records on RocksDB


I'm trying to insert 1 hundred millions of records on RocksDB but i get SIGSEGV:Segmentation fault, after 287481 insert on this line:

0   ??  /lib/x86_64-linux-gnu/libc.so.6     0x7ffff6086341  
1   rocksdb::Slice::Slice   slice.h 43  0x40efd5    
2   main    main.cpp    75  0x40e857    

here is the code:

int main(int argc, char *argv[]) {
   rocksdb::DB *db;
   rocksdb::Options options;
   options.create_if_missing=true;
   rocksdb::Status status = rocksdb::DB::Open(options,"/tmp/testdb1",&db);
   assert(status.ok());
   for (long var = 0; var < 100000000L; ++var) {
       db->Put(rocksdb::WriteOptions(),""+var,"v"+var);
       qDebug()<<var;
   }
}

Thank you for ur help.


Solution

  • You should not be adding "k" (const char*) and var (long). Please construct the string like this:

    std::string key("k" + std::to_string(var));

    And same thing for the value.