Skip to content

Commit

Permalink
fix hastable bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmo committed Feb 26, 2020
1 parent 954b48d commit bfe012a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
3 changes: 3 additions & 0 deletions core/src/db/DB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<meta::TableSchema>& table_schema_array) = 0;

Expand Down
44 changes: 37 additions & 7 deletions core/src/db/DBImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<meta::TableSchema>& table_schema_array) {
if (!initialized_.load(std::memory_order_acquire)) {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions core/src/db/DBImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<meta::TableSchema>& table_schema_array) override;

Expand Down
2 changes: 1 addition & 1 deletion core/src/server/delivery/request/HasTableRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
10 changes: 10 additions & 0 deletions core/unittest/db/test_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bfe012a

Please sign in to comment.