diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt index 20147da6f2d..d42de9d128b 100644 --- a/src/daemons/CMakeLists.txt +++ b/src/daemons/CMakeLists.txt @@ -72,3 +72,34 @@ target_link_libraries( ) +add_executable( + metad + MetaDaemon.cpp + $ + $ + $ + $ + $ + $ + $ +) +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 +) diff --git a/src/daemons/MetaDaemon.cpp b/src/daemons/MetaDaemon.cpp new file mode 100644 index 00000000000..71ed9baf1e5 --- /dev/null +++ b/src/daemons/MetaDaemon.cpp @@ -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 +#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(); + auto server = std::make_shared(); + 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"; +} + diff --git a/src/interface/CMakeLists.txt b/src/interface/CMakeLists.txt index 43b7967224a..58a77910066 100644 --- a/src/interface/CMakeLists.txt +++ b/src/interface/CMakeLists.txt @@ -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 @@ -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) diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift new file mode 100644 index 00000000000..84e92831815 --- /dev/null +++ b/src/interface/meta.thrift @@ -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 children, +} + +service MetaService { + ExecResponse createNode(1: CreateNodeRequest req); + ExecResponse setNode(1: SetNodeRequest req); + GetNodeResponse getNode(1: GetNodeRequest req); + ListChildrenResponse listChildren(1: ListChildrenRequest req); +} + diff --git a/src/meta/CMakeLists.txt b/src/meta/CMakeLists.txt index 0ac1abcba13..c6e27b75e3d 100644 --- a/src/meta/CMakeLists.txt +++ b/src/meta/CMakeLists.txt @@ -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) diff --git a/src/meta/MetaServiceHandler.cpp b/src/meta/MetaServiceHandler.cpp new file mode 100644 index 00000000000..00d4514fd1a --- /dev/null +++ b/src/meta/MetaServiceHandler.cpp @@ -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 +MetaServiceHandler::future_createNode(const cpp2::CreateNodeRequest& req) { + UNUSED(req); + folly::Promise p; + return p.getFuture(); +} + +folly::Future +MetaServiceHandler::future_setNode(const cpp2::SetNodeRequest& req) { + UNUSED(req); + folly::Promise p; + return p.getFuture(); +} + +folly::Future +MetaServiceHandler::future_getNode(const cpp2::GetNodeRequest& req) { + UNUSED(req); + folly::Promise p; + return p.getFuture(); +} + +folly::Future +MetaServiceHandler::future_listChildren(const cpp2::ListChildrenRequest& req) { + UNUSED(req); + folly::Promise p; + return p.getFuture(); +} + +} // namespace meta +} // namespace nebula diff --git a/src/meta/MetaServiceHandler.h b/src/meta/MetaServiceHandler.h new file mode 100644 index 00000000000..5ede1f00c49 --- /dev/null +++ b/src/meta/MetaServiceHandler.h @@ -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 + future_createNode(const cpp2::CreateNodeRequest& req) override; + + folly::Future + future_setNode(const cpp2::SetNodeRequest& req) override; + + folly::Future + future_getNode(const cpp2::GetNodeRequest& req) override; + + folly::Future + future_listChildren(const cpp2::ListChildrenRequest& req) override; + +private: + kvstore::KVStore* kvstore_ = nullptr; +}; + +} // namespace meta +} // namespace nebula +#endif // META_METASERVICEHANDLER_H_