diff --git a/cpp/src/db/Utils.cpp b/cpp/src/db/Utils.cpp index f03624451bc17aae3a0ae02d0d4a9b3d5d68d43e..2c9173f6a7bce29e74f03e7f5afaf587524b0da8 100644 --- a/cpp/src/db/Utils.cpp +++ b/cpp/src/db/Utils.cpp @@ -135,7 +135,7 @@ Status GetTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& tab } } - std::string msg = "Table file doesn't exist: " + table_file.file_id_; + std::string msg = "Table file doesn't exist: " + file_path; ENGINE_LOG_ERROR << msg; return Status(DB_ERROR, msg); } diff --git a/cpp/src/db/meta/MySQLMetaImpl.cpp b/cpp/src/db/meta/MySQLMetaImpl.cpp index 19ac25b8862adaf05d17904e66c61cbb185d1300..2910210a50fd03db10d3a400a87bb29797cc9002 100644 --- a/cpp/src/db/meta/MySQLMetaImpl.cpp +++ b/cpp/src/db/meta/MySQLMetaImpl.cpp @@ -814,7 +814,6 @@ Status MySQLMetaImpl::CreateTableFile(TableFileSchema &file_schema) { file_schema.engine_type_ = table_schema.engine_type_; file_schema.nlist_ = table_schema.nlist_; file_schema.metric_type_ = table_schema.metric_type_; - utils::GetTableFilePath(options_, file_schema); std::string id = "NULL"; //auto-increment std::string table_id = file_schema.table_id_; @@ -924,7 +923,10 @@ Status MySQLMetaImpl::FilesToIndex(TableFilesSchema &files) { table_file.nlist_ = groups[table_file.table_id_].nlist_; table_file.metric_type_ = groups[table_file.table_id_].metric_type_; - utils::GetTableFilePath(options_, table_file); + auto status = utils::GetTableFilePath(options_, table_file); + if(!status.ok()) { + return status; + } files.push_back(table_file); } @@ -1027,7 +1029,10 @@ Status MySQLMetaImpl::FilesToSearch(const std::string &table_id, table_file.dimension_ = table_schema.dimension_; - utils::GetTableFilePath(options_, table_file); + auto status = utils::GetTableFilePath(options_, table_file); + if(!status.ok()) { + return status; + } auto dateItr = files.find(table_file.date_); if (dateItr == files.end()) { @@ -1113,7 +1118,10 @@ Status MySQLMetaImpl::FilesToMerge(const std::string &table_id, table_file.dimension_ = table_schema.dimension_; - utils::GetTableFilePath(options_, table_file); + auto status = utils::GetTableFilePath(options_, table_file); + if(!status.ok()) { + return status; + } auto dateItr = files.find(table_file.date_); if (dateItr == files.end()) { @@ -1203,7 +1211,10 @@ Status MySQLMetaImpl::GetTableFiles(const std::string &table_id, file_schema.dimension_ = table_schema.dimension_; - utils::GetTableFilePath(options_, file_schema); + auto status = utils::GetTableFilePath(options_, file_schema); + if(!status.ok()) { + return status; + } table_files.emplace_back(file_schema); } diff --git a/cpp/src/db/meta/SqliteMetaImpl.cpp b/cpp/src/db/meta/SqliteMetaImpl.cpp index 559ffd29ff06f7a79c65d4e0f6147aa0d49e54a1..730a3035ea3396485ca4e354fb872c575a3c3308 100644 --- a/cpp/src/db/meta/SqliteMetaImpl.cpp +++ b/cpp/src/db/meta/SqliteMetaImpl.cpp @@ -614,7 +614,10 @@ Status SqliteMetaImpl::FilesToIndex(TableFilesSchema &files) { table_file.engine_type_ = std::get<7>(file); table_file.created_on_ = std::get<8>(file); - utils::GetTableFilePath(options_, table_file); + auto status = utils::GetTableFilePath(options_, table_file); + if(!status.ok()) { + return status; + } auto groupItr = groups.find(table_file.table_id_); if (groupItr == groups.end()) { TableSchema table_schema; @@ -707,7 +710,11 @@ Status SqliteMetaImpl::FilesToSearch(const std::string &table_id, table_file.nlist_ = table_schema.nlist_; table_file.metric_type_ = table_schema.metric_type_; - utils::GetTableFilePath(options_, table_file); + auto status = utils::GetTableFilePath(options_, table_file); + if(!status.ok()) { + return status; + } + auto dateItr = files.find(table_file.date_); if (dateItr == files.end()) { files[table_file.date_] = TableFilesSchema(); @@ -773,7 +780,11 @@ Status SqliteMetaImpl::FilesToMerge(const std::string &table_id, table_file.nlist_ = table_schema.nlist_; table_file.metric_type_ = table_schema.metric_type_; - utils::GetTableFilePath(options_, table_file); + auto status = utils::GetTableFilePath(options_, table_file); + if(!status.ok()) { + return status; + } + auto dateItr = files.find(table_file.date_); if (dateItr == files.end()) { files[table_file.date_] = TableFilesSchema(); @@ -827,7 +838,10 @@ Status SqliteMetaImpl::GetTableFiles(const std::string& table_id, file_schema.nlist_ = table_schema.nlist_; file_schema.metric_type_ = table_schema.metric_type_; - utils::GetTableFilePath(options_, file_schema); + auto status = utils::GetTableFilePath(options_, file_schema); + if(!status.ok()) { + return status; + } table_files.emplace_back(file_schema); } diff --git a/cpp/unittest/db/db_tests.cpp b/cpp/unittest/db/db_tests.cpp index 2c300849b429b5a7574a09a6dee0423f6e467c83..67d61a05c29ef96b35db9e82c876561f657a7d92 100644 --- a/cpp/unittest/db/db_tests.cpp +++ b/cpp/unittest/db/db_tests.cpp @@ -315,6 +315,79 @@ TEST_F(DBTest, PRELOADTABLE_TEST) { } +TEST_F(DBTest, SHUTDOWN_TEST) { + db_->Stop(); + + engine::meta::TableSchema table_info = BuildTableSchema(); + engine::Status stat = db_->CreateTable(table_info); + ASSERT_FALSE(stat.ok()); + + stat = db_->DescribeTable(table_info); + ASSERT_FALSE(stat.ok()); + + bool has_table = false; + stat = db_->HasTable(table_info.table_id_, has_table); + ASSERT_FALSE(stat.ok()); + + engine::IDNumbers ids; + stat = db_->InsertVectors(table_info.table_id_, 0, nullptr, ids); + ASSERT_FALSE(stat.ok()); + + stat = db_->PreloadTable(table_info.table_id_); + ASSERT_FALSE(stat.ok()); + + uint64_t row_count = 0; + stat = db_->GetTableRowCount(table_info.table_id_, row_count); + ASSERT_FALSE(stat.ok()); + + engine::TableIndex index; + stat = db_->CreateIndex(table_info.table_id_, index); + ASSERT_FALSE(stat.ok()); + + stat = db_->DescribeIndex(table_info.table_id_, index); + ASSERT_FALSE(stat.ok()); + + engine::meta::DatesT dates; + engine::QueryResults results; + stat = db_->Query(table_info.table_id_, 1, 1, 1, nullptr, dates, results); + ASSERT_FALSE(stat.ok()); + std::vector file_ids; + stat = db_->Query(table_info.table_id_, file_ids, 1, 1, 1, nullptr, dates, results); + ASSERT_FALSE(stat.ok()); + + stat = db_->DeleteTable(table_info.table_id_, dates); + ASSERT_FALSE(stat.ok()); +} + +TEST_F(DBTest, INDEX_TEST) { + engine::meta::TableSchema table_info = BuildTableSchema(); + engine::Status stat = db_->CreateTable(table_info); + + int64_t nb = VECTOR_COUNT; + std::vector xb; + BuildVectors(nb, xb); + + engine::IDNumbers vector_ids; + db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); + ASSERT_EQ(vector_ids.size(), nb); + + engine::TableIndex index; + index.engine_type_ = (int)engine::EngineType::FAISS_IVFSQ8; + index.metric_type_ = (int)engine::MetricType::IP; + stat = db_->CreateIndex(table_info.table_id_, index); + ASSERT_TRUE(stat.ok()); + + engine::TableIndex index_out; + stat = db_->DescribeIndex(table_info.table_id_, index); + ASSERT_TRUE(stat.ok()); + ASSERT_EQ(index.engine_type_, index_out.engine_type_); + ASSERT_EQ(index.nlist_, index_out.nlist_); + ASSERT_EQ(index.metric_type_, index_out.metric_type_); + + stat = db_->DropIndex(table_info.table_id_); + ASSERT_TRUE(stat.ok()); +} + TEST_F(DBTest2, ARHIVE_DISK_CHECK) { engine::meta::TableSchema table_info = BuildTableSchema(); diff --git a/cpp/unittest/server/util_test.cpp b/cpp/unittest/server/util_test.cpp index 68e74a846f2402509b9f386293c60d4fc716843c..730eedbd33392f34b312c8e51bec416573d5db11 100644 --- a/cpp/unittest/server/util_test.cpp +++ b/cpp/unittest/server/util_test.cpp @@ -5,6 +5,7 @@ //////////////////////////////////////////////////////////////////////////////// #include #include +#include #include "utils/CommonUtil.h" #include "utils/Error.h"