Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Properly handle deleting collection via an alias.

kishorenc222ab345be3e
diff --git a/src/collection_manager.cpp b/src/collection_manager.cpp
index ba6e9447..4a25e9b6 100644
--- a/src/collection_manager.cpp
+++ b/src/collection_manager.cpp
@@ -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;
diff --git a/test/collection_manager_test.cpp b/test/collection_manager_test.cpp
index 2b49a754..8ce28d31 100644
--- a/test/collection_manager_test.cpp
+++ b/test/collection_manager_test.cpp
@@ -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");