[SCM] CTDB repository - branch master updated - ctdb-1.0.104-9-g6427f0b
Ronnie Sahlberg
sahlberg at samba.org
Wed Nov 18 01:08:29 MST 2009
The branch, master has been updated
via 6427f0b68d60b556a023f64e15e156000ba6f943 (commit)
from 29d2ee8d9c6c6f36b2334480f646d6db209f370e (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 6427f0b68d60b556a023f64e15e156000ba6f943
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Wed Nov 18 19:10:50 2009 +1100
make the ringbuffer logging more efficient and marshall the data by writing to a tmpfile instead of continously talloc resizing a blob
-----------------------------------------------------------------------
Summary of changes:
common/ctdb_logging.c | 71 +++++++++++++++++++++++++++--------------------
include/ctdb_private.h | 8 -----
tools/ctdb.c | 21 ++------------
3 files changed, 44 insertions(+), 56 deletions(-)
Changeset truncated at 500 lines:
diff --git a/common/ctdb_logging.c b/common/ctdb_logging.c
index 3183fe8..efb47c6 100644
--- a/common/ctdb_logging.c
+++ b/common/ctdb_logging.c
@@ -20,6 +20,7 @@
#include "includes.h"
#include "lib/events/events.h"
#include "lib/tdb/include/tdb.h"
+#include "system/time.h"
#include "../include/ctdb_private.h"
#include "../include/ctdb.h"
@@ -82,49 +83,59 @@ void log_ringbuffer(const char *format, ...)
static void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr)
{
- char *buf = talloc_size(NULL, 0);
- struct ctdb_log_entry_wire *log_entry;
- uint32_t old_size, len;
TDB_DATA data;
+ FILE *f;
+ long fsize;
+ int tmp_entry;
+ int count = 0;
+ DEBUG(DEBUG_ERR,("Marshalling log entries first:%d last:%d\n", first_entry, last_entry));
+
+ /* dump to a file, then send the file as a blob */
+ f = tmpfile();
+ if (f == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Unable to open tmpfile - %s\n", strerror(errno)));
+ return;
+ }
- DEBUG(DEBUG_INFO,("Marshalling log entries\n"));
- while (first_entry != last_entry) {
- int slen = strlen(log_entries[first_entry].message);
+ tmp_entry = first_entry;
+ while (tmp_entry != last_entry) {
+ struct tm *tm;
+ char tbuf[100];
- if (log_entries[first_entry].level > log_addr->level) {
- first_entry++;
- if (first_entry >= MAX_LOG_ENTRIES) {
- first_entry = 0;
+ if (log_entries[tmp_entry].level > log_addr->level) {
+ tmp_entry++;
+ if (tmp_entry >= MAX_LOG_ENTRIES) {
+ tmp_entry = 0;
}
- continue;
+ continue;
}
- len = offsetof(struct ctdb_log_entry_wire, message) + slen + 1;
- /* pad it to uint42 */
- len = (len+3)&0xfffffffc;
+ tm = localtime(&log_entries[tmp_entry].t.tv_sec);
+ strftime(tbuf, sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
- old_size = talloc_get_size(buf);
- buf = talloc_realloc_size(NULL, buf, old_size + len);
-
- log_entry = (struct ctdb_log_entry_wire *)&buf[old_size];
- log_entry->level = log_entries[first_entry].level;
- log_entry->t = log_entries[first_entry].t;
- log_entry->message_len = slen;
- memcpy(log_entry->message, log_entries[first_entry].message, slen);
- log_entry->message[slen] = 0;
+ if (log_entries[tmp_entry].message) {
+ count += fprintf(f, "%s:%s %s", tbuf, get_debug_by_level(log_entries[tmp_entry].level), log_entries[tmp_entry].message);
+ }
- first_entry++;
- if (first_entry >= MAX_LOG_ENTRIES) {
- first_entry = 0;
+ tmp_entry++;
+ if (tmp_entry >= MAX_LOG_ENTRIES) {
+ tmp_entry = 0;
}
}
- data.dptr = (uint8_t *)buf;
- data.dsize = talloc_get_size(buf);
- DEBUG(DEBUG_INFO,("Marshalling log entries into a blob of %d bytes\n", (int)data.dsize));
+ fsize = ftell(f);
+ rewind(f);
+ data.dptr = talloc_size(NULL, fsize);
+ CTDB_NO_MEMORY_VOID(ctdb, data.dptr);
+ data.dsize = fread(data.dptr, 1, fsize, f);
+ fclose(f);
+
+ DEBUG(DEBUG_ERR,("Marshalling log entries into a blob of %d bytes\n", (int)data.dsize));
- DEBUG(DEBUG_INFO,("Send log to %d:%d\n", (int)log_addr->pnn, (int)log_addr->srvid));
+ DEBUG(DEBUG_ERR,("Send log to %d:%d\n", (int)log_addr->pnn, (int)log_addr->srvid));
ctdb_send_message(ctdb, log_addr->pnn, log_addr->srvid, data);
+
+ talloc_free(data.dptr);
}
int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr)
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index 48fb29b..674b0ac 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -1529,14 +1529,6 @@ struct ctdb_get_log_addr {
int32_t level;
};
-/* wire data for log entries, padded to uint32 */
-struct ctdb_log_entry_wire {
- int32_t level;
- struct timeval t;
- int32_t message_len;
- char message[1];
-};
-
int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr);
int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
diff --git a/tools/ctdb.c b/tools/ctdb.c
index e89640a..2cc7193 100644
--- a/tools/ctdb.c
+++ b/tools/ctdb.c
@@ -2357,26 +2357,11 @@ static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
static void log_handler(struct ctdb_context *ctdb, uint64_t srvid,
TDB_DATA data, void *private_data)
{
- struct ctdb_log_entry_wire *entry;
- int size;
- struct tm *tm;
- char tbuf[100];
-
DEBUG(DEBUG_ERR,("Log data received\n"));
- while (data.dsize > 0) {
- entry = (struct ctdb_log_entry_wire *)data.dptr;
- size = offsetof(struct ctdb_log_entry_wire, message) + entry->message_len + 1;
- size = (size+3)&0xfffffffc;
-
- tm = localtime(&entry->t.tv_sec);
-
- strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
-
- printf("%s:%s %s", tbuf, get_debug_by_level(entry->level), entry->message);
-
- data.dsize -= size;
- data.dptr += size;
+ if (data.dsize > 0) {
+ printf("%s", data.dptr);
}
+
exit(0);
}
--
CTDB repository
More information about the samba-cvs
mailing list