You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-12-15 12:09:09 +03:00
Added the local storage stand-in for cloud ops.
Modded Config to allow using envvars. Added a copyobject op to the cloudstorage base class.
This commit is contained in:
@@ -23,6 +23,7 @@ set(storagemanager_SRCS
|
|||||||
src/Config.cpp
|
src/Config.cpp
|
||||||
src/CloudStorage.cpp
|
src/CloudStorage.cpp
|
||||||
src/S3Storage.cpp
|
src/S3Storage.cpp
|
||||||
|
src/LocalStorage.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
option(TRACE "Enable some tracing output" OFF)
|
option(TRACE "Enable some tracing output" OFF)
|
||||||
@@ -31,10 +32,10 @@ if (TRACE)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(StorageManager src/main.cpp ${storagemanager_SRCS})
|
add_executable(StorageManager src/main.cpp ${storagemanager_SRCS})
|
||||||
target_link_libraries(StorageManager boost_system boost_thread boost_filesystem aws-cpp-sdk-s3)
|
target_link_libraries(StorageManager boost_system boost_thread boost_filesystem boost_regex aws-cpp-sdk-s3)
|
||||||
|
|
||||||
add_executable(unit_tests src/unit_tests.cpp ${storagemanager_SRCS})
|
add_executable(unit_tests src/unit_tests.cpp ${storagemanager_SRCS})
|
||||||
target_link_libraries(unit_tests boost_system boost_thread boost_filesystem)
|
target_link_libraries(unit_tests boost_system boost_thread boost_filesystem boost_regex)
|
||||||
|
|
||||||
# config & import the AWS SDK
|
# config & import the AWS SDK
|
||||||
option(ENABLE_UNITY_BUILD "" ON)
|
option(ENABLE_UNITY_BUILD "" ON)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class CloudStorage
|
|||||||
virtual int getObject(const std::string &sourceKey, const std::string &destFile) = 0;
|
virtual int getObject(const std::string &sourceKey, const std::string &destFile) = 0;
|
||||||
virtual int putObject(const std::string &sourceFile, const std::string &destKey) = 0;
|
virtual int putObject(const std::string &sourceFile, const std::string &destKey) = 0;
|
||||||
virtual void deleteObject(const std::string &key) = 0;
|
virtual void deleteObject(const std::string &key) = 0;
|
||||||
|
virtual int copyObject(const std::string &sourceKey, const std::string &destKey) = 0;
|
||||||
|
|
||||||
// this will return a CloudStorage instance of the type specified in StorageManager.cnf
|
// this will return a CloudStorage instance of the type specified in StorageManager.cnf
|
||||||
static CloudStorage *get();
|
static CloudStorage *get();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <boost/property_tree/ini_parser.hpp>
|
#include <boost/property_tree/ini_parser.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -32,7 +33,7 @@ Config * Config::get()
|
|||||||
Config::Config()
|
Config::Config()
|
||||||
{
|
{
|
||||||
/* This will search the current directory,
|
/* This will search the current directory,
|
||||||
then the $COLUMNSTORE_INSTALL_DIR/etc,
|
then $COLUMNSTORE_INSTALL_DIR/etc,
|
||||||
then /etc
|
then /etc
|
||||||
looking for storagemanager.cnf
|
looking for storagemanager.cnf
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ Config::Config()
|
|||||||
vector<string> paths;
|
vector<string> paths;
|
||||||
|
|
||||||
// the paths to search in order
|
// the paths to search in order
|
||||||
paths.push_back("./");
|
paths.push_back(".");
|
||||||
if (cs_install_dir)
|
if (cs_install_dir)
|
||||||
paths.push_back(cs_install_dir);
|
paths.push_back(cs_install_dir);
|
||||||
paths.push_back("/etc");
|
paths.push_back("/etc");
|
||||||
@@ -62,9 +63,20 @@ 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)
|
||||||
|
{
|
||||||
|
char *env = getenv(envvar[1].str().c_str());
|
||||||
|
return (env ? env : "");
|
||||||
|
}
|
||||||
|
|
||||||
string Config::getValue(const string §ion, const string &key) const
|
string Config::getValue(const string §ion, const string &key) const
|
||||||
{
|
{
|
||||||
return contents.get<string>(section + "." + key);
|
// if we care, move this envvar substition stuff to where the file is loaded
|
||||||
|
string ret = contents.get<string>(section + "." + key);
|
||||||
|
boost::regex re("\\$\\{(.+)\\}");
|
||||||
|
|
||||||
|
ret = boost::regex_replace(ret, re, use_envvar);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
78
src/LocalStorage.cpp
Normal file
78
src/LocalStorage.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <syslog.h>
|
||||||
|
#include "LocalStorage.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace boost::filesystem;
|
||||||
|
|
||||||
|
namespace storagemanager
|
||||||
|
{
|
||||||
|
|
||||||
|
LocalStorage::LocalStorage()
|
||||||
|
{
|
||||||
|
prefix = Config::get()->getValue("LocalStorage", "path");
|
||||||
|
cout << "LS: got prefix " << prefix << endl;
|
||||||
|
if (!is_directory(prefix))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
create_directories(prefix);
|
||||||
|
}
|
||||||
|
catch (exception &e)
|
||||||
|
{
|
||||||
|
syslog(LOG_CRIT, "Failed to create %s, got: %s", prefix.string().c_str(), e.what());
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalStorage::~LocalStorage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int LocalStorage::copy(const path &source, const path &dest)
|
||||||
|
{
|
||||||
|
boost::system::error_code err;
|
||||||
|
copy_file(source, dest, copy_option::fail_if_exists, err);
|
||||||
|
if (!err)
|
||||||
|
{
|
||||||
|
errno = err.value();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
path operator+(const path &p1, const path &p2)
|
||||||
|
{
|
||||||
|
path ret(p1);
|
||||||
|
ret+=p2;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LocalStorage::getObject(const string &source, const string &dest)
|
||||||
|
{
|
||||||
|
return copy(prefix + source, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
int LocalStorage::putObject(const string &source, const string &dest)
|
||||||
|
{
|
||||||
|
return copy(source, prefix + dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
int LocalStorage::copyObject(const string &source, const string &dest)
|
||||||
|
{
|
||||||
|
return copy(prefix + source, prefix + dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalStorage::deleteObject(const string &key)
|
||||||
|
{
|
||||||
|
boost::system::error_code err;
|
||||||
|
|
||||||
|
boost::filesystem::remove(prefix + key, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
src/LocalStorage.h
Normal file
30
src/LocalStorage.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef LOCALSTORAGE_H_
|
||||||
|
#define LOCALSTORAGE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "CloudStorage.h"
|
||||||
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
|
namespace storagemanager
|
||||||
|
{
|
||||||
|
|
||||||
|
class LocalStorage : public CloudStorage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LocalStorage();
|
||||||
|
virtual ~LocalStorage();
|
||||||
|
|
||||||
|
int getObject(const std::string &sourceKey, const std::string &destFile);
|
||||||
|
int putObject(const std::string &sourceFile, const std::string &destKey);
|
||||||
|
void deleteObject(const std::string &key);
|
||||||
|
int copyObject(const std::string &sourceKey, const std::string &destKey);
|
||||||
|
|
||||||
|
private:
|
||||||
|
boost::filesystem::path prefix;
|
||||||
|
|
||||||
|
int copy(const boost::filesystem::path &sourceKey, const boost::filesystem::path &destKey);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -14,7 +14,7 @@ S3Storage::~S3Storage()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int S3Storage::getObject(const string &courceKey, const string &destFile)
|
int S3Storage::getObject(const string &sourceKey, const string &destFile)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -28,4 +28,9 @@ void S3Storage::deleteObject(const string &key)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int S3Storage::copyObject(const string &sourceKey, const string &destKey)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class S3Storage : public CloudStorage
|
|||||||
int getObject(const std::string &sourceKey, const std::string &destFile);
|
int getObject(const std::string &sourceKey, const std::string &destFile);
|
||||||
int putObject(const std::string &sourceFile, const std::string &destKey);
|
int putObject(const std::string &sourceFile, const std::string &destKey);
|
||||||
void deleteObject(const std::string &key);
|
void deleteObject(const std::string &key);
|
||||||
|
int copyObject(const std::string &sourceKey, const std::string &destKey);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ region = us-west-1
|
|||||||
# ex, by setting AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY envvars.
|
# ex, by setting AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY envvars.
|
||||||
# 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]
|
||||||
|
path = ${HOME}/fake-cloud/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user