提交 814da906 编写于 作者: W wangjiawei04

add kvdb to resource

Change-Id: I73890ecaffe1d500dfc66c76d83b0fa8e64732e5
上级 d3175966
...@@ -23,13 +23,13 @@ using baidu::paddle_serving::predictor::format::KVDBRes; ...@@ -23,13 +23,13 @@ using baidu::paddle_serving::predictor::format::KVDBRes;
using baidu::paddle_serving::predictor::echo_kvdb_service::Request; using baidu::paddle_serving::predictor::echo_kvdb_service::Request;
using baidu::paddle_serving::predictor::echo_kvdb_service::Response; using baidu::paddle_serving::predictor::echo_kvdb_service::Response;
std::shared_ptr<RocksDBWrapper> KVDBEchoOp::db;
int KVDBEchoOp::inference() { int KVDBEchoOp::inference() {
debug(); debug();
} }
int KVDBEchoOp::debug() { int KVDBEchoOp::debug() {
//TODO: implement DEBUG mode //TODO: implement DEBUG mode
this->DBInit(); baidu::paddle_serving::predictor::Resource& resource = baidu::paddle_serving::predictor::Resource::instance();
std::shared_ptr<RocksDBWrapper> db = resource.getDB();
const Request* req = dynamic_cast<const Request*>(get_request_message()); const Request* req = dynamic_cast<const Request*>(get_request_message());
Response* res = mutable_data<Response>(); Response* res = mutable_data<Response>();
LOG(INFO) << "Receive request in KVDB echo service: " << req->ShortDebugString(); LOG(INFO) << "Receive request in KVDB echo service: " << req->ShortDebugString();
...@@ -51,11 +51,7 @@ int KVDBEchoOp::debug() { ...@@ -51,11 +51,7 @@ int KVDBEchoOp::debug() {
return 0; return 0;
} }
void KVDBEchoOp::DBInit() {
if (db.get() == nullptr) {
db = RocksDBWrapper::RocksDBWrapperFactory("kvdb");
}
}
DEFINE_OP(KVDBEchoOp); DEFINE_OP(KVDBEchoOp);
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#pragma once #pragma once
#include "demo-serving/echo_kvdb_service.pb.h" #include "demo-serving/echo_kvdb_service.pb.h"
#include "predictor/framework/resource.h"
#include "predictor/common/inner_common.h" #include "predictor/common/inner_common.h"
#include "predictor/framework/channel.h" #include "predictor/framework/channel.h"
#include "predictor/framework/op_repository.h" #include "predictor/framework/op_repository.h"
...@@ -30,9 +30,6 @@ class KVDBEchoOp: public OpWithChannel<baidu::paddle_serving::predictor::echo_kv ...@@ -30,9 +30,6 @@ class KVDBEchoOp: public OpWithChannel<baidu::paddle_serving::predictor::echo_kv
DECLARE_OP(KVDBEchoOp); DECLARE_OP(KVDBEchoOp);
int inference(); int inference();
int debug(); int debug();
protected:
static std::shared_ptr<RocksDBWrapper> db;
void DBInit();
}; };
} // namespace predictor } // namespace predictor
......
...@@ -6,15 +6,17 @@ include(framework/CMakeLists.txt) ...@@ -6,15 +6,17 @@ include(framework/CMakeLists.txt)
#include(plugin/CMakeLists.txt) #include(plugin/CMakeLists.txt)
include(src/CMakeLists.txt) include(src/CMakeLists.txt)
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../kvdb/include)
add_library(pdserving ${pdserving_srcs}) add_library(pdserving ${pdserving_srcs})
set_source_files_properties( set_source_files_properties(
${pdserving_srcs} ${pdserving_srcs}
PROPERTIES PROPERTIES
COMPILE_FLAGS "-Wno-strict-aliasing -Wno-unused-variable -Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor") COMPILE_FLAGS "-Wno-strict-aliasing -Wno-unused-variable -Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor")
add_dependencies(pdserving protobuf boost brpc leveldb pdcodegen configure) add_dependencies(pdserving protobuf kvdb boost brpc leveldb pdcodegen configure)
target_link_libraries(pdserving target_link_libraries(pdserving
brpc protobuf boost leveldb configure -lpthread -lcrypto -lm -lrt -lssl -ldl -lz) brpc protobuf boost leveldb configure kvdb -lpthread -lcrypto -lm -lrt -lssl -ldl -lz)
# install # install
install(TARGETS pdserving install(TARGETS pdserving
......
...@@ -36,7 +36,13 @@ DynamicResource::DynamicResource() {} ...@@ -36,7 +36,13 @@ DynamicResource::DynamicResource() {}
DynamicResource::~DynamicResource() {} DynamicResource::~DynamicResource() {}
int DynamicResource::initialize() { return 0; } int DynamicResource::initialize() {
return 0;
}
std::shared_ptr<RocksDBWrapper> Resource::getDB() {
return db;
}
int DynamicResource::clear() { return 0; } int DynamicResource::clear() { return 0; }
...@@ -80,6 +86,11 @@ int Resource::initialize(const std::string& path, const std::string& file) { ...@@ -80,6 +86,11 @@ int Resource::initialize(const std::string& path, const std::string& file) {
LOG(ERROR) << "unable to create tls_bthread_key of thrd_data"; LOG(ERROR) << "unable to create tls_bthread_key of thrd_data";
return -1; return -1;
} }
//init rocksDB instance
if (db.get() == nullptr) {
db = RocksDBWrapper::RocksDBWrapperFactory("kvdb");
}
THREAD_SETSPECIFIC(_tls_bspec_key, NULL); THREAD_SETSPECIFIC(_tls_bspec_key, NULL);
return 0; return 0;
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <string> #include <string>
#include "predictor/common/inner_common.h" #include "predictor/common/inner_common.h"
#include "predictor/framework/memory.h" #include "predictor/framework/memory.h"
#include "kvdb/paddle_rocksdb.h"
namespace baidu { namespace baidu {
namespace paddle_serving { namespace paddle_serving {
...@@ -30,6 +31,7 @@ struct DynamicResource { ...@@ -30,6 +31,7 @@ struct DynamicResource {
int initialize(); int initialize();
int clear(); int clear();
}; };
class Resource { class Resource {
...@@ -53,6 +55,8 @@ class Resource { ...@@ -53,6 +55,8 @@ class Resource {
int finalize(); int finalize();
std::shared_ptr<RocksDBWrapper> getDB();
DynamicResource* get_dynamic_resource() { DynamicResource* get_dynamic_resource() {
return reinterpret_cast<DynamicResource*>( return reinterpret_cast<DynamicResource*>(
THREAD_GETSPECIFIC(_tls_bspec_key)); THREAD_GETSPECIFIC(_tls_bspec_key));
...@@ -60,7 +64,8 @@ class Resource { ...@@ -60,7 +64,8 @@ class Resource {
private: private:
int thread_finalize() { return 0; } int thread_finalize() { return 0; }
std::shared_ptr<RocksDBWrapper> db;
THREAD_KEY_T _tls_bspec_key; THREAD_KEY_T _tls_bspec_key;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册