diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2010-01-15 15:38:56 +1100 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2010-01-15 15:38:56 +1100 |
commit | a1d60b1511c710a093bf4c76a69b789288b1bd7d (patch) | |
tree | e436460545a915b7a06d198327b0f34861079f08 | |
parent | f066939a62c72dde8858c53c7e38e3dd3892e7c8 (diff) | |
download | samba-a1d60b1511c710a093bf4c76a69b789288b1bd7d.tar.gz samba-a1d60b1511c710a093bf4c76a69b789288b1bd7d.tar.xz samba-a1d60b1511c710a093bf4c76a69b789288b1bd7d.zip |
Make the size of the in memory ringbuffer for keeping the recent log messages
configureable using --log-ringbuf-size=<num-entries>.
Add an entry in the sysconfig file to set this persistently.
(This used to be ctdb commit c79c2da69bc352f509e7fca4b9172a4b7f23c0f8)
-rw-r--r-- | ctdb/common/ctdb_logging.c | 25 | ||||
-rwxr-xr-x | ctdb/config/ctdb.init | 1 | ||||
-rw-r--r-- | ctdb/config/ctdb.sysconfig | 7 | ||||
-rw-r--r-- | ctdb/include/ctdb_private.h | 4 | ||||
-rw-r--r-- | ctdb/server/ctdbd.c | 1 |
5 files changed, 32 insertions, 6 deletions
diff --git a/ctdb/common/ctdb_logging.c b/ctdb/common/ctdb_logging.c index 64507f4a20f..ea4d2716302 100644 --- a/ctdb/common/ctdb_logging.c +++ b/ctdb/common/ctdb_logging.c @@ -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; } } diff --git a/ctdb/config/ctdb.init b/ctdb/config/ctdb.init index 2e25cf168c4..96ffb1ece65 100755 --- a/ctdb/config/ctdb.init +++ b/ctdb/config/ctdb.init @@ -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" } diff --git a/ctdb/config/ctdb.sysconfig b/ctdb/config/ctdb.sysconfig index bc3100150e4..68d0bf6e699 100644 --- a/ctdb/config/ctdb.sysconfig +++ b/ctdb/config/ctdb.sysconfig @@ -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 diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 6107bdfc2d3..6a99736bf9d 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -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 *), diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c index 00f630b99ac..41a1bed485e 100644 --- a/ctdb/server/ctdbd.c +++ b/ctdb/server/ctdbd.c @@ -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; |