<HTML><BODY>branch: gh-3026-fix-force-recovery-on-empty-xlog<br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_15174123610000000725_BODY"><br><br>
> From 0cf1e8263a28766319895108de2d17cf9d972e23 Mon Sep 17 00:00:00 2001<br>
> From: Konstantin Belyavskiy <<a href="mailto:k.belyavskiy@tarantool.org">k.belyavskiy@tarantool.org</a>><br>
> Date: Thu, 25 Jan 2018 15:46:22 +0300<br>
> Subject: [PATCH] Fix force_recovery on empty xlog<br>
> <br>
> * Fix force_recovery behaviour on empty xlog files and ones with corrupted header.<br>
> * Add a test<br>
> <br>
> Closes #3026, #3076<br>
> ---<br>
> src/box/recovery.cc | 25 +++++-----<br>
> src/box/xlog.c | 2 -<br>
> test/xlog/force_recovery.lua | 8 ++++<br>
> test/xlog/force_recovery.result | 98 +++++++++++++++++++++++++++++++++++++++<br>
> test/xlog/force_recovery.test.lua | 47 +++++++++++++++++++<br>
> 5 files changed, 167 insertions(+), 13 deletions(-)<br>
> create mode 100644 test/xlog/force_recovery.lua<br>
> create mode 100644 test/xlog/force_recovery.result<br>
> create mode 100644 test/xlog/force_recovery.test.lua<br>
> <br>
> diff --git a/src/box/recovery.cc b/src/box/recovery.cc<br>
> index 281ac1838..c3a6bb367 100644<br>
> --- a/src/box/recovery.cc<br>
> +++ b/src/box/recovery.cc<br>
> @@ -330,20 +330,24 @@ recovery_finalize(struct recovery *r, struct xstream *stream)<br>
> recovery_close_log(r);<br>
> <br>
> /*<br>
> - * Check that the last xlog file has rows.<br>
> + * Rename last corrupted xlog if any. Cases:<br>
> + * - file has corrupted rows<br>
> + * - file has corrupted header<br>
> + * - file has zero size<br><br>
The comment needs polishing. Please explain why we need to do this and<br>
why it is supposed to work.</div></div></div></div></blockquote><br>Update comment<br><br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_15174123610000000725_BODY"><br><br>
> */<br>
> - if (vclockset_last(&r->wal_dir.index) != NULL &&<br>
> - vclock_sum(&r->vclock) ==<br>
> - vclock_sum(vclockset_last(&r->wal_dir.index))) {<br>
> - /*<br>
> - * Delete the last empty xlog file.<br>
> - */<br><br>
> + if (vclockset_last(&r->wal_dir.index) != NULL) {<br><br>
I think you don't need this check any more.<br><br>
> char *name = xdir_format_filename(&r->wal_dir,<br>
> vclock_sum(&r->vclock),<br>
> NONE);<br>
> - if (unlink(name) != 0) {<br>
> - tnt_raise(SystemError, "%s: failed to unlink file",<br>
> - name);<br>
> + if (access(name, F_OK) == 0) {<br>
> + say_info("rename corrupted xlog %s", name);<br>
> + char to[PATH_MAX];<br>
> + snprintf(to, sizeof(to), "%s.corrupted", name);<br>
> + if (rename(name, to) != 0) {<br>
> + tnt_raise(SystemError,<br>
> + "%s: can't rename corrupted xlog",<br>
> + name);<br>
> + }<br>
> }<br>
> }<br>
> }<br></div></div></div></div></blockquote>
<br>Yes, you are right, remove it.<br>
<br>С уважением,<br>Konstantin Belyavskiy<br>k.belyavskiy@tarantool.org<br><style type="text/css"></style></BODY></HTML>