1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-12-13 23:02:14 +03:00

Added 'k, m, g' suffix processing to Config class

Started writing the Cache class.  Mostly stubs right now.
This commit is contained in:
Patrick LeBlanc
2019-02-21 16:19:29 -06:00
parent 449702895b
commit 402a49c27a
5 changed files with 141 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ set(storagemanager_SRCS
src/CloudStorage.cpp src/CloudStorage.cpp
src/S3Storage.cpp src/S3Storage.cpp
src/LocalStorage.cpp src/LocalStorage.cpp
src/Cache.cpp
) )
option(TRACE "Enable some tracing output" OFF) option(TRACE "Enable some tracing output" OFF)

79
src/Cache.cpp Normal file
View File

@@ -0,0 +1,79 @@
#include "Cache.h"
#include "Config.h"
#include <iostream>
#include <syslog.h>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;
namespace storagemanager
{
Cache::Cache()
{
Config *conf = Config::get();
string ssize = conf->getValue("Cache", "cache_size");
if (ssize.empty())
{
syslog(LOG_CRIT, "Cache/cache_size is not set");
throw runtime_error("Please set Cache/cache_size in the storagemanager.cnf file");
}
try
{
maxCacheSize = stol(ssize);
}
catch (invalid_argument &)
{
syslog(LOG_CRIT, "Cache/cache_size is not a number");
throw runtime_error("Please set Cache/cache_size to a number");
}
prefix = conf->getValue("Cache", "path");
if (prefix.empty())
{
syslog(LOG_CRIT, "Cache/path is not set");
throw runtime_error("Please set Cache/path in the storagemanager.cnf file");
}
try
{
boost::filesystem::create_directories(prefix);
}
catch (exception &e)
{
syslog(LOG_CRIT, "Failed to create %s, got: %s", prefix.string().c_str(), e.what());
throw e;
}
}
Cache::~Cache()
{
}
void Cache::read(const vector<string> &keys)
{
}
void Cache::exists(const vector<string> &keys, vector<bool> *out)
{
}
void Cache::newObject(const string &key, size_t size)
{
}
void Cache::deletedObject(const string &key, size_t size)
{
}
void Cache::setCacheSize(size_t size)
{
}
void Cache::makeSpace(size_t size)
{
}
}

34
src/Cache.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef CACHE_H_
#define CACHE_H_
#include <string>
#include <vector>
#include <boost/utility.hpp>
#include <boost/filesystem/path.hpp>
namespace storagemanager
{
class Cache : public boost::noncopyable
{
public:
Cache();
virtual ~Cache();
void read(const std::vector<std::string> &keys);
void exists(const std::vector<std::string> &keys, std::vector<bool> *out);
void newObject(const std::string &key, size_t size);
void deletedObject(const std::string &key, size_t size);
void setCacheSize(size_t size);
void makeSpace(size_t size);
private:
boost::filesystem::path prefix;
size_t maxCacheSize;
};
}
#endif

View File

@@ -63,12 +63,26 @@ Config::Config()
boost::property_tree::ini_parser::read_ini(filename, contents); boost::property_tree::ini_parser::read_ini(filename, contents);
} }
string use_envvar(boost::smatch envvar) string use_envvar(const boost::smatch &envvar)
{ {
char *env = getenv(envvar[1].str().c_str()); char *env = getenv(envvar[1].str().c_str());
return (env ? env : ""); return (env ? env : "");
} }
string expand_numbers(const boost::smatch &match)
{
long num = stol(match[1].str());
char suffix = (char) ::tolower(match[2].str()[0]);
if (suffix == 'g')
num <<= 30;
else if (suffix == 'm')
num <<= 20;
else if (suffix == 'k')
num <<= 10;
return ::to_string(num);
}
string Config::getValue(const string &section, const string &key) const string Config::getValue(const string &section, const string &key) const
{ {
// if we care, move this envvar substition stuff to where the file is loaded // if we care, move this envvar substition stuff to where the file is loaded
@@ -76,6 +90,13 @@ string Config::getValue(const string &section, const string &key) const
boost::regex re("\\$\\{(.+)\\}"); boost::regex re("\\$\\{(.+)\\}");
ret = boost::regex_replace(ret, re, use_envvar); ret = boost::regex_replace(ret, re, use_envvar);
// do the numeric substitutions. ex, the suffixes m, k, g
// ehhhhh. going to end up turning a string to a number, to a string, and then to a number again
// don't like that. OTOH who cares.
boost::regex num_re("^([[:digit:]]+)([mMkKgG])$", boost::regex::extended);
ret = boost::regex_replace(ret, num_re, expand_numbers);
return ret; return ret;
} }

View File

@@ -12,5 +12,9 @@ region = us-west-1
# see https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html # see https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
[LocalStorage] [LocalStorage]
path = ${HOME}/fake-cloud/ path = ${HOME}/fake-cloud
[Cache]
cache_size = 2g
path = ${HOME}/cache