From d978328555e243d2b2155f98ea2875461409d906 Mon Sep 17 00:00:00 2001 From: oetiker Date: Sun, 28 Sep 2008 19:12:22 +0000 Subject: [PATCH] added support for FLUSHALL command -- kevin brintnall git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1535 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/doc/rrdcached.pod | 5 +++++ program/src/rrd_daemon.c | 42 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/program/doc/rrdcached.pod b/program/doc/rrdcached.pod index bf289c59..9254888e 100644 --- a/program/doc/rrdcached.pod +++ b/program/doc/rrdcached.pod @@ -316,6 +316,11 @@ Causes the daemon to put I to the B of the update queue (possibly moving it there if the node is already enqueued). The answer will be sent B the node has been dequeued. +=item B + +Causes the daemon to start flushing ALL pending values to disk. This +returns immediately, even though the writes may take a long time. + =item B [I] Returns a short usage message. If no command is given, or I is diff --git a/program/src/rrd_daemon.c b/program/src/rrd_daemon.c index f746a35c..0e29f131 100644 --- a/program/src/rrd_daemon.c +++ b/program/src/rrd_daemon.c @@ -769,8 +769,9 @@ static int handle_request_help (int fd, /* {{{ */ char *help_help[] = { - "4 Command overview\n", + "5 Command overview\n", "FLUSH \n", + "FLUSHALL\n", "HELP []\n", "UPDATE [ ...]\n", "STATS\n" @@ -787,6 +788,15 @@ static int handle_request_help (int fd, /* {{{ */ }; size_t help_flush_len = sizeof (help_flush) / sizeof (help_flush[0]); + char *help_flushall[] = + { + "3 Help for FLUSHALL\n", + "Usage: FLUSHALL\n", + "\n", + "Triggers writing of all pending updates. Returns immediately.\n" + }; + size_t help_flushall_len = sizeof(help_flushall) / sizeof(help_flushall[0]); + char *help_update[] = { "9 Help for UPDATE\n", @@ -830,6 +840,11 @@ static int handle_request_help (int fd, /* {{{ */ help_text = help_flush; help_text_len = help_flush_len; } + else if (strcasecmp (command, "flushall") == 0) + { + help_text = help_flushall; + help_text_len = help_flushall_len; + } else if (strcasecmp (command, "stats") == 0) { help_text = help_stats; @@ -992,6 +1007,27 @@ static int handle_request_flush (int fd, /* {{{ */ return (0); } /* }}} int handle_request_flush */ +static int handle_request_flushall(int fd) /* {{{ */ +{ + int status; + char answer[] ="0 Started flush.\n"; + + RRDD_LOG(LOG_DEBUG, "Received FLUSHALL"); + + pthread_mutex_lock(&cache_lock); + flush_old_values(-1); + pthread_mutex_unlock(&cache_lock); + + status = swrite(fd, answer, strlen(answer)); + if (status < 0) + { + status = errno; + RRDD_LOG(LOG_INFO, "handle_request_flushall: swrite returned an error."); + } + + return (status); +} + static int handle_request_update (int fd, /* {{{ */ char *buffer, size_t buffer_size) { @@ -1222,6 +1258,10 @@ static int handle_request (int fd, char *buffer, size_t buffer_size) /* {{{ */ { return (handle_request_flush (fd, buffer_ptr, buffer_size)); } + else if (strcasecmp (command, "flushall") == 0) + { + return (handle_request_flushall(fd)); + } else if (strcasecmp (command, "stats") == 0) { return (handle_request_stats (fd, buffer_ptr, buffer_size)); -- 2.30.2