You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-3557: add config change listeners.
This commit is contained in:
@ -56,24 +56,11 @@ Cache::Cache()
|
|||||||
Config *conf = Config::get();
|
Config *conf = Config::get();
|
||||||
logger = SMLogging::get();
|
logger = SMLogging::get();
|
||||||
|
|
||||||
string stmp = conf->getValue("Cache", "cache_size");
|
configListener();
|
||||||
if (stmp.empty())
|
conf->addConfigListener(this);
|
||||||
{
|
|
||||||
logger->log(LOG_CRIT, "Cache/cache_size is not set");
|
|
||||||
throw runtime_error("Please set Cache/cache_size in the storagemanager.cnf file");
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
maxCacheSize = stoul(stmp);
|
|
||||||
}
|
|
||||||
catch (invalid_argument &)
|
|
||||||
{
|
|
||||||
logger->log(LOG_CRIT, "Cache/cache_size is not a number");
|
|
||||||
throw runtime_error("Please set Cache/cache_size to a number");
|
|
||||||
}
|
|
||||||
//cout << "Cache got cache size " << maxCacheSize << endl;
|
//cout << "Cache got cache size " << maxCacheSize << endl;
|
||||||
|
|
||||||
stmp = conf->getValue("ObjectStorage", "object_size");
|
string stmp = conf->getValue("ObjectStorage", "object_size");
|
||||||
if (stmp.empty())
|
if (stmp.empty())
|
||||||
{
|
{
|
||||||
logger->log(LOG_CRIT, "ObjectStorage/object_size is not set");
|
logger->log(LOG_CRIT, "ObjectStorage/object_size is not set");
|
||||||
@ -129,6 +116,7 @@ Cache::Cache()
|
|||||||
|
|
||||||
Cache::~Cache()
|
Cache::~Cache()
|
||||||
{
|
{
|
||||||
|
Config::get()->removeConfigListener(this);
|
||||||
for (auto it = prefixCaches.begin(); it != prefixCaches.end(); ++it)
|
for (auto it = prefixCaches.begin(); it != prefixCaches.end(); ++it)
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
@ -334,6 +322,39 @@ void Cache::shutdown()
|
|||||||
downloader.reset();
|
downloader.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Cache::configListener()
|
||||||
|
{
|
||||||
|
Config *conf = Config::get();
|
||||||
|
SMLogging* logger = SMLogging::get();
|
||||||
|
|
||||||
|
if (maxCacheSize == 0)
|
||||||
|
maxCacheSize = 2147483648;
|
||||||
|
string stmp = conf->getValue("Cache", "cache_size");
|
||||||
|
if (stmp.empty())
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "Cache/cache_size is not set. Using current value = %zi",maxCacheSize);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
size_t newMaxCacheSize = stoull(stmp);
|
||||||
|
if (newMaxCacheSize != maxCacheSize)
|
||||||
|
{
|
||||||
|
if (newMaxCacheSize >= MIN_CACHE_SIZE)
|
||||||
|
{
|
||||||
|
setMaxCacheSize(newMaxCacheSize);
|
||||||
|
logger->log(LOG_INFO, "Cache/cache_size = %zi",maxCacheSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "Cache/cache_size is below %u. Check value and suffix are correct in configuration file. Using current value = %zi",MIN_CACHE_SIZE,maxCacheSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (invalid_argument &)
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "Cache/cache_size is not a number. Using current value = %zi",maxCacheSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "Downloader.h"
|
#include "Downloader.h"
|
||||||
#include "SMLogging.h"
|
#include "SMLogging.h"
|
||||||
#include "PrefixCache.h"
|
#include "PrefixCache.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -35,10 +36,16 @@
|
|||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
|
|
||||||
|
// Setting to min possible based on
|
||||||
|
// using 1k in config file. If wrong
|
||||||
|
// letter is used will not value be
|
||||||
|
// set to less than 1k
|
||||||
|
#define MIN_CACHE_SIZE 1024
|
||||||
|
|
||||||
namespace storagemanager
|
namespace storagemanager
|
||||||
{
|
{
|
||||||
|
|
||||||
class Cache : public boost::noncopyable
|
class Cache : public boost::noncopyable , public ConfigListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Cache *get();
|
static Cache *get();
|
||||||
@ -94,6 +101,7 @@ class Cache : public boost::noncopyable
|
|||||||
void reset();
|
void reset();
|
||||||
void validateCacheSize();
|
void validateCacheSize();
|
||||||
|
|
||||||
|
virtual void configListener() override;
|
||||||
private:
|
private:
|
||||||
Cache();
|
Cache();
|
||||||
|
|
||||||
|
@ -131,7 +131,8 @@ void Config::reloadThreadFcn()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
reload();
|
reload();
|
||||||
// TODO: add a listener interface to inform upstream of config changes
|
for (auto& listener : configListeners)
|
||||||
|
listener->configListener();
|
||||||
boost::this_thread::sleep(reloadInterval);
|
boost::this_thread::sleep(reloadInterval);
|
||||||
}
|
}
|
||||||
catch (boost::property_tree::ini_parser_error &e)
|
catch (boost::property_tree::ini_parser_error &e)
|
||||||
@ -207,4 +208,17 @@ string Config::getValue(const string §ion, const string &key) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Config::addConfigListener(ConfigListener *listener)
|
||||||
|
{
|
||||||
|
configListeners.push_back(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::removeConfigListener(ConfigListener *listener)
|
||||||
|
{
|
||||||
|
auto iterator = std::find(configListeners.begin(), configListeners.end(), listener);
|
||||||
|
|
||||||
|
if (iterator != configListeners.end())
|
||||||
|
configListeners.erase(iterator);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,20 @@
|
|||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/* TODO. Need a config change listener impl. */
|
/* TODO. Need a config change listener impl. */
|
||||||
|
|
||||||
namespace storagemanager
|
namespace storagemanager
|
||||||
{
|
{
|
||||||
|
class ConfigListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void configListener() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class Config : public boost::noncopyable
|
class Config : public boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -39,13 +46,17 @@ class Config : public boost::noncopyable
|
|||||||
|
|
||||||
// for testing, lets caller specify a config file to use
|
// for testing, lets caller specify a config file to use
|
||||||
static Config *get(const std::string &);
|
static Config *get(const std::string &);
|
||||||
|
|
||||||
|
void addConfigListener(ConfigListener *listener);
|
||||||
|
void removeConfigListener(ConfigListener *listener);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config();
|
Config();
|
||||||
Config(const std::string &);
|
Config(const std::string &);
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
void reloadThreadFcn();
|
void reloadThreadFcn();
|
||||||
|
std::vector<ConfigListener *> configListeners;
|
||||||
struct ::timespec last_mtime;
|
struct ::timespec last_mtime;
|
||||||
mutable boost::mutex mutex;
|
mutable boost::mutex mutex;
|
||||||
boost::thread reloader;
|
boost::thread reloader;
|
||||||
@ -56,6 +67,9 @@ class Config : public boost::noncopyable
|
|||||||
bool die;
|
bool die;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,17 +31,8 @@ namespace storagemanager
|
|||||||
Downloader::Downloader() : maxDownloads(0)
|
Downloader::Downloader() : maxDownloads(0)
|
||||||
{
|
{
|
||||||
storage = CloudStorage::get();
|
storage = CloudStorage::get();
|
||||||
string sMaxDownloads = Config::get()->getValue("ObjectStorage", "max_concurrent_downloads");
|
configListener();
|
||||||
try
|
Config::get()->addConfigListener(this);
|
||||||
{
|
|
||||||
maxDownloads = stoul(sMaxDownloads);
|
|
||||||
}
|
|
||||||
catch(invalid_argument)
|
|
||||||
{
|
|
||||||
logger->log(LOG_WARNING, "Downloader: Invalid arg for ObjectStorage/max_concurrent_downloads, using default of 20");
|
|
||||||
}
|
|
||||||
if (maxDownloads == 0)
|
|
||||||
maxDownloads = 20;
|
|
||||||
workers.setMaxThreads(maxDownloads);
|
workers.setMaxThreads(maxDownloads);
|
||||||
workers.setName("Downloader");
|
workers.setName("Downloader");
|
||||||
logger = SMLogging::get();
|
logger = SMLogging::get();
|
||||||
@ -51,6 +42,7 @@ Downloader::Downloader() : maxDownloads(0)
|
|||||||
|
|
||||||
Downloader::~Downloader()
|
Downloader::~Downloader()
|
||||||
{
|
{
|
||||||
|
Config::get()->removeConfigListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Downloader::download(const vector<const string *> &keys, vector<int> *errnos, vector<size_t> *sizes,
|
void Downloader::download(const vector<const string *> &keys, vector<int> *errnos, vector<size_t> *sizes,
|
||||||
@ -216,4 +208,29 @@ inline bool Downloader::DLEquals::operator()(const boost::shared_ptr<Download> &
|
|||||||
return (d1->key == d2->key);
|
return (d1->key == d2->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Downloader::configListener()
|
||||||
|
{
|
||||||
|
// Downloader threads
|
||||||
|
string stmp = Config::get()->getValue("ObjectStorage", "max_concurrent_downloads");
|
||||||
|
if (maxDownloads == 0)
|
||||||
|
maxDownloads = 20;
|
||||||
|
if (stmp.empty())
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "max_concurrent_downloads is not set. Using current value = %u",maxDownloads);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint newValue = stoul(stmp);
|
||||||
|
if (newValue != maxDownloads)
|
||||||
|
{
|
||||||
|
maxDownloads = newValue;
|
||||||
|
workers.setMaxThreads(maxDownloads);
|
||||||
|
logger->log(LOG_INFO, "max_concurrent_downloads = %u",maxDownloads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (invalid_argument &)
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "max_concurrent_downloads is not a number. Using current value = %u",maxDownloads);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include "ThreadPool.h"
|
#include "ThreadPool.h"
|
||||||
#include "CloudStorage.h"
|
#include "CloudStorage.h"
|
||||||
#include "SMLogging.h"
|
#include "SMLogging.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -34,7 +36,7 @@
|
|||||||
namespace storagemanager
|
namespace storagemanager
|
||||||
{
|
{
|
||||||
|
|
||||||
class Downloader
|
class Downloader : public ConfigListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Downloader();
|
Downloader();
|
||||||
@ -49,6 +51,8 @@ class Downloader
|
|||||||
const boost::filesystem::path & getTmpPath() const;
|
const boost::filesystem::path & getTmpPath() const;
|
||||||
|
|
||||||
void printKPIs() const;
|
void printKPIs() const;
|
||||||
|
|
||||||
|
virtual void configListener() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint maxDownloads;
|
uint maxDownloads;
|
||||||
|
@ -63,18 +63,9 @@ Synchronizer::Synchronizer() : maxUploads(0)
|
|||||||
flushesTriggeredBySize = flushesTriggeredByTimer = journalsMerged =
|
flushesTriggeredBySize = flushesTriggeredByTimer = journalsMerged =
|
||||||
objectsSyncedWithNoJournal = bytesReadBySync = bytesReadBySyncWithJournal = 0;
|
objectsSyncedWithNoJournal = bytesReadBySync = bytesReadBySyncWithJournal = 0;
|
||||||
|
|
||||||
string stmp = config->getValue("ObjectStorage", "max_concurrent_uploads");
|
configListener();
|
||||||
try
|
config->addConfigListener(this);
|
||||||
{
|
|
||||||
maxUploads = stoul(stmp);
|
|
||||||
}
|
|
||||||
catch(invalid_argument)
|
|
||||||
{
|
|
||||||
logger->log(LOG_WARNING, "Downloader: Invalid arg for ObjectStorage/max_concurrent_uploads, using default of 20");
|
|
||||||
}
|
|
||||||
if (maxUploads == 0)
|
|
||||||
maxUploads = 20;
|
|
||||||
|
|
||||||
journalPath = cache->getJournalPath();
|
journalPath = cache->getJournalPath();
|
||||||
cachePath = cache->getCachePath();
|
cachePath = cache->getCachePath();
|
||||||
threadPool.reset(new ThreadPool());
|
threadPool.reset(new ThreadPool());
|
||||||
@ -91,6 +82,7 @@ Synchronizer::~Synchronizer()
|
|||||||
or save the list it's working on.....
|
or save the list it's working on.....
|
||||||
For milestone 2, this will do the safe thing and finish working first.
|
For milestone 2, this will do the safe thing and finish working first.
|
||||||
Later we can get fancy. */
|
Later we can get fancy. */
|
||||||
|
Config::get()->removeConfigListener(this);
|
||||||
forceFlush();
|
forceFlush();
|
||||||
die = true;
|
die = true;
|
||||||
syncThread.join();
|
syncThread.join();
|
||||||
@ -772,4 +764,29 @@ void Synchronizer::Job::operator()()
|
|||||||
sync->process(it);
|
sync->process(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Synchronizer::configListener()
|
||||||
|
{
|
||||||
|
// Uploader threads
|
||||||
|
string stmp = Config::get()->getValue("ObjectStorage", "max_concurrent_uploads");
|
||||||
|
if (maxUploads == 0)
|
||||||
|
maxUploads = 20;
|
||||||
|
if (stmp.empty())
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "max_concurrent_uploads is not set. Using current value = %u",maxUploads);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint newValue = stoul(stmp);
|
||||||
|
if (newValue != maxUploads)
|
||||||
|
{
|
||||||
|
maxUploads = newValue;
|
||||||
|
threadPool->setMaxThreads(maxUploads);
|
||||||
|
logger->log(LOG_INFO, "max_concurrent_uploads = %u",maxUploads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (invalid_argument &)
|
||||||
|
{
|
||||||
|
logger->log(LOG_CRIT, "max_concurrent_uploads is not a number. Using current value = %u",maxUploads);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "Replicator.h"
|
#include "Replicator.h"
|
||||||
#include "ThreadPool.h"
|
#include "ThreadPool.h"
|
||||||
#include "CloudStorage.h"
|
#include "CloudStorage.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
namespace storagemanager
|
namespace storagemanager
|
||||||
{
|
{
|
||||||
@ -38,7 +39,7 @@ namespace storagemanager
|
|||||||
class Cache; // break circular dependency in header files
|
class Cache; // break circular dependency in header files
|
||||||
class IOCoordinator;
|
class IOCoordinator;
|
||||||
|
|
||||||
class Synchronizer : public boost::noncopyable
|
class Synchronizer : public boost::noncopyable , public ConfigListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Synchronizer *get();
|
static Synchronizer *get();
|
||||||
@ -61,6 +62,9 @@ class Synchronizer : public boost::noncopyable
|
|||||||
boost::filesystem::path getJournalPath();
|
boost::filesystem::path getJournalPath();
|
||||||
boost::filesystem::path getCachePath();
|
boost::filesystem::path getCachePath();
|
||||||
void printKPIs() const;
|
void printKPIs() const;
|
||||||
|
|
||||||
|
virtual void configListener() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Synchronizer();
|
Synchronizer();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user