commit 79fe74c2ffc3e5721e2d5622c8f08f23014b22e4 from: Magomed Kostoev via: Serge Petrenko <35663196+sergepetrenko@users.noreply.github.com> date: Thu Aug 29 11:25:23 2024 UTC memtx: refactor the in-index tuple stories iteration out The `memtx_tx_index_invisible_count_slow` iterates over stoies of tuples existing in the index in order to count invisible ones. A similar functionality will be required when count gaps will be implemented, so let's refactor this part out of the function and make it macro. Needed for #8204 NO_DOC=refactoring NO_TEST=refactoring NO_CHANGELOG=refactoring commit - 89424284376966e184041c846c52ff69dc554b14 commit + 79fe74c2ffc3e5721e2d5622c8f08f23014b22e4 blob - 349ae8b65acfa73f96c5232af0a83a9531c99e39 blob + 564626d5ca584c689f81a7c7bb4468d2276b9464 --- src/box/memtx_tx.c +++ src/box/memtx_tx.c @@ -2886,36 +2886,37 @@ memtx_tx_tuple_clarify_slow(struct txn *txn, struct sp return res; } +/** + * Run @a code on stories of tuples actually existing in @a index of @a space. + * Excluded tuples have their own chains consisting of the only excluded story, + * these are skipped since they are not actually inserted to index. + */ +#define memtx_tx_foreach_in_index_tuple_story(space, index, story, code) do { \ + rlist_foreach_entry(story, &(space)->memtx_stories, in_space_stories) {\ + assert((index)->dense_id < story->index_count); \ + struct memtx_story_link *link = \ + &story->link[index->dense_id]; \ + if (link->in_index == NULL) { \ + assert(link->newer_story != NULL); \ + continue; \ + } \ + assert(link->newer_story == NULL); \ + if (tuple_key_is_excluded(story->tuple, index->def->key_def, \ + MULTIKEY_NONE)) { \ + assert(link->older_story == NULL); \ + continue; \ + } \ + code; \ + } \ +} while (0) + uint32_t memtx_tx_index_invisible_count_slow(struct txn *txn, struct space *space, struct index *index) { uint32_t res = 0; struct memtx_story *story; - rlist_foreach_entry(story, &space->memtx_stories, in_space_stories) { - assert(index->dense_id < story->index_count); - struct memtx_story_link *link = &story->link[index->dense_id]; - /* - * A history chain is represented by the top story, which is - * stored in index. - */ - if (link->in_index == NULL) { - assert(link->newer_story != NULL); - continue; - } - assert(link->newer_story == NULL); - - /* - * Excluded tuples have their own chains consisting of the only - * excluded story. Such stories must be skipped since they are - * not actually inserted to index. - */ - if (tuple_key_is_excluded(story->tuple, index->def->key_def, - MULTIKEY_NONE)) { - assert(link->older_story == NULL); - continue; - } - + memtx_tx_foreach_in_index_tuple_story(space, index, story, { struct tuple *visible = NULL; bool is_prepared_ok = detect_whether_prepared_ok(txn); bool unused; @@ -2924,7 +2925,7 @@ memtx_tx_index_invisible_count_slow(struct txn *txn, &unused); if (visible == NULL) res++; - } + }); memtx_tx_story_gc(); return res; }