Skip to content

Commit 19d1f1c

Browse files
committed
tuple: don't use offset_slot_cache in vinyl threads
`key_part::offset_slot_cache` and `key_part::format_epoch` are used for speeding up tuple field lookup in `tuple_field_raw_by_part()`. These structure members are accessed and updated without any locks, assuming this code is executed exclusively in the tx thread. However, this isn't necessarily true because we also perform tuple field lookups in vinyl read threads. Apparently, this can result in unexpected races and bugs, for example: ``` tarantool#1 0x590be9f7eb6d in crash_collect+256 tarantool#2 0x590be9f7f5a9 in crash_signal_cb+100 tarantool#3 0x72b111642520 in __sigaction+80 tarantool#4 0x590bea385e3c in load_u32+35 tarantool#5 0x590bea231eba in field_map_get_offset+46 tarantool#6 0x590bea23242a in tuple_field_raw_by_path+417 tarantool#7 0x590bea23282b in tuple_field_raw_by_part+203 tarantool#8 0x590bea23288c in tuple_field_by_part+91 tarantool#9 0x590bea24cd2d in unsigned long tuple_hint<(field_type)5, false, false>(tuple*, key_def*)+103 tarantool#10 0x590be9d4fba3 in tuple_hint+40 tarantool#11 0x590be9d50acf in vy_stmt_hint+178 tarantool#12 0x590be9d53531 in vy_page_stmt+168 tarantool#13 0x590be9d535ea in vy_page_find_key+142 tarantool#14 0x590be9d545e6 in vy_page_read_cb+210 tarantool#15 0x590be9f94ef0 in cbus_call_perform+44 tarantool#16 0x590be9f94eae in cmsg_deliver+52 tarantool#17 0x590be9f9583e in cbus_process+100 tarantool#18 0x590be9f958a5 in cbus_loop+28 tarantool#19 0x590be9d512da in vy_run_reader_f+381 tarantool#20 0x590be9cb4147 in fiber_cxx_invoke(int (*)(__va_list_tag*), __va_list_tag*)+34 tarantool#21 0x590be9f8b697 in fiber_loop+219 tarantool#22 0x590bea374bb6 in coro_init+120 ``` Fix this by skipping this optimization for threads other than tx. No test is added because reproducing this race is tricky. Ideally, bugs like this one should be caught by fuzzing tests or thread sanitizers. Closes tarantool#10123 NO_DOC=bug fix NO_TEST=tested manually with fuzzer
1 parent 7b72080 commit 19d1f1c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## bugfix/vinyl
2+
3+
* Fixed a bug when internal optimization algorithm caused a crash while a read
4+
thread tried to look up a tuple field (gh-10123).

src/box/tuple.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,19 +1106,23 @@ tuple_field_raw_by_part(struct tuple_format *format, const char *data,
11061106
const uint32_t *field_map,
11071107
struct key_part *part, int multikey_idx)
11081108
{
1109-
if (unlikely(part->format_epoch != format->epoch)) {
1110-
assert(format->epoch != 0);
1111-
part->format_epoch = format->epoch;
1112-
/*
1113-
* Clear the offset slot cache, since it's stale.
1114-
* The cache will be reset by the lookup.
1115-
*/
1116-
part->offset_slot_cache = TUPLE_OFFSET_SLOT_NIL;
1109+
int32_t *offset_slot_cache = NULL;
1110+
if (cord_is_main()) {
1111+
offset_slot_cache = &part->offset_slot_cache;
1112+
if (unlikely(part->format_epoch != format->epoch)) {
1113+
assert(format->epoch != 0);
1114+
part->format_epoch = format->epoch;
1115+
/*
1116+
* Clear the offset slot cache, since it's stale.
1117+
* The cache will be reset by the lookup.
1118+
*/
1119+
*offset_slot_cache = TUPLE_OFFSET_SLOT_NIL;
1120+
}
11171121
}
11181122
return tuple_field_raw_by_path(format, data, field_map, part->fieldno,
11191123
part->path, part->path_len,
11201124
TUPLE_INDEX_BASE,
1121-
&part->offset_slot_cache, multikey_idx);
1125+
offset_slot_cache, multikey_idx);
11221126
}
11231127

11241128
/**

0 commit comments

Comments
 (0)