Skip to content

vinyl: fix cache invalidation on rollback of DELETE statement#10900

Merged
locker merged 3 commits intotarantool:masterfrom
locker:vy-invalidate-cache-on-rollback-fix
Dec 10, 2024
Merged

vinyl: fix cache invalidation on rollback of DELETE statement#10900
locker merged 3 commits intotarantool:masterfrom
locker:vy-invalidate-cache-on-rollback-fix

Conversation

@locker
Copy link
Member

@locker locker commented Dec 5, 2024

Once a statement is prepared to be committed to WAL, it becomes visible (in the 'read-committed' isolation level) so it can be added to the tuple cache. That's why if the statement is rolled back due to a WAL error, we have to invalidate the cache. The problem is that the function invalidating the cache (vy_cache_on_write) ignores the statement if it's a DELETE judging that "there was nothing and there is nothing now". This is apparently wrong for rollback. Fix it.

While we are at it, let's also do a bit of related refactoring. It isn't necessary to fix the bug, but it should make the code more straightforward.

Closes #10879

There's no point in doing so because if the committed tuple has been
overwritten by the time it's committed, the statement that overwrote
it must have already invalidated the cache, see `vy_tx_write()`.
The code invalidating the cache on commit was added along with the
cache implementation without any justification.

NO_DOC=minor
NO_TEST=minor
NO_CHANGELOG=minor
vy_lsm.c seems to be a more appropriate place for cache invalidation
because (a) it's vy_lsm that owns the cache and (b) we invalidate
the cache on rollback in vy_lsm_rollback_stmt().

While we are at it, let's inline vy_tx_write() and vy_tx_write_prepare()
because they are trivial and used in just one place.

NO_DOC=refactoring
NO_TEST=refactoring
NO_CHANGELOG=refactoring
Once a statement is prepared to be committed to WAL, it becomes visible
(in the 'read-committed' isolation level) so it can be added to the
tuple cache. That's why if the statement is rolled back due to a WAL
error, we have to invalidate the cache. The problem is that the function
invalidating the cache (`vy_cache_on_write`) ignores the statement if
it's a DELETE judging that "there was nothing and there is nothing now".
This is apparently wrong for rollback. Fix it.

Closes tarantool#10879

NO_DOC=bug fix
@locker locker requested a review from a team as a code owner December 5, 2024 15:00
@locker locker requested a review from nshy December 5, 2024 15:12
@coveralls
Copy link

Coverage Status

coverage: 87.349% (-0.002%) from 87.351%
when pulling 7dfce0f on locker:vy-invalidate-cache-on-rollback-fix
into 5091a3f
on tarantool:master
.

Copy link
Contributor

@nshy nshy left a comment

Choose a reason for hiding this comment

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

LGTM.

@nshy nshy assigned locker and unassigned nshy Dec 9, 2024
@locker locker added the full-ci Enables all tests for a pull request label Dec 10, 2024
@locker locker merged commit d64e29d into tarantool:master Dec 10, 2024
@locker locker deleted the vy-invalidate-cache-on-rollback-fix branch December 10, 2024 08:22
@locker
Copy link
Member Author

locker commented Dec 10, 2024

Cherry-picked to 2.11, 3.2, 3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Enables all tests for a pull request

Projects

None yet

4 participants