Skip to content

Commit

Permalink
change leveldb to rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
songzhao committed Jul 13, 2015
1 parent d9b2dad commit c273ddf
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "third/leveldb"]
path = third/leveldb
url = https://github.com/google/leveldb.git
[submodule "third/glog"]
path = third/glog
url = https://github.com/google/glog.git
[submodule "third/nemo"]
path = third/nemo
url = [email protected]:baotiao/nemo.git
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CXX = g++
CXXFLAGS = -Wall -W -DDEBUG -g -O0 -D__XDEBUG__ -fPIC -Wno-unused-function
CXXFLAGS = -Wall -W -DDEBUG -g -O0 -D__XDEBUG__ -fPIC -Wno-unused-function -std=c++11
OBJECT = pika
SRC_DIR = ./src
THIRD_PATH = ./third
Expand All @@ -9,15 +9,21 @@ OUTPUT = ./output
INCLUDE_PATH = -I./include/ \
-I./src/ \
-I$(THIRD_PATH)/glog/src/ \
-I$(THIRD_PATH)/leveldb/include/
-I$(THIRD_PATH)/nemo/output/include/

LIB_PATH = -L./ \
-L$(THIRD_PATH)/leveldb/
-L$(THIRD_PATH)/nemo/output/lib/ \
-L$(THIRD_PATH)/nemo/3rdparty/rocksdb/


LIBS = -lpthread \
-lglog \
-lleveldb
-lnemo \
-lrocksdb \
-lz \
-lbz2 \
-lsnappy \
-lrt

GLOG = /usr/local/lib/libglog.a

Expand All @@ -42,7 +48,7 @@ all: $(OBJECT)


$(OBJECT): $(GLOG) $(OBJS)
make -C $(THIRD_PATH)/leveldb/
make -C $(THIRD_PATH)/nemo/
$(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(INCLUDE_PATH) $(LIB_PATH) -Wl,-Bdynamic $(LIBS)

$(GLOG):
Expand Down
12 changes: 7 additions & 5 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#include "csapp.h"
#include "xdebug.h"
#include "pika_define.h"
#include "leveldb/db.h"
#include "leveldb/write_batch.h"
#include "nemo.h"
//#include "leveldb/db.h"
//#include "leveldb/write_batch.h"

class PikaThread;
class PikaEpoll;
Expand All @@ -32,7 +33,7 @@ class PikaServer
void RunProcess();

static void* StartThread(void* arg);
leveldb::DB* GetHandle() {return db_;};
nemo::Nemo* GetHandle() {return db_;};

private:
friend class PikaConn;
Expand All @@ -54,9 +55,10 @@ class PikaServer
/*
* The leveldb handler
*/
leveldb::DB *db_;
nemo::Nemo *db_;
// leveldb::DB *db_;

leveldb::Options options_;
// leveldb::Options options_;

/*
* Here we used auto poll to find the next work thread,
Expand Down
3 changes: 1 addition & 2 deletions src/pika_cmdget.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "pika_command.h"
#include "pika_server.h"
#include "leveldb/db.h"
#include <algorithm>
#include <map>

Expand All @@ -18,7 +17,7 @@ void GetCmd::Do(std::list<std::string> &argv, std::string &ret) {
std::string key = argv.front();
argv.pop_front();
std::string value;
leveldb::Status s = g_pikaServer->GetHandle()->Get(leveldb::ReadOptions(), key, &value);
nemo::Status s = g_pikaServer->GetHandle()->Get(key, &value);
if (s.ok()) {
char buf[32];
snprintf(buf, sizeof(buf), "$%d\r\n", (int)value.size());
Expand Down
3 changes: 1 addition & 2 deletions src/pika_cmdset.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "pika_command.h"
#include "pika_server.h"
#include "leveldb/db.h"
#include <algorithm>
#include <map>

Expand Down Expand Up @@ -45,7 +44,7 @@ void SetCmd::Do(std::list<std::string> &argv, std::string &ret) {
return;
}
}
leveldb::Status s = g_pikaServer->GetHandle()->Put(leveldb::WriteOptions(), key, value);
nemo::Status s = g_pikaServer->GetHandle()->Set(key, value);
if (s.ok()) {
ret = "+OK\r\n";
} else {
Expand Down
1 change: 0 additions & 1 deletion src/pika_conn.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "pika_conn.h"
#include "pika_util.h"
#include "pika_command.h"
#include "leveldb/db.h"
#include "pika_define.h"
#include "zmalloc.h"
#include "util.h"
Expand Down
13 changes: 7 additions & 6 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ PikaServer::PikaServer()
pikaThread_[i] = new PikaThread();
}

options_.create_if_missing = true;
options_.write_buffer_size = 1500000000;
// options_.create_if_missing = true;
// options_.write_buffer_size = 1500000000;
// leveldb::Status s = leveldb::DB::Open(options_, "/tmp/testdb", &db_);
leveldb::Status s = leveldb::DB::Open(options_, "/tmp/testdb", &db_);
if (!s.ok()) {
log_err("Open db failed");
}
// leveldb::Status s = leveldb::DB::Open(options_, "/tmp/testdb", &db_);
db_ = new nemo::Nemo("/tmp/testdb");
// if (!s.ok()) {
// log_err("Open db failed");
// }

// start the pikaThread_ thread
for (int i = 0; i < g_pikaConf->thread_num(); i++) {
Expand Down
1 change: 0 additions & 1 deletion third/leveldb
Submodule leveldb deleted from 803d69
1 change: 1 addition & 0 deletions third/nemo
Submodule nemo added at 3b9943

0 comments on commit c273ddf

Please sign in to comment.