de-duplicate journal replay somewhat

we've been using indices to separate master/slave state for a long time,
so there is no point in using pairs of matching brackets to signify the
side in the journal. instead, use somewhat descriptive letters (S[een],
F[ind], T[rashed]) and the index itself.
This commit is contained in:
Oswald Buddenhagen 2017-03-31 12:39:12 +02:00
parent af4b8896f0
commit 6705604c4a

View File

@ -596,7 +596,7 @@ clean_strdup( const char *s )
} }
#define JOURNAL_VERSION "2" #define JOURNAL_VERSION "3"
static int static int
prepare_state( sync_vars_t *svars ) prepare_state( sync_vars_t *svars )
@ -826,27 +826,21 @@ load_state( sync_vars_t *svars )
buf[t] = 0; buf[t] = 0;
if ((c = buf[0]) == '#' ? if ((c = buf[0]) == '#' ?
(t3 = 0, (sscanf( buf + 2, "%d %d %n", &t1, &t2, &t3 ) < 2) || !t3 || (t - t3 != TUIDL + 2)) : (t3 = 0, (sscanf( buf + 2, "%d %d %n", &t1, &t2, &t3 ) < 2) || !t3 || (t - t3 != TUIDL + 2)) :
c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || c == '!' ? c == '!' ?
(sscanf( buf + 2, "%d", &t1 ) != 1) : (sscanf( buf + 2, "%d", &t1 ) != 1) :
c == '+' || c == '&' || c == '-' || c == '|' || c == '/' || c == '\\' ? c == 'S' || c == 'F' || c == 'T' || c == '+' || c == '&' || c == '-' || c == '|' || c == '/' || c == '\\' ?
(sscanf( buf + 2, "%d %d", &t1, &t2 ) != 2) : (sscanf( buf + 2, "%d %d", &t1, &t2 ) != 2) :
(sscanf( buf + 2, "%d %d %d", &t1, &t2, &t3 ) != 3)) (sscanf( buf + 2, "%d %d %d", &t1, &t2, &t3 ) != 3))
{ {
error( "Error: malformed journal entry at %s:%d\n", svars->jname, line ); error( "Error: malformed journal entry at %s:%d\n", svars->jname, line );
goto jbail; goto jbail;
} }
if (c == '(') if (c == 'S')
svars->maxuid[M] = t1; svars->maxuid[t1] = t2;
else if (c == ')') else if (c == 'F')
svars->maxuid[S] = t1; svars->newuid[t1] = t2;
else if (c == '{') else if (c == 'T')
svars->newuid[M] = t1; *int_array_append( &svars->trashed_msgs[t1] ) = t2;
else if (c == '}')
svars->newuid[S] = t1;
else if (c == '[')
*int_array_append( &svars->trashed_msgs[M] ) = t1;
else if (c == ']')
*int_array_append( &svars->trashed_msgs[S] ) = t1;
else if (c == '!') else if (c == '!')
svars->smaxxuid = t1; svars->smaxxuid = t1;
else if (c == '|') { else if (c == '|') {
@ -1819,7 +1813,7 @@ box_loaded( int sts, void *aux )
fdatasync( fileno( svars->jfp ) ); fdatasync( fileno( svars->jfp ) );
for (t = 0; t < 2; t++) { for (t = 0; t < 2; t++) {
svars->newuid[t] = svars->ctx[t]->uidnext; svars->newuid[t] = svars->ctx[t]->uidnext;
jFprintf( svars, "%c %d\n", "{}"[t], svars->newuid[t] ); jFprintf( svars, "F %d %d\n", t, svars->newuid[t] );
svars->new_msgs[t] = svars->ctx[1-t]->msgs; svars->new_msgs[t] = svars->ctx[1-t]->msgs;
msgs_copied( svars, t ); msgs_copied( svars, t );
if (check_cancel( svars )) if (check_cancel( svars ))
@ -1929,7 +1923,7 @@ msgs_copied( sync_vars_t *svars, int t )
if (svars->new_pending[t]) if (svars->new_pending[t])
goto out; goto out;
jFprintf( svars, "%c %d\n", ")("[t], svars->maxuid[1-t] ); jFprintf( svars, "S %d %d\n", 1-t, svars->maxuid[1-t] );
sync_close( svars, 1-t ); sync_close( svars, 1-t );
if (check_cancel( svars )) if (check_cancel( svars ))
goto out; goto out;
@ -2100,7 +2094,7 @@ msg_trashed( int sts, void *aux )
return; return;
INIT_SVARS(vars->aux); INIT_SVARS(vars->aux);
debug( " -> trashed %s %d\n", str_ms[t], vars->msg->uid ); debug( " -> trashed %s %d\n", str_ms[t], vars->msg->uid );
jFprintf( svars, "%c %d\n", "[]"[t], vars->msg->uid ); jFprintf( svars, "T %d %d\n", t, vars->msg->uid );
free( vars ); free( vars );
trash_done[t]++; trash_done[t]++;
stats(); stats();
@ -2123,7 +2117,7 @@ msg_rtrashed( int sts, int uid ATTR_UNUSED, copy_vars_t *vars )
} }
t ^= 1; t ^= 1;
debug( " -> remote trashed %s %d\n", str_ms[t], vars->msg->uid ); debug( " -> remote trashed %s %d\n", str_ms[t], vars->msg->uid );
jFprintf( svars, "%c %d\n", "[]"[t], vars->msg->uid ); jFprintf( svars, "T %d %d\n", t, vars->msg->uid );
free( vars ); free( vars );
trash_done[t]++; trash_done[t]++;
stats(); stats();