commit 39c13db14b5db6a137e191729194d086795ea317 from: Aleksandr Lyapunov via: Nikita Pettik date: Thu Jul 16 14:31:35 2020 UTC txm: introduce dirty tuples If the tuple is marked as dirty that usually means that it was somehow affected by a transaction. If a tuple found in index is dirty - we cannot immediately return to user, instead we must clarify it in transaction manager. Part of #4897 commit - 8078509f88c5f471da50c4a65eaa719b6114fecd commit + 39c13db14b5db6a137e191729194d086795ea317 blob - c6a15a3997e5440d9cae04d93bb3d838d09d9a13 blob + 1460e81066d1d30a9a3fd5df72601ada747553a9 --- src/box/memtx_engine.c +++ src/box/memtx_engine.c @@ -1170,6 +1170,7 @@ memtx_tuple_new(struct tuple_format *format, const cha tuple->format_id = tuple_format_id(format); tuple_format_ref(format); tuple->data_offset = data_offset; + tuple->is_dirty = false; char *raw = (char *) tuple + tuple->data_offset; field_map_build(&builder, raw - field_map_size); memcpy(raw, data, tuple_len); blob - b1f3422f1eca7d3990180178b64d3c18be767b75 blob + c9d307f50e6b18afe0b05cb977488f1b5d1a994e --- src/box/tuple.c +++ src/box/tuple.c @@ -105,6 +105,7 @@ runtime_tuple_new(struct tuple_format *format, const c tuple->format_id = tuple_format_id(format); tuple_format_ref(format); tuple->data_offset = data_offset; + tuple->is_dirty = false; char *raw = (char *) tuple + data_offset; field_map_build(&builder, raw - field_map_size); memcpy(raw, data, data_len); blob - 9a887721986c0d2efcb4a336ce409a95effdac36 blob + 4752323e495b1cec38ba9ce23e287f5a5a150cca --- src/box/tuple.h +++ src/box/tuple.h @@ -319,7 +319,13 @@ struct PACKED tuple /** * Offset to the MessagePack from the begin of the tuple. */ - uint16_t data_offset; + uint16_t data_offset : 15; + /** + * The tuple (if it's found in index for example) could be invisible + * for current transactions. The flag means that the tuple must + * be clarified by transaction engine. + */ + bool is_dirty : 1; /** * Engine specific fields and offsets array concatenated * with MessagePack fields array. @@ -1081,8 +1087,10 @@ tuple_unref(struct tuple *tuple) assert(tuple->refs - 1 >= 0); if (unlikely(tuple->is_bigref)) tuple_unref_slow(tuple); - else if (--tuple->refs == 0) + else if (--tuple->refs == 0) { + assert(!tuple->is_dirty); tuple_delete(tuple); + } } extern struct tuple *box_tuple_last; blob - faf038abec41d65549f92b3f3846d2fbb78b3b5e blob + bae6c67cda44274d25a149a226cd5768238f4fea --- src/box/tuple_format.c +++ src/box/tuple_format.c @@ -501,8 +501,8 @@ tuple_format_create(struct tuple_format *format, struc assert(tuple_format_field(format, 0)->offset_slot == TUPLE_OFFSET_SLOT_NIL || json_token_is_multikey(&tuple_format_field(format, 0)->token)); size_t field_map_size = -current_slot * sizeof(uint32_t); - if (field_map_size > UINT16_MAX) { - /** tuple->data_offset is 16 bits */ + if (field_map_size > INT16_MAX) { + /** tuple->data_offset is 15 bits */ diag_set(ClientError, ER_INDEX_FIELD_COUNT_LIMIT, -current_slot); return -1; blob - cd4dfd08906c778669bd8a79e98a348c5a960e0a blob + ee501f81e6c73ced62d7585194a1c286c700ce22 --- src/box/vy_stmt.c +++ src/box/vy_stmt.c @@ -198,6 +198,7 @@ vy_stmt_alloc(struct tuple_format *format, uint32_t da tuple_format_ref(format); tuple->bsize = bsize; tuple->data_offset = data_offset; + tuple->is_dirty = false; vy_stmt_set_lsn(tuple, 0); vy_stmt_set_type(tuple, 0); vy_stmt_set_flags(tuple, 0); blob - 11b4da39f0cf020de63256fa8d4a65f4c54f3fa8 blob + 45022cc542c868bb4b07f7f72a4175dc8379f4b6 --- test/box/huge_field_map.result +++ test/box/huge_field_map.result @@ -38,7 +38,7 @@ test_run:cmd("setopt delimiter ''"); pcall(test) -- must fail but not crash | --- | - false - | - 'Can''t create tuple: metadata size 65558 is too big' + | - 'Can''t create tuple: metadata size 32790 is too big' | ... test = nil blob - d7971aef82a38ea07c1dba32ab8987c06a1dfb7d blob + cb4790074df6d2cab2032805f0c5fb75cb8ce7d3 --- test/box/huge_field_map_long.result +++ test/box/huge_field_map_long.result @@ -40,7 +40,7 @@ test_run:cmd("setopt delimiter ''"); pcall(test) -- must fail but not crash | --- | - false - | - 'Can''t create tuple: metadata size 65542 is too big' + | - 'Can''t create tuple: metadata size 32774 is too big' | ... test = nil