Download mongodb and rocksdb
$ git clone https://github.com/mongodb/mongo.git
$ git clone https://github.com/facebook/rocksdb.git
Build Rocksdb
$ cd rocksdb
$ make static_lib
$ cp librocksdb.a /usr/local/lib
$ cp -r include/* /usr/local/include
Build mongodb
$ cd ..
$ cd mongo
For MAC
$ scons --rocksdb --rocksdb --libc++ --osx-version-min-10.7 mongo mongod
For Linux
$ scons --rocksdb --rocksdb
mongo mongod
Kickoff parallel build with -j <n>
Experiment with mongod/rocksdb in local build directory without installing
$ mkdir ./data
$ ./mongod --dbpath ./data --storageEngine=rocksExperiment
Ready to interact with mongodb with rocksdb storage engine
$ ./mongo
Sample Program to Interface with RocksDB
========================================
#include <iostream>
#include "rocksdb/db.h"
using namespace std;
int
main()
{
std::string value;
std::string key1, key2;
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db);
cout << status.ToString() + "\n";
key1 = string("foo");
value = string("data");
rocksdb::Status s = db->Get(rocksdb::ReadOptions(), key1, &value);
if (s.ok()) {
s = db->Put(rocksdb::WriteOptions(), key1, value);
cout << "Key Found " + key1 + " Value " + value + "\n";
} else {
cout << "Key Not Found Insert Key\n";
s = db->Put(rocksdb::WriteOptions(), key1, value);
if (s.ok()) {
s = db->Get(rocksdb::ReadOptions(), key1, &value);
if (s.ok()) {
cout << "Key Found " + key1 + " Value " + value + "\n";
}
}
}
//db->Delete(rocksdb::WriteOptions(), key1);
/* Close DB */
delete db;
}
Compile Sample Program
======================
g++ -std=c++0x rocks_db.cpp -lrocksdb -lpthread -lz
No comments:
Post a Comment