Commit df83892e authored by Giorgio Azzinnaro's avatar Giorgio Azzinnaro

fixed db.proto, testing grpc

parent 39782b15
cmake_minimum_required(VERSION 2.6)
project(ProdisDB)
set(ProdisDB_VERSION_MAJOR 0)
set(ProdisDB_VERSION_MINOR 1)
include_directories("${PROJECT_SOURCE_DIR}/src")
add_executable(ProdisDB
src/prodisdb/server/main.cpp
src/prodisdb/server/prodis_error_collector.cpp
src/prodisdb/protobuf/options.pb.cc)
target_link_libraries(ProdisDB protobuf)
logo.png

95.4 KB

File added
......@@ -10,16 +10,16 @@ option objc_class_prefix = "PDB";
message Empty {}
message Serializable {
string descriptor = 1;
string type = 1;
bytes blob = 2;
}
message PrimaryKey {
string descriptor = 1;
string type = 1;
bytes uid = 2;
}
service Prodis {
service Db {
rpc Get (PrimaryKey) returns (Serializable);
rpc Create (Serializable) returns (Empty);
......
......@@ -6,38 +6,42 @@
#include <prodisdb/protobuf/options.pb.h>
#include <prodisdb/server/prodis_error_collector.h>
const std::string VIRTUAL_PROTO_MAP = "schema";
const std::string PROTO_DIR = "/home/giorgio/Documents/ProdisDB/test"; // TODO Should be config
using namespace google::protobuf;
int main(int argc, char *argv[]) {
google::protobuf::compiler::DiskSourceTree *sourceTree;
google::protobuf::io::ZeroCopyInputStream *inputStream;
google::protobuf::compiler::MultiFileErrorCollector *errCollector = new ProdisErrorCollector();
google::protobuf::compiler::Importer *importer;
google::protobuf::compiler::SourceTreeDescriptorDatabase *descriptorDb;
google::protobuf::DescriptorPool *pool;
compiler::DiskSourceTree *sourceTree;
io::ZeroCopyInputStream *inputStream;
compiler::MultiFileErrorCollector *errCollector = new ProdisErrorCollector();
compiler::Importer *importer;
compiler::SourceTreeDescriptorDatabase *descriptorDb;
DescriptorPool *pool;
sourceTree = new compiler::DiskSourceTree();
sourceTree->MapPath("", "/home/giorgio/Documents/ProdisDB/src"); // prodis options
sourceTree->MapPath("", "/usr/include"); // /usr/include is for google/protobuf/... files
sourceTree = new google::protobuf::compiler::DiskSourceTree();
sourceTree->MapPath(VIRTUAL_PROTO_MAP, PROTO_DIR);
sourceTree->MapPath("", "/home/giorgio/Documents/ProdisDB/src");
sourceTree->MapPath("", "/usr/include");
sourceTree->MapPath("", PROTO_DIR); // Here goes the schema defined by the user
inputStream = sourceTree->Open(VIRTUAL_PROTO_MAP);
inputStream = sourceTree->Open(""); // To load files in PROTO_DIR
if (inputStream == NULL) {
std::cerr << "Couldn't open .proto source tree: " << sourceTree->GetLastErrorMessage() << "\n";
}
descriptorDb = new google::protobuf::compiler::SourceTreeDescriptorDatabase(sourceTree);
descriptorDb = new compiler::SourceTreeDescriptorDatabase(sourceTree);
descriptorDb->RecordErrorsTo(errCollector);
pool = new google::protobuf::DescriptorPool(descriptorDb);
pool = new DescriptorPool(descriptorDb);
// HACK DescriptorPool::BuildFile should be used (for performance)
pool->FindFileByName("prodisdb/protobuf/options.proto");
pool->FindFileByName(VIRTUAL_PROTO_MAP + "/test.proto");
pool->FindFileByName("test.proto");
const google::protobuf::Descriptor *message = pool->FindMessageTypeByName("test.Test");
const google::protobuf::FieldDescriptor *fd;
const Descriptor *message = pool->FindMessageTypeByName("test.Test");
const FieldDescriptor *fd;
// TODO Should check for multiple keys (might be supported later), for now throw error
for (int idx = 0; idx < message->field_count(); idx++) {
fd = message->field(idx);
std::cout
......
#include "prodis_server.h"
ProdisServer::~ProdisServer()
{
server->Shutdown();
cq->Shutdown();
}
#ifndef PRODISSERVER_H
#define PRODISSERVER_H
#include <grpc++/grpc++.h>
#include <prodisdb/protobuf/db.pb.h>
#include <prodisdb/protobuf/db.grpc.pb.h>
using prodisdb::protobuf::Empty;
using prodisdb::protobuf::Serializable;
using prodisdb::protobuf::PrimaryKey;
using prodisdb::protobuf::Db;
class ProdisServer
{
public:
~ProdisServer();
void Run();
private:
void HandleRpcs();
std::unique_ptr<grpc::ServerCompletionQueue> cq;
Db::AsyncService service;
std::unique_ptr<grpc::Server> server;
class CallData {
public:
CallData(Db::AsyncService *service, grpc::ServerCompletionQueue *cq);
void Proceed();
private:
Db::AsyncService *mService;
grpc::ServerCompletionQueue *mCq;
grpc::ServerContext mContext;
Empty pbEmpty;
Serializable pbSerializable;
PrimaryKey pbPrimaryKey;
grpc::ServerAsyncResponseWriter<Serializable> serializableResp;
grpc::ServerAsyncResponseWriter<Empty> emptyResp;
enum CallStatus { CREATE, PROCESS, FINISH };
CallStatus mStatus;
};
};
#endif // PRODISSERVER_H
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