configureable using --log-ringbuf-size=<num-entries>.
Add an entry in the sysconfig file to set this persistently.
#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;
};
-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
{
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);
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;
}
}
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;
}
tmp_entry++;
- if (tmp_entry >= MAX_LOG_ENTRIES) {
+ if (tmp_entry >= log_ringbuf_size) {
tmp_entry = 0;
}
}
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"
}
# "-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
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 *),
{ "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;