diff --git a/core/src/db/DB.h b/core/src/db/DB.h index 9275568ea9eec..f70b806473065 100644 --- a/core/src/db/DB.h +++ b/core/src/db/DB.h @@ -52,6 +52,9 @@ class DB { virtual Status HasTable(const std::string& table_id, bool& has_or_not_) = 0; + virtual Status + HasNativeTable(const std::string& table_id, bool& has_or_not_) = 0; + virtual Status AllTables(std::vector& table_schema_array) = 0; diff --git a/core/src/db/DBImpl.cpp b/core/src/db/DBImpl.cpp index 4529e9a615ba7..c01494d134fd1 100644 --- a/core/src/db/DBImpl.cpp +++ b/core/src/db/DBImpl.cpp @@ -219,6 +219,29 @@ DBImpl::HasTable(const std::string& table_id, bool& has_or_not) { return meta_ptr_->HasTable(table_id, has_or_not); } +Status +DBImpl::HasNativeTable(const std::string& table_id, bool& has_or_not_) { + if (!initialized_.load(std::memory_order_acquire)) { + return SHUTDOWN_ERROR; + } + + engine::meta::TableSchema table_schema; + table_schema.table_id_ = table_id; + auto status = DescribeTable(table_schema); + if (!status.ok()) { + has_or_not_ = false; + return status; + } else { + if (!table_schema.owner_table_.empty()) { + has_or_not_ = false; + return Status(DB_NOT_FOUND, ""); + } + + has_or_not_ = true; + return Status::OK(); + } +} + Status DBImpl::AllTables(std::vector& table_schema_array) { if (!initialized_.load(std::memory_order_acquire)) { @@ -589,14 +612,21 @@ DBImpl::Compact(const std::string& table_id) { return SHUTDOWN_ERROR; } - bool has_table; - auto status = HasTable(table_id, has_table); - if (!has_table) { - ENGINE_LOG_ERROR << "Table to compact does not exist: " << table_id; - return Status(DB_NOT_FOUND, "Table to compact does not exist"); - } + engine::meta::TableSchema table_schema; + table_schema.table_id_ = table_id; + auto status = DescribeTable(table_schema); if (!status.ok()) { - return Status(DB_ERROR, status.message()); + if (status.code() == DB_NOT_FOUND) { + ENGINE_LOG_ERROR << "Table to compact does not exist: " << table_id; + return Status(DB_NOT_FOUND, "Table to compact does not exist"); + } else { + return status; + } + } else { + if (!table_schema.owner_table_.empty()) { + ENGINE_LOG_ERROR << "Table to compact does not exist: " << table_id; + return Status(DB_NOT_FOUND, "Table to compact does not exist"); + } } ENGINE_LOG_DEBUG << "Compacting table: " << table_id; diff --git a/core/src/db/DBImpl.h b/core/src/db/DBImpl.h index 6529cb513f131..7c0de3a7b844a 100644 --- a/core/src/db/DBImpl.h +++ b/core/src/db/DBImpl.h @@ -61,6 +61,9 @@ class DBImpl : public DB { Status HasTable(const std::string& table_id, bool& has_or_not) override; + Status + HasNativeTable(const std::string& table_id, bool& has_or_not_) override; + Status AllTables(std::vector& table_schema_array) override; diff --git a/core/src/server/delivery/request/HasTableRequest.cpp b/core/src/server/delivery/request/HasTableRequest.cpp index d5aec6fb16cef..ccde75772b2f3 100644 --- a/core/src/server/delivery/request/HasTableRequest.cpp +++ b/core/src/server/delivery/request/HasTableRequest.cpp @@ -44,7 +44,7 @@ HasTableRequest::OnExecute() { } // step 2: check table existence - status = DBWrapper::DB()->HasTable(table_name_, has_table_); + status = DBWrapper::DB()->HasNativeTable(table_name_, has_table_); fiu_do_on("HasTableRequest.OnExecute.table_not_exist", status = Status(milvus::SERVER_UNEXPECTED_ERROR, "")); fiu_do_on("HasTableRequest.OnExecute.throw_std_exception", throw std::exception()); if (!status.ok()) { diff --git a/core/unittest/db/test_db.cpp b/core/unittest/db/test_db.cpp index c916d22c41024..d986176b6de35 100644 --- a/core/unittest/db/test_db.cpp +++ b/core/unittest/db/test_db.cpp @@ -793,6 +793,16 @@ TEST_F(DBTest, PARTITION_TEST) { ASSERT_EQ(partition_schema_array[i].table_id_, table_name + "_" + std::to_string(i)); } + // check table existence + std::string special_part = "special"; + stat = db_->CreatePartition(table_name, special_part, special_part); + ASSERT_TRUE(stat.ok()); + bool has_table = false; + stat = db_->HasNativeTable(special_part, has_table); + ASSERT_FALSE(has_table); + stat = db_->HasTable(special_part, has_table); + ASSERT_TRUE(has_table); + { // build index milvus::engine::TableIndex index; index.engine_type_ = (int)milvus::engine::EngineType::FAISS_IVFFLAT;