merge + conflict resolution

This commit is contained in:
Marko Budiselic 2017-01-13 10:47:17 +01:00
commit d7de5cfe08
16 changed files with 115 additions and 78 deletions

View File

@ -2,6 +2,9 @@
#include "utils/config/config.hpp"
#include <string>
#include <set>
namespace config
{
@ -15,6 +18,7 @@ class MemgraphConfig
public:
static const char *env_config_key;
static const char *default_file_path;
static std::set<std::string> arguments;
};
// -- all possible Memgraph's keys --
@ -31,6 +35,8 @@ inline size_t to_int(std::string &&s) { return stoull(s); }
// code uses this define for key access
// _KEY_ is value from all possible keys that are listed above
#define CONFIG_REGISTER_ARGS(ARGC, ARGV) \
config::Config<config::MemgraphConfig>::instance().register_args(ARGC, ARGV);
#define CONFIG(_KEY_) config::Config<config::MemgraphConfig>::instance()[_KEY_]
#define CONFIG_INTEGER(_KEY_) config::to_int(CONFIG(_KEY_))

View File

@ -13,12 +13,9 @@ public:
Ast() = default;
Ast(const Ast&) = delete;
Ast(Ast&& other)
Ast(Ast&& other) : root(other.root), items(std::move(other.items))
{
this->root = other.root;
other.root = nullptr;
this->items = std::move(other.items);
}
Ast& operator=(Ast&& other)

View File

