Skip to content
Snippets Groups Projects
Commit 99d6a4f4 authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Konstantin Osipov
Browse files

alter: init space truncate_count after recovering snapshot

The replace trigger of _truncate system space (on_replace_dd_truncate)
does nothing on insertion into or deletion from the space - it only
updates space truncate_count when a tuple gets updated. As a result,
space truncate_count isn't initialized properly after recovering
snapshot. This does no harm to memtx, because it doesn't use space
truncate_count at all, but it breaks the assumption made by vinyl that
if space truncate_count is less than index truncate_count (which is
loaded from vylog), the space will be truncated during WAL recovery and
hence there's no point in applying statements to the space (see
vy_is_committed_one). As a result, all statements inserted into a vinyl
space after snapshot following truncation of the space, are ignored on
WAL recovery. To fix that, we must initialize space truncate_count when
a tuple is inserted into _truncate system space.

Closes #2521
parent 72be507f
No related branches found
No related tags found
No related merge requests found
......@@ -1400,20 +1400,26 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event)
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
if (old_tuple == NULL || new_tuple == NULL) {
/* Space create or drop. */
if (new_tuple == NULL) {
/* Space drop - nothing to do. */
return;
}
/*
* Truncate counter is updated - truncate the space.
*/
uint32_t space_id =
tuple_field_u32_xc(new_tuple, BOX_TRUNCATE_FIELD_SPACE_ID);
uint64_t truncate_count =
tuple_field_u64_xc(new_tuple, BOX_TRUNCATE_FIELD_COUNT);
struct space *old_space = space_cache_find(space_id);
if (old_tuple == NULL) {
/* Space create - initialize truncate_count. */
old_space->truncate_count = truncate_count;
return;
}
/*
* Truncate counter is updated - truncate the space.
*/
struct truncate_space *truncate =
region_calloc_object_xc(&fiber()->gc, struct truncate_space);
......
......@@ -248,6 +248,9 @@ box.snapshot()
---
- ok
...
_ = s1:insert{321, 123}
---
...
s2:truncate()
---
...
......@@ -291,10 +294,12 @@ s3 = box.space.test3
s1.index.i1:select()
---
- - [123, 321]
- [321, 123]
...
s1.index.i2:select()
---
- - [123, 321]
- - [321, 123]
- [123, 321]
...
s2.index.i1:select()
---
......
......@@ -112,6 +112,7 @@ _ = s2:insert{10, 30}
_ = s2:insert{20, 20}
_ = s2:insert{30, 10}
box.snapshot()
_ = s1:insert{321, 123}
s2:truncate()
_ = s2:insert{456, 654}
s3 = box.schema.create_space('test3', {engine = engine})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment