From 96293bcded429f016e12e3a6c40412faa62f33a4 Mon Sep 17 00:00:00 2001 From: "isabel@lotus" Date: Thu, 13 Sep 2018 16:09:43 -0700 Subject: [PATCH] KEP-616: Out of file handlers The issue is that a new daemon starting with a large state dir will replay its entire history, sending an audit notification for each message that's committed. For now, I'm just disabling audit by default. In pbft, messages will not be replayed in this way so it won't be such a concern. --- options/simple_options.cpp | 3 +++ options/simple_options.hpp | 1 + raft/raft.cpp | 6 ++++++ raft/raft.hpp | 2 ++ swarm/main.cpp | 12 ++++++++++-- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/options/simple_options.cpp b/options/simple_options.cpp index 3686d3cb..bc906ace 100644 --- a/options/simple_options.cpp +++ b/options/simple_options.cpp @@ -108,6 +108,9 @@ simple_options::build_options() po::options_description audit("Audit"); audit.add_options() + (AUDIT_ENABLED.c_str(), + po::value()->default_value(false), + "enable audit module") (AUDIT_MEM_SIZE.c_str(), po::value()->default_value(10000), "max size of audit datastructures") diff --git a/options/simple_options.hpp b/options/simple_options.hpp index c6f23b23..3c340ee4 100644 --- a/options/simple_options.hpp +++ b/options/simple_options.hpp @@ -20,6 +20,7 @@ namespace bzn::option_names { const std::string AUDIT_MEM_SIZE = "audit_mem_size"; + const std::string AUDIT_ENABLED = "audit_enabled"; const std::string BOOTSTRAP_PEERS_FILE = "bootstrap_file"; const std::string BOOTSTRAP_PEERS_URL = "bootstrap_url"; const std::string DEBUG_LOGGING = "debug_logging"; diff --git a/raft/raft.cpp b/raft/raft.cpp index 818bc5e3..a10c298b 100644 --- a/raft/raft.cpp +++ b/raft/raft.cpp @@ -1227,3 +1227,9 @@ raft::shutdown_on_exceeded_max_storage(bool do_throw) do_throw ? throw std::runtime_error(MSG_ERROR_MAXIMUM_STORAGE_EXCEEDED) : raise(SIGINT); } } + +void +raft::set_audit_enabled(bool val) +{ + this->enable_audit = val; +} diff --git a/raft/raft.hpp b/raft/raft.hpp index d6063ec0..fe216769 100644 --- a/raft/raft.hpp +++ b/raft/raft.hpp @@ -80,6 +80,8 @@ namespace bzn bool get_peer_validation_enabled() override { return this->enable_peer_validation; }; + void set_audit_enabled(bool val); + private: friend class raft_log_base; friend class raft_log; diff --git a/swarm/main.cpp b/swarm/main.cpp index 1e6fe973..9e5d9efa 100644 --- a/swarm/main.cpp +++ b/swarm/main.cpp @@ -33,6 +33,7 @@ #include #include #include +#include void @@ -218,7 +219,11 @@ main(int argc, const char* argv[]) auto audit = std::make_shared(io_context, node, options.get_monitor_endpoint(io_context), options.get_uuid(), options.get_audit_mem_size(), options.pbft_enabled()); node->start(); - audit->start(); + + if (options.get_simple_options().get(bzn::option_names::AUDIT_ENABLED)) + { + audit->start(); + } if (options.pbft_enabled()) { @@ -228,6 +233,8 @@ main(int argc, const char* argv[]) , failure_detector ); + pbft->set_audit_enabled(options.get_simple_options().get(bzn::option_names::AUDIT_ENABLED)); + pbft->start(); } else @@ -242,8 +249,9 @@ main(int argc, const char* argv[]) auto http_server = std::make_shared(io_context, crud, ep); auto status = std::make_shared(node, bzn::status::status_provider_list_t{raft}); - raft->initialize_storage_from_log(storage); + raft->set_audit_enabled(options.get_simple_options().get(bzn::option_names::AUDIT_ENABLED)); + raft->initialize_storage_from_log(storage); // These are here because they are not yet integrated with pbft http_server->start();