@@ -263,6 +263,7 @@ Status BasicMetaImpl::LoadDatabase(const std::string& db_catalog_path, const std
263263 }
264264
265265 databases_[db_name] = db_schema;
266+ db_mutexes_[db_name]; // Initializes a mutex for the new database
266267 loaded_databases_paths_.insert (db_catalog_path);
267268
268269 return Status::OK ();
@@ -304,6 +305,7 @@ Status BasicMetaImpl::DropDatabase(const std::string& db_name) {
304305 }
305306 loaded_databases_paths_.erase (path);
306307 databases_.erase (db_name);
308+ db_mutexes_.erase (db_name); // Remove mutex for the dropped database
307309 return Status::OK ();
308310}
309311
@@ -445,6 +447,7 @@ Status ValidateSchema(TableSchema& table_schema, std::vector<EmbeddingModel> &em
445447}
446448
447449Status BasicMetaImpl::CreateTable (const std::string& db_name, TableSchema& table_schema, size_t & table_id) {
450+ std::lock_guard<std::mutex> lock (db_mutexes_[db_name]); // Acquire lock for this database
448451 // Table name cannot be duplicated.
449452 bool has_table = false ;
450453 auto status = HasTable (db_name, table_schema.name_ , has_table);
@@ -519,6 +522,7 @@ Status BasicMetaImpl::GetTable(const std::string& db_name, const std::string& ta
519522}
520523
521524Status BasicMetaImpl::DropTable (const std::string& db_name, const std::string& table_name) {
525+ std::lock_guard<std::mutex> lock (db_mutexes_[db_name]); // Acquire lock for this database
522526 auto it = databases_.find (db_name);
523527 if (it == databases_.end ()) {
524528 return Status (DB_NOT_FOUND, " Database not found: " + db_name);
0 commit comments