Skip to content
Snippets Groups Projects
Commit b37e6c1b authored by Ashwin's avatar Ashwin
Browse files

Take care of duplicate value for the same key

parent b554cffb
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <unordered_map>
#include "rocksdb/db.h" #include "rocksdb/db.h"
#include "rocksdb/options.h" #include "rocksdb/options.h"
...@@ -22,8 +23,10 @@ namespace fs = std::experimental::filesystem; ...@@ -22,8 +23,10 @@ namespace fs = std::experimental::filesystem;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if(argc != 3) { if(argc != 3) {
std::cerr << "Wrong number of arguments\nusage : ./<executable> <folder_having_rocksDB_directories_to_be_merged> <destination_folder>\n"; std::cerr << "Wrong number of arguments\nusage : ./<executable> <folder_having_rocksDB_directories_to_be_merged> <destination_folder>\n";
return 1; exit(0);
} }
std::unordered_map<std::string, std::string> xid_uid_mp;
std::string destinationDB = argv[2]; std::string destinationDB = argv[2];
DB* db; DB* db;
Options options; Options options;
...@@ -52,9 +55,14 @@ int main(int argc, char* argv[]) { ...@@ -52,9 +55,14 @@ int main(int argc, char* argv[]) {
rocksdb::Iterator* it = cur_db->NewIterator(rocksdb::ReadOptions()); rocksdb::Iterator* it = cur_db->NewIterator(rocksdb::ReadOptions());
for (it->SeekToFirst(); it->Valid(); it->Next()) { for (it->SeekToFirst(); it->Valid(); it->Next()) {
std::cout << it->key().ToString() << ": " << it->value().ToString() << std::endl; if(xid_uid_mp.count(it->key().ToString()) != 0 && xid_uid_mp[it->key().ToString()] != it->value().ToString()) {
s = db->Put(WriteOptions(), it->key().ToString(), it->value().ToString()); std::cerr << "FATAL : Different value for same key : " << it->key().ToString() << std::endl;
assert(s.ok()); exit(0);
} else {
xid_uid_mp[it->key().ToString()] = it->value().ToString();
s = db->Put(WriteOptions(), it->key().ToString(), it->value().ToString());
assert(s.ok());
}
} }
assert(it->status().ok()); // Check for any errors found during the scan assert(it->status().ok()); // Check for any errors found during the scan
delete it; delete it;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment