From 698f9ff173d472a777ab63ca2f095b9ba7a8e9b5 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 11 Dec 2021 15:43:21 +0100 Subject: [PATCH] don't log right before saving state unless requested only the journal replay autotest really needs it. in other cases it's just wasting time and ssd life. --- src/common.h | 1 + src/main.c | 3 +++ src/run-tests.pl | 2 +- src/sync.c | 8 ++++---- src/sync_p.h | 21 +++++++++++++-------- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/common.h b/src/common.h index bb557e6..48651e4 100644 --- a/src/common.h +++ b/src/common.h @@ -115,6 +115,7 @@ BIT_ENUM( ZERODELAY, KEEPJOURNAL, + FORCEJOURNAL, FORCEASYNC(2), ) diff --git a/src/main.c b/src/main.c index 892af95..70e35fa 100644 --- a/src/main.c +++ b/src/main.c @@ -438,6 +438,9 @@ main( int argc, char **argv ) case 'j': DFlags |= KEEPJOURNAL; break; + case 'J': + DFlags |= FORCEJOURNAL; + break; case 's': JLimit = strtol( ochar, &ochar, 10 ); break; diff --git a/src/run-tests.pl b/src/run-tests.pl index ef9f5e0..d2630b4 100755 --- a/src/run-tests.pl +++ b/src/run-tests.pl @@ -765,7 +765,7 @@ sub test_impl($$$$) mkchan($sx); - my ($xc, $ret) = runsync($async, "-Tj", "1-initial.log"); + my ($xc, $ret) = runsync($async, "-Tj -TJ", "1-initial.log"); my $rtx = readchan($$sx{state}) if (!$xc); if ($xc || cmpchan($rtx, $tx)) { print "Input:\n"; diff --git a/src/sync.c b/src/sync.c index 9c43ad1..3320531 100644 --- a/src/sync.c +++ b/src/sync.c @@ -1735,7 +1735,7 @@ box_closed_p2( sync_vars_t *svars, int t ) // of interruption - in particular skipping messages would otherwise // up the limit too early. if (svars->maxuid[t] != svars->oldmaxuid[t]) - JLOG( "N %d %u", (t, svars->maxuid[t]), "up maxuid of %s", str_fn[t] ); + PC_JLOG( "N %d %u", (t, svars->maxuid[t]), "up maxuid of %s", str_fn[t] ); } if (((svars->state[F] | svars->state[N]) & ST_DID_EXPUNGE) || svars->chan->max_messages) { @@ -1746,14 +1746,14 @@ box_closed_p2( sync_vars_t *svars, int t ) if (!srec->uid[N] || ((srec->status & S_DEL(N)) && (svars->state[N] & ST_DID_EXPUNGE))) { if (!srec->uid[F] || ((srec->status & S_DEL(F)) && (svars->state[F] & ST_DID_EXPUNGE)) || ((srec->status & S_EXPIRED) && svars->maxuid[F] >= srec->uid[F] && svars->maxxfuid >= srec->uid[F])) { - JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "killing" ); + PC_JLOG( "- %u %u", (srec->uid[F], srec->uid[N]), "killing" ); srec->status = S_DEAD; } else if (srec->uid[N]) { - JLOG( "> %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" ); + PC_JLOG( "> %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" ); srec->uid[N] = 0; } } else if (srec->uid[F] && ((srec->status & S_DEL(F)) && (svars->state[F] & ST_DID_EXPUNGE))) { - JLOG( "< %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" ); + PC_JLOG( "< %u %u 0", (srec->uid[F], srec->uid[N]), "orphaning" ); srec->uid[F] = 0; } } diff --git a/src/sync_p.h b/src/sync_p.h index 9fc48ee..581f939 100644 --- a/src/sync_p.h +++ b/src/sync_p.h @@ -72,17 +72,22 @@ void delete_state( sync_vars_t *svars ); void ATTR_PRINTFLIKE(2, 3) jFprintf( sync_vars_t *svars, const char *msg, ... ); -#define JLOG_(log_fmt, log_args, dbg_fmt, ...) \ +#define JLOG_(pre_commit, log_fmt, log_args, dbg_fmt, ...) \ do { \ - debug( "-> log: " log_fmt " (" dbg_fmt ")\n", __VA_ARGS__ ); \ - jFprintf( svars, log_fmt "\n", deparen(log_args) ); \ + if (pre_commit && !(DFlags & FORCEJOURNAL)) { \ + debug( "-> (log: " log_fmt ") (" dbg_fmt ")\n", __VA_ARGS__ ); \ + } else { \ + debug( "-> log: " log_fmt " (" dbg_fmt ")\n", __VA_ARGS__ ); \ + jFprintf( svars, log_fmt "\n", deparen(log_args) ); \ + } \ } while (0) -#define JLOG3(log_fmt, log_args, dbg_fmt) \ - JLOG_(log_fmt, log_args, dbg_fmt, deparen(log_args)) -#define JLOG4(log_fmt, log_args, dbg_fmt, dbg_args) \ - JLOG_(log_fmt, log_args, dbg_fmt, deparen(log_args), deparen(dbg_args)) +#define JLOG3(pre_commit, log_fmt, log_args, dbg_fmt) \ + JLOG_(pre_commit, log_fmt, log_args, dbg_fmt, deparen(log_args)) +#define JLOG4(pre_commit, log_fmt, log_args, dbg_fmt, dbg_args) \ + JLOG_(pre_commit, log_fmt, log_args, dbg_fmt, deparen(log_args), deparen(dbg_args)) #define JLOG_SEL(_1, _2, _3, _4, x, ...) x -#define JLOG(...) JLOG_SEL(__VA_ARGS__, JLOG4, JLOG3, NO_JLOG2, NO_JLOG1)(__VA_ARGS__) +#define JLOG(...) JLOG_SEL(__VA_ARGS__, JLOG4, JLOG3, NO_JLOG2, NO_JLOG1)(0, __VA_ARGS__) +#define PC_JLOG(...) JLOG_SEL(__VA_ARGS__, JLOG4, JLOG3, NO_JLOG2, NO_JLOG1)(1, __VA_ARGS__) void assign_uid( sync_vars_t *svars, sync_rec_t *srec, int t, uint uid );