Skip to content

memtx: fix story delete statement list#7215

Merged
alyapunov merged 1 commit intotarantool:masterfrom
CuriousGeorgiy:memtx-tx-history-prepare-insert-delete-stmt
Jul 6, 2022
Merged

memtx: fix story delete statement list#7215
alyapunov merged 1 commit intotarantool:masterfrom
CuriousGeorgiy:memtx-tx-history-prepare-insert-delete-stmt

Conversation

@CuriousGeorgiy
Copy link
Member

@CuriousGeorgiy CuriousGeorgiy commented May 30, 2022

Current implementation of tracking statements that delete a story has a
flaw, consider the following example:

tx1('box.space.s:replace{0, 0}') -- statement 1

tx2('box.space.s:replace{0, 1}') -- statement 2
tx2('box.space.s:delete{0}') -- statement 3
tx2('box.space.s:replace{0, 2}') -- statement 4

When statment 1 is prepared, both statements 2 and 4 will be linked to the
delete statement list of {0, 0}'s story, though, apparently, statement 4
does not delete {0, 0}.

Let us notice the following: statement 4 is "pure" in the sense that, in
the transaction's scope, it is guaranteed not to replace any tuple — we can
retrieve this information when we check where the insert statement violates
replacement rules, use it to determine "pure" insert statements, and skip
them later on when, during preparation of insert statements, we handle
other insert statements which assume they do not replace anything (i.e.,
have no visible old tuple).

We also need to fix relinking of delete statements from the older story
(in terms of the history chain) to the new one during preparation of insert
statements: a statement needs to be relinked iff it comes from a different
transaction (to be precise, there must, actually, be no more than one
delete statement from the same transaction).

Additionally, added assertions to verify the invariant that the story's
add (delete) psn is equal to the psn of the add (delete) statement's
transaction psn and to verify that no self-conflicting of transactions
occurs.

Closes #7214
Closes #7217

@CuriousGeorgiy CuriousGeorgiy added this to the 2.10.1 milestone May 30, 2022
@CuriousGeorgiy CuriousGeorgiy self-assigned this May 30, 2022
@CuriousGeorgiy CuriousGeorgiy force-pushed the memtx-tx-history-prepare-insert-delete-stmt branch 4 times, most recently from 5965bd4 to 3f115ab Compare May 31, 2022 12:43
@CuriousGeorgiy CuriousGeorgiy force-pushed the memtx-tx-history-prepare-insert-delete-stmt branch from 3f115ab to bc9fc39 Compare June 6, 2022 09:55
* If @a is_prepared_ok is true that prepared statements are visible for
* that lookup, and not visible otherwise.
*
* `is_own_change` is set to true iff `old_tuple` was modified (either
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no old_tuple here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the comment was CP. Fixed: changed the comment to match the function signature.

struct point_hole_item *item = list;
do {
if (memtx_tx_save_conflict(inserter, item->txn,
if (inserter != item->txn &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Irrelevant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: rebased on master.

@alyapunov alyapunov requested a review from Korablev77 June 23, 2022 11:33
@alyapunov alyapunov removed the request for review from drewdzzz June 23, 2022 11:33
@CuriousGeorgiy CuriousGeorgiy force-pushed the memtx-tx-history-prepare-insert-delete-stmt branch 2 times, most recently from 507609e to 06afeff Compare June 23, 2022 13:40
@CuriousGeorgiy CuriousGeorgiy force-pushed the memtx-tx-history-prepare-insert-delete-stmt branch from 06afeff to 9be6d21 Compare July 4, 2022 09:04
end)
end

g.test_repeatable_insert_primary_idx_gh_7217 = function()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split tests into two files with corresponding names.

Copy link
Member Author

@CuriousGeorgiy CuriousGeorgiy Jul 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: split tests and changelogs into two files with names corresponding to GitHub tickets.

@CuriousGeorgiy CuriousGeorgiy added the full-ci Enables all tests for a pull request label Jul 4, 2022
@coveralls
Copy link

coveralls commented Jul 4, 2022

Coverage Status

Coverage increased (+0.01%) to 84.931% when pulling cd2bd28 on CuriousGeorgiy:memtx-tx-history-prepare-insert-delete-stmt into 8504016 on tarantool:master.

@CuriousGeorgiy CuriousGeorgiy added the do not merge Not ready to be merged label Jul 5, 2022
@CuriousGeorgiy CuriousGeorgiy force-pushed the memtx-tx-history-prepare-insert-delete-stmt branch 2 times, most recently from 26d864b to 9d6a3e1 Compare July 6, 2022 06:31
@CuriousGeorgiy CuriousGeorgiy removed the do not merge Not ready to be merged label Jul 6, 2022
Current implementation of tracking statements that delete a story has a
flaw, consider the following example:

tx1('box.space.s:replace{0, 0}') -- statement 1

tx2('box.space.s:replace{0, 1}') -- statement 2
tx2('box.space.s:delete{0}') -- statement 3
tx2('box.space.s:replace{0, 2}') -- statement 4

When statement 1 is prepared, both statements 2 and 4 will be linked to the
delete statement list of {0, 0}'s story, though, apparently, statement 4
does not delete {0, 0}.

Let us notice the following: statement 4 is "pure" in the sense that, in
the transaction's scope, it is guaranteed not to replace any tuple — we
can retrieve this information when we check where the insert statement
violates replacement rules, use it to determine "pure" insert statements,
and skip them later on when, during preparation of insert statements, we
handle other insert statements which assume they do not replace anything
(i.e., have no visible old tuple).

On the contrary, statements 1 and 2 are "dirty": they assume that they
replaced nothing (i.e., there was no visible tuple in the index) — when one
of them gets prepared — the other one needs to be either aborted or
relinked to replace the prepared tuple.

We also need to fix relinking of delete statements from the older story
(in terms of the history chain) to the new one during preparation of insert
statements: a statement needs to be relinked iff it comes from a different
transaction (to be precise, there must, actually, be no more than one
delete statement from the same transaction).

Additionally, add assertions to verify the invariant that the story's
add (delete) psn is equal to the psn of the add (delete) statement's
transaction psn.

Closes tarantool#7214
Closes tarantool#7217

NO_DOC=bugfix
@CuriousGeorgiy CuriousGeorgiy force-pushed the memtx-tx-history-prepare-insert-delete-stmt branch from 9d6a3e1 to cd2bd28 Compare July 6, 2022 06:57
@alyapunov alyapunov merged commit 654cf49 into tarantool:master Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working complicated full-ci Enables all tests for a pull request memtx mvcc

Projects

None yet

5 participants