|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From dd87b1840c966fd25b81a7aa1071e8488c624db8 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Thu, 25 Sep 2014 17:26:40 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] journal-remote: fix counting of events written
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
After recent changes the number was always reported as 0, because
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
the accounting was done server_destroy(), called after the message was
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
already printed. But even before this change, the counts were wrong
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
because seqnum start at 0 only for newly created journal files, so when
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
appending to existing files, the calculated count was wrong anyway.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Also do some variable renaming for consistency and disable some low-level
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
debug messages.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/journal-remote/journal-remote-parse.c | 6 ++---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/journal-remote/journal-remote-write.c | 44 +++++++++++++++++--------------
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
2 files changed, 27 insertions(+), 23 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index e7eb1516fb..224e8f140b 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/journal-remote/journal-remote-parse.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/journal-remote/journal-remote-parse.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -367,7 +367,7 @@ int process_data(RemoteSource *source) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert(source->data_size == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = get_data_size(source);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- log_debug("get_data_size() -> %d", r);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ // log_debug("get_data_size() -> %d", r);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r == 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -386,7 +386,7 @@ int process_data(RemoteSource *source) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert(source->data_size > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = get_data_data(source, &data);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- log_debug("get_data_data() -> %d", r);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ // log_debug("get_data_data() -> %d", r);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r == 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -409,7 +409,7 @@ int process_data(RemoteSource *source) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
case STATE_DATA_FINISH:
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = get_data_newline(source);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- log_debug("get_data_newline() -> %d", r);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ // log_debug("get_data_newline() -> %d", r);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r == 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 8ede950bea..0139f851a5 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/journal-remote/journal-remote-write.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/journal-remote/journal-remote-write.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -99,11 +99,8 @@ Writer* writer_free(Writer *w) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
journal_file_close(w->journal);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (w->server) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- w->server->event_count += w->seqnum;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (w->hashmap_key)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- hashmap_remove(w->server->writers, w->hashmap_key);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (w->server && w->hashmap_key)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ hashmap_remove(w->server->writers, w->hashmap_key);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
free(w->hashmap_key);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -129,40 +126,47 @@ Writer* writer_ref(Writer *w) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return w;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int writer_write(Writer *s,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int writer_write(Writer *w,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
struct iovec_wrapper *iovw,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
dual_timestamp *ts,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
bool compress,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
bool seal) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- assert(s);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ assert(w);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert(iovw);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
assert(iovw->count > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (journal_file_rotate_suggested(s->journal, 0)) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (journal_file_rotate_suggested(w->journal, 0)) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_info("%s: Journal header limits reached or header out-of-date, rotating",
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- s->journal->path);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = do_rotate(&s->journal, compress, seal);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ w->journal->path);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = do_rotate(&w->journal, compress, seal);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = journal_file_append_entry(s->journal, ts, iovw->iovec, iovw->count,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- &s->seqnum, NULL, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- if (r >= 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = journal_file_append_entry(w->journal, ts, iovw->iovec, iovw->count,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ &w->seqnum, NULL, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r >= 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (w->server)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ w->server->event_count += 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- log_debug("%s: Write failed, rotating: %s", s->journal->path, strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = do_rotate(&s->journal, compress, seal);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_debug("%s: Write failed, rotating: %s", w->journal->path, strerror(-r));
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = do_rotate(&w->journal, compress, seal);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
else
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- log_info("%s: Successfully rotated journal", s->journal->path);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ log_info("%s: Successfully rotated journal", w->journal->path);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
log_debug("Retrying write.");
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- r = journal_file_append_entry(s->journal, ts, iovw->iovec, iovw->count,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- &s->seqnum, NULL, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- return r < 0 ? r : 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = journal_file_append_entry(w->journal, ts, iovw->iovec, iovw->count,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ &w->seqnum, NULL, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (w->server)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ w->server->event_count += 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|