r23810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23809‎ | r23810 | r23811 >
Date:23:51, 6 July 2007
Author:river
Status:old
Tags:
Comment:
"twctl status" should show lag behind master
Modified paths:
  • /trunk/tools/trainwreck/trainwreck.c (modified) (history)
  • /trunk/tools/trainwreck/twctl.c (modified) (history)

Diff [purge]

Index: trunk/tools/trainwreck/trainwreck.c
@@ -141,6 +141,7 @@
142142 pthread_t wr_thread;
143143 logpos_t wr_last_executed_pos;
144144 char *wr_last_executed_file;
 145+ uint32_t wr_last_executed_time;
145146 le_queue_t wr_log_queue;
146147 MYSQL *wr_conn;
147148 int wr_rstat;
@@ -875,6 +876,7 @@
876877 self->wr_num, e->le_database);
877878
878879 self->wr_status = ST_EXECUTING;
 880+ self->wr_last_executed_time = e->le_time;
879881 if (mysql_select_db(self->wr_conn, e->le_database) != 0) {
880882 logmsg("%s,%lu: cannot select \"%s\": %s",
881883 e->le_file, (unsigned long) e->le_pos,
@@ -1148,7 +1150,7 @@
11491151 case RQ_WRITER_POSITION:
11501152 pthread_mutex_lock(&wst_mtx);
11511153 offs = 2;
1152 - st = alloca(1 + (6 + BINLOG_NAMELEN) * nwriters);
 1154+ st = alloca(1 + (10 + BINLOG_NAMELEN) * nwriters);
11531155 st[0] = RR_OK;
11541156 st[1] = nwriters;
11551157
@@ -1161,9 +1163,10 @@
11621164
11631165 blen = strlen(writers[i].wr_last_executed_file);
11641166 int4store(st + offs, writers[i].wr_last_executed_pos);
1165 - int2store(st + offs + 4, (uint16_t) blen);
1166 - memcpy(st + offs + 6, writers[i].wr_last_executed_file, blen);
1167 - offs += 6 + blen;
 1167+ int4store(st + offs + 4, (uint32_t) writers[i].wr_last_executed_time);
 1168+ int2store(st + offs + 8, (uint16_t) blen);
 1169+ memcpy(st + offs + 10, writers[i].wr_last_executed_file, blen);
 1170+ offs += 10 + blen;
11681171 }
11691172
11701173 pthread_mutex_unlock(&wst_mtx);
Index: trunk/tools/trainwreck/twctl.c
@@ -25,6 +25,7 @@
2626 static int rq_shutdown(void);
2727
2828 static char const *status_to_name(int);
 29+static char const *format_seconds(uint32_t nsecs);
2930
3031 static int door;
3132 static door_arg_t args;
@@ -135,7 +136,7 @@
136137 rq_status()
137138 {
138139 char rq = RQ_STATUS;
139 -uint32_t logpos;
 140+uint32_t logpos, logtime;
140141 char *logname;
141142 int rstat;
142143 char *wstats;
@@ -243,10 +244,16 @@
244245 continue;
245246 }
246247
247 - loglen = uint2korr(args.rbuf + 4);
 248+ logtime = uint4korr(args.rbuf + 4);
 249+ loglen = uint2korr(args.rbuf + 8);
248250 (void) printf(" log position: %.*s,%lu\n",
249 - loglen, args.rbuf + 6,
 251+ loglen, args.rbuf + 10,
250252 (unsigned long) logpos);
 253+ if (logtime != 0) {
 254+ time_t now = time(NULL);
 255+ (void) printf(" seconds behind master: %s\n",
 256+ format_seconds(now - logtime));
 257+ }
251258 args.rbuf += 6 + loglen;
252259 i++;
253260 }
@@ -346,3 +353,31 @@
347354 return "unknown";
348355 }
349356 }
 357+
 358+static char const *
 359+format_seconds(t)
 360+ uint32_t t;
 361+{
 362+static char buf[512], *p = buf;
 363+int weeks, days, hours, minutes, seconds;
 364+ weeks = t / (60 * 60 * 24 * 7);
 365+ t %= (60 * 60 * 24 * 7);
 366+ days = t / (60 * 60 * 24);
 367+ t %= (60 * 60 * 24);
 368+ hours = t / (60 * 60);
 369+ t %= (60 * 60);
 370+ minutes = t / 60;
 371+ t %= 60;
 372+ seconds = t;
 373+
 374+ if (weeks)
 375+ p += sprintf(p, " %dw", weeks);
 376+ if (days)
 377+ p += sprintf(p, " %dd", days);
 378+ if (hours)
 379+ p += sprintf(p, " %dh", hours);
 380+ if (minutes)
 381+ p += sprintf(p, " %dm", minutes);
 382+ sprintf(p, " %ds", seconds);
 383+ return buf + 1;
 384+}

Status & tagging log