r23795 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23794‎ | r23795 | r23796 >
Date:18:11, 6 July 2007
Author:river
Status:old
Tags:
Comment:
- slave write thread forgot to free binlog events, leaked memory
- add max-buffer config option, maximum number of binlog event to buffer in
each writer
Modified paths:
  • /trunk/tools/trainwreck/trainwreck.c (modified) (history)

Diff [purge]

Index: trunk/tools/trainwreck/trainwreck.c
@@ -92,6 +92,7 @@
9393
9494 static char *binlog_file;
9595 static int64_t binlog_pos = 4;
 96+static int max_buffer = 0;
9697
9798 regex_t *db_regex;
9899
@@ -128,6 +129,7 @@
129130 pthread_mutex_t lq_mtx;
130131 pthread_cond_t lq_cond;
131132 struct lqhead lq_head;
 133+ int lq_entries;
132134 } le_queue_t;
133135
134136 static void lq_init(le_queue_t *);
@@ -329,6 +331,8 @@
330332 do_ignore_errno(atoi(value));
331333 } else if (!strcmp(opt, "nwriters")) {
332334 nwriters = atoi(value);
 335+ } else if (!strcmp(opt, "max-buffer")) {
 336+ max_buffer = atoi(value);
333337 } else if (!strcmp(opt, "only-replicate")) {
334338 int err;
335339 db_regex = calloc(1, sizeof(*db_regex));
@@ -736,6 +740,7 @@
737741 le_queue_t *q;
738742 {
739743 TAILQ_INIT(&q->lq_head);
 744+ q->lq_entries = 0;
740745 }
741746
742747 static void
@@ -745,9 +750,17 @@
746751 {
747752 lq_entry_t *entry;
748753 pthread_mutex_lock(&q->lq_mtx);
 754+ while (q->lq_entries >= max_buffer) {
 755+ logmsg("queue is full, sleeping...");
 756+ pthread_mutex_unlock(&q->lq_mtx);
 757+ sleep(5);
 758+ pthread_mutex_lock(&q->lq_mtx);
 759+ }
 760+
749761 entry = calloc(1, sizeof(lq_entry_t));
750762 entry->lqe_item = e;
751763 TAILQ_INSERT_TAIL(&q->lq_head, entry, lqe_q);
 764+ q->lq_entries++;
752765 pthread_cond_signal(&q->lq_cond);
753766 pthread_mutex_unlock(&q->lq_mtx);
754767 }
@@ -785,6 +798,7 @@
786799
787800 qe = TAILQ_FIRST(&q->lq_head);
788801 TAILQ_REMOVE(&q->lq_head, qe, lqe_q);
 802+ q->lq_entries--;
789803
790804 pthread_mutex_unlock(&q->lq_mtx);
791805
@@ -891,6 +905,7 @@
892906 }
893907 executed_up_to(self, e->le_file, e->le_pos);
894908 }
 909+ free_log_entry(e);
895910 self->wr_status = ST_WAIT_FOR_ENTRY;
896911 }
897912 return NULL;

Status & tagging log