From 2bf4484f650eb4c0781d4db2b334ac9f23e8edd9 Mon Sep 17 00:00:00 2001 From: Aleksandr Lyapunov <alyapunov@tarantool.org> Date: Mon, 26 Jul 2021 15:40:34 +0300 Subject: [PATCH] txm: split memtx_tx_track_read method into two parts No logical changes, only for the next commit simplification Part of #6206 --- src/box/memtx_tx.c | 66 ++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/box/memtx_tx.c b/src/box/memtx_tx.c index 629aa4c4a7..7d83989d44 100644 --- a/src/box/memtx_tx.c +++ b/src/box/memtx_tx.c @@ -1900,41 +1900,19 @@ memtx_tx_on_space_delete(struct space *space) } } -int -memtx_tx_track_read(struct txn *txn, struct space *space, struct tuple *tuple) +static int +memtx_tx_track_read_story(struct txn *txn, struct space *space, + struct memtx_story *story) { - if (tuple == NULL) - return 0; if (txn == NULL) return 0; if (space == NULL) return 0; if (space->def->opts.is_ephemeral) return 0; - - struct memtx_story *story; + assert(story != NULL); struct tx_read_tracker *tracker = NULL; - if (!tuple->is_dirty) { - story = memtx_tx_story_new(space, tuple); - if (story == NULL) - return -1; - size_t sz; - tracker = region_alloc_object(&txn->region, - struct tx_read_tracker, &sz); - if (tracker == NULL) { - diag_set(OutOfMemory, sz, "tx region", "read_tracker"); - memtx_tx_story_delete(story); - return -1; - } - tracker->reader = txn; - tracker->story = story; - rlist_add(&story->reader_list, &tracker->in_reader_list); - rlist_add(&txn->read_set, &tracker->in_read_set); - return 0; - } - story = memtx_tx_story_get(tuple); - struct rlist *r1 = story->reader_list.next; struct rlist *r2 = txn->read_set.next; while (r1 != &story->reader_list && r2 != &txn->read_set) { @@ -1973,6 +1951,42 @@ memtx_tx_track_read(struct txn *txn, struct space *space, struct tuple *tuple) return 0; } +int +memtx_tx_track_read(struct txn *txn, struct space *space, struct tuple *tuple) +{ + if (tuple == NULL) + return 0; + if (txn == NULL) + return 0; + if (space == NULL) + return 0; + if (space->def->opts.is_ephemeral) + return 0; + + if (tuple->is_dirty) { + struct memtx_story *story = memtx_tx_story_get(tuple); + return memtx_tx_track_read_story(txn, space, story); + } else { + struct memtx_story *story = memtx_tx_story_new(space, tuple); + if (story == NULL) + return -1; + size_t sz; + struct tx_read_tracker *tracker; + tracker = region_alloc_object(&txn->region, + struct tx_read_tracker, &sz); + if (tracker == NULL) { + diag_set(OutOfMemory, sz, "tx region", "read_tracker"); + memtx_tx_story_delete(story); + return -1; + } + tracker->reader = txn; + tracker->story = story; + rlist_add(&story->reader_list, &tracker->in_reader_list); + rlist_add(&txn->read_set, &tracker->in_read_set); + return 0; + } +} + /** * Create new point_hole_item by given argumnets and put it to hash table. */ -- GitLab