Memtx MVCC: support of multikey index variants #12313
CuriousGeorgiy
started this conversation in
RFC
Replies: 1 comment
-
|
At least, we should come up with an optimization to avoid hash table lookups when mk indexes are not used. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Table of Contents
replacememtx_story_link_keymemtx_index_keystory_link_key_storageProblem at large
Currently, we do not support multikey index variants in memtx MVCC. There are two reasons for this.
Firstly, we rely on the index
replaceinterface to collect the read and write set of a transaction statement through theresult(replaced) andsuccessorreturn values. However, multikey index variants internally process multiple tuples at a time, yielding multipleresultandsuccessorvalues which cannot be returned through the existing interface. Furthermore, (scope of #12285).Secondly, we rely on the fact that there is a 1:1 mapping between stories (versions) and tuples they correspond to. Based on this assumption, there is a single story chain for each tuple in the index. However, multikey index variants break this assumption, since a story starts to be associated with an array of keys rather than one key. This means that we need a new abstraction to manage the relationship between a story and its keys in the index (scope of this RFC).
Goal
Ultimately, we want to support multikey index variants in memtx MVCC. This suggests two goals.
Most importantly, we need to avoid changing any abstractions outside of memtx MVCC. We must keep all the required logic contained in memtx MVCC.
We need to abstract away the differences between different index variants (regular, multikey, functional).
Ideally, we need to design an abstraction that would keep all the existing memtx MVCC logic, and would simply generalize it to multiple keys per story.
Problem breakdown
To support multikey index variants, we need to solve several subproblems identified below.
Index
replaceCurrently, an index
replaceoperates on tuples rather than multikey keys. This implies that a multikey indexreplaceinternally processes all the multikey keys of the tuple. However, since in the context of memtx MVCC each multikey key can form a separate history chain, the presence of each multikey key in the index needs to managed separately. Therefore, thereplaceinterface needs to be generalized to operate on a multikey key rather than on a tuple (scope of #12285).Tracking read/write sets
For regular indexes it was enough to use the tuple to uniquely identify a key in the index and to have a single history chain. However, in the case of multikey indexes, multiple keys can map to the same tuple. This also means that each story has to participate in multiple history chains for each of its associated keys. Therefore, the existing
memtx_storyneeds to be generalized for the case of multiple keys to be able to track the state of each multikey index key. Furthermore, the existing tuple-based read/write set operations need to be generalized to work on a multikey key rather than a tuple.Looking up tracked states
For regular multikey indexes, we could use a
memtx_story-local array of tracking states to index into using the multikey key. However, for functional multikey indexes, we need to use a generic search structure. Creating such a search structure per eachmemtx_storyseems infeasible. Therefore, themh_history_tregistry needs to be generalized for the case of multiple keys to be able to look up multikey index key tracking states.Functional key management
For unikey functional indexes it was enough to use the tuple to uniquely identify a functional key in the index. However, in the case of multikey indexes, multiple functional keys can map to the same tuple. Therefore the functional key management needs to be generalized for multikey functional indexes.
Solution
The solution will be based on the new abstractions described below. These abstractions will allow to generalize a story, a tuple and state lookup in the case of multikey index variants.
memtx_story_link_keyWe will introduce a new abstraction that generalizes a story in the case of multikey index variants,
memtx_story_link_key:Each
memtx_story_linkwill have a list of keys:Each
memtx_story_link_keywill form a separate history chain based on its key, i.e., each story will be part of multiple distinct history chains formed by its keys.The lifetime of a story will become the lifetime of all its keys, i.e., a story will be retained as long as any of its keys is referenced by MVCC.
All read/write set logic will use
memtx_link_keys instead ofmemtx_links.This will solve Tracking read/write sets, as it will allow to track the state of each multikey key.
memtx_index_keyIn the scope of #12285, we will introduce new abstractions that generalize a tuple and
replacein the case of multikey index variants:memtx_index_keyandmemtx_index_replace_key.Each
tuplein memtx MVCC logic will be replaced by amemtx_index_keyand all story-wise logic will be multiplexed formemtx_story_link::key_countiterations over eachmemtx_story_link_key. Particularly, each chain-wisememtx_index_replacein memtx MVCC will be replaced withmemtx_index_replace_key.For instance, this piece of code handling secondary index duplicate conflicts:
https://github.com/tarantool/tarantool/blame/5fe44d8445f209330b874d2eb11a76086da1a804/src/box/memtx_tx.c#L3085-L3098
Will look like this:
The tuple- (key-) wise logic will use
memtx_index_keyinstead oftupleto uniquely identify a key in an index.For instance,
memtx_tx_track_gap_slow:tarantool/src/box/memtx_tx.c
Lines 3910 to 3935 in 5fe44d8
Will look like this (
memtx_tx_story_link_key_getis discussed instory_link_key_storage):This will solve Index
replaceand Tracking read/write sets, as it will to process each multikey key independently.story_link_key_storageWe will introduce a new abstraction that will allow to look up a
memtx_story_link_keybymemtx_index_keyand generalizefunc_key_storage:In order to track the read and write set of a
memtx_index_keyusingmemtx_story_link_key, memtx MVCC logic will be modified to usememtx_tx_story_link_get. This will effectively solve Looking up tracked states.Beta Was this translation helpful? Give feedback.
All reactions