Commit 91213061 authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

refactor to ProfaneDB

parent 565760ce
cmake_minimum_required(VERSION 3.0)
project(ProdisDB)
project(ProfaneDB)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g")
......@@ -9,5 +9,5 @@ find_package(Threads REQUIRED)
find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)
add_subdirectory(src/prodisdb/protobuf)
add_subdirectory(src/prodisdb/server)
add_subdirectory(src/profanedb/protobuf)
add_subdirectory(src/profanedb/server)
# ProdisDB
# ProfaneDB
ProdisDB is a database for Protocol Buffer objects.
ProfaneDB is a database for Protocol Buffer objects.
The key used for retrieval of objects is defined within `.proto` files, this is then used to store a single copy of each object, and allow references between objects without data duplication.
......@@ -4,5 +4,5 @@ PROTOBUF_GENERATE_GRPC_CPP(GRPC_CC GRPC_H ${Proto})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../..)
add_library(prodisdb_protobuf ${PROTO_CC} ${PROTO_H} ${GRPC_CC} ${GRPC_H})
target_link_libraries(prodisdb_protobuf ${CMAKE_THREAD_LIBS_INIT} ${PROTOBUF_LIBRARIES} ${GRPC_LIBRARIES})
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})
syntax = "proto3";
package prodisdb.protobuf;
package profanedb.protobuf;
option go_package = "gitlab.com/prodisdb/protobuf/db";
option csharp_namespace = "ProdisDB.Protobuf";
option java_package = "com.prodisdb.protobuf";
option go_package = "gitlab.com/profanedb/protobuf/db";
option csharp_namespace = "ProfaneDB.Protobuf";
option java_package = "com.profanedb.protobuf";
option objc_class_prefix = "PDB";
import "google/protobuf/any.proto";
......
syntax = "proto2";
package prodisdb.protobuf;
package profanedb.protobuf;
option go_package = "gitlab.com/prodisdb/protobuf/options";
option csharp_namespace = "ProdisDB.Protobuf";
option java_package = "com.prodisdb.protobuf";
option go_package = "gitlab.com/profanedb/protobuf/options";
option csharp_namespace = "ProfaneDB.Protobuf";
option java_package = "com.profanedb.protobuf";
option objc_class_prefix = "PDB";
import "google/protobuf/descriptor.proto";
......
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../.. ${CMAKE_CURRENT_SOURCE_DIR}/../..)
add_executable(prodisdb_server main.cpp parser.cpp server.cpp)
target_link_libraries(prodisdb_server prodisdb_protobuf)
add_executable(profanedb_server main.cpp parser.cpp server.cpp)
target_link_libraries(profanedb_server profanedb_protobuf)
......@@ -3,14 +3,12 @@
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <prodisdb/protobuf/options.pb.h>
#include <prodisdb/server/server.h>
const std::string PROTO_DIR = "/home/giorgio/Documents/ProdisDB/test"; // TODO Should be config
#include <profanedb/protobuf/options.pb.h>
#include <profanedb/server/server.h>
using namespace google::protobuf;
int main(int argc, char* argv[]) {
prodisdb::server::Server server;
profanedb::server::Server server;
server.Run();
}
#include "parser.h"
prodisdb::server::Parser::Parser()
profanedb::server::Parser::Parser()
{
sourceTree.MapPath("", "/usr/include"); // google/protobuf/... should be here
sourceTree.MapPath("", "/home/giorgio/Documents/ProdisDB/src"); // HACK prodisdb/options
sourceTree.MapPath("", "/home/giorgio/Documents/ProdisDB/test"); // HACK The DB schema defined by the user
sourceTree.MapPath("", "/home/giorgio/Documents/ProfaneDB/src"); // HACK profanedb/options
sourceTree.MapPath("", "/home/giorgio/Documents/ProfaneDB/test"); // HACK The DB schema defined by the user
inputStream = sourceTree.Open("");
if (inputStream == NULL) {
......@@ -16,15 +16,15 @@ prodisdb::server::Parser::Parser()
pool = new DescriptorPool(descriptorDb);
pool->FindFileByName("prodisdb/protobuf/options.proto");
pool->FindFileByName("profanedb/protobuf/options.proto");
pool->FindFileByName("test.proto");
}
prodisdb::server::Parser::~Parser()
profanedb::server::Parser::~Parser()
{
}
void prodisdb::server::Parser::ParseMessage(const Any& serializable)
void profanedb::server::Parser::ParseMessage(const Any& serializable)
{
std::string type = serializable.type_url();
......@@ -35,7 +35,7 @@ void prodisdb::server::Parser::ParseMessage(const Any& serializable)
for (int idx = 0; idx < definition->field_count(); idx++) {
fd = definition->field(idx);
if (fd->options().GetExtension(prodisdb::protobuf::options).key()) {
if (fd->options().GetExtension(profanedb::protobuf::options).key()) {
std::cout << fd->full_name() << " is key" << std::endl;
break;
}
......@@ -47,11 +47,11 @@ void prodisdb::server::Parser::ParseMessage(const Any& serializable)
std::cout << container->GetReflection()->GetInt32(*container, fd) << std::endl;
}
prodisdb::server::Parser::ErrorCollector::ErrorCollector()
profanedb::server::Parser::ErrorCollector::ErrorCollector()
{
}
void prodisdb::server::Parser::ErrorCollector::AddError(const string& filename, int line, int column, const string& message)
void profanedb::server::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 prodisdb::server::Parser::ErrorCollector::AddError(const string& filename,
}
}
void prodisdb::server::Parser::ErrorCollector::AddWarning(const string& filename, int line, int column, const string& message)
void profanedb::server::Parser::ErrorCollector::AddWarning(const string& filename, int line, int column, const string& message)
{
std::cerr << filename << " " << line+1 << ":" << column+1 << " warning: " << message << "\n";
}
......@@ -7,12 +7,12 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/dynamic_message.h>
#include <prodisdb/protobuf/db.pb.h>
#include <prodisdb/protobuf/options.pb.h>
#include <profanedb/protobuf/db.pb.h>
#include <profanedb/protobuf/options.pb.h>
using namespace google::protobuf;
namespace prodisdb {
namespace profanedb {
namespace server {
class Parser
......
#include "server.h"
prodisdb::server::Server::Server()
profanedb::server::Server::Server()
{
}
prodisdb::server::Server::~Server()
profanedb::server::Server::~Server()
{
server->Shutdown();
}
void prodisdb::server::Server::Run()
void profanedb::server::Server::Run()
{
std::string address("0.0.0.0:50051");
......@@ -25,22 +25,22 @@ void prodisdb::server::Server::Run()
HandleRpcs();
}
void prodisdb::server::Server::HandleRpcs()
void profanedb::server::Server::HandleRpcs()
{
server->Wait();
}
grpc::Status prodisdb::server::Server::DbServiceImpl::Get(grpc::ServerContext* context, const prodisdb::protobuf::GetReq* request, prodisdb::protobuf::GetResp* response)
grpc::Status profanedb::server::Server::DbServiceImpl::Get(grpc::ServerContext* context, const profanedb::protobuf::GetReq* request, profanedb::protobuf::GetResp* response)
{
}
grpc::Status prodisdb::server::Server::DbServiceImpl::Put(grpc::ServerContext* context, const prodisdb::protobuf::PutReq* request, prodisdb::protobuf::PutResp* response)
grpc::Status profanedb::server::Server::DbServiceImpl::Put(grpc::ServerContext* context, const profanedb::protobuf::PutReq* request, profanedb::protobuf::PutResp* response)
{
parser.ParseMessage(request->serializable());
return grpc::Status::OK;
}
grpc::Status prodisdb::server::Server::DbServiceImpl::Delete(grpc::ServerContext* context, const prodisdb::protobuf::DelReq* request, prodisdb::protobuf::DelResp* response)
grpc::Status profanedb::server::Server::DbServiceImpl::Delete(grpc::ServerContext* context, const profanedb::protobuf::DelReq* request, profanedb::protobuf::DelResp* response)
{
}
......@@ -4,14 +4,14 @@
#include <grpc++/grpc++.h>
#include <grpc/support/log.h>
#include <prodisdb/server/parser.h>
#include <profanedb/server/parser.h>
#include <prodisdb/protobuf/db.pb.h>
#include <prodisdb/protobuf/db.grpc.pb.h>
#include <profanedb/protobuf/db.pb.h>
#include <profanedb/protobuf/db.grpc.pb.h>
using prodisdb::protobuf::Db;
using profanedb::protobuf::Db;
namespace prodisdb {
namespace profanedb {
namespace server {
class Server
......@@ -29,11 +29,11 @@ private:
class DbServiceImpl : public Db::Service {
public:
grpc::Status Get(grpc::ServerContext* context, const prodisdb::protobuf::GetReq* request, prodisdb::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 prodisdb::protobuf::PutReq* request, prodisdb::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 prodisdb::protobuf::DelReq* request, prodisdb::protobuf::DelResp* response) override;
grpc::Status Delete(grpc::ServerContext* context, const profanedb::protobuf::DelReq* request, profanedb::protobuf::DelResp* response) override;
private:
Parser parser;
......
syntax = "proto3";
package prodisdb.protobuf;
package profanedb.protobuf;
option go_package = "gitlab.com/prodisdb/protobuf/db";
option csharp_namespace = "ProdisDB.Protobuf";
option java_package = "com.prodisdb.protobuf";
option go_package = "gitlab.com/profanedb/protobuf/db";
option csharp_namespace = "ProfaneDB.Protobuf";
option java_package = "com.profanedb.protobuf";
option objc_class_prefix = "PDB";
import "google/protobuf/any.proto";
......
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc
import prodisdb.protobuf.db_pb2 as prodisdb_dot_protobuf_dot_db__pb2
import profanedb.protobuf.db_pb2 as profanedb_dot_protobuf_dot_db__pb2
class DbStub(object):
......@@ -13,19 +13,19 @@ class DbStub(object):
channel: A grpc.Channel.
"""
self.Get = channel.unary_unary(
'/prodisdb.protobuf.Db/Get',
request_serializer=prodisdb_dot_protobuf_dot_db__pb2.GetReq.SerializeToString,
response_deserializer=prodisdb_dot_protobuf_dot_db__pb2.GetResp.FromString,
'/profanedb.protobuf.Db/Get',
request_serializer=profanedb_dot_protobuf_dot_db__pb2.GetReq.SerializeToString,
response_deserializer=profanedb_dot_protobuf_dot_db__pb2.GetResp.FromString,
)
self.Put = channel.unary_unary(
'/prodisdb.protobuf.Db/Put',
request_serializer=prodisdb_dot_protobuf_dot_db__pb2.PutReq.SerializeToString,
response_deserializer=prodisdb_dot_protobuf_dot_db__pb2.PutResp.FromString,
'/profanedb.protobuf.Db/Put',
request_serializer=profanedb_dot_protobuf_dot_db__pb2.PutReq.SerializeToString,
response_deserializer=profanedb_dot_protobuf_dot_db__pb2.PutResp.FromString,
)
self.Delete = channel.unary_unary(
'/prodisdb.protobuf.Db/Delete',
request_serializer=prodisdb_dot_protobuf_dot_db__pb2.DelReq.SerializeToString,
response_deserializer=prodisdb_dot_protobuf_dot_db__pb2.DelResp.FromString,
'/profanedb.protobuf.Db/Delete',
request_serializer=profanedb_dot_protobuf_dot_db__pb2.DelReq.SerializeToString,
response_deserializer=profanedb_dot_protobuf_dot_db__pb2.DelResp.FromString,
)
......@@ -51,20 +51,20 @@ def add_DbServicer_to_server(servicer, server):
rpc_method_handlers = {
'Get': grpc.unary_unary_rpc_method_handler(
servicer.Get,
request_deserializer=prodisdb_dot_protobuf_dot_db__pb2.GetReq.FromString,
response_serializer=prodisdb_dot_protobuf_dot_db__pb2.GetResp.SerializeToString,
request_deserializer=profanedb_dot_protobuf_dot_db__pb2.GetReq.FromString,
response_serializer=profanedb_dot_protobuf_dot_db__pb2.GetResp.SerializeToString,
),
'Put': grpc.unary_unary_rpc_method_handler(
servicer.Put,
request_deserializer=prodisdb_dot_protobuf_dot_db__pb2.PutReq.FromString,
response_serializer=prodisdb_dot_protobuf_dot_db__pb2.PutResp.SerializeToString,
request_deserializer=profanedb_dot_protobuf_dot_db__pb2.PutReq.FromString,
response_serializer=profanedb_dot_protobuf_dot_db__pb2.PutResp.SerializeToString,
),
'Delete': grpc.unary_unary_rpc_method_handler(
servicer.Delete,
request_deserializer=prodisdb_dot_protobuf_dot_db__pb2.DelReq.FromString,
response_serializer=prodisdb_dot_protobuf_dot_db__pb2.DelResp.SerializeToString,
request_deserializer=profanedb_dot_protobuf_dot_db__pb2.DelReq.FromString,
response_serializer=profanedb_dot_protobuf_dot_db__pb2.DelResp.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'prodisdb.protobuf.Db', rpc_method_handlers)
'profanedb.protobuf.Db', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
syntax = "proto2";
package prodisdb.protobuf;
package profanedb.protobuf;
option go_package = "gitlab.com/prodisdb/protobuf/options";
option csharp_namespace = "ProdisDB.Protobuf";
option java_package = "com.prodisdb.protobuf";
option go_package = "gitlab.com/profanedb/protobuf/options";
option csharp_namespace = "ProfaneDB.Protobuf";
option java_package = "com.profanedb.protobuf";
option objc_class_prefix = "PDB";
import "google/protobuf/descriptor.proto";
......
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: prodisdb/protobuf/options.proto
# source: profanedb/protobuf/options.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
......@@ -17,10 +17,10 @@ from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor
DESCRIPTOR = _descriptor.FileDescriptor(
name='prodisdb/protobuf/options.proto',
package='prodisdb.protobuf',
name='profanedb/protobuf/options.proto',
package='profanedb.protobuf',
syntax='proto2',
serialized_pb=_b('\n\x1fprodisdb/protobuf/options.proto\x12\x11prodisdb.protobuf\x1a google/protobuf/descriptor.proto\"\x1b\n\x0c\x46ieldOptions\x12\x0b\n\x03key\x18\x01 \x01(\x08:Q\n\x07options\x12\x1d.google.protobuf.FieldOptions\x18\x9f\x8d\x06 \x01(\x0b\x32\x1f.prodisdb.protobuf.FieldOptionsBW\n\x15\x63om.prodisdb.protobufZ$gitlab.com/prodisdb/protobuf/options\xa2\x02\x03PDB\xaa\x02\x11ProdisDB.Protobuf')
serialized_pb=_b('\n profanedb/protobuf/options.proto\x12\x12profanedb.protobuf\x1a google/protobuf/descriptor.proto\"\x1b\n\x0c\x46ieldOptions\x12\x0b\n\x03key\x18\x01 \x01(\x08:R\n\x07options\x12\x1d.google.protobuf.FieldOptions\x18\x9f\x8d\x06 \x01(\x0b\x32 .profanedb.protobuf.FieldOptionsBZ\n\x16\x63om.profanedb.protobufZ%gitlab.com/profanedb/protobuf/options\xa2\x02\x03PDB\xaa\x02\x12ProfaneDB.Protobuf')
,
dependencies=[google_dot_protobuf_dot_descriptor__pb2.DESCRIPTOR,])
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
......@@ -28,7 +28,7 @@ _sym_db.RegisterFileDescriptor(DESCRIPTOR)
OPTIONS_FIELD_NUMBER = 99999
options = _descriptor.FieldDescriptor(
name='options', full_name='prodisdb.protobuf.options', index=0,
name='options', full_name='profanedb.protobuf.options', index=0,
number=99999, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
......@@ -38,13 +38,13 @@ options = _descriptor.FieldDescriptor(
_FIELDOPTIONS = _descriptor.Descriptor(
name='FieldOptions',
full_name='prodisdb.protobuf.FieldOptions',
full_name='profanedb.protobuf.FieldOptions',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='key', full_name='prodisdb.protobuf.FieldOptions.key', index=0,
name='key', full_name='profanedb.protobuf.FieldOptions.key', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
......@@ -62,8 +62,8 @@ _FIELDOPTIONS = _descriptor.Descriptor(
extension_ranges=[],
oneofs=[
],
serialized_start=88,
serialized_end=115,
serialized_start=90,
serialized_end=117,
)
DESCRIPTOR.message_types_by_name['FieldOptions'] = _FIELDOPTIONS
......@@ -71,8 +71,8 @@ DESCRIPTOR.extensions_by_name['options'] = options
FieldOptions = _reflection.GeneratedProtocolMessageType('FieldOptions', (_message.Message,), dict(
DESCRIPTOR = _FIELDOPTIONS,
__module__ = 'prodisdb.protobuf.options_pb2'
# @@protoc_insertion_point(class_scope:prodisdb.protobuf.FieldOptions)
__module__ = 'profanedb.protobuf.options_pb2'
# @@protoc_insertion_point(class_scope:profanedb.protobuf.FieldOptions)
))
_sym_db.RegisterMessage(FieldOptions)
......@@ -80,7 +80,7 @@ options.message_type = _FIELDOPTIONS
google_dot_protobuf_dot_descriptor__pb2.FieldOptions.RegisterExtension(options)
DESCRIPTOR.has_options = True
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.prodisdb.protobufZ$gitlab.com/prodisdb/protobuf/options\242\002\003PDB\252\002\021ProdisDB.Protobuf'))
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\026com.profanedb.protobufZ%gitlab.com/profanedb/protobuf/options\242\002\003PDB\252\002\022ProfaneDB.Protobuf'))
try:
# THESE ELEMENTS WILL BE DEPRECATED.
# Please use the generated *_pb2_grpc.py files instead.
......
......@@ -2,10 +2,10 @@ syntax = "proto3";
package test;
import "prodisdb/protobuf/options.proto";
import "profanedb/protobuf/options.proto";
message Test {
int32 field_one_int = 1 [ (prodisdb.protobuf.options).key = true ];
int32 field_one_int = 1 [ (profanedb.protobuf.options).key = true ];
string field_two_str = 2;
bool field_three_bool = 3;
bytes field_four_bytes = 4;
......
import grpc
from prodisdb.protobuf import db_pb2, db_pb2_grpc
from profanedb.protobuf import db_pb2, db_pb2_grpc
import test_pb2
......
......@@ -13,16 +13,16 @@ from google.protobuf import descriptor_pb2
_sym_db = _symbol_database.Default()
from prodisdb.protobuf import options_pb2 as prodisdb_dot_protobuf_dot_options__pb2
from profanedb.protobuf import options_pb2 as profanedb_dot_protobuf_dot_options__pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name='test.proto',
package='test',
syntax='proto3',
serialized_pb=_b('\n\ntest.proto\x12\x04test\x1a\x1fprodisdb/protobuf/options.proto\"p\n\x04Test\x12\x1d\n\rfield_one_int\x18\x01 \x01(\x05\x42\x06\xfa\xe9\x30\x02\x08\x01\x12\x15\n\rfield_two_str\x18\x02 \x01(\t\x12\x18\n\x10\x66ield_three_bool\x18\x03 \x01(\x08\x12\x18\n\x10\x66ield_four_bytes\x18\x04 \x01(\x0c\x62\x06proto3')
serialized_pb=_b('\n\ntest.proto\x12\x04test\x1a profanedb/protobuf/options.proto\"p\n\x04Test\x12\x1d\n\rfield_one_int\x18\x01 \x01(\x05\x42\x06\xfa\xe9\x30\x02\x08\x01\x12\x15\n\rfield_two_str\x18\x02 \x01(\t\x12\x18\n\x10\x66ield_three_bool\x18\x03 \x01(\x08\x12\x18\n\x10\x66ield_four_bytes\x18\x04 \x01(\x0c\x62\x06proto3')
,
dependencies=[prodisdb_dot_protobuf_dot_options__pb2.DESCRIPTOR,])
dependencies=[profanedb_dot_protobuf_dot_options__pb2.DESCRIPTOR,])
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
......@@ -75,8 +75,8 @@ _TEST = _descriptor.Descriptor(
extension_ranges=[],
oneofs=[
],
serialized_start=53,
serialized_end=165,
serialized_start=54,
serialized_end=166,
)
DESCRIPTOR.message_types_by_name['Test'] = _TEST
......
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