Properly handle deleting collection via an alias.

This commit is contained in:
kishorenc 2021-02-20 20:05:54 +05:30
parent b191a74016
commit 222ab345be
2 changed files with 15 additions and 3 deletions

View File

@ -413,6 +413,9 @@ Option<nlohmann::json> CollectionManager::drop_collection(const std::string& col
return Option<nlohmann::json>(404, "No collection with name `" + collection_name + "` found.");
}
// to handle alias resolution
const std::string actual_coll_name = collection->get_name();
nlohmann::json collection_json = collection->get_summary_json();
if(remove_from_store) {
@ -426,11 +429,11 @@ Option<nlohmann::json> CollectionManager::drop_collection(const std::string& col
}
delete iter;
store->remove(Collection::get_next_seq_id_key(collection_name));
store->remove(Collection::get_meta_key(collection_name));
store->remove(Collection::get_next_seq_id_key(actual_coll_name));
store->remove(Collection::get_meta_key(actual_coll_name));
}
collections.erase(collection_name);
collections.erase(actual_coll_name);
collection_id_names.erase(collection->get_collection_id());
delete collection;

View File

@ -435,6 +435,15 @@ TEST_F(CollectionManagerTest, Symlinking) {
ASSERT_TRUE(collection_option.ok());
ASSERT_EQ("collection1", collection_option.get());
// try to drop a collection using the alias `collection1_link`
auto drop_op = cmanager.drop_collection("collection1_link");
ASSERT_TRUE(drop_op.ok());
// try to list collections now
nlohmann::json summaries = cmanager.get_collection_summaries();
ASSERT_EQ(0, summaries.size());
// remap alias to another non-existing collection
inserted = cmanager.upsert_symlink("collection1_link", "collection2");
ASSERT_TRUE(inserted.ok());
collection_option = cmanager.resolve_symlink("collection1_link");