@ -24,7 +24,7 @@ public:
class Entry
{
public:
Entry(Printer &printer) : printer(printer), valid(true)
explicit Entry(Printer &printer) : printer(printer), valid(true)
{
printer.level++;
@ -77,7 +77,8 @@ public:
size_t level = 0;
};
PrintVisitor(std::ostream &stream) : printer(stream, "Printing AST") {}
explicit PrintVisitor(std::ostream &stream)
: printer(stream, "Printing AST") {}
void visit(ast::Start &start) override
{

View File

@ -14,7 +14,7 @@ class Pool : Lockable<std::mutex>
public:
using sptr = std::shared_ptr<Pool>;
Pool(size_t n = std::thread::hardware_concurrency()) : alive(true)
explicit Pool(size_t n = std::thread::hardware_concurrency()) : alive(true)
{
threads.reserve(n);

View File

@ -1,63 +1,82 @@
#pragma once
#include <cstring>
#include <string>
#include <stdexcept>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <string>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
// TODO: isolate from caller (caller shouldn't know that his dependency is)
// yaml-cpp
#include "utils/command_line/arguments.hpp"
#include "yaml-cpp/yaml.h"
namespace config
{
namespace config {
template <class Definition>
class Config
{
private:
YAML::Node _config;
class Config {
private:
using KeyValueMap = std::map<std::string, std::string>;
Config()
{
// config places: priority
// 1. default system | (/etc/name/config)
// 2. default user | (/home/user/.name/config)
// 3. ENV var | (PATH)
// 4. program argument \ / (PATH)
if (const char* env_path = std::getenv(Definition::env_config_key))
{
_config = YAML::LoadFile(env_path);
// TODO: error handling
}
else
{
_config = YAML::LoadFile(Definition::default_file_path);
// TODO: error handling
}
KeyValueMap dict;
// TODO:
// * default system
// * default user
// * program argument
void load_configuration(std::string path) {
try {
YAML::Node node = YAML::LoadFile(path);
for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
dict[it->first.as<std::string>()] = it->second.as<std::string>();
}
} catch (std::exception ex) {
// configuration doesn't exist or invalid!!!
}
}
Config() {
// config places: priority
// 1. default system | (/etc/memgraph/config)
// 2. default user | (/home/user/.memgraph/config)
// 3. ENV var | (PATH)
// 4. program argument \ / (PATH)
// default system configuration
load_configuration(Definition::default_file_path);
// default user configuration
// fetches user configuration folder
std::string homedir = std::getenv("HOME");
if ((homedir == "")) {
homedir = getpwuid(getuid())->pw_dir;
}
homedir += "/.memgraph/config.yaml";
load_configuration(homedir);
// environment variable configuratoin
if (const char* env_path = std::getenv(Definition::env_config_key))
load_configuration(env_path);
}
public:
static Config<Definition>& instance() {
static Config<Definition> config;
return config;
}
void register_args(int argc, char** argv) {
REGISTER_ARGS(argc, argv);
for (const auto& argument : Definition::arguments) {
dict[argument] = GET_ARG("--" + argument, dict[argument]).get_string();
}
public:
static Config<Definition>& instance()
{
static Config<Definition> config;
return config;
}
}
void register_program_arguments()
{
}
std::string operator[](const char* key)
{
return _config[key].template as<std::string>();
}
std::string operator[](const char* key) {
return dict[key];
}
};
}

View File

@ -4,6 +4,15 @@ namespace config
{
const char *MemgraphConfig::env_config_key = "MEMGRAPH_CONFIG";
const char *MemgraphConfig::default_file_path = "config.yaml";
const char *MemgraphConfig::default_file_path = "/etc/memgraph/config.yaml";
// configuration for arguments which can be passed threw command line
// TODO add support for shortened names
// Example:
// --cleaning_cycle_sec or -ccs, etc.
std::set<std::string> MemgraphConfig::arguments = {
"cleaning_cycle_sec",
"snapshot_cycle_sec",
};
}

View File

@ -20,9 +20,6 @@ Db &Dbms::active(const std::string &name)
// create db if it doesn't exist
auto it = acc.find(name);
if (it == acc.end()) {
// It doesn't exist.
Snapshoter &snap = snapshoter;
it = acc.emplace(name, std::forward_as_tuple(name),
std::forward_as_tuple(name))
.first;

View File

@ -9,19 +9,26 @@
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
#include "utils/config/config.hpp"
#include "utils/signals/handler.hpp"
#include "utils/terminate_handler.hpp"
#include "utils/stacktrace/log.hpp"
#include "utils/terminate_handler.hpp"
static bolt::Server<bolt::Worker> *serverptr;
Logger logger;
// TODO: load from configuration
// TODO: load from config
static constexpr const char *interface = "0.0.0.0";
static constexpr const char *port = "7687";
int main(void)
void throw_and_stacktace(std::string message)
{
Stacktrace stacktrace;
logger.info(stacktrace.dump());
}
int main(int argc, char **argv)
{
// logging init
#ifdef SYNC_LOGGER
@ -31,14 +38,14 @@ int main(void)
#endif
logging::log->pipe(std::make_unique<Stdout>());
// logger init
// get logger
logger = logging::log->logger("Main");
logger.info("{}", logging::log->type());
// unhandled exception handler
// unhandled exception handler init
std::set_terminate(&terminate_handler);
// signal handling
// signal handling init
SignalHandler::register_handler(Signal::SegmentationFault, []() {
log_stacktrace("SegmentationFault signal raised");
std::exit(EXIT_FAILURE);
@ -52,6 +59,9 @@ int main(void)
std::exit(EXIT_FAILURE);
});
// register args
CONFIG_REGISTER_ARGS(argc, argv);
// initialize socket
io::Socket socket;
try

View File

@ -1,5 +1,4 @@
#ifndef MEMGRAPH_SERVER_HTTP_HTTP_ERROR_HPP
#define MEMGRAPH_SERVER_HTTP_HTTP_ERROR_HPP
#pragma once
#include <stdexcept>
#include <string>
@ -10,7 +9,7 @@ namespace http
class HttpError : public std::runtime_error
{
public:
HttpError(const std::string& message)
explicit HttpError(const std::string& message)
: std::runtime_error(message) {}
};

View File

@ -22,7 +22,7 @@ class HttpServer
public:
using request_cb_t = std::function<void(Req&, Res&)>;
HttpServer(uv::UvLoop& loop);
explicit HttpServer(uv::UvLoop& loop);
void listen(const Ipv4& ip, request_cb_t callback);

View File

@ -9,8 +9,8 @@ namespace http
static BlockAllocator<65536> buffer_allocator;
template <class Req, class Res>
HttpServer<Req, Res>::HttpServer(uv::UvLoop& loop)
: loop(loop), stream(loop) {}
HttpServer<Req, Res>::HttpServer(uv::UvLoop& l)
: loop(l), stream(l) {}
template <class Req, class Res>
void HttpServer<Req, Res>::listen(const Ipv4& ip, request_cb_t callback)

View File

@ -21,7 +21,7 @@ class Response
using response_t = Response<Req, Res>;
public:
Response(connection_t& connection);
explicit Response(connection_t& connection);
void send(const std::string& body);
void send(Status code, const std::string& body);

View File

@ -12,8 +12,8 @@ namespace http
static BlockAllocator<sizeof(uv_write_t)> write_req_allocator;
template <class Req, class Res>
Response<Req, Res>::Response(connection_t& connection)
: status(Status::Ok), connection(connection), buffer() {}
Response<Req, Res>::Response(connection_t& conn)
: status(Status::Ok), connection(conn), buffer() {}
template <class Req, class Res>
void Response<Req, Res>::send(Status status, const std::string& body)

View File

@ -92,7 +92,7 @@ public:
r3::route* route;
};
R3(size_t capacity)
explicit R3(size_t capacity)
{
root = r3::r3_tree_create(capacity);
}
@ -104,10 +104,8 @@ public:
R3(R3&) = delete;
R3(R3&& other)
R3(R3&& other) : routes(std::move(other.routes), root(other.root)
{
this->routes = std::move(other.routes);
this->root = other.root;
other.root = nullptr;
}

View File

@ -10,7 +10,7 @@ using namespace std;
template <class T>
class ListNode {
public:
ListNode(T value) : value(value) {}
explicit ListNode(T value) : value(value) {}
std::atomic<T> value;
std::atomic<ListNode<T>*> prev;

View File

@ -3,6 +3,7 @@
namespace utils
{
// TODO CPPCheck -> function never used
void str_tolower(std::string& s)
{
// en_US.utf8 localization