Commit 87ccc7bc authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

libPDB started

in profanedb/storage is an exportable interface, so that profane can also
be embedded. grpc is a thin layer for this

RocksDB added
parent 91213061
......@@ -8,6 +8,10 @@ set(PROTOBUF_IMPORT_DIRS "${CMAKE_SOURCE_DIR}/src")
find_package(Threads REQUIRED)
find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)
find_package(RocksDB REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(src/profanedb/protobuf)
add_subdirectory(src/profanedb/storage)
add_subdirectory(src/profanedb/server)
# Copyright (c) 2014 Stefan.Eilemann@epfl.ch
# - Try to find the Rocksdb library
# Once done this will define
#
# ROCKSDB_ROOT - Set this variable to the root installation
#
# Read-Only variables:
# ROCKSDB_FOUND - system has the Rocksdb library
# ROCKSDB_INCLUDE_DIR - the Rocksdb include directory
# ROCKSDB_LIBRARIES - The libraries needed to use Rocksdb
# ROCKSDB_VERSION - This is set to $major.$minor.$patch (eg. 0.9.8)
include(FindPackageHandleStandardArgs)
if(rocksdb_FIND_REQUIRED)
set(_ROCKSDB_output_type FATAL_ERROR)
set(_ROCKSDB_output 1)
else()
set(_ROCKSDB_output_type STATUS)
if(rocksdb_FIND_QUIETLY)
set(_ROCKSDB_output)
else()
set(_ROCKSDB_output 1)
endif()
endif()
find_path(_ROCKSDB_INCLUDE_DIR rocksdb/db.h
HINTS ${CMAKE_SOURCE_DIR}/../../.. $ENV{ROCKSDB_ROOT} ${ROCKSDB_ROOT}
PATH_SUFFIXES include
PATHS /usr /usr/local /opt /opt/local)
if(EXISTS "${_ROCKSDB_INCLUDE_DIR}/rocksdb/version.h")
set(_ROCKSDB_Version_file "${_ROCKSDB_INCLUDE_DIR}/rocksdb/version.h")
elseif(EXISTS "${_ROCKSDB_INCLUDE_DIR}/rocksdb/db.h")
set(_ROCKSDB_Version_file "${_ROCKSDB_INCLUDE_DIR}/rocksdb/db.h")
endif()
if(_ROCKSDB_INCLUDE_DIR AND _ROCKSDB_Version_file)
file(READ ${_ROCKSDB_Version_file} _ROCKSDB_header_contents)
string(REGEX REPLACE ".*kMajorVersion = ([0-9]+).*kMinorVersion = ([0-9]+).*"
"\\1.\\2" _ROCKSDB_VERSION "${_ROCKSDB_header_contents}")
string(REGEX REPLACE ".*ROCKSDB_MAJOR ([0-9]+).*ROCKSDB_MINOR ([0-9]+).*"
"\\1.\\2" _ROCKSDB_VERSION "${_ROCKSDB_header_contents}")
set(ROCKSDB_VERSION ${_ROCKSDB_VERSION} CACHE INTERNAL
"The version of rocksdb which was detected")
else()
set(_ROCKSDB_EPIC_FAIL TRUE)
if(_ROCKSDB_output)
message(${_ROCKSDB_output_type}
"Can't find rocksdb header file rocksdb/db.h.")
endif()
endif()
# Version checking
if(ROCKSDB_FIND_VERSION AND ROCKSDB_VERSION)
if(ROCKSDB_FIND_VERSION_EXACT)
if(NOT ROCKSDB_VERSION VERSION_EQUAL ${ROCKSDB_FIND_VERSION})
set(_ROCKSDB_version_not_exact TRUE)
endif()
else()
# version is too low
if(NOT ROCKSDB_VERSION VERSION_EQUAL ${ROCKSDB_FIND_VERSION} AND
NOT ROCKSDB_VERSION VERSION_GREATER ${ROCKSDB_FIND_VERSION})
set(_ROCKSDB_version_not_high_enough TRUE)
endif()
endif()
endif()
find_library(ROCKSDB_LIBRARY rocksdb
HINTS ${CMAKE_SOURCE_DIR}/../../.. $ENV{ROCKSDB_ROOT} ${ROCKSDB_ROOT}
PATH_SUFFIXES lib lib64
PATHS /usr /usr/local /opt /opt/local)
# Inform the users with an error message based on what version they
# have vs. what version was required.
if(NOT ROCKSDB_VERSION)
set(_ROCKSDB_EPIC_FAIL TRUE)
if(_ROCKSDB_output)
message(${_ROCKSDB_output_type}
"Version not found in ${_ROCKSDB_Version_file}.")
endif()
elseif(_ROCKSDB_version_not_high_enough)
set(_ROCKSDB_EPIC_FAIL TRUE)
if(_ROCKSDB_output)
message(${_ROCKSDB_output_type}
"Version ${ROCKSDB_FIND_VERSION} or higher of rocksdb is required. "
"Version ${ROCKSDB_VERSION} was found in ${_ROCKSDB_Version_file}.")
endif()
elseif(_ROCKSDB_version_not_exact)
set(_ROCKSDB_EPIC_FAIL TRUE)
if(_ROCKSDB_output)
message(${_ROCKSDB_output_type}
"Version ${ROCKSDB_FIND_VERSION} of rocksdb is required exactly. "
"Version ${ROCKSDB_VERSION} was found.")
endif()
else()
if(ROCKSDB_FIND_REQUIRED)
if(ROCKSDB_LIBRARY MATCHES "ROCKSDB_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Missing the rocksdb library.\n"
"Consider using CMAKE_PREFIX_PATH or the ROCKSDB_ROOT environment variable. "
"See the ${CMAKE_CURRENT_LIST_FILE} for more details.")
endif()
endif()
find_package_handle_standard_args(ROCKSDB DEFAULT_MSG
ROCKSDB_LIBRARY _ROCKSDB_INCLUDE_DIR)
endif()
if(_ROCKSDB_EPIC_FAIL)
# Zero out everything, we didn't meet version requirements
set(ROCKSDB_FOUND FALSE)
set(ROCKSDB_LIBRARY)
set(_ROCKSDB_INCLUDE_DIR)
set(ROCKSDB_INCLUDE_DIRS)
set(ROCKSDB_LIBRARIES)
else()
set(ROCKSDB_INCLUDE_DIRS ${_ROCKSDB_INCLUDE_DIR})
set(ROCKSDB_LIBRARIES ${ROCKSDB_LIBRARY})
if(_ROCKSDB_output)
message(STATUS
"Found rocksdb ${ROCKSDB_VERSION} in ${ROCKSDB_INCLUDE_DIRS};${ROCKSDB_LIBRARIES}")
endif()
endif()
......@@ -2,7 +2,8 @@ file(GLOB Proto "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
PROTOBUF_GENERATE_CPP(PROTO_CC PROTO_H ${Proto})
PROTOBUF_GENERATE_GRPC_CPP(GRPC_CC GRPC_H ${Proto})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../..)
add_library(profanedb_protobuf ${PROTO_CC} ${PROTO_H})
add_library(profanedb_grpc ${GRPC_CC} ${GRPC_H})
add_library(profanedb_protobuf ${PROTO_CC} ${PROTO_H} ${GRPC_CC} ${GRPC_H})
target_link_libraries(profanedb_protobuf ${CMAKE_THREAD_LIBS_INIT} ${PROTOBUF_LIBRARIES} ${GRPC_LIBRARIES})
target_link_libraries(profanedb_protobuf ${CMAKE_THREAD_LIBS_INIT} ${PROTOBUF_LIBRARIES})
target_link_libraries(profanedb_grpc profanedb_protobuf ${GRPC_LIBRARIES})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../.. ${CMAKE_CURRENT_SOURCE_DIR}/../..)
add_executable(profanedb_server main.cpp parser.cpp server.cpp)
target_link_libraries(profanedb_server profanedb_protobuf)
add_executable(profanedb_server main.cpp server.cpp)
target_link_libraries(profanedb_server profanedb_grpc profanedb_storage)
#include <iostream>
#include <string>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <profanedb/protobuf/options.pb.h>
#include <profanedb/server/server.h>
using namespace google::protobuf;
#include "server.h"
int main(int argc, char* argv[]) {
profanedb::server::Server server;
......
......@@ -32,15 +32,21 @@ void profanedb::server::Server::HandleRpcs()
grpc::Status profanedb::server::Server::DbServiceImpl::Get(grpc::ServerContext* context, const profanedb::protobuf::GetReq* request, profanedb::protobuf::GetResp* response)
{
db.Get(*request);
return grpc::Status::OK;
}
grpc::Status profanedb::server::Server::DbServiceImpl::Put(grpc::ServerContext* context, const profanedb::protobuf::PutReq* request, profanedb::protobuf::PutResp* response)
{
parser.ParseMessage(request->serializable());
db.Put(*request);
return grpc::Status::OK;
}
grpc::Status profanedb::server::Server::DbServiceImpl::Delete(grpc::ServerContext* context, const profanedb::protobuf::DelReq* request, profanedb::protobuf::DelResp* response)
{
db.Delete(*request);
return grpc::Status::OK;
}
......@@ -4,7 +4,7 @@
#include <grpc++/grpc++.h>
#include <grpc/support/log.h>
#include <profanedb/server/parser.h>
#include <profanedb/storage/db.h>
#include <profanedb/protobuf/db.pb.h>
#include <profanedb/protobuf/db.grpc.pb.h>
......@@ -29,14 +29,14 @@ private:
class DbServiceImpl : public Db::Service {
public:
grpc::Status Get(grpc::ServerContext* context, const profanedb::protobuf::GetReq* request, profanedb::protobuf::GetResp* response) override;
grpc::Status Get(grpc::ServerContext * context, const profanedb::protobuf::GetReq * request, profanedb::protobuf::GetResp* response) override;
grpc::Status Put(grpc::ServerContext* context, const profanedb::protobuf::PutReq* request, profanedb::protobuf::PutResp* response) override;
grpc::Status Put(grpc::ServerContext * context, const profanedb::protobuf::PutReq * request, profanedb::protobuf::PutResp * response) override;
grpc::Status Delete(grpc::ServerContext* context, const profanedb::protobuf::DelReq* request, profanedb::protobuf::DelResp* response) override;
grpc::Status Delete(grpc::ServerContext * context, const profanedb::protobuf::DelReq * request, profanedb::protobuf::DelResp * response) override;
private:
Parser parser;
profanedb::storage::Db db;
};
DbServiceImpl service;
};
......
add_library(profanedb_storage parser.cpp db.cpp)
target_link_libraries(profanedb_storage profanedb_protobuf ${ROCKSDB_LIBRARIES})
#include "db.h"
profanedb::storage::Db::Db()
{
options.create_if_missing = true;
rocksdb::DB::Open(options, "/tmp/profanedb", &db);
}
profanedb::protobuf::GetResp profanedb::storage::Db::Get(const profanedb::protobuf::GetReq & request)
{
}
profanedb::protobuf::PutResp profanedb::storage::Db::Put(const profanedb::protobuf::PutReq & request)
{
parser.ParseMessage(request.serializable());
}
profanedb::protobuf::DelResp profanedb::storage::Db::Delete(const profanedb::protobuf::DelReq & request)
{
}
#ifndef DB_H
#define DB_H
#include "parser.h"
#include <rocksdb/db.h>
#include <profanedb/protobuf/db.pb.h>
namespace profanedb {
namespace storage {
class Db
{
public:
Db();
protobuf::GetResp Get(const protobuf::GetReq & request);
protobuf::PutResp Put(const protobuf::PutReq & request);
protobuf::DelResp Delete(const protobuf::DelReq & request);
private:
rocksdb::DB * db;
rocksdb::Options options;
Parser parser;
};
}
}
#endif // DB_H
#include "parser.h"
profanedb::server::Parser::Parser()
profanedb::storage::Parser::Parser()
{
sourceTree.MapPath("", "/usr/include"); // google/protobuf/... should be here
sourceTree.MapPath("", "/home/giorgio/Documents/ProfaneDB/src"); // HACK profanedb/options
......@@ -20,11 +20,11 @@ profanedb::server::Parser::Parser()
pool->FindFileByName("test.proto");
}
profanedb::server::Parser::~Parser()
profanedb::storage::Parser::~Parser()
{
}
void profanedb::server::Parser::ParseMessage(const Any& serializable)
void profanedb::storage::Parser::ParseMessage(const Any& serializable)
{
std::string type = serializable.type_url();
......@@ -47,11 +47,11 @@ void profanedb::server::Parser::ParseMessage(const Any& serializable)
std::cout << container->GetReflection()->GetInt32(*container, fd) << std::endl;
}
profanedb::server::Parser::ErrorCollector::ErrorCollector()
profanedb::storage::Parser::ErrorCollector::ErrorCollector()
{
}
void profanedb::server::Parser::ErrorCollector::AddError(const string& filename, int line, int column, const string& message)
void profanedb::storage::Parser::ErrorCollector::AddError(const string& filename, int line, int column, const string& message)
{
if (line == -1) { // Entire file error
std::cerr << filename << " error: " << message << "\n";
......@@ -60,7 +60,7 @@ void profanedb::server::Parser::ErrorCollector::AddError(const string& filename,
}
}
void profanedb::server::Parser::ErrorCollector::AddWarning(const string& filename, int line, int column, const string& message)
void profanedb::storage::Parser::ErrorCollector::AddWarning(const string& filename, int line, int column, const string& message)
{
std::cerr << filename << " " << line+1 << ":" << column+1 << " warning: " << message << "\n";
}
......@@ -13,22 +13,24 @@
using namespace google::protobuf;
namespace profanedb {
namespace server {
namespace storage {
// Given a Any message, Parser looks for the corresponding definition in .proto files,
// and generates a Graph
class Parser
{
public:
Parser();
~Parser();
void ParseMessage(const Any& serializable);
void ParseMessage(const Any & serializable);
private:
io::ZeroCopyInputStream* inputStream;
io::ZeroCopyInputStream * inputStream;
compiler::DiskSourceTree sourceTree;
compiler::MultiFileErrorCollector* errCollector = new ErrorCollector();
compiler::SourceTreeDescriptorDatabase* descriptorDb;
DescriptorPool* pool;
compiler::MultiFileErrorCollector * errCollector = new ErrorCollector();
compiler::SourceTreeDescriptorDatabase * descriptorDb;
DescriptorPool * pool;
DynamicMessageFactory messageFactory;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment