diff --git a/src/tateyama/authentication/authentication.cpp b/src/tateyama/authentication/authentication.cpp index fd36209..5cd3ee0 100644 --- a/src/tateyama/authentication/authentication.cpp +++ b/src/tateyama/authentication/authentication.cpp @@ -15,13 +15,11 @@ */ #include #include +#include +#include #include -#include -#include -#include - #include #include "authentication.h" @@ -67,9 +65,9 @@ void auth_options() { #endif return; } - const auto pre_defined_auth_file = boost::filesystem::path(std::string(pre_defined_auth_file_name)); - if (boost::filesystem::exists(pre_defined_auth_file)) { - boost::filesystem::ifstream istrm{}; + const auto pre_defined_auth_file = std::filesystem::path(std::string(pre_defined_auth_file_name)); + if (std::filesystem::exists(pre_defined_auth_file)) { + std::ifstream istrm{}; istrm.open(pre_defined_auth_file, std::ios_base::in); istrm.seekg( 0, std::ios_base::end ); diff --git a/src/tateyama/configuration/bootstrap_configuration.cpp b/src/tateyama/configuration/bootstrap_configuration.cpp index 8ded8f1..2627a3d 100644 --- a/src/tateyama/configuration/bootstrap_configuration.cpp +++ b/src/tateyama/configuration/bootstrap_configuration.cpp @@ -48,10 +48,6 @@ static constexpr std::string_view default_configuration { // NOLINT "port=12345\n" "threads=104\n" - "[fdw]\n" - "name=tsurugi\n" - "threads=104\n" - "[datastore]\n" "log_location=\n" "logging_max_parallelism=112\n" @@ -61,8 +57,13 @@ static constexpr std::string_view default_configuration { // NOLINT "waiting_resolver_threads=2\n" "[system]\n" - "pid_directory = /var/lock\n" + "pid_directory=/var/lock\n" + "[glog]\n" + "logtostderr=false\n" + "minloglevel=0\n" + "log_dir=\n" + "v=0\n" }; } // namespace details diff --git a/src/tateyama/configuration/bootstrap_configuration.h b/src/tateyama/configuration/bootstrap_configuration.h index 1b08fbf..3a99981 100644 --- a/src/tateyama/configuration/bootstrap_configuration.h +++ b/src/tateyama/configuration/bootstrap_configuration.h @@ -22,17 +22,14 @@ #include #include -#include - #include namespace tateyama::configuration { -static const std::string_view DEFAULT_PID_DIR = "/tmp"; // NOLINT and obsolete static const std::string_view PID_FILE_PREFIX = "tsurugi"; static const char *ENV_CONF = "TSURUGI_CONF"; // NOLINT static const char *ENV_HOME = "TSURUGI_HOME"; // NOLINT -static const boost::filesystem::path HOME_CONF_FILE = boost::filesystem::path("var/etc/tsurugi.ini"); // NOLINT +static const std::filesystem::path HOME_CONF_FILE = std::filesystem::path("var/etc/tsurugi.ini"); // NOLINT std::string_view default_property_for_bootstrap(); class bootstrap_configuration { @@ -47,22 +44,22 @@ class bootstrap_configuration { std::shared_ptr get_configuration() { return configuration_; } - [[nodiscard]] boost::filesystem::path lock_file() const { + [[nodiscard]] std::filesystem::path lock_file() const { return lock_file_; } [[nodiscard]] std::string digest() { - return digest(boost::filesystem::canonical(conf_file_).string()); + return digest(std::filesystem::canonical(conf_file_).string()); } [[nodiscard]] bool valid() const { return valid_; } - [[nodiscard]] boost::filesystem::path conf_file() const { // for test purpose + [[nodiscard]] std::filesystem::path conf_file() const { // for test purpose return conf_file_; } private: - boost::filesystem::path conf_file_; - boost::filesystem::path lock_file_; + std::filesystem::path conf_file_; + std::filesystem::path lock_file_; std::shared_ptr configuration_{}; bool valid_{}; @@ -73,25 +70,25 @@ class bootstrap_configuration { // tsurugi.ini if (!fname.empty()) { - conf_file_ = boost::filesystem::path(std::string(fname)); + conf_file_ = std::filesystem::path(std::string(fname)); } else { if (auto env_conf = getenv(ENV_CONF); env_conf != nullptr) { - conf_file_ = boost::filesystem::path(env_conf); + conf_file_ = std::filesystem::path(env_conf); } else { if (env_home != nullptr) { - conf_file_ = boost::filesystem::path(env_home) / HOME_CONF_FILE; + conf_file_ = std::filesystem::path(env_home) / HOME_CONF_FILE; } else { throw std::runtime_error("no configuration file specified"); } } } // do sanity check for conf_file_ - boost::system::error_code error; - const bool result = boost::filesystem::exists(conf_file_, error); + std::error_code error; + const bool result = std::filesystem::exists(conf_file_, error); if (!result || error) { throw std::runtime_error(std::string("cannot find configuration file: ") + conf_file_.string()); } - if (boost::filesystem::is_directory(conf_file_)) { + if (std::filesystem::is_directory(conf_file_)) { throw std::runtime_error(conf_file_.string() + " is a directory"); } configuration_ = tateyama::api::configuration::create_configuration(conf_file_.string(), default_property_for_bootstrap()); @@ -99,18 +96,20 @@ class bootstrap_configuration { if (env_home != nullptr) { configuration_->base_path(std::filesystem::path(env_home)); } - std::string directory{DEFAULT_PID_DIR}; if (auto system_config = configuration_->get_section("system"); system_config) { - if (auto pid_dir = system_config->get("pid_directory"); pid_dir) { - directory = pid_dir.value(); + if (auto pid_dir = system_config->get("pid_directory"); pid_dir) { + std::filesystem::path directory = pid_dir.value(); + + std::string pid_file_name(PID_FILE_PREFIX); + pid_file_name += "-"; + pid_file_name += digest(std::filesystem::canonical(conf_file_).string()); + pid_file_name += ".pid"; + lock_file_ = directory / std::filesystem::path(pid_file_name); + valid_ = true; + return; } } - std::string pid_file_name(PID_FILE_PREFIX); - pid_file_name += "-"; - pid_file_name += digest(boost::filesystem::canonical(conf_file_).string()); - pid_file_name += ".pid"; - lock_file_ = boost::filesystem::path(std::string(directory)) / boost::filesystem::path(pid_file_name); - valid_ = true; + throw std::runtime_error("error in lock file location"); } std::string digest(const std::string& path_string) { auto hash = std::hash{}(path_string); diff --git a/src/tateyama/datastore/backup.cpp b/src/tateyama/datastore/backup.cpp index cdc1b77..a0fe842 100644 --- a/src/tateyama/datastore/backup.cpp +++ b/src/tateyama/datastore/backup.cpp @@ -19,12 +19,10 @@ #include #include #include +#include #include -#include -#include - #include #include @@ -146,22 +144,22 @@ tgctl::return_code tgctl_backup_create(const std::string& path_to_backup) { if (rtnv == tgctl::return_code::ok) { auto backup_id = static_cast(rbgn.success().id()); - auto location = boost::filesystem::path(path_to_backup); + auto location = std::filesystem::path(path_to_backup); std::size_t total_bytes = 0; if(!FLAGS_monitor.empty()) { for (auto&& file : rbgn.success().simple_source().files()) { - auto src = boost::filesystem::path(file); - total_bytes += boost::filesystem::file_size(src); + auto src = std::filesystem::path(file); + total_bytes += std::filesystem::file_size(src); } } std::size_t completed_bytes = 0; for (auto&& file : rbgn.success().simple_source().files()) { - auto src = boost::filesystem::path(file); - boost::filesystem::copy_file(src, location / src.filename()); + auto src = std::filesystem::path(file); + std::filesystem::copy_file(src, location / src.filename()); if(!FLAGS_monitor.empty()) { - completed_bytes += boost::filesystem::file_size(src); + completed_bytes += std::filesystem::file_size(src); if (total_bytes > 0) { monitor_output->progress(static_cast(completed_bytes) / static_cast(total_bytes)); } else { diff --git a/src/tateyama/process/control.cpp b/src/tateyama/process/control.cpp index 3fd92a9..9697352 100644 --- a/src/tateyama/process/control.cpp +++ b/src/tateyama/process/control.cpp @@ -18,11 +18,10 @@ #include #include #include // std::runtime_error +#include #include -#include -#include #include #include @@ -130,13 +129,13 @@ tgctl::return_code tgctl_start(const std::string& argv0, bool need_check, tateya } std::string server_name(server_name_string); - boost::filesystem::path path_for_this{}; - if (auto a0f = boost::filesystem::path(argv0); a0f.parent_path().string().empty()) { - path_for_this = boost::filesystem::canonical(boost::process::search_path(a0f)); + std::filesystem::path path_for_this{}; + if (auto a0f = std::filesystem::path(argv0); a0f.is_absolute()) { + path_for_this = std::filesystem::canonical(a0f); } else{ - path_for_this = boost::filesystem::canonical(a0f); + path_for_this = std::filesystem::canonical(std::filesystem::path(boost::process::search_path(argv0).string())); } - if (!boost::filesystem::exists(path_for_this)) { + if (!std::filesystem::exists(path_for_this)) { std::cerr << "cannot find " << server_name_string << std::endl; return tgctl::return_code::err; } @@ -162,17 +161,17 @@ tgctl::return_code tgctl_start(const std::string& argv0, bool need_check, tateya *static_cast(shm_data) = 0; if (fork() == 0) { - auto base = boost::filesystem::canonical(path_for_this).parent_path().parent_path(); - auto exec = base / boost::filesystem::path("libexec") / boost::filesystem::path(server_name); + auto base = std::filesystem::canonical(path_for_this).parent_path().parent_path(); + auto exec = base / std::filesystem::path("libexec") / std::filesystem::path(server_name); std::vector args{}; build_args(args, mode); - boost::process::child cld(exec, boost::process::args (args)); + boost::process::child cld(exec.string(), boost::process::args (args)); pid_t child_pid = cld.id(); *static_cast(shm_data) = child_pid; cld.detach(); std::string undertaker_name(undertaker_name_string); - auto undertaker = base / boost::filesystem::path("libexec") / boost::filesystem::path(undertaker_name); + auto undertaker = base / std::filesystem::path("libexec") / std::filesystem::path(undertaker_name); execl(undertaker.string().c_str(), undertaker.string().c_str(), std::to_string(child_pid).c_str(), nullptr); // NOLINT exit(-1); // should not reach here } diff --git a/src/tateyama/process/proc_mutex.h b/src/tateyama/process/proc_mutex.h index c645c0a..3965ea2 100644 --- a/src/tateyama/process/proc_mutex.h +++ b/src/tateyama/process/proc_mutex.h @@ -19,10 +19,8 @@ #include #include #include // std::runtime_error - -#include -#include -#include +#include +#include namespace tateyama::process { @@ -35,9 +33,9 @@ class proc_mutex { error, }; - explicit proc_mutex(boost::filesystem::path lock_file, bool create_file = true, bool throw_exception = true) + explicit proc_mutex(std::filesystem::path lock_file, bool create_file = true, bool throw_exception = true) : lock_file_(std::move(lock_file)), create_file_(create_file) { - if (!create_file_ && throw_exception && !boost::filesystem::exists(lock_file_)) { + if (!create_file_ && throw_exception && !std::filesystem::exists(lock_file_)) { throw std::runtime_error("the lock file does not exist"); } } @@ -81,12 +79,12 @@ class proc_mutex { return lock_file_.generic_string(); } [[nodiscard]] lock_state check() { - boost::system::error_code error; - const bool result = boost::filesystem::exists(lock_file_, error); + std::error_code error; + const bool result = std::filesystem::exists(lock_file_, error); if (!result || error) { return lock_state::no_file; } - if (!boost::filesystem::is_regular_file(lock_file_)) { + if (!std::filesystem::is_regular_file(lock_file_)) { return lock_state::error; } if (fd_ = open(lock_file_.generic_string().c_str(), O_WRONLY); fd_ < 0) { // NOLINT @@ -118,7 +116,7 @@ class proc_mutex { } private: - boost::filesystem::path lock_file_; + std::filesystem::path lock_file_; int fd_{}; const bool create_file_; @@ -126,9 +124,9 @@ class proc_mutex { if (do_check && check() != lock_state::locked) { return false; } - auto size = static_cast(boost::filesystem::file_size(lock_file_)); + auto size = static_cast(std::filesystem::file_size(lock_file_)); str.resize(size, '\0'); - boost::filesystem::ifstream file(lock_file_); + std::ifstream file(lock_file_); file.read(str.data(), static_cast(size)); return true; } diff --git a/src/tateyama/server/utils.cpp b/src/tateyama/server/utils.cpp index a77719e..1be10e4 100644 --- a/src/tateyama/server/utils.cpp +++ b/src/tateyama/server/utils.cpp @@ -21,9 +21,6 @@ #include "gflags/gflags.h" -#include "boost/filesystem/path.hpp" -#include "boost/filesystem/operations.hpp" - DEFINE_int32(dump_batch_size, 1024, "Batch size for dump"); //NOLINT DEFINE_int32(load_batch_size, 1024, "Batch size for load"); //NOLINT @@ -42,11 +39,11 @@ namespace jogasaki::utils { "STOCK" }; - boost::filesystem::path prepare(std::string location) { - boost::filesystem::path dir(location); + std::filesystem::path prepare(const std::string& location) { + std::filesystem::path dir(location); dir = dir / "dump"; - if (!boost::filesystem::exists(dir)) { - if (!boost::filesystem::create_directories(dir)) { + if (!std::filesystem::exists(dir)) { + if (!std::filesystem::create_directories(dir)) { throw std::ios_base::failure("Failed to create directory."); } } @@ -56,7 +53,7 @@ namespace jogasaki::utils { void dump([[maybe_unused]] jogasaki::api::database& tgdb, std::string &location) { - boost::filesystem::path dir = prepare(location); + std::filesystem::path dir = prepare(location); for (auto& table : tables) { std::ofstream ofs((dir / (table+".tbldmp")).c_str()); if (ofs.fail()) { @@ -69,7 +66,7 @@ namespace jogasaki::utils { void load([[maybe_unused]] jogasaki::api::database& tgdb, std::string &location) { - boost::filesystem::path dir = prepare(location); + std::filesystem::path dir = prepare(location); for (auto& table : tables) { std::ifstream ifs((dir / (table+".tbldmp")).c_str()); if (ifs.fail()) { @@ -94,7 +91,7 @@ namespace jogasaki::utils { void dump_tpch(jogasaki::api::database& tgdb, std::string &location) { - boost::filesystem::path dir = prepare(location); + std::filesystem::path dir = prepare(location); for (auto& table : tpch_tables) { std::ofstream ofs((dir / (table+".tbldmp")).c_str()); if (ofs.fail()) { @@ -107,7 +104,7 @@ namespace jogasaki::utils { void load_tpch(jogasaki::api::database& tgdb, std::string &location) { - boost::filesystem::path dir = prepare(location); + std::filesystem::path dir = prepare(location); for (auto& table : tpch_tables) { std::ifstream ifs((dir / (table+".tbldmp")).c_str()); if (ifs.fail()) { diff --git a/test/test_root.h b/test/test_root.h index b11af0a..e2c4bcf 100644 --- a/test/test_root.h +++ b/test/test_root.h @@ -21,10 +21,8 @@ #include #include #include +#include -#include -#include -#include #include #define BOOST_BIND_GLOBAL_PLACEHOLDERS // to retain the current behavior #include @@ -151,10 +149,10 @@ class directory_helper { std::ofstream strm_; }; -static bool validate_json(boost::filesystem::path file) +static bool validate_json(std::filesystem::path file) { bool result = true; - boost::filesystem::ifstream strm; + std::ifstream strm; std::stringstream ss; std::string line;