Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config for log cleaner #1171

Merged
merged 9 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ dir /tmp/kvrocks
# We also can send logs to stdout/stderr is as simple as:
#
log-dir stdout
# log-dir log

# You can configure log-retention-days to control whether to enable logcleaner
# and the maximum number of days that the INFO level logs will be kept.
# if set to -1 , this mean disable logcleaner.
# if set to between 0 to INT_MAX , this mean enable logcleaner ,
# and INFO level log file whose last modified time is greater than log-retention-days will be unlinked.
# if set to 0 , during the flush, the previous INFO level logs will be immediately unlinked.
# By default the log-retention-days is -1.
log-retention-days -1
IoCing marked this conversation as resolved.
Show resolved Hide resolved

# When running in daemonize mode, kvrocks writes a PID file in ${CONFIG_DIR}/kvrocks.pid by
# default. You can specify a custom pid file location here.
Expand Down
10 changes: 10 additions & 0 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Config::Config() {
{"migrate-sequence-gap", false, new IntField(&sequence_gap, 10000, 1, INT_MAX)},
{"unixsocket", true, new StringField(&unixsocket, "")},
{"unixsocketperm", true, new OctalField(&unixsocketperm, 0777, 1, INT_MAX)},
{"log-retention-days", false, new IntField(&log_retention_days, -1, -1, INT_MAX)},

/* rocksdb options */
{"rocksdb.compression", false, new EnumField(&RocksDB.compression, compression_type_enum, 0)},
Expand Down Expand Up @@ -457,6 +458,15 @@ void Config::initFieldCallback() {
if (cluster_enabled) srv->slot_migrate_->SetSequenceGapSize(sequence_gap);
return Status::OK();
}},
{"log-retention-days",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (log_retention_days != -1) {
IoCing marked this conversation as resolved.
Show resolved Hide resolved
google::EnableLogCleaner(log_retention_days);
} else {
google::DisableLogCleaner();
}
return Status::OK();
}},
{"rocksdb.target_file_size_base",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
Expand Down
1 change: 1 addition & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct Config {
int pipeline_size;
int sequence_gap;

int log_retention_days;
// profiling
int profiling_sample_ratio = 0;
int profiling_sample_record_threshold_ms = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ static void initGoogleLog(const Config *config) {
FLAGS_stderrthreshold = google::ERROR;
FLAGS_logtostdout = true;
} else {
FLAGS_log_dir = config->log_dir;
FLAGS_log_dir = config->log_dir + "/";
if (config->log_retention_days != -1) {
google::EnableLogCleaner(config->log_retention_days);
}
}
}

Expand Down