From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH 06/10] ddl: restore sequence value if drop is rolled back Date: Wed, 3 Jul 2019 22:30:08 +0300 [thread overview] Message-ID: <c4b69329f171765850f160c1f8e85888a1765cf4.1562181197.git.vdavydov.dev@gmail.com> (raw) In-Reply-To: <cover.1562181197.git.vdavydov.dev@gmail.com> In-Reply-To: <cover.1562181197.git.vdavydov.dev@gmail.com> A sequence isn't supposed to roll back to the old value if the transaction it was used in is aborted for some reason. However, if a sequence is dropped, we do want to restore the original value on rollback so that we don't lose it on an unsuccessful attempt to drop the sequence. --- src/box/alter.cc | 24 ++++++++++++++++++++++++ test/box/sequence.result | 21 +++++++++++++++++++++ test/box/sequence.test.lua | 10 ++++++++++ 3 files changed, 55 insertions(+) diff --git a/src/box/alter.cc b/src/box/alter.cc index 89ab9c65..4f046ef6 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -3460,6 +3460,20 @@ on_replace_dd_sequence(struct trigger * /* trigger */, void *event) trigger_run_xc(&on_alter_sequence, seq); } +/** Restore the old sequence value on rollback. */ +static void +on_drop_sequence_data_rollback(struct trigger *trigger, void * /* event */) +{ + struct tuple *tuple = (struct tuple *)trigger->data; + uint32_t id = tuple_field_u32_xc(tuple, BOX_SEQUENCE_DATA_FIELD_ID); + int64_t val = tuple_field_i64_xc(tuple, BOX_SEQUENCE_DATA_FIELD_VALUE); + + struct sequence *seq = sequence_by_id(id); + assert(seq != NULL); + if (sequence_set(seq, val) != 0) + panic("Can't restore sequence value"); +} + /** * A trigger invoked on replace in space _sequence_data. * Used to update a sequence value. @@ -3483,6 +3497,16 @@ on_replace_dd_sequence_data(struct trigger * /* trigger */, void *event) if (sequence_set(seq, value) != 0) diag_raise(); } else { /* DELETE */ + /* + * A sequence isn't supposed to roll back to the old + * value if the transaction it was used in is aborted + * for some reason. However, if a sequence is dropped, + * we do want to restore the original sequence value + * on rollback. + */ + struct trigger *on_rollback = txn_alter_trigger_new( + on_drop_sequence_data_rollback, old_tuple); + txn_on_rollback(txn, on_rollback); sequence_reset(seq); } } diff --git a/test/box/sequence.result b/test/box/sequence.result index 99eed0ec..91795290 100644 --- a/test/box/sequence.result +++ b/test/box/sequence.result @@ -2249,3 +2249,24 @@ sq:drop() s:drop() --- ... +-- +-- Check that if a deletion from _sequence_data is rolled back, +-- the sequence state is restored. +-- +sq = box.schema.sequence.create('test') +--- +... +sq:next() -- 1 +--- +- 1 +... +box.begin() box.space._sequence_data:delete{sq.id} box.rollback() +--- +... +sq:next() -- 2 +--- +- 2 +... +sq:drop() +--- +... diff --git a/test/box/sequence.test.lua b/test/box/sequence.test.lua index 9615c447..b0ec020e 100644 --- a/test/box/sequence.test.lua +++ b/test/box/sequence.test.lua @@ -761,3 +761,13 @@ s:insert{box.NULL} -- ok s.index.pk:alter{sequence = false} sq:drop() s:drop() + +-- +-- Check that if a deletion from _sequence_data is rolled back, +-- the sequence state is restored. +-- +sq = box.schema.sequence.create('test') +sq:next() -- 1 +box.begin() box.space._sequence_data:delete{sq.id} box.rollback() +sq:next() -- 2 +sq:drop() -- 2.11.0
next prev parent reply other threads:[~2019-07-03 19:30 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-03 19:30 [PATCH 00/10] Prepare box/alter.cc for transactional DDL Vladimir Davydov 2019-07-03 19:30 ` [PATCH 01/10] ddl: unreference view on space drop synchronously Vladimir Davydov 2019-07-03 19:37 ` Konstantin Osipov 2019-07-03 19:30 ` [PATCH 02/10] ddl: synchronize user cache with actual data state Vladimir Davydov 2019-07-03 19:43 ` Konstantin Osipov 2019-07-03 20:00 ` Vladimir Davydov 2019-07-04 7:42 ` [tarantool-patches] " Konstantin Osipov 2019-07-03 19:30 ` [PATCH 03/10] ddl: synchronize func " Vladimir Davydov 2019-07-04 8:12 ` Konstantin Osipov 2019-07-03 19:30 ` [PATCH 04/10] ddl: synchronize sequence " Vladimir Davydov 2019-07-04 8:16 ` Konstantin Osipov 2019-07-03 19:30 ` [PATCH 05/10] ddl: fix _space_sequence rollback Vladimir Davydov 2019-07-03 19:30 ` Vladimir Davydov [this message] 2019-07-03 19:30 ` [PATCH 07/10] ddl: don't use txn_last_stmt on _collation commit/rollback Vladimir Davydov 2019-07-03 19:30 ` [PATCH 08/10] ddl: don't use txn_last_stmt on _trigger commit/rollback Vladimir Davydov 2019-07-03 19:30 ` [PATCH 09/10] ddl: don't use txn_last_stmt on _ck_constraint commit/rollback Vladimir Davydov 2019-07-03 19:30 ` [PATCH 10/10] ddl: don't use txn_last_stmt on _cluster commit/rollback Vladimir Davydov 2019-07-04 15:01 ` [PATCH 00/10] Prepare box/alter.cc for transactional DDL 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=c4b69329f171765850f160c1f8e85888a1765cf4.1562181197.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 06/10] ddl: restore sequence value if drop is rolled back' \ /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