From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH 2/3] wal: rollback vclock on write failure Date: Fri, 15 Jun 2018 18:48:21 +0300 [thread overview] Message-ID: <b05491486b91c350fee7656f1af926504e439ac4.1529075903.git.vdavydov.dev@gmail.com> (raw) In-Reply-To: <cover.1529075903.git.vdavydov.dev@gmail.com> In-Reply-To: <cover.1529075903.git.vdavydov.dev@gmail.com> In order to determine whether we need to rebootstrap the instance on startup, we need to know its vclock. To find it out, we scan the last xlog file before proceeding to local recovery, but this means in case rebootstrap is not required we scan the last xlog twice, which is sub-optimal. To avoid double scan, we can create a new empty xlog before shutting down the server and reopen it after restart. However, since we promote WAL writer vclock even if xlog write fails, there will be an LSN gap between the last xlog and the one created on shutdown in case we failed to write last few records. To avoid that, let's rollback WAL writer vclock if write fails. BTW this will make it consistent with replicaset vclock - see commit 3c4bac715960a ("Follow vclock only for success wal writes"). --- src/box/wal.c | 8 +++++++- test/xlog/panic_on_lsn_gap.result | 33 +++++++++++++-------------------- test/xlog/panic_on_lsn_gap.test.lua | 15 ++++----------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/box/wal.c b/src/box/wal.c index f6b0fa66..1c6d2422 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -637,14 +637,18 @@ wal_write_to_disk(struct cmsg *msg) */ struct journal_entry *entry; struct stailq_entry *last_committed = NULL; + struct vclock last_committed_vclock; + vclock_copy(&last_committed_vclock, &writer->vclock); stailq_foreach_entry(entry, &wal_msg->commit, fifo) { wal_assign_lsn(writer, entry->rows, entry->rows + entry->n_rows); entry->res = vclock_sum(&writer->vclock); int rc = xlog_write_entry(l, entry); if (rc < 0) goto done; - if (rc > 0) + if (rc > 0) { last_committed = &entry->fifo; + vclock_copy(&last_committed_vclock, &writer->vclock); + } /* rc == 0: the write is buffered in xlog_tx */ } if (xlog_flush(l) < 0) @@ -670,6 +674,8 @@ done: stailq_cut_tail(&wal_msg->commit, last_committed, &rollback); if (!stailq_empty(&rollback)) { + /* Reset WAL writer vclock. */ + vclock_copy(&writer->vclock, &last_committed_vclock); /* Update status of the successfully committed requests. */ stailq_foreach_entry(entry, &rollback, fifo) entry->res = -1; diff --git a/test/xlog/panic_on_lsn_gap.result b/test/xlog/panic_on_lsn_gap.result index 313850a6..731eec4e 100644 --- a/test/xlog/panic_on_lsn_gap.result +++ b/test/xlog/panic_on_lsn_gap.result @@ -31,10 +31,6 @@ box.info.vclock s = box.space._schema --- ... --- we need to have at least one record in the --- xlog otherwise the server believes that there --- is an lsn gap during recovery. --- s:replace{"key", 'test 1'} --- - ['key', 'test 1'] @@ -83,8 +79,8 @@ t - Failed to write to disk ... -- --- Before restart: oops, our LSN is 11, --- even though we didn't insert anything. +-- Before restart: our LSN is 1, because +-- we didn't insert anything. -- name = string.match(arg[0], "([^,]+)%.lua") --- @@ -100,8 +96,7 @@ require('fio').glob(name .. "/*.xlog") test_run:cmd("restart server panic") -- -- after restart: our LSN is the LSN of the --- last *written* row, all the failed --- rows are gone from lsn counter. +-- last written row, i.e. 1 again. -- box.info.vclock --- @@ -161,9 +156,7 @@ box.error.injection.set("ERRINJ_WAL_WRITE", false) ... -- -- Write a good row after a series of failed --- rows. There is a gap in LSN, correct, --- but it's *inside* a single WAL, so doesn't --- affect WAL search in recover_remaining_wals() +-- rows. There is no gap in LSN. -- s:replace{'key', 'test 2'} --- @@ -176,12 +169,12 @@ s:replace{'key', 'test 2'} -- box.info.vclock --- -- {1: 12} +- {1: 2} ... test_run:cmd("restart server panic") box.info.vclock --- -- {1: 12} +- {1: 2} ... box.space._schema:select{'key'} --- @@ -217,7 +210,7 @@ require('fio').glob(name .. "/*.xlog") --- - - panic/00000000000000000000.xlog - panic/00000000000000000001.xlog - - panic/00000000000000000012.xlog + - panic/00000000000000000002.xlog ... box.error.injection.set("ERRINJ_WAL_WRITE", true) --- @@ -229,14 +222,14 @@ box.space._schema:replace{"key", 'test 3'} ... box.info.vclock --- -- {1: 22} +- {1: 12} ... require('fio').glob(name .. "/*.xlog") --- - - panic/00000000000000000000.xlog - panic/00000000000000000001.xlog + - panic/00000000000000000002.xlog - panic/00000000000000000012.xlog - - panic/00000000000000000022.xlog ... -- and the next one (just to be sure box.space._schema:replace{"key", 'test 3'} @@ -245,14 +238,14 @@ box.space._schema:replace{"key", 'test 3'} ... box.info.vclock --- -- {1: 22} +- {1: 12} ... require('fio').glob(name .. "/*.xlog") --- - - panic/00000000000000000000.xlog - panic/00000000000000000001.xlog + - panic/00000000000000000002.xlog - panic/00000000000000000012.xlog - - panic/00000000000000000022.xlog ... box.error.injection.set("ERRINJ_WAL_WRITE", false) --- @@ -265,14 +258,14 @@ box.space._schema:replace{"key", 'test 4'} ... box.info.vclock --- -- {1: 25} +- {1: 13} ... require('fio').glob(name .. "/*.xlog") --- - - panic/00000000000000000000.xlog - panic/00000000000000000001.xlog + - panic/00000000000000000002.xlog - panic/00000000000000000012.xlog - - panic/00000000000000000022.xlog ... -- restart is ok test_run:cmd("restart server panic") diff --git a/test/xlog/panic_on_lsn_gap.test.lua b/test/xlog/panic_on_lsn_gap.test.lua index 248a3e63..7f16d68e 100644 --- a/test/xlog/panic_on_lsn_gap.test.lua +++ b/test/xlog/panic_on_lsn_gap.test.lua @@ -13,10 +13,6 @@ test_run:cmd("start server panic") test_run:cmd("switch panic") box.info.vclock s = box.space._schema --- we need to have at least one record in the --- xlog otherwise the server believes that there --- is an lsn gap during recovery. --- s:replace{"key", 'test 1'} box.info.vclock box.error.injection.set("ERRINJ_WAL_WRITE", true) @@ -34,8 +30,8 @@ end; test_run:cmd("setopt delimiter ''"); t -- --- Before restart: oops, our LSN is 11, --- even though we didn't insert anything. +-- Before restart: our LSN is 1, because +-- we didn't insert anything. -- name = string.match(arg[0], "([^,]+)%.lua") box.info.vclock @@ -43,8 +39,7 @@ require('fio').glob(name .. "/*.xlog") test_run:cmd("restart server panic") -- -- after restart: our LSN is the LSN of the --- last *written* row, all the failed --- rows are gone from lsn counter. +-- last written row, i.e. 1 again. -- box.info.vclock box.space._schema:select{'key'} @@ -65,9 +60,7 @@ box.info.vclock box.error.injection.set("ERRINJ_WAL_WRITE", false) -- -- Write a good row after a series of failed --- rows. There is a gap in LSN, correct, --- but it's *inside* a single WAL, so doesn't --- affect WAL search in recover_remaining_wals() +-- rows. There is no gap in LSN. -- s:replace{'key', 'test 2'} -- -- 2.11.0
next prev parent reply other threads:[~2018-06-15 15:48 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-08 17:34 [PATCH v2 00/11] Replica rejoin Vladimir Davydov 2018-06-08 17:34 ` [PATCH v2 01/11] box: retrieve instance uuid before starting local recovery Vladimir Davydov 2018-06-08 17:51 ` Konstantin Osipov 2018-06-08 17:34 ` [PATCH v2 02/11] box: refactor hot standby recovery Vladimir Davydov 2018-06-08 17:34 ` [PATCH v2 03/11] box: retrieve end vclock before starting local recovery Vladimir Davydov 2018-06-14 12:58 ` Konstantin Osipov 2018-06-08 17:34 ` [PATCH v2 04/11] box: open the port " Vladimir Davydov 2018-06-13 20:43 ` Konstantin Osipov 2018-06-14 8:31 ` Vladimir Davydov 2018-06-14 12:59 ` Konstantin Osipov 2018-06-15 15:48 ` [PATCH 0/3] Speed up recovery in case rebootstrap is not needed Vladimir Davydov 2018-06-15 15:48 ` [PATCH 1/3] xlog: erase eof marker when reopening existing file for writing Vladimir Davydov 2018-06-27 17:09 ` Konstantin Osipov 2018-06-15 15:48 ` Vladimir Davydov [this message] 2018-06-27 17:22 ` [PATCH 2/3] wal: rollback vclock on write failure Konstantin Osipov 2018-06-15 15:48 ` [PATCH 3/3] wal: create empty xlog on shutdown Vladimir Davydov 2018-06-27 17:29 ` Konstantin Osipov 2018-06-08 17:34 ` [PATCH v2 05/11] box: connect to remote peers before starting local recovery Vladimir Davydov 2018-06-13 20:45 ` Konstantin Osipov 2018-06-14 8:34 ` Vladimir Davydov 2018-06-14 12:59 ` Konstantin Osipov 2018-06-08 17:34 ` [PATCH v2 06/11] box: factor out local recovery function Vladimir Davydov 2018-06-13 20:50 ` Konstantin Osipov 2018-06-08 17:34 ` [PATCH v2 07/11] applier: inquire oldest vclock on connect Vladimir Davydov 2018-06-13 20:51 ` Konstantin Osipov 2018-06-14 8:40 ` Vladimir Davydov 2018-06-08 17:34 ` [PATCH v2 08/11] replication: rebootstrap instance on startup if it fell behind Vladimir Davydov 2018-06-13 20:55 ` Konstantin Osipov 2018-06-14 8:58 ` Vladimir Davydov 2018-06-08 17:34 ` [PATCH v2 09/11] vinyl: simplify vylog recovery from backup Vladimir Davydov 2018-06-08 17:34 ` [PATCH v2 10/11] vinyl: pass flags to vy_recovery_new Vladimir Davydov 2018-06-13 20:56 ` Konstantin Osipov 2018-06-08 17:34 ` [PATCH v2 11/11] vinyl: implement rebootstrap support Vladimir Davydov 2018-06-10 12:02 ` Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=b05491486b91c350fee7656f1af926504e439ac4.1529075903.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 2/3] wal: rollback vclock on write failure' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox