Skip to content

Commit

Permalink
Define meta service interface (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangleptr authored Jan 14, 2019
1 parent 795218c commit 015a731
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/daemons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,34 @@ target_link_libraries(
)


add_executable(
metad
MetaDaemon.cpp
$<TARGET_OBJECTS:meta_service_handler>
$<TARGET_OBJECTS:kvstore_obj>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:fs_obj>
)
target_link_libraries(
metad
${ROCKSDB_LIBRARIES}
${THRIFT_LIBRARIES}
wangle
folly
boost_system
boost_context
${OPENSSL_LIBRARIES}
${KRB5_LIBRARIES}
glog
gflags
event
${COMPRESSION_LIBRARIES}
resolv
double-conversion
dl
jemalloc
-pthread
)
32 changes: 32 additions & 0 deletions src/daemons/MetaDaemon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved
*
* This source code is licensed under Apache 2.0 License
* (found in the LICENSE.Apache file in the root directory)
*/

#include "base/Base.h"
#include <thrift/lib/cpp2/server/ThriftServer.h>
#include "meta/MetaServiceHandler.h"

DEFINE_int32(port, 45500, "Meta daemon listening port");


int main(int argc, char *argv[]) {
folly::init(&argc, &argv, true);

using namespace nebula::meta;

LOG(INFO) << "Starting the meta Daemon on port " << FLAGS_port;

auto handler = std::make_shared<MetaServiceHandler>();
auto server = std::make_shared<apache::thrift::ThriftServer>();
CHECK(!!server) << "Failed to create the thrift server";

server->setInterface(handler);
server->setPort(FLAGS_port);

server->serve(); // Will wait until the server shuts down

LOG(INFO) << "The storage Daemon on port " << FLAGS_port << " stopped";
}

24 changes: 24 additions & 0 deletions src/interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ add_custom_command(
DEPENDS storage.thrift
)

add_custom_command(
OUTPUT
gen-cpp2/MetaService.cpp
gen-cpp2/MetaServiceAsyncClient.cpp
gen-cpp2/MetaService_processmap_binary.cpp
gen-cpp2/MetaService_processmap_compact.cpp
gen-cpp2/meta_constants.cpp
gen-cpp2/meta_data.cpp
gen-cpp2/meta_types.cpp
COMMAND "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/bin/thrift1" "--allow-neg-enum-vals" "--templates" "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/include/thrift/templates" "--gen" "mstch_cpp2:include_prefix=\"interface\",process_in_event_base,stack_arguments" "--gen" "java:hashcode" "--gen" "go" "-o" "." "./meta.thrift"
DEPENDS meta.thrift
)

add_custom_target(
clean-interface
Expand Down Expand Up @@ -83,3 +95,15 @@ add_library(
gen-cpp2/storage_types.cpp
)
add_dependencies(storage_thrift_obj tgt_fbthrift)

add_library(
meta_thrift_obj OBJECT
gen-cpp2/MetaService.cpp
gen-cpp2/MetaServiceAsyncClient.cpp
gen-cpp2/MetaService_processmap_binary.cpp
gen-cpp2/MetaService_processmap_compact.cpp
gen-cpp2/meta_constants.cpp
gen-cpp2/meta_data.cpp
gen-cpp2/meta_types.cpp
)
add_dependencies(meta_thrift_obj tgt_fbthrift)
79 changes: 79 additions & 0 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved
*
* This source code is licensed under Apache 2.0 License
* (found in the LICENSE.Apache file in the root directory)
*/

namespace cpp nebula.meta
namespace java nebula.meta
namespace go nebula.meta

cpp_include "base/ThriftTypes.h"

typedef i32 (cpp.type = "nebula::IPv4") IPv4
typedef i32 (cpp.type = "nebula::Port") Port

enum ErrorCode {
SUCCEEDED = 0,

// RPC Failure
E_DISCONNECTED = -1,
E_FAIL_TO_CONNECT = -2,
E_RPC_FAILURE = -3,

E_LEADER_CHANAGED = -11,

// Operation Failure
E_NODE_HAS_EXISTED = -21,
E_NODE_NOT_EXISTED = -22,
} (cpp.enum_strict)

struct HostAddr {
1: IPv4 ip,
2: Port port,
}

struct ExecResponse {
1: ErrorCode ret,
// Valid if ret equals E_LEADER_CHANAGED.
2: HostAddr leader,
}

struct CreateNodeRequest {
1: string path,
2: string value,
}

struct SetNodeRequest {
1: string path,
2: string value,
}

struct GetNodeRequest {
1: string path,
}

struct GetNodeResponse {
1: ErrorCode ret,
2: HostAddr leader,
3: string value,
4: i64 last_updated_time,
}

struct ListChildrenRequest {
1: string path,
}

struct ListChildrenResponse {
1: ErrorCode ret,
2: HostAddr leader,
3: list<string> children,
}

service MetaService {
ExecResponse createNode(1: CreateNodeRequest req);
ExecResponse setNode(1: SetNodeRequest req);
GetNodeResponse getNode(1: GetNodeRequest req);
ListChildrenResponse listChildren(1: ListChildrenRequest req);
}

8 changes: 7 additions & 1 deletion src/meta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ add_library(
)
add_dependencies(meta_obj common dataman_obj)

#add_subdirectory(test)
add_library(
meta_service_handler OBJECT
MetaServiceHandler.cpp
)

add_dependencies(meta_service_handler common meta_thrift_obj kvstore_obj)

#add_subdirectory(test)
40 changes: 40 additions & 0 deletions src/meta/MetaServiceHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved
*
* This source code is licensed under Apache 2.0 License
* (found in the LICENSE.Apache file in the root directory)
*/
#include "meta/MetaServiceHandler.h"

namespace nebula {
namespace meta {

folly::Future<cpp2::ExecResponse>
MetaServiceHandler::future_createNode(const cpp2::CreateNodeRequest& req) {
UNUSED(req);
folly::Promise<cpp2::ExecResponse> p;
return p.getFuture();
}

folly::Future<cpp2::ExecResponse>
MetaServiceHandler::future_setNode(const cpp2::SetNodeRequest& req) {
UNUSED(req);
folly::Promise<cpp2::ExecResponse> p;
return p.getFuture();
}

folly::Future<cpp2::GetNodeResponse>
MetaServiceHandler::future_getNode(const cpp2::GetNodeRequest& req) {
UNUSED(req);
folly::Promise<cpp2::GetNodeResponse> p;
return p.getFuture();
}

folly::Future<cpp2::ListChildrenResponse>
MetaServiceHandler::future_listChildren(const cpp2::ListChildrenRequest& req) {
UNUSED(req);
folly::Promise<cpp2::ListChildrenResponse> p;
return p.getFuture();
}

} // namespace meta
} // namespace nebula
37 changes: 37 additions & 0 deletions src/meta/MetaServiceHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved
*
* This source code is licensed under Apache 2.0 License
* (found in the LICENSE.Apache file in the root directory)
*/

#ifndef META_METASERVICEHANDLER_H_
#define META_METASERVICEHANDLER_H_

#include "base/Base.h"
#include "interface/gen-cpp2/MetaService.h"
#include "kvstore/include/KVStore.h"

namespace nebula {
namespace meta {

class MetaServiceHandler final : public cpp2::MetaServiceSvIf {
public:
folly::Future<cpp2::ExecResponse>
future_createNode(const cpp2::CreateNodeRequest& req) override;

folly::Future<cpp2::ExecResponse>
future_setNode(const cpp2::SetNodeRequest& req) override;

folly::Future<cpp2::GetNodeResponse>
future_getNode(const cpp2::GetNodeRequest& req) override;

folly::Future<cpp2::ListChildrenResponse>
future_listChildren(const cpp2::ListChildrenRequest& req) override;

private:
kvstore::KVStore* kvstore_ = nullptr;
};

} // namespace meta
} // namespace nebula
#endif // META_METASERVICEHANDLER_H_

0 comments on commit 015a731

Please sign in to comment.