diff --git a/src/collection.cpp b/src/collection.cpp index 05268e26..5b83ab6a 100644 --- a/src/collection.cpp +++ b/src/collection.cpp @@ -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]; } diff --git a/src/collection_manager.cpp b/src/collection_manager.cpp index bf88c86d..5d1ea24b 100644 --- a/src/collection_manager.cpp +++ b/src/collection_manager.cpp @@ -328,7 +328,9 @@ std::vector CollectionManager::get_collections() const { } Option 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(404, "No collection with name `" + collection_name + "` found."); @@ -357,7 +359,7 @@ Option 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(collection_json); } diff --git a/src/index.cpp b/src/index.cpp index 203ace2c..83278f55 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -48,6 +48,8 @@ Index::Index(const std::string name, const std::unordered_map 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 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();