Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define meta service interface #78

Merged
merged 2 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/daemons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,34 @@ target_link_libraries(
)


add_executable(
metad
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether we should add a letter "n" (short for nebula) in front of all daemons, such as ngraphd, nstoraged, nmetad.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good.

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)

#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_