From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/rgw/driver/dbstore/dbstore_mgr.cc | 140 ++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/rgw/driver/dbstore/dbstore_mgr.cc (limited to 'src/rgw/driver/dbstore/dbstore_mgr.cc') diff --git a/src/rgw/driver/dbstore/dbstore_mgr.cc b/src/rgw/driver/dbstore/dbstore_mgr.cc new file mode 100644 index 000000000..6835f526b --- /dev/null +++ b/src/rgw/driver/dbstore/dbstore_mgr.cc @@ -0,0 +1,140 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "dbstore_mgr.h" +#include "common/dbstore_log.h" + +#include + +static constexpr auto dout_subsys = ceph_subsys_rgw; + +using namespace std; + + +/* Given a tenant, find and return the DBStore handle. + * If not found and 'create' set to true, create one + * and return + */ +DB *DBStoreManager::getDB (string tenant, bool create) +{ + map::iterator iter; + DB *dbs = nullptr; + pair::iterator,bool> ret; + + if (tenant.empty()) + return default_db; + + if (DBStoreHandles.empty()) + goto not_found; + + iter = DBStoreHandles.find(tenant); + + if (iter != DBStoreHandles.end()) + return iter->second; + +not_found: + if (!create) + return nullptr; + + dbs = createDB(tenant); + + return dbs; +} + +/* Create DBStore instance */ +DB *DBStoreManager::createDB(std::string tenant) { + DB *dbs = nullptr; + pair::iterator,bool> ret; + const auto& db_path = g_conf().get_val("dbstore_db_dir"); + const auto& db_name = g_conf().get_val("dbstore_db_name_prefix") + "-" + tenant; + + auto db_full_path = std::filesystem::path(db_path) / db_name; + ldout(cct, 0) << "DB initialization full db_path("<Initialize("", -1) < 0) { + ldout(cct, 0) << "DB initialization failed for tenant("<(tenant, dbs)); + + /* + * Its safe to check for already existing entry (just + * incase other thread raced and created the entry) + */ + if (ret.second == false) { + /* Entry already created by another thread */ + delete dbs; + + dbs = ret.first->second; + } + + return dbs; +} + +void DBStoreManager::deleteDB(string tenant) { + map::iterator iter; + DB *dbs = nullptr; + + if (tenant.empty() || DBStoreHandles.empty()) + return; + + /* XXX: Check if we need to perform this operation under a lock */ + iter = DBStoreHandles.find(tenant); + + if (iter == DBStoreHandles.end()) + return; + + dbs = iter->second; + + DBStoreHandles.erase(iter); + dbs->Destroy(dbs->get_def_dpp()); + delete dbs; + + return; +} + +void DBStoreManager::deleteDB(DB *dbs) { + if (!dbs) + return; + + (void)deleteDB(dbs->getDBname()); +} + + +void DBStoreManager::destroyAllHandles(){ + map::iterator iter; + DB *dbs = nullptr; + + if (DBStoreHandles.empty()) + return; + + for (iter = DBStoreHandles.begin(); iter != DBStoreHandles.end(); + ++iter) { + dbs = iter->second; + dbs->Destroy(dbs->get_def_dpp()); + delete dbs; + } + + DBStoreHandles.clear(); + + return; +} + + -- cgit v1.2.3