summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--daemon/main.c33
-rw-r--r--database/engine/journalfile.c4
-rw-r--r--database/engine/journalfile.h2
-rw-r--r--database/engine/rrdengine.c2
4 files changed, 31 insertions, 10 deletions
diff --git a/daemon/main.c b/daemon/main.c
index 2c10cb00bb..0d067c86a0 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -591,6 +591,32 @@ int killpid(pid_t pid) {
return ret;
}
+static void set_nofile_limit(struct rlimit *rl) {
+ // get the num files allowed
+ if(getrlimit(RLIMIT_NOFILE, rl) != 0) {
+ error("getrlimit(RLIMIT_NOFILE) failed");
+ return;
+ }
+
+ info("resources control: allowed file descriptors: soft = %zu, max = %zu",
+ (size_t) rl->rlim_cur, (size_t) rl->rlim_max);
+
+ // make the soft/hard limits equal
+ rl->rlim_cur = rl->rlim_max;
+ if (setrlimit(RLIMIT_NOFILE, rl) != 0) {
+ error("setrlimit(RLIMIT_NOFILE, { %llu, %llu }) failed", rl->rlim_cur, rl->rlim_max);
+ }
+
+ // sanity check to make sure we have enough file descriptors available to open
+ if (getrlimit(RLIMIT_NOFILE, rl) != 0) {
+ error("getrlimit(RLIMIT_NOFILE) failed");
+ return;
+ }
+
+ if (rl->rlim_cur < 1024)
+ error("Number of open file descriptors allowed for this process is too low (RLIMIT_NOFILE=%zu)", (size_t) rl->rlim_cur);
+}
+
void cancel_main_threads() {
error_log_limit_unlimited();
@@ -1883,12 +1909,7 @@ int main(int argc, char **argv) {
}
#endif /* NETDATA_INTERNAL_CHECKS */
- // get the max file limit
- if(getrlimit(RLIMIT_NOFILE, &rlimit_nofile) != 0)
- error("getrlimit(RLIMIT_NOFILE) failed");
- else
- info("resources control: allowed file descriptors: soft = %zu, max = %zu", (size_t)rlimit_nofile.rlim_cur, (size_t)rlimit_nofile.rlim_max);
-
+ set_nofile_limit(&rlimit_nofile);
delta_startup_time("become daemon");
diff --git a/database/engine/journalfile.c b/database/engine/journalfile.c
index 1391fbadef..f188fe7e35 100644
--- a/database/engine/journalfile.c
+++ b/database/engine/journalfile.c
@@ -213,10 +213,10 @@ static bool journalfile_v2_mounted_data_unmount(struct rrdengine_journalfile *jo
return unmounted;
}
-void journalfile_v2_data_unmount_cleanup(time_t now_s) {
+void journalfile_v2_data_unmount_cleanup(time_t now_s, int storage_tiers) {
// DO NOT WAIT ON ANY LOCK!!!
- for(size_t tier = 0; tier < RRD_STORAGE_TIERS ;tier++) {
+ for(size_t tier = 0; tier < storage_tiers ;tier++) {
struct rrdengine_instance *ctx = multidb_ctx[tier];
if(!ctx) continue;
diff --git a/database/engine/journalfile.h b/database/engine/journalfile.h
index 55ef5be239..36cba44750 100644
--- a/database/engine/journalfile.h
+++ b/database/engine/journalfile.h
@@ -152,6 +152,6 @@ size_t journalfile_v2_data_size_get(struct rrdengine_journalfile *journalfile);
void journalfile_v2_data_set(struct rrdengine_journalfile *journalfile, int fd, void *journal_data, uint32_t journal_data_size);
struct journal_v2_header *journalfile_v2_data_acquire(struct rrdengine_journalfile *journalfile, size_t *data_size, time_t wanted_first_time_s, time_t wanted_last_time_s);
void journalfile_v2_data_release(struct rrdengine_journalfile *journalfile);
-void journalfile_v2_data_unmount_cleanup(time_t now_s);
+void journalfile_v2_data_unmount_cleanup(time_t now_s, int storage_tiers);
#endif /* NETDATA_JOURNALFILE_H */ \ No newline at end of file
diff --git a/database/engine/rrdengine.c b/database/engine/rrdengine.c
index 97d3ece202..35fb03fdb3 100644
--- a/database/engine/rrdengine.c
+++ b/database/engine/rrdengine.c
@@ -1487,7 +1487,7 @@ void timer_cb(uv_timer_t* handle) {
time_t now_s = now_monotonic_sec();
if(now_s - last_run_s >= 10) {
last_run_s = now_s;
- journalfile_v2_data_unmount_cleanup(now_s);
+ journalfile_v2_data_unmount_cleanup(now_s, storage_tiers);
}
}