diff --git a/cpp/build.sh b/cpp/build.sh index 1279725162ff059f44ee708168ab359b4e0c137a..42a7d714a612d3b0f33456ee0fe87acbadc1654d 100755 --- a/cpp/build.sh +++ b/cpp/build.sh @@ -11,7 +11,7 @@ PROFILING="OFF" BUILD_FAISS_WITH_MKL="OFF" USE_JFROG_CACHE="OFF" KNOWHERE_OPTS="" -MILVUS_WITH_THRIFT="OFF" +MILVUS_WITH_THRIFT="ON" while getopts "p:d:t:uhlrcgmj" arg do diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index de6e405d1f386ffa5c3a13b391987196f06516bb..363935fd9cae50dac495be1c6021109c4f9a7671 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -80,9 +80,12 @@ include_directories(grpc/gen-status) include_directories(grpc/gen-milvus) if (MILVUS_WITH_THRIFT STREQUAL "ON") + message("Build thrift server") + add_definitions("-DMILVUS_ENABLE_THRIFT") set(client_thrift_lib thrift) else() + message("Build grpc server") set(client_grpc_lib grpcpp_channelz grpc++ @@ -200,7 +203,7 @@ set(knowhere_libs ) if (MILVUS_WITH_THRIFT STREQUAL "ON") - add_executable(milvus_thrift_server + add_executable(milvus_server ${config_files} ${server_files} ${thriftserver_files} @@ -219,33 +222,15 @@ else() ) endif() -if (ENABLE_LICENSE STREQUAL "ON") - add_executable(get_sys_info ${get_sys_info_files}) - add_executable(license_generator ${license_generator_files}) - - target_link_libraries(get_sys_info ${license_libs} license_check ${third_party_libs}) - target_link_libraries(license_generator ${license_libs} ${third_party_libs}) - - if(MILVUS_WITH_THRIFT STREQUAL "ON") - target_link_libraries(milvus_thrift_server ${server_libs} license_check ${knowhere_libs} ${third_party_libs}) - else() - target_link_libraries(milvus_server ${server_libs} license_check ${knowhere_libs} ${third_party_libs}) - endif() - -else () - if(MILVUS_WITH_THRIFT STREQUAL "ON") - target_link_libraries(milvus_thrift_server ${server_libs} ${knowhere_libs} ${third_party_libs}) - else() - target_link_libraries(milvus_server ${server_libs} ${knowhere_libs} ${third_party_libs}) - endif() -endif() - -if (MILVUS_WITH_THRIFT STREQUAL "ON") - install(TARGETS milvus_thrift_server DESTINATION bin) +if(MILVUS_WITH_THRIFT STREQUAL "ON") + target_link_libraries(milvus_server ${server_libs} ${knowhere_libs} ${third_party_libs}) else() - install(TARGETS milvus_server DESTINATION bin) + target_link_libraries(milvus_server ${server_libs} ${knowhere_libs} ${third_party_libs}) endif() + +install(TARGETS milvus_server DESTINATION bin) + install(FILES ${KNOWHERE_BUILD_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}tbb${CMAKE_SHARED_LIBRARY_SUFFIX} ${KNOWHERE_BUILD_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}tbb${CMAKE_SHARED_LIBRARY_SUFFIX}.2 diff --git a/cpp/src/sdk/CMakeLists.txt b/cpp/src/sdk/CMakeLists.txt index 21fec895c1acd8b5f5dc37bf107a1a64cb8fa6f1..8dde7f9f9e98d29cd94a2861f3348ae70e7983f5 100644 --- a/cpp/src/sdk/CMakeLists.txt +++ b/cpp/src/sdk/CMakeLists.txt @@ -23,17 +23,12 @@ if (MILVUS_WITH_THRIFT STREQUAL "ON") ${CMAKE_SOURCE_DIR}/src/thrift/gen-cpp/milvus_types.cpp ) - add_library(milvus_thrift_sdk STATIC + add_library(milvus_sdk STATIC ${interface_files} ${thrift_client_files} ${util_files} ${thrift_service_files} ) - - target_link_libraries(milvus_thrift_sdk - ${third_party_libs} - ) - install(TARGETS milvus_thrift_sdk DESTINATION lib) else() aux_source_directory(grpc grpc_client_files) @@ -47,17 +42,18 @@ else() ${CMAKE_SOURCE_DIR}/src/grpc/gen-status/status.pb.cc ) - add_library(milvus_grpc_sdk STATIC + add_library(milvus_sdk STATIC ${interface_files} ${grpc_client_files} ${util_files} ${grpc_service_files} ) - - target_link_libraries(milvus_grpc_sdk - ${third_party_libs} - ) - install(TARGETS milvus_grpc_sdk DESTINATION lib) endif() +target_link_libraries(milvus_sdk + ${third_party_libs} + ) + +install(TARGETS milvus_sdk DESTINATION lib) + add_subdirectory(examples) diff --git a/cpp/src/sdk/examples/grpcsimple/CMakeLists.txt b/cpp/src/sdk/examples/grpcsimple/CMakeLists.txt index e0dd829ca8b05a315be94ce4c47968622e5c5561..36f63647800d4bb5344d55a3bba053f83aabd55a 100644 --- a/cpp/src/sdk/examples/grpcsimple/CMakeLists.txt +++ b/cpp/src/sdk/examples/grpcsimple/CMakeLists.txt @@ -11,14 +11,14 @@ include_directories(../../include) link_directories(${CMAKE_BINARY_DIR}) -add_executable(grpc_sdk_simple +add_executable(sdk_simple main.cpp ${src_files} ) -target_link_libraries(grpc_sdk_simple - milvus_grpc_sdk +target_link_libraries(sdk_simple + milvus_sdk pthread ) -install(TARGETS grpc_sdk_simple DESTINATION bin) +install(TARGETS sdk_simple DESTINATION bin) diff --git a/cpp/src/sdk/examples/thriftsimple/CMakeLists.txt b/cpp/src/sdk/examples/thriftsimple/CMakeLists.txt index 5c4b4183ce4bfc001032831c29293cd2782f7476..a288965aa3a4a9c3f510120c5c47ccb005374054 100644 --- a/cpp/src/sdk/examples/thriftsimple/CMakeLists.txt +++ b/cpp/src/sdk/examples/thriftsimple/CMakeLists.txt @@ -11,14 +11,14 @@ include_directories(../../include) link_directories(${CMAKE_BINARY_DIR}) -add_executable(thrift_sdk_simple +add_executable(sdk_simple ./main.cpp ${src_files} ) -target_link_libraries(thrift_sdk_simple - milvus_thrift_sdk +target_link_libraries(sdk_simple + milvus_sdk pthread ) -install(TARGETS thrift_sdk_simple DESTINATION bin) +install(TARGETS sdk_simple DESTINATION bin) diff --git a/cpp/src/sdk/examples/thriftsimple/src/ClientTest.cpp b/cpp/src/sdk/examples/thriftsimple/src/ClientTest.cpp index 8af900d78656c208b765c1783f22f6f04b3d734e..38420c64e01a03ccdafd53792341a44e2db735cf 100644 --- a/cpp/src/sdk/examples/thriftsimple/src/ClientTest.cpp +++ b/cpp/src/sdk/examples/thriftsimple/src/ClientTest.cpp @@ -22,7 +22,7 @@ namespace { constexpr int64_t NQ = 10; constexpr int64_t TOP_K = 10; constexpr int64_t SEARCH_TARGET = 5000; //change this value, result is different - constexpr int64_t ADD_VECTOR_LOOP = 10; + constexpr int64_t ADD_VECTOR_LOOP = 5; constexpr int64_t SECONDS_EACH_HOUR = 3600; #define BLOCK_SPLITER std::cout << "===========================================" << std::endl; @@ -173,7 +173,7 @@ namespace { std::vector topk_query_result_array; { TimeRecorder rc(phase_name); - Status stat = conn->SearchVector(TABLE_NAME, record_array, query_range_array, TOP_K, topk_query_result_array); + Status stat = conn->Search(TABLE_NAME, record_array, query_range_array, TOP_K, topk_query_result_array); std::cout << "SearchVector function call status: " << stat.ToString() << std::endl; } @@ -209,7 +209,7 @@ ClientTest::Test(const std::string& address, const std::string& port) { std::cout << "All tables: " << std::endl; for(auto& table : tables) { int64_t row_count = 0; - stat = conn->GetTableRowCount(table, row_count); + stat = conn->CountTable(table, row_count); std::cout << "\t" << table << "(" << row_count << " rows)" << std::endl; } } @@ -241,7 +241,7 @@ ClientTest::Test(const std::string& address, const std::string& port) { int64_t begin_index = i * BATCH_ROW_COUNT; BuildVectors(begin_index, begin_index + BATCH_ROW_COUNT, record_array); std::vector record_ids; - Status stat = conn->AddVector(TABLE_NAME, record_array, record_ids); + Status stat = conn->Insert(TABLE_NAME, record_array, record_ids); std::cout << "AddVector function call status: " << stat.ToString() << std::endl; std::cout << "Returned id array count: " << record_ids.size() << std::endl; @@ -261,7 +261,9 @@ ClientTest::Test(const std::string& address, const std::string& port) { {//wait unit build index finish TimeRecorder recorder("Build index"); std::cout << "Wait until build all index done" << std::endl; - Status stat = conn->BuildIndex(TABLE_NAME); + IndexParam index_param; + index_param.table_name = TABLE_NAME; + Status stat = conn->CreateIndex(index_param); std::cout << "BuildIndex function call status: " << stat.ToString() << std::endl; } @@ -270,7 +272,7 @@ ClientTest::Test(const std::string& address, const std::string& port) { } {//delete table - Status stat = conn->DeleteTable(TABLE_NAME); + Status stat = conn->DropTable(TABLE_NAME); std::cout << "DeleteTable function call status: " << stat.ToString() << std::endl; } diff --git a/cpp/src/sdk/thrift/ClientProxy.cpp b/cpp/src/sdk/thrift/ClientProxy.cpp index 0dc57caa30af0ee1fbc49fd7675501516a622290..dff5b98eb6fbff545e74154632c668634a647dd6 100644 --- a/cpp/src/sdk/thrift/ClientProxy.cpp +++ b/cpp/src/sdk/thrift/ClientProxy.cpp @@ -112,7 +112,7 @@ ClientProxy::HasTable(const std::string &table_name) { } Status -ClientProxy::DeleteTable(const std::string &table_name) { +ClientProxy::DropTable(const std::string &table_name) { if(!IsConnected()) { return Status(StatusCode::NotConnected, "not connected to server"); } @@ -128,18 +128,13 @@ ClientProxy::DeleteTable(const std::string &table_name) { } Status -ClientProxy::DropTable(const std::string &table_name) { - return this->DeleteTable(table_name); -} - -Status -ClientProxy::BuildIndex(const std::string &table_name) { +ClientProxy::CreateIndex(const IndexParam &index_param) { if(!IsConnected()) { return Status(StatusCode::NotConnected, "not connected to server"); } try { - ClientPtr()->interface()->BuildIndex(table_name); + ClientPtr()->interface()->BuildIndex(index_param.table_name); } catch ( std::exception& ex) { return Status(StatusCode::UnknownError, "failed to build index: " + std::string(ex.what())); @@ -149,7 +144,7 @@ ClientProxy::BuildIndex(const std::string &table_name) { } Status -ClientProxy::AddVector(const std::string &table_name, +ClientProxy::Insert(const std::string &table_name, const std::vector &record_array, std::vector &id_array) { if(!IsConnected()) { @@ -179,14 +174,7 @@ ClientProxy::AddVector(const std::string &table_name, } Status -ClientProxy::InsertVector(const std::string &table_name, - const std::vector &record_array, - std::vector &id_array) { - return this->AddVector(table_name, record_array, id_array); -} - -Status -ClientProxy::SearchVector(const std::string &table_name, +ClientProxy::Search(const std::string &table_name, const std::vector &query_record_array, const std::vector &query_range_array, int64_t topk, @@ -277,7 +265,7 @@ ClientProxy::DescribeTable(const std::string &table_name, TableSchema &table_sch } Status -ClientProxy::GetTableRowCount(const std::string &table_name, int64_t &row_count) { +ClientProxy::CountTable(const std::string &table_name, int64_t &row_count) { if(!IsConnected()) { return Status(StatusCode::NotConnected, "not connected to server"); } @@ -337,5 +325,23 @@ ClientProxy::ServerStatus() const { return "connection lost"; } } + +Status ClientProxy::DeleteByRange(Range &range, const std::string &table_name) { + return Status::OK(); +} + +Status ClientProxy::PreloadTable(const std::string &table_name) const { + return Status::OK(); +} + +IndexParam ClientProxy::DescribeIndex(const std::string &table_name) const { + IndexParam index_param; + index_param.table_name = table_name; + return index_param; +} + +Status ClientProxy::DropIndex(const std::string &table_name) const { + return Status::OK(); +} } diff --git a/cpp/src/sdk/thrift/ClientProxy.h b/cpp/src/sdk/thrift/ClientProxy.h index 041fda69d30d05ebab7a2adb8f3c2e06819a6f8d..60e070ba8cd4de443f0f8d8cc611c08becc3e9e0 100644 --- a/cpp/src/sdk/thrift/ClientProxy.h +++ b/cpp/src/sdk/thrift/ClientProxy.h @@ -25,21 +25,15 @@ public: virtual bool HasTable(const std::string &table_name) override; - virtual Status DeleteTable(const std::string &table_name) override; - virtual Status DropTable(const std::string &table_name) override; - virtual Status BuildIndex(const std::string &table_name) override; - - virtual Status AddVector(const std::string &table_name, - const std::vector &record_array, - std::vector &id_array) override; + virtual Status CreateIndex(const IndexParam &index_param) override; - virtual Status InsertVector(const std::string &table_name, + virtual Status Insert(const std::string &table_name, const std::vector &record_array, std::vector &id_array) override; - virtual Status SearchVector(const std::string &table_name, + virtual Status Search(const std::string &table_name, const std::vector &query_record_array, const std::vector &query_range_array, int64_t topk, @@ -47,7 +41,7 @@ public: virtual Status DescribeTable(const std::string &table_name, TableSchema &table_schema) override; - virtual Status GetTableRowCount(const std::string &table_name, int64_t &row_count) override; + virtual Status CountTable(const std::string &table_name, int64_t &row_count) override; virtual Status ShowTables(std::vector &table_array) override; @@ -57,6 +51,14 @@ public: virtual std::string ServerStatus() const override; + virtual Status DeleteByRange(Range &range, const std::string &table_name) override; + + virtual Status PreloadTable(const std::string &table_name) const override; + + virtual IndexParam DescribeIndex(const std::string &table_name) const override; + + virtual Status DropIndex(const std::string &table_name) const override; + private: std::shared_ptr& ClientPtr() const; diff --git a/cpp/src/server/Server.cpp b/cpp/src/server/Server.cpp index a6e2cd9599d9f3fd56f2e2962a4720fc9e961a3e..b73a5aaf73a23e7db0af5e530e1fe28edd674ba3 100644 --- a/cpp/src/server/Server.cpp +++ b/cpp/src/server/Server.cpp @@ -6,11 +6,11 @@ #include #include "Server.h" //#include "ServerConfig.h" -//#ifdef MILVUS_ENABLE_THRIFT +#ifdef MILVUS_ENABLE_THRIFT #include "server/thrift_impl/MilvusServer.h" -//#else +#else #include "server/grpc_impl/GrpcMilvusServer.h" -//#endif +#endif #include "utils/Log.h" #include "utils/SignalUtil.h" @@ -225,15 +225,20 @@ Server::LoadConfig() { void Server::StartService() { -// std::thread thrift_thread = std::thread(&MilvusServer::StartService); +#ifdef MILVUS_ENABLE_THRIFT + MilvusServer::StartService(); +#else grpc::GrpcMilvusServer::StartService(); -// thrift_thread.join(); +#endif } void Server::StopService() { -// MilvusServer::StartService(); +#ifdef MILVUS_ENABLE_THRIFT + MilvusServer::StopService(); +#else grpc::GrpcMilvusServer::StopService(); +#endif } }