Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from XiaoMi/master
Browse files Browse the repository at this point in the history
replica-server: support remote command useless-dir-reserve-seconds (#…
  • Loading branch information
mentoswang authored Jan 10, 2019
2 parents b69aeef + a173cbc commit fb86225
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/dsn/tool-api/command_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class command_manager : public ::dsn::utils::singleton<command_manager>
#define HANDLE_CLI_FLAGS(flag, args) \
do { \
std::string ret_msg("OK"); \
if (args.size() <= 0) { \
if (args.empty()) { \
ret_msg = flag ? "true" : "false"; \
} else { \
if (strcmp(args[0].c_str(), "true") == 0) { \
Expand Down
43 changes: 41 additions & 2 deletions src/dist/replication/lib/replica_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <dsn/cpp/json_helper.h>
#include <dsn/utility/filesystem.h>
#include <dsn/utility/rand.h>
#include <dsn/utility/string_conv.h>
#include <dsn/tool-api/command_manager.h>
#include <dsn/dist/replication/replication_app_base.h>
#include <vector>
Expand All @@ -60,9 +61,12 @@ replica_stub::replica_stub(replica_state_subscriber subscriber /*= nullptr*/,
_trigger_chkpt_command(nullptr),
_query_compact_command(nullptr),
_query_app_envs_command(nullptr),
_useless_dir_reserve_seconds_command(nullptr),
_deny_client(false),
_verbose_client_log(false),
_verbose_commit_log(false),
_gc_disk_error_replica_interval_seconds(3600),
_gc_disk_garbage_replica_interval_seconds(3600),
_learn_app_concurrent_count(0),
_fs_manager(false)
{
Expand Down Expand Up @@ -288,6 +292,8 @@ void replica_stub::initialize(const replication_options &opts, bool clear /* = f
_deny_client = _options.deny_client_on_start;
_verbose_client_log = _options.verbose_client_log_on_start;
_verbose_commit_log = _options.verbose_commit_log_on_start;
_gc_disk_error_replica_interval_seconds = _options.gc_disk_error_replica_interval_seconds;
_gc_disk_garbage_replica_interval_seconds = _options.gc_disk_garbage_replica_interval_seconds;

// clear dirs if need
if (clear) {
Expand Down Expand Up @@ -1583,8 +1589,8 @@ void replica_stub::on_disk_stat()
uint64_t last_write_time = (uint64_t)mt;
uint64_t current_time_ms = dsn_now_ms();
uint64_t interval_seconds = (name.substr(name.length() - 4) == ".err"
? _options.gc_disk_error_replica_interval_seconds
: _options.gc_disk_garbage_replica_interval_seconds);
? _gc_disk_error_replica_interval_seconds
: _gc_disk_garbage_replica_interval_seconds);
if (last_write_time + interval_seconds <= current_time_ms / 1000) {
if (!dsn::utils::filesystem::remove_path(fpath)) {
dwarn("gc_disk: failed to delete directory '%s', time_used_ms = %" PRIu64,
Expand Down Expand Up @@ -1950,6 +1956,37 @@ void replica_stub::open_service()
}
});
});

_useless_dir_reserve_seconds_command = dsn::command_manager::instance().register_app_command(
{"useless-dir-reserve-seconds"},
"useless-dir-reserve-seconds [num | DEFAULT]",
"control gc_disk_error_replica_interval_seconds and "
"gc_disk_garbage_replica_interval_seconds",
[this](const std::vector<std::string> &args) {
std::string result("OK");
if (args.empty()) {
result = "error_dir_reserve_seconds=" +
std::to_string(_gc_disk_error_replica_interval_seconds) +
",garbage_dir_reserve_seconds=" +
std::to_string(_gc_disk_garbage_replica_interval_seconds);
} else {
if (args[0] == "DEFAULT") {
_gc_disk_error_replica_interval_seconds =
_options.gc_disk_error_replica_interval_seconds;
_gc_disk_garbage_replica_interval_seconds =
_options.gc_disk_garbage_replica_interval_seconds;
} else {
int32_t seconds = 0;
if (!dsn::buf2int32(args[0], seconds) || seconds < 0) {
result = std::string("ERR: invalid arguments");
} else {
_gc_disk_error_replica_interval_seconds = seconds;
_gc_disk_garbage_replica_interval_seconds = seconds;
}
}
}
return result;
});
}

std::string
Expand Down Expand Up @@ -2074,6 +2111,7 @@ void replica_stub::close()
dsn::command_manager::instance().deregister_command(_trigger_chkpt_command);
dsn::command_manager::instance().deregister_command(_query_compact_command);
dsn::command_manager::instance().deregister_command(_query_app_envs_command);
dsn::command_manager::instance().deregister_command(_useless_dir_reserve_seconds_command);

_kill_partition_command = nullptr;
_deny_client_command = nullptr;
Expand All @@ -2082,6 +2120,7 @@ void replica_stub::close()
_trigger_chkpt_command = nullptr;
_query_compact_command = nullptr;
_query_app_envs_command = nullptr;
_useless_dir_reserve_seconds_command = nullptr;

if (_config_sync_timer_task != nullptr) {
_config_sync_timer_task->cancel(true);
Expand Down
3 changes: 3 additions & 0 deletions src/dist/replication/lib/replica_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,13 @@ class replica_stub : public serverlet<replica_stub>, public ref_counter
dsn_handle_t _trigger_chkpt_command;
dsn_handle_t _query_compact_command;
dsn_handle_t _query_app_envs_command;
dsn_handle_t _useless_dir_reserve_seconds_command;

bool _deny_client;
bool _verbose_client_log;
bool _verbose_commit_log;
int32_t _gc_disk_error_replica_interval_seconds;
int32_t _gc_disk_garbage_replica_interval_seconds;

// we limit LT_APP max concurrent count, because nfs service implementation is
// too simple, it do not support priority.
Expand Down
9 changes: 5 additions & 4 deletions src/dist/replication/meta_server/server_load_balancer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "server_load_balancer.h"
#include <dsn/utility/extensible_object.h>
#include <dsn/utility/string_conv.h>
#include <dsn/tool-api/command_manager.h>
#include <boost/lexical_cast.hpp>

Expand Down Expand Up @@ -877,15 +878,15 @@ void simple_load_balancer::unregister_ctrl_commands()
std::string simple_load_balancer::ctrl_assign_delay_ms(const std::vector<std::string> &args)
{
std::string result("OK");
if (args.size() <= 0) {
if (args.empty()) {
result = std::to_string(_replica_assign_delay_ms_for_dropouts);
} else {
if (args[0] == "DEFAULT") {
_replica_assign_delay_ms_for_dropouts =
_svc->get_meta_options()._lb_opts.replica_assign_delay_ms_for_dropouts;
} else {
int v = atoi(args[0].c_str());
if (v <= 0) {
int32_t v = 0;
if (!dsn::buf2int32(args[0], v) || v <= 0) {
result = std::string("ERR: invalid arguments");
} else {
_replica_assign_delay_ms_for_dropouts = v;
Expand All @@ -900,7 +901,7 @@ simple_load_balancer::ctrl_assign_secondary_black_list(const std::vector<std::st
{
std::string invalid_arguments("invalid arguments");
std::stringstream oss;
if (args.size() <= 0) {
if (args.empty()) {
dsn::zauto_read_lock l(_black_list_lock);
oss << "get ok: ";
for (auto iter = _assign_secondary_black_list.begin();
Expand Down
7 changes: 4 additions & 3 deletions src/dist/replication/meta_server/server_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/

#include <dsn/utility/factory_store.h>
#include <dsn/utility/string_conv.h>
#include <dsn/tool-api/task.h>
#include <dsn/tool-api/command_manager.h>
#include <dsn/tool-api/async_calls.h>
Expand Down Expand Up @@ -130,15 +131,15 @@ void server_state::register_cli_commands()
"control the max count to add secondary for one node",
[this](const std::vector<std::string> &args) {
std::string result("OK");
if (args.size() <= 0) {
if (args.empty()) {
result = std::to_string(_add_secondary_max_count_for_one_node);
} else {
if (args[0] == "DEFAULT") {
_add_secondary_max_count_for_one_node =
_meta_svc->get_meta_options().add_secondary_max_count_for_one_node;
} else {
int v = atoi(args[0].c_str());
if (v < 0) {
int32_t v = 0;
if (!dsn::buf2int32(args[0], v) || v < 0) {
result = std::string("ERR: invalid arguments");
} else {
_add_secondary_max_count_for_one_node = v;
Expand Down

0 comments on commit fb86225

Please sign in to comment.