Unique lock before dropping a collection.

This commit is contained in:
Kishore Nallan 2021-04-11 20:15:48 +05:30
parent 60a5cff291
commit 68e25fac09
3 changed files with 9 additions and 2 deletions

View File

@ -54,6 +54,8 @@ Collection::Collection(const std::string& name, const uint32_t collection_id, co
}
Collection::~Collection() {
std::unique_lock lock(mutex);
for(size_t i = 0; i < indices.size(); i++) {
delete indices[i];
}

View File

@ -328,7 +328,9 @@ std::vector<Collection*> CollectionManager::get_collections() const {
}
Option<nlohmann::json> CollectionManager::drop_collection(const std::string& collection_name, const bool remove_from_store) {
auto collection = get_collection(collection_name); // locked_resource_view_t
std::unique_lock lock(mutex);
auto collection = get_collection_unsafe(collection_name);
if(collection == nullptr) {
return Option<nlohmann::json>(404, "No collection with name `" + collection_name + "` found.");
@ -357,7 +359,7 @@ Option<nlohmann::json> CollectionManager::drop_collection(const std::string& col
collections.erase(actual_coll_name);
collection_id_names.erase(collection->get_collection_id());
delete collection.get();
delete collection;
return Option<nlohmann::json>(collection_json);
}

View File

@ -48,6 +48,8 @@ Index::Index(const std::string name, const std::unordered_map<std::string, field
}
Index::~Index() {
std::unique_lock lock(mutex);
for(auto & name_tree: search_index) {
art_tree_destroy(name_tree.second);
delete name_tree.second;
@ -388,6 +390,7 @@ Option<uint32_t> Index::validate_index_in_memory(nlohmann::json& document, uint3
void Index::scrub_reindex_doc(nlohmann::json& update_doc, nlohmann::json& del_doc, nlohmann::json& old_doc) {
std::vector<std::string> del_keys;
std::shared_lock lock(mutex);
for(auto it = del_doc.cbegin(); it != del_doc.cend(); it++) {
const std::string& field_name = it.key();