1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

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)
This commit is contained in:
Ronnie Sahlberg 2010-01-15 15:38:56 +11:00
parent f066939a62
commit a1d60b1511
5 changed files with 32 additions and 6 deletions

View 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;
}
}

View File

@ -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"
}

View 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

View 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 *),

View 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;