From 597b26e4329133c605729c4a67322ed43449fbe0 Mon Sep 17 00:00:00 2001 From: Emeric Brun Date: Fri, 12 Aug 2016 11:23:31 +0200 Subject: [PATCH] BUG/MINOR: peers: empty chunks after a resync. After pushing the last update related to a resync process, the teacher resets the re-connection's origin to the saved one (pointer position when he receive the resync request). But the last acknowledgement overwrites this pointer to an inconsistent value. In peersv2, it results with empty table chunks regularly pushed. The fix consist to move the confirm code to assure that the confirm message is always sent after the last acknowledgement related to the resync. And to reset the re-connection's origin to the saved one when a confirm message is received. This bug affects versions 1.6 and superior. For older versions (peersv1), this inconsistent state should not generate side effects because chunks are not used and a next acknowlegement message resets the pointer in a valid state. --- src/peers.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/peers.c b/src/peers.c index b3a14e6..6f88c19 100644 --- a/src/peers.c +++ b/src/peers.c @@ -886,6 +886,7 @@ switchstate: curpeer->confirm++; } else if (msg_head[1] == PEER_MSG_CTRL_RESYNCCONFIRM) { + struct shared_table *st; /* If stopping state */ if (stopping) { @@ -894,6 +895,10 @@ switchstate: appctx->st0 = PEER_SESS_ST_END; goto switchstate; } + for (st = curpeer->tables; st; st = st->next) { + st->update = st->last_pushed = st->teaching_origin; + st->flags = 0; + } /* reset teaching flags to 0 */ curpeer->flags &= PEER_TEACH_RESET; @@ -1224,25 +1229,6 @@ incomplete: } - /* Confirm finished or partial messages */ - while (curpeer->confirm) { - unsigned char msg[2]; - - /* There is a confirm messages to send */ - msg[0] = PEER_MSG_CLASS_CONTROL; - msg[1] = PEER_MSG_CTRL_RESYNCCONFIRM; - - /* message to buffer */ - repl = bi_putblk(si_ic(si), (char *)msg, sizeof(msg)); - if (repl <= 0) { - /* no more write possible */ - if (repl == -1) - goto full; - appctx->st0 = PEER_SESS_ST_END; - goto switchstate; - } - curpeer->confirm--; - } /* Need to request a resync */ @@ -1491,7 +1477,6 @@ incomplete: /* push local updates */ if (!eb || eb->key > st->teaching_origin) { st->flags |= SHTABLE_F_TEACH_STAGE2; - st->last_pushed = st->teaching_origin; break; } @@ -1548,6 +1533,26 @@ incomplete: curpeer->flags |= PEER_F_TEACH_FINISHED; } + /* Confirm finished or partial messages */ + while (curpeer->confirm) { + unsigned char msg[2]; + + /* There is a confirm messages to send */ + msg[0] = PEER_MSG_CLASS_CONTROL; + msg[1] = PEER_MSG_CTRL_RESYNCCONFIRM; + + /* message to buffer */ + repl = bi_putblk(si_ic(si), (char *)msg, sizeof(msg)); + if (repl <= 0) { + /* no more write possible */ + if (repl == -1) + goto full; + appctx->st0 = PEER_SESS_ST_END; + goto switchstate; + } + curpeer->confirm--; + } + /* noting more to do */ goto out; } -- 1.7.10.4