1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

Remove global lock from OAMCache

Config now uses a single atomic variable to speed up its operations
Config has a special method to re-read a config file if it changed on disk
This commit is contained in:
Roman Nozdrin
2021-03-19 16:28:51 +00:00
committed by Roman Nozdrin
parent b0da7f4974
commit 2aa5380d51
5 changed files with 125 additions and 110 deletions

View File

@ -21,10 +21,10 @@
#include <cassert>
#include <map>
#include <set>
#include <atomic>
using namespace std;
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
using namespace boost;
#define OAMCACHE_DLLEXPORT
@ -38,19 +38,27 @@ using namespace boost;
namespace
{
oam::OamCache* oamCache = 0;
boost::mutex cacheLock;
oam::OamCache* oamCache = nullptr;
boost::mutex cacheLock;
}
namespace oam
{
std::atomic_bool hasOAMCache{false};
OamCache* OamCache::makeOamCache()
{
boost::mutex::scoped_lock lk(cacheLock);
if (!hasOAMCache.load(std::memory_order_relaxed))
{
boost::mutex::scoped_lock lk(cacheLock);
if (oamCache == 0)
oamCache = new OamCache();
if (oamCache == nullptr)
{
oamCache = new OamCache();
oamCache->checkReload();
hasOAMCache.store(true, std::memory_order_relaxed);
}
}
return oamCache;
}
@ -80,7 +88,7 @@ void OamCache::checkReload()
dbRootPMMap.reset(new map<int, int>());
//cout << "reloading oamcache\n";
//cerr << "reloading oamcache\n";
for (uint32_t i = 0; i < dbroots.size(); i++)
{
oam.getDbrootPmConfig(dbroots[i], temp);
@ -154,64 +162,41 @@ void OamCache::checkReload()
OamCache::dbRootPMMap_t OamCache::getDBRootToPMMap()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return dbRootPMMap;
}
OamCache::dbRootPMMap_t OamCache::getDBRootToConnectionMap()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return dbRootConnectionMap;
}
OamCache::PMDbrootsMap_t OamCache::getPMToDbrootsMap()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return pmDbrootsMap;
}
uint32_t OamCache::getDBRootCount()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return numDBRoots;
}
DBRootConfigList& OamCache::getDBRootNums()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return dbroots;
}
std::vector<int>& OamCache::getModuleIds()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return moduleIds;
}
std::string OamCache::getOAMParentModuleName()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return OAMParentModuleName;
}
int OamCache::getLocalPMId()
{
boost::mutex::scoped_lock lk(cacheLock);
// This comes from the file /var/lib/columnstore/local/module, not from the xml.
// Thus, it's not refreshed during checkReload().
if (mLocalPMId > 0)
@ -252,16 +237,11 @@ int OamCache::getLocalPMId()
string OamCache::getSystemName()
{
boost::mutex::scoped_lock lk(cacheLock);
checkReload();
return systemName;
}
string OamCache::getModuleName()
{
boost::mutex::scoped_lock lk(cacheLock);
if (!moduleName.empty())
return moduleName;