Make the size of the in memory ringbuffer for keeping the recent log messages
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 15 Jan 2010 04:38:56 +0000 (15:38 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 15 Jan 2010 04:38:56 +0000 (15:38 +1100)
configureable using --log-ringbuf-size=<num-entries>.

Add an entry in the sysconfig file to set this persistently.

common/ctdb_logging.c
config/ctdb.init
config/ctdb.sysconfig
include/ctdb_private.h
server/ctdbd.c

index 64507f4a20faa80299570678e20e422a96bac182..ea4d2716302e8abd2281bd76db1a0dcdc550ec68 100644 (file)
@@ -24,7 +24,8 @@
 #include "../include/ctdb_private.h"
 #include "../include/ctdb.h"
 
-#define MAX_LOG_ENTRIES 500000
+int log_ringbuf_size;
+
 #define MAX_LOG_SIZE 128
 
 static int first_entry;
@@ -37,7 +38,7 @@ struct ctdb_log_entry {
 };
 
 
-static struct ctdb_log_entry log_entries[MAX_LOG_ENTRIES];
+static struct ctdb_log_entry *log_entries;
 
 /*
  * this function logs all messages for all levels to a ringbuffer
@@ -46,6 +47,14 @@ static void log_ringbuffer_v(const char *format, va_list ap)
 {
        int ret;
 
+       if (log_entries == NULL && log_ringbuf_size != 0) {
+               /* Hope this works. We cant log anything if it doesnt anyway */
+               log_entries = malloc(sizeof(struct ctdb_log_entry) * log_ringbuf_size);
+       }
+       if (log_entries == NULL) {
+               return;
+       }
+
        log_entries[last_entry].message[0] = '\0';
 
        ret = vsnprintf(&log_entries[last_entry].message[0], MAX_LOG_SIZE, format, ap);
@@ -57,13 +66,13 @@ static void log_ringbuffer_v(const char *format, va_list ap)
        log_entries[last_entry].t = timeval_current();
 
        last_entry++;
-       if (last_entry >= MAX_LOG_ENTRIES) {
+       if (last_entry >= log_ringbuf_size) {
                last_entry = 0;
        }
        if (first_entry == last_entry) {
                first_entry++;
        }
-       if (first_entry >= MAX_LOG_ENTRIES) {
+       if (first_entry >= log_ringbuf_size) {
                first_entry = 0;
        }
 }
@@ -100,9 +109,13 @@ static void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr
                struct tm *tm;
                char tbuf[100];
 
+               if (log_entries == NULL) {
+                       break;
+               }
+
                if (log_entries[tmp_entry].level > log_addr->level) {
                        tmp_entry++;
-                       if (tmp_entry >= MAX_LOG_ENTRIES) {
+                       if (tmp_entry >= log_ringbuf_size) {
                                tmp_entry = 0;
                        }
                        continue;
@@ -116,7 +129,7 @@ static void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr
                }
 
                tmp_entry++;
-               if (tmp_entry >= MAX_LOG_ENTRIES) {
+               if (tmp_entry >= log_ringbuf_size) {
                        tmp_entry = 0;
                }
        }
index 2e25cf168c4238e61b06fe8854fafb723e0f5768..96ffb1ece651069a2df0dc4da191be97614db2ff 100755 (executable)
@@ -102,6 +102,7 @@ build_ctdb_options () {
     maybe_set "--no-lmaster"             "$CTDB_CAPABILITY_LMASTER"   "no"
     maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
     maybe_set "--script-log-level"       "$CTDB_SCRIPT_LOG_LEVEL"
+    maybe_set "--log-ringbuf-size"       "$CTDB_LOG_RINGBUF_SIZE"
     maybe_set "--syslog"                 "$CTDB_SYSLOG"               "yes"
     maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
 }
index bc3100150e4a0b7c40374bfaf743bc6dc405942c..68d0bf6e699733fb731ffc364c0baa9cc998945c 100644 (file)
@@ -208,6 +208,13 @@ CTDB_DEBUGLEVEL=ERR
 # "-1" means wait forever.
 # CTDB_MAX_PERSISTENT_CHECK_ERRORS=0
 
+# All log entries up to level 9 are also collected into a in-memory ringbuffer
+# in addition to the log that is written to the log file.
+# This parameter controls how many entries we allow for this in memory log
+# CTDB_LOG_RINGBUF_SIZE=500000
+
+# 
+#
 # set any default tuning options for ctdb
 # use CTDB_SET_XXXX=value where XXXX is the name of the tuning
 # variable
index 6107bdfc2d3286ae4b3eda95f05aa57419aaebe4..6a99736bf9de29444cba4122d54478c8d46b15e1 100644 (file)
@@ -1538,8 +1538,12 @@ struct ctdb_get_log_addr {
        int32_t level;
 };
 
+extern int log_ringbuf_size;
+
 int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr);
 int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
+
+
 struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
                                              struct ctdb_context *ctdb,
                                              void (*logfn)(const char *, uint16_t, void *),
index 00f630b99ac406566aec90214fa7893ac4bbe812..41a1bed485e9c4904cfd936c0fe9b563c1cf4e29 100644 (file)
@@ -143,6 +143,7 @@ int main(int argc, const char *argv[])
                { "max-persistent-check-errors", 0, POPT_ARG_INT,
                  &options.max_persistent_check_errors, 0,
                  "max allowed persistent check errors (default 0)", NULL },
+               { "log-ringbuf-size", 0, POPT_ARG_INT, &log_ringbuf_size, DEBUG_ERR, "Number of log messages we can store in the memory ringbuffer", NULL },
                POPT_TABLEEND
        };
        int opt, ret;