You've already forked mariadb-columnstore-engine
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:
@@ -24,6 +24,7 @@ set(storagemanager_SRCS
|
||||
src/CloudStorage.cpp
|
||||
src/S3Storage.cpp
|
||||
src/LocalStorage.cpp
|
||||
src/Cache.cpp
|
||||
)
|
||||
|
||||
option(TRACE "Enable some tracing output" OFF)
|
||||
|
||||
79
src/Cache.cpp
Normal file
79
src/Cache.cpp
Normal 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
34
src/Cache.h
Normal 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
|
||||
@@ -63,12 +63,26 @@ Config::Config()
|
||||
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());
|
||||
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 §ion, const string &key) const
|
||||
{
|
||||
// if we care, move this envvar substition stuff to where the file is loaded
|
||||
@@ -76,6 +90,13 @@ string Config::getValue(const string §ion, const string &key) const
|
||||
boost::regex re("\\$\\{(.+)\\}");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,5 +12,9 @@ region = us-west-1
|
||||
# see https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
|
||||
|
||||
[LocalStorage]
|
||||
path = ${HOME}/fake-cloud/
|
||||
path = ${HOME}/fake-cloud
|
||||
|
||||
[Cache]
|
||||
cache_size = 2g
|
||||
path = ${HOME}/cache
|
||||
|
||||
|
||||
Reference in New Issue
Block a user