Efficient in-memory multi-version concurrency control for trie data structure based databases
The trie data structure with a combined indirection layer and search index in MVCC systems addresses inefficiencies in version storage and garbage collection, enhancing performance and memory management in database systems.
Patent Information
- Application Number
- JP2021515453
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2018-09-19
- Filing Date
- 2019-09-18
- Publication Date
- 2024-11-11
- Estimated Expiration
- 2039-09-18
AI Technical Summary
Existing database management systems face inefficiencies in multi-version concurrency control (MVCC) due to the need to maintain multiple versions of objects, perform garbage collection, and manage indexes, leading to performance degradation and increased memory usage.
The use of a trie data structure with a combined indirection layer and search index, along with a copy-on-write approach, allows for efficient version storage, garbage collection, and index management by maintaining a consistent snapshot view and optimizing node allocation and deallocation within the trie.
This approach reduces the overhead of traversing version chains and improves query performance by providing a consistent snapshot view, while efficiently managing memory and reducing the need for frequent index updates.
Smart Images

Figure 0007580371000001 
Figure 0007580371000002 
Figure 0007580371000003
Abstract
Description
[Technical field]
[0001] The present invention relates generally to the efficient use of trie data structures in databases and information retrieval systems for multi-version concurrency control (MVCC), including version storage, garbage collection, and index management.
[0002] Reference is made to International Patent Application PCT / EP2018 / 056592, which is incorporated herein by reference in its entirety. [Background technology]
[0003] Multiversion concurrency control (MVCC) is a common transaction management scheme in database management systems (DBMS). It improves parallelism while maintaining the serializability typically required during transaction processing. Multiversioning allows multiple read-only transactions to access current or older versions of records simultaneously, even for consistent snapshots of multiple records, without preventing write transactions from simultaneously generating new versions.
[0004] To support MVCC, a database needs to maintain multiple physical versions of each object. In relational databases, these objects are tuples (records), in document-oriented databases they are documents, and in key-value databases objects are (opaque) values. By using MVCC, updates to an object create a new version of said object rather than overwriting the object or part of it with the new data.
[0005] Using MVCC introduces some difficulties related to how to perform the storage of multiple versions, how to find the correct version during read access (version storage), how to remove versions that are not in use and will never be read again (garbage collection), and, because databases require indexes to improve query performance, there are further difficulties in how to achieve MVCC-aware index updates and how to execute queries using indexes (index management).
[0006] A concurrency control protocol coordinates the execution of concurrent read and write transactions. The version that each transaction sees or has access to depends on the isolation level implemented by MVCC. A common isolation level implemented is snapshot isolation, where a transaction can access the state of the data as it was at the time the transaction began. The following discussion focuses on snapshot isolation.
[0007] Version Storage FIG. 1A illustrates different version storage schemes for storing multiple versions.
[0008] In append-only schemas 101, 102, for an update, an object is copied, modified and the new version is appended to the storage space. A chain of versions needs to be maintained for each object. The drawback of this approach is that a potentially long chain needs to be traversed to find the appropriate version. Unused versions need to be pruned frequently to maintain performance. The head version of this chain can be the oldest or the newest version depending on the implementation. The index needs to be updated during garbage collection if the head points to the oldest version or after an update if the head points to a newer version. Alternatively, a doubly linked chain can be used, but this incurs further maintenance overhead.
[0009] Time travel storage 103 is similar to the append-only schema, but versions are stored in a separate time travel storage space. In the main storage space, a master version is kept with reference to the version chain in the time travel storage space. In the case of an update, a new object is copied to the time travel storage space. The master version can be the oldest or latest version depending on the implementation, and accordingly, either the new copy or the master version in the time travel storage space is changed by the update. The index points to the master version and is not affected.
[0010] In delta storage 104, a master version is maintained at a storage location, typically the current version. Update changes are logged in a delta storage called a rollback segment that stores changes to the original version or parts of it, e.g., changed attributes of a record. This results in high overhead during read accesses, since the original object must be retrieved and the logged changes applied to get the resulting object version.
[0011] All the above variants create a chain of object versions, where either the current object version or the first still-held version is the head of the chain, and the index always points to only one version of the object.
[0012] Garbage Collection As transactions create new object versions during MVCC updates, the system needs to reclaim space for unused versions to prevent it from running out of space, and as mentioned above, keeping too many versions around can degrade performance in some cases.
[0013] First, garbage collection needs to be able to detect unused versions. An object version is unused if it is replaced by a new (current) version, and in the case of snapshot isolation, there are no active transactions in which the old version is still visible. This can be detected by having monotonically increasing IDs for each transaction, and each replaced object is marked with the ID of the transaction that replaced it. All objects with a replacement ID smaller than any ID of all active transactions can be removed and their storage space reclaimed.
[0014] Depending on the version storage scheme, the object needs to be unlinked from the chain, copied, and the index updated. The physical space can then be reclaimed. For in-memory databases, this leads to common memory management problems.
[0015] A common approach to performing garbage collection is via a routine "vacuum". A background thread periodically scans the database looking for outdated object versions. However, scanning the entire database does not scale to larger databases. To mitigate this, transactions mark or register objects that have been replaced, and the garbage collector considers these objects to see if they are no longer in use.
[0016] Index Management According to Yingjun Wu, Joy Arulraj, Jiexi Lin, Ran Xian, and Andrew Pavlo. 2017. An empirical evaluation of in memory multi-version concurrency control. Proc. VLDB Endow. 10, 7 (March 2017), 781-792. DOI: https: / / doi.org / 10.14778 / 3067421.3067427, prior art MVCC database management systems separate database version information from indexes. This implies that the presence of a key in an index means that there is some version with that key, but the index entry does not contain any information about the version.
[0017] Thus, index lookups never produce false positives because there is always some version of the key, but they can still produce false positives because the index may point to a version of the key that is not visible to a particular transaction. This introduces performance-degrading overhead as the results of queries that used the index must be filtered to remove the false positive matches.
[0018] Figure 1B shows two common approaches to how indexes reference objects: using logical pointers 111, and using physical pointers 110. Indexes that use logical pointers use a layer of indirection that maps a fixed object identifier (object ID) to physical object storage. Depending on the version storage, this will be the head of a version chain or a master version. This approach avoids the problem of having to update all indexes to point to new physical locations every time a change occurs. Summary of the Invention
[0019] One or more of the above mentioned objects are achieved by the subject matter of the independent claims. Preferred embodiments are the subject matter of the dependent claims.
[0020] A first embodiment of the present invention is a computer-implemented method for determining a storage location of a particular version of a database object in an electronic database application or information retrieval system, where an index for each version of the database object is stored in a trie having a root node corresponding to the particular version, the method including: determining a trie corresponding to the particular version by accessing the root node of the trie corresponding to the particular version; determining an object identifier for the database object by traversing the trie corresponding to the particular version using a secondary key associated with the database object as a search key; and determining a storage location of the database object by traversing the trie corresponding to the particular version using the determined object identifier as a search key.
[0021] According to the second embodiment, in the first embodiment, information on whether the search key is an object identifier or a secondary key related to a database object is included in the search key.
[0022] According to a third embodiment, in any one of the first to second embodiments, the secondary key includes information about one or more properties encoded within the secondary key.
[0023] According to a fourth embodiment, in the third embodiment, the one or more properties encoded in the secondary key include one of a name, an address, and the like.
[0024] According to the fifth embodiment, in any one of the first to fourth embodiments, an index is defined as having a key and a value.
[0025] According to the sixth embodiment, in any one of the first to fifth embodiments, a first index is defined by having a secondary key as a key and an object identifier as a value, and a second index is defined by having an object identifier as a key and a storage location of the database object as a value.
[0026] According to a seventh embodiment, in any one of the first to sixth embodiments, a trie having a root node corresponding to a particular version is created by creating a new root node for the particular version, copying and modifying the corrected nodes with respect to nodes of a previous trie having a root node corresponding to the previous version, and creating a reference pointing to the node of the previous trie that has not been corrected.
[0027] According to an eighth embodiment, in the seventh embodiment, creating a trie having a root node corresponding to a particular version is performed during a transaction, and the particular version is associated with the transaction.
[0028] According to the ninth embodiment, in the eighth embodiment, the transaction is identified by a transaction identifier.
[0029] A tenth embodiment of the present invention is a computer-implemented method for identifying unused memory to be freed that is occupied by trie nodes of one or more tries that comprise a database index of an electronic database application or information retrieval system, the method comprising: storing an array including one or more chunks, the chunks configured to store trie nodes, the array including at least a first chunk that includes a first trie node; storing a free chunk list indicating which chunks of the array are free for storing a new trie node; while updating the first trie node during the first transaction, determining whether the first trie node was created during the first transaction; and adding the first chunk that includes the first trie node to the free chunk list in response to a result of the determination.
[0030] According to an eleventh embodiment, in the tenth embodiment, if it is determined that the first trie node was created during the first transaction, the method further includes adding a first chunk that includes the first trie node to a free chunk list.
[0031] According to a twelfth embodiment, in any one of the tenth to eleventh embodiments, determining whether a first trie node was created during a second transaction, and adding a first chunk including the first trie node to a pending free chunk list if it is determined that the first trie node was created during a second transaction prior to the first transaction.
[0032] According to a thirteenth embodiment, in the twelfth embodiment, adding a first chunk including a first trie node to the pending free chunk list includes generating a list entry in the pending free chunk list that is associated with the first transaction and includes a reference to the first chunk.
[0033] According to the fourteenth embodiment, the thirteenth embodiment allows list entries in a pending free chunk list associated with a first transaction to reference all chunks that were created during one or more transactions prior to the first transaction and updated during the first transaction.
[0034] According to the fifteenth embodiment, in the fourteenth embodiment, referencing all chunks created during one or more transactions prior to the first transaction and updated during the first transaction is achieved with a pointer associated with the first transaction that points to a chain of chunks created during one or more transactions prior to the first transaction and updated in the first transaction.
[0035] According to a 16th embodiment, in any one of the 12th to 15th embodiments, the method further includes storing a transaction list including active database transactions, determining whether the pending free chunk list includes one or more entries associated with a transaction older than the oldest transaction in the transaction list, and if it is determined that the pending free chunk list includes one or more entries associated with a transaction older than the oldest transaction in the transaction list, moving chunks associated with the one or more entries to the free chunk list.
[0036] According to the seventeenth embodiment, in any one of the tenth to sixteenth embodiments, each chunk includes a payload value and a value that identifies the transaction during which it is being created.
[0037] According to an 18th embodiment, in any one of the 10th to 17th embodiments, updating the first trie node during the first transaction includes creating a second trie node as a copy of the first trie node having the updated value.
[0038] According to the 19th embodiment, in any one of the 17th to 18th embodiments, updating the first trie node during the first transaction includes creating a second chunk including a second trie node, and a value identifying the transaction during which the chunk is created corresponds to the first transaction.
[0039] According to the twentieth embodiment, in any one of the seventeenth to nineteenth embodiments, a value that identifies a transaction while a node is being created is a transaction identifier.
[0040] According to the twenty-first embodiment, in the twentieth embodiment, determining whether the first trie node was created during the first transaction is performed by comparing a transaction identifier of the first transaction with a transaction identifier of the first chunk.
[0041] According to the 22nd embodiment, in any one of the 20th to 21st embodiments, the determination of whether a transaction is older than the oldest transaction in the transaction list is performed by comparing transaction identifiers, the older transaction having a lower transaction identifier than the newer transaction.
[0042] According to a twenty-third embodiment, in any one of the tenth to twenty-second embodiments, the array further includes free space that is not occupied by the chunks.
[0043] According to the twenty-fourth embodiment, in any one of the tenth to twenty-third embodiments, each node on the array is stored as a long integer.
[0044] According to a twenty-fifth embodiment, in any one of the tenth to twenty-fourth embodiments, each node in the trie is referenced by a pointer that contains the index of the node in the array.
[0045] According to the twenty-sixth embodiment, in any one of the tenth to twenty-fifth embodiments, the size of the array is limited.
[0046] According to the 27th embodiment, in any one of the 10th to 26th embodiments, one or more chunks include chunks having different sizes and chunks having the same size, each chunk of different sizes is referenced by a pointer stored in the free chunk list, and a chunk referenced by a pointer stored in the free chunk list includes a pointer to a chunk of the same size as itself.
[0047] According to the twenty-eighth embodiment, in the twenty-seventh embodiment, the one or more chunks include 64 chunks of different sizes.
[0048] According to the twenty-ninth embodiment, in any one of the twenty-seventh to twenty-eighth embodiments, a different size is associated with the number of pointers included in each node that point to child nodes.
[0049] According to the 30th embodiment, in any one of the 27th to 29th embodiments, chunks of the same size are linked to each other by pointers.
[0050] A thirty-first embodiment of the present invention is a computer-implemented method for identifying unused memory to be freed that is occupied by trie nodes that store a database index for an electronic database application or information retrieval system, the method comprising: storing one or more arrays, and an active array configured to store trie nodes, each trie node being associated with a current trie root node corresponding to a current transaction and / or one or more previous trie root nodes corresponding to previous transactions; during an eviction transaction, determining whether one of the one or more arrays satisfies a criterion, and if it is determined that one of the one or more arrays satisfies the criterion, selecting an array that satisfies the criterion; if the selected array includes one or more nodes associated with the current trie root node, copying one or more nodes of the selected array associated with the current trie root node to the active array; and identifying the memory occupied by the selected array as unused memory to be freed, the step of copying one or more nodes of the selected array associated with the current trie root node to the active array comprises: and performing, including: traversing nodes associated with the current trie root node; while traversing the nodes, copying nodes stored in the selected array and ignoring nodes not stored in the selected array; and not traversing child nodes and nodes of nodes stored in arrays created before the selected array.
[0051] According to a thirty-second embodiment, in the thirty-first embodiment, copying one or more nodes of the selected array associated with the current trie root node to the active array further includes: while traversing the nodes associated with the current trie root node, simultaneously traversing nodes associated with a previous trie root node that was created after the selected array became the active array; comparing the nodes associated with the current trie root node with the nodes associated with the previous trie root node level by level from top to bottom; and not traversing the node and child nodes of the node if the comparison determines that the node is associated with the current trie root node but not associated with the previous trie root node.
[0052] According to the thirty-third embodiment, in the thirty-second embodiment, the previous trie root node created after the selected array becomes the active array is the first trie root node created after the selected array becomes the active array.
[0053] According to a thirty-fourth embodiment, in any one of the thirty-second to thirty-third embodiments, comparing the nodes associated with the current trie root node with the nodes associated with the previous trie root node level by level from top to bottom includes comparing references to child nodes of the nodes.
[0054] According to the thirty-fifth embodiment, in the thirty-fourth embodiment, references to child nodes of a node are compared by an AND operation.
[0055] According to the thirty-sixth embodiment, in the thirty-fifth embodiment, the references to the child nodes of a node are represented by a bitmap and the comparison is performed by a bitwise AND operation.
[0056] According to a 37th embodiment, in any one of the 31st to 36th embodiments, the method further includes, before identifying the memory occupied by the selected array as unused memory to be released, determining whether the selected array includes one or more nodes associated with one or more previous trie root nodes used in one or more pending transactions, and waiting until the pending transactions are finished if it is determined that the selected array includes one or more nodes that are part of one or more previous trie root nodes used in one or more pending transactions.
[0057] According to the thirty-eighth embodiment, in the thirty-seventh embodiment, the determination of whether the pending transaction is to be terminated is performed by comparing the pending transaction with the eviction transaction, and if it is determined that the pending transaction does not include a transaction older than the eviction transaction, it is determined that the pending transaction is to be terminated.
[0058] According to a thirty-ninth embodiment, in any one of the thirty-first to thirty-eighth embodiments, the active array is an array as defined in the tenth to thirtieth embodiments.
[0059] According to a fortieth embodiment, in any one of the thirty-first to thirty-ninth embodiments, the method further includes, before copying one or more nodes of the selected array that are part of the current trie root node to the active array, determining whether the active array has sufficient free space to contain the nodes, and if it is determined that the active array does not have enough free space, creating a new array to become the active array, where the previous active array becomes one of the one or more arrays.
[0060] According to the forty-first embodiment, in any one of the thirty-first to fortieth embodiments, the active array and the one or more arrays have a limited size.
[0061] According to a 42nd embodiment, in any one of the 31st to 41st embodiments, the criteria include the number of transactions currently using the array and / or the number of nodes of one or more previous tries included in the array.
[0062] According to a 43rd embodiment, in any one of the 31st to 42nd embodiments, the criteria include the amount and size of nodes in the replaced array.
[0063] According to a 44th embodiment, in any one of the 31st to 43rd embodiments, each node in the trie is referenced by a pointer that contains a reference to the respective array and the index of the node within the array.
[0064] A forty-fifth embodiment of the present invention is a computer program, in particular a database application or information retrieval system program, comprising instructions for carrying out any one of the first to forty-fourth methods.
[0065] A 46th embodiment of the present invention is a data processing device or system including one or more processors and a memory, the data processing device or system configured to execute any one of the methods of the 1st to 44th embodiments.
[0066] A forty-seventh embodiment of the present invention is a preferably non-transitory computer readable medium having stored thereon the computer program of the forty-fifth embodiment. [Brief description of the drawings]
[0067] [Figure 1A] 1 illustrates different version storage schemes for storing multiple versions. [Figure 1B] Here are two common approaches to how indexes can reference objects: [Diagram 2]1 illustrates a prior art logical pointer approach. [Figure 3a-3b] 1 illustrates the basic principles of how version storage garbage collection can be achieved according to the prior art. [Figure 4] The copy-on-write approach for tries is illustrated with an example showing two tries with two different trie root nodes. [Diagram 5] 1 illustrates one embodiment that implements a logical pointer and copy-on-write approach for secondary indexes in accordance with the present invention. [Figure 6] Here is an example of glibc-malloc from the prior art: [Figure 7] 1 illustrates trie memory management according to the present invention. [Figure 8] 1 illustrates one embodiment for efficiently garbage collecting multiple arrays in accordance with the present invention. [Figure 9] 9 illustrates an example of garbage collection of multiple arrays according to FIG. 8. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0068] To support MVCC, the database needs to maintain multiple versions of each object.
[0069] FIG. 2 illustrates a prior art logical pointer approach in which a specific object ID and a specific version pointer are mapped to the physical location of the object in storage.
[0070] In the embodiment shown in Fig. 2, the objects 206, 209 are stored in a persistent storage 202, which may be one or more files and / or persistent memory. To store the objects, a log-structured storage concept is applied, which means that new objects are appended to the storage 202 after the last used position 210.
[0071] Every object is identified by a primary key or ID, for example a record ID or document ID in the case of a relational or document-oriented database. A map (index) from ID to physical location is used to derive, for a given ID, the physical location of the object in storage 202. Throughout this specification, an index is defined as a key / value pair.
[0072] In the embodiment of Figure 2, an object can be modified by a transaction. When a transaction modifies an object, a copy of the object is made and compensation is performed on the copied object. The original object is not compensated or overwritten.
[0073] Every transaction that modifies or creates an object creates a new version of the created or modified object and a new version of the ID-to-physical location map for deriving the object's physical location in storage 202.
[0074] 2, there is a first object 206 having an object ID "1" and a second object 209 also having an object ID "1". The first object is a first version and the second object is a second version of the object. As mentioned above, when an object is modified, a copy of the object is made and the copy of the object is modified. Thus, storage 202 contains two versions of the object.
[0075] Such a change also results in two versions of the map from IDs to physical locations, namely 204 and 208. A lookup of a first version "version 1" of an object having object ID "1" can be achieved by using a pointer 203 that points to map 204, which leads to the storage location 205 of the first version of the object. A lookup of a second version "version 2" of the same object ID, but can be achieved by using a pointer 207 that points to a map 208 corresponding to a later or newer transaction, which leads to the storage location of the second version of the object 209.
[0076] It is important that the map 204 remains accessible as long as there is a transaction pending using the corresponding snapshot view (the version referenced by the pointer 203) and the corresponding object version.
[0077] 3a and 3b show the basic principles of how version storage garbage collection can be achieved according to the prior art.
[0078] In the examples of Figures 3a and 3b, all files are limited to a certain file length or size. If the file length is reached while appending new data, a new "active" file is created to be written to and the old file is no longer modified.
[0079] FIG. 3a illustrates the start of garbage collection. Such an example may include two files, file 1 and file 2, with different objects, where file 1 has reached its length limit and file 2 still has space to append to and is therefore an active file. File 1 stores three objects with different object IDs. An object with object ID 1 stores two versions (v1 and v2) and therefore two objects in the file. An object with object ID 2 stores a first version (v1) and a tombstone indicating that the object has been deleted from the file. File 2 contains the latest version of the object with object ID 3. The current versions of the objects are referenced by "ID to pos map t1", where "t1" indicates that this is a map of transactions with transaction id 1.
[0080] Figure 3b shows how garbage collection for version storage works in principle. A copy garbage collection method (eviction) is applied. The first step is to "clean" file 1, which means that if the file contains objects of the current version, they are still used and referenced by the current map "ID to pos map t1" and need to be transferred to the active file. Thus, the file is scanned and a lookup, for example by using object IDs, is performed in the current ID-to-physical-location map "ID to pos map t1", which contains the physical locations of the latest versions of the objects.
[0081] If this location obtained from the lookup is still the same as the location derived from the file scan, then the object is copied (written) to the active file, i.e., file 2. In this example, the object with object ID 1 and version 2 needs to be copied from file 1 to file 2. The object with object ID 1 and version 1 can be ignored because the map contains an object with the same ID but a newer version. Thus, the location obtained from the scan differs from the location in the file scan. Also, the object with object ID 2 and version 1 can be ignored because it has been deleted and does not appear in the map at all. There is no need to copy the object with object ID 3 because its latest version is not in file 1 but is already in the active file 2.
[0082] Statistics are maintained for each file to know which object version store files are good candidates for eviction (also referred to as garbage collection in this application). Such statistics may include the amount and size of objects that have been replaced with new versions or deleted. If a file contains less than a certain amount of still current object versions, it becomes eligible for garbage collection, which means that the corresponding memory is identified as memory to be freed. Such memory can then be rewritten or overwritten by other data. For files that have memory to free, the file can be deleted. Before deleting a file, it is necessary to ensure that there are no pending transactions that still need to access the file, for example, reading data from the version stored in the file.
[0083] The model described in Figures 3a and 3b requires creating a new modified copy of the map for every transaction, which is infeasible and inefficient because creating such a map consumes a lot of additional memory space and processing time.
[0084] It is an object of the present invention to provide a space- and performance-efficient persistent data structure for storing such maps, a data structure that always retains the previous version when modified.
[0085] The solution is achieved by extending the trie described in International Patent Application PCT / EP2018 / 056592 to act as a space- and performance-efficient persistent data structure.
[0086] Tree-based structures can easily be used as persistent data structures by making a partial copy of the tree for every change up to the root node.
[0087] FIG. 4 illustrates the copy-on-write approach for tries with an example showing two tries with two different trie root nodes.
[0088] Before the modification, trie structure 401 contains two tries at trie root nodes 402 and 406. Both trie root nodes 402 and 406 correspond to two different versions, which may have been created, for example, during two different transactions. The first trie referenced by trie root node 402 contains the keys "007" and "042", which are encoded by child nodes 403, 404, and 405.
[0089] The removal of key "042" and the addition of key "045" in one transaction results in a second trie referenced by new trie root node 406. The modified nodes are copied and modified. Node 407 is a modified copy of node 403, and node 409 is a modified copy of node 405. The unchanged node 404 is referenced at 408 by the new node 407.
[0090] For example, a typical persistent map implementation using a tree has O(log n) access time complexity, making the use of logical pointers typically very expensive. A trie has a constant O(1) time complexity, since the access time does not depend on the amount of entries in the map.
[0091] Based on an inventive combination of the approaches described so far, the present invention solves many of the problems mentioned in the introduction: The problem of how to store multiple object versions and how to find the right version during read access (snapshot isolation) is solved by using the current root pointer of the trie at transaction start throughout the transaction.
[0092] Furthermore, the inventive combination of the described approaches allows queries to use indexes that are also MVCC-aware. This has the advantage that secondary indexes that point to object identifiers (IDs) are also versioned. This concept is explained in more detail with respect to FIG. 5.
[0093] FIG. 5 illustrates one embodiment for implementing the logical pointer and copy-on-write approach of the secondary index in accordance with the present invention.
[0094] In the embodiment of Figure 5, the logical pointer and copy-on-write approach of the secondary index is realized by storing the ID-to-physical-location map trie indexes 503, 508 and the other secondary index tries 504, 509 in one combined physical trie. This is achieved by using the composite key functionality of the trie, as described in detail in International Patent Application PCT / EP2018 / 056592.
[0095] Information about whether a composite key (also referred to in this application as a "search key") is an object identifier (ID) or a secondary key associated with a database object is included in the search key.
[0096] The root of this combined trie provides a consistent (snapshot) view of object versions. Such objects are sometimes called database objects because they are maintained in a database and may be created and amended by database transactions. To access an object using a secondary key, the secondary key 504 is used to derive an object ID 505, which is then used to determine the physical object location. Modifying the trie referenced by trie root node 502 within a transaction results in a new partial copy of the trie with a new trie root node 507, which again provides a consistent view of all object versions and indexes.
[0097] This approach addresses the shortcomings of current solutions in version storage, object garbage collection, and index management.
[0098] As mentioned above, with respect to the prior art, the search index and the indirection layer (logical-physical mapping) are typically different data structures. Generally, in such separate structures, the index points to only one version, which may or may not be the requested version. If the version referenced by the index is not the requested version, then the version chain needs to be traversed to find the requested version. The "requested version" may also be called the "visible version" since it is the version that is correctly visible to the transaction requesting the object.
[0099] The present invention solves the drawbacks of incrementally traversing version chains by combining the indirection layer and the search index into a single physical trie that is always snapshot consistent.
[0100] As an example, consider an object with logical ID "1" that has two versions, "1" and "2." The first version is stored in physical location 506 and the second version is stored in physical location 511.
[0101] In addition, there may be a search index on the property "name" of an object: a first object version contains the value "Peter" as the name, and a second object version contains a modified value, i.e. the name "Matt".
[0102] As a function of the composite keys, the trie pointed to by root node 402 then contains two entries: "ID-Map, 1, 506" and "Name, 'Peter', 1". The first entry corresponds to ID-Physical Location 503, and the second entry corresponds to Secondary Key 504. After the update, the trie referenced by trie root node 507 contains "ID-Map, 1, 511" and "Name, 'Matt', 1".
[0103] So the secondary key can look up the property "Name" with the value "Peter", returning the object ID "1". The trie is then traversed to find the physical storage location "506" using the object ID "1". So the indirection layer (logical-physical mapping) is just another search index in the set of search indexes that the trie contains. Note that the ID-Map and name of the first key part may be physically stored in the trie as strings or integers (enumerations), for example the ID-Map may be "1" and the name "2", resulting in the following entries: "1, 1, 506" and "2, 'Peter', 1". Note also that there may be multiple parameters for the same key, for example "Name, 'Peter', Age, 30, 1". Also, as already mentioned above, a trie may contain different secondary keys. So there may also be a key "Age, 30, 1" contained in the same trie.
[0104] It should be noted that the above examples are merely illustrative of the principles, and the scope of protection is not limited to specific values and parameters.
[0105] A further object of the present invention is to provide a practical, usable and efficient multi-version trie with efficient node allocation and deallocation, thus solving the aforementioned problem of how unused and never-to-be-read versions are removed (garbage collection).
[0106] The prior art is silent on how to efficiently perform node allocation and deallocation, and does not disclose how allocation and deallocation may be performed in general, nor how garbage collection of unused nodes and their physical space may be performed while supporting multiple versions.
[0107] As mentioned above, the copy-on-write approach of tries leads to increased memory demands. Therefore, a solution is needed to discard unused nodes and reclaim space in the trie.
[0108] As also disclosed in International Patent Application PCT / EP2018 / 056592, a first aspect is to store nodes in an array rather than allocating them individually in memory (see also FIG. 7). Nodes may be stored in an array of long integers instead of using a node's memory pointer. In such an example, the current node may be specified by an index into this array. The child pointer may be an index of the node's position in the array. When traversing the trie, an offset to find the index of the child node based on the current node index may then be determined based on the space occupied by the current node. The child node may follow the current node and thus may be stored next to (or after) the current node in the array. With respect to the node structure described in International Patent Application PCT / EP2018 / 056592, the position of the child node in the array may be the amount of the least significant bit set in the bitmap before the target position plus one in the bitmap.
[0109] The preferred embodiment works with several such arrays (see also FIG. 8). In such a case, a pointer to a node may contain two parts: the first part, e.g., the bottom part of the pointer, may be an index into the array, and the second part of the pointer, e.g., the top part, is a reference to the array. Since it is not always possible to allocate arrays of arbitrarily large size, it may be necessary to use multiple arrays for memory management reasons. For example, in Java, the size of an array is limited to 32-bit integers, and 2 31 (positive values only) = 2,147,483,648 entries, resulting in an array size of 2,147,483,648 entries. However, many real-world applications require arrays containing many more entries.
[0110] Classical memory allocation and deallocation methods as known in the art do not consider multiple versions. This is illustrated by the example of glibc-malloc, a well-known library for managing allocated memory in an application's address space, which is briefly described in Figure 6.
[0111] Figure 6 shows an example of glibc-malloc according to the prior art. In glibc-malloc, memory is divided into chunks from a larger area of memory called the "heap" 501. The unused (free / available) chunks are linked into a chain. To allocate a certain amount of memory to an application, a suitable unused chunk needs to be found. If a free chunk of the requested size is not available, a larger free chunk is selected and divided into parts, resulting in the so-called memory fragmentation. Thus, the objective is to find an unused chunk of a suitable size.
[0112] If there is only one chained list, finding a chunk of a suitable size is expensive. Therefore, there is a bin (free list bin) 602 that chains chunks of a particular size (603, 604 for size a, 605 for size b). As an example, if chunk 605 is the correct size b for the allocation request, the chunk is unlinked from the free list chain and a pointer 606 to the available payload 607 is returned. Pointer 606 is the memory pointer returned to the application, but the chunk still has a header that contains the size and other memory management information. For example, the chunk may have a flag indicating whether the chunk is free or used.
[0113] When deallocated by an application, a chunk is returned to the appropriate chain of unused chunks. To reduce fragmentation, so-called coalescing is performed, which means that adjacent chunks are combined into larger chunks.
[0114] FIG. 7 illustrates trie memory management according to the present invention.
[0115] The following aspects must be considered when implementing trie memory management: Updating a trie during a transaction requires either allocating space for new nodes or copying and modifying existing nodes as part of a copy-on-write strategy. Memory space of existing nodes cannot be immediately reused, since the nodes still need to be accessible to pending transactions.
[0116] As mentioned above and as described in International Patent Application PCT / EP2018 / 056592, nodes may be held in multiple arrays. The embodiment shown in Figure 7 illustrates a trie memory management based on a single array 701.
[0117] In the embodiment shown in Figure 7, each node of the trie may be stored in a respective chunk 703, 705, 706, and 707. Each chunk that is not free and therefore contains a node includes a payload value that contains the node 706 and a value that identifies the transaction during which it was created (see transaction ID in Figure 7).
[0118] To allocate space for a trie node, the free list bin (also called the "free chunk list") 702 is first checked. Different nodes having different sizes may be stored in a trie. Examples of different nodes are described in detail in International Patent Application PCT / EP2018 / 056592. Such examples may include regular nodes with corresponding bitmaps and pointers, linked optimized nodes, or terminal optimized nodes.
[0119] If there is no free chunk of the requested size in the free list bin 602, the bin is checked for a double sized free chunk. If a double sized chunk is found, the double sized free chunk is split into two chunks.
[0120] Since a typical node has 1 to 64 child nodes, empirical testing has shown that having 64 bins (64 different chunk sizes) of corresponding size is a preferred and efficient approach. The array is filled successively, and the free pointer 708 points to the next available free space for allocating further chunks. Thus, if a free chunk is not available via the free list bin ("free chunk list") 702, the allocation appends a new chunk to the respective node at the location indicated by the free pointer 708.
[0121] In a preferred embodiment of the invention, the array is stored in a durable manner using a memory-mapped file (again as version storage). To achieve this, the array needs to be written to the file periodically. If all changes to the trie were written to persistent storage immediately, performance would degrade significantly. However, a system crash would result in an inconsistent state, since the trie is not stored after each change. To avoid an inconsistent state, the following crash recovery process is applied: The last saved state of the trie and the object store acting as a write-ahead log are read, and all changes present in the object store are applied to the last persisted version of the trie.
[0122] Note that the data structures and algorithms described in PCT / EP2018 / 056592 use an index pointer into the payload 709 and do not recognize the header information of the chunk 707 that maintains the chunk size and transaction information.
[0123] As mentioned above, it is an object of the present invention to provide a practical, usable and efficient multi-version try with efficient node allocation and deallocation. However, allocation and deallocation techniques known in the art, such as glibc-malloc, do not take into account different versions of objects and may not determine based on transaction information whether a chunk containing a node can be deallocated.
[0124] During a transaction, the following try operations may occur:
[0125] New trie nodes can be created. In this case, a chunk of the size required for the new node may be selected and the node is stored in this chunk. The chunk selected to accommodate the new node is removed from the list of free chunks (free list bin) 702. As mentioned above, if a free chunk of the required size is not available, a new chunk needs to be allocated first. Each chunk contains header information, e.g., its size, pointers to other chunks, and the transaction identifier that modified the chunk by storing the node in the chunk. Therefore, when inserting a node into a chunk, the transaction identifier that stored the node in the chunk needs to be updated.
[0126] The trie nodes created by the previous transaction are updated.
[0127] In this case, a copy of the node is made and the copy may be modified: in particular, a new chunk may be created and adapted to contain the node whose payload value has been modified, and the chunk's transaction identifying value (transaction ID) is set to the transaction identifier that created the chunk.
[0128] However, the "replaced" node may not be deleted immediately, since there may be pending transactions that still require access to the particular "replaced node." However, in order to allow the memory occupied by the "replaced node" to be reused as soon as possible, the node shall be deallocated as soon as there are no remaining transactions that require it.
[0129] To identify and monitor such chunks that contain "replaced nodes," chunks may be added to a pending free chunk list 703 (also referred to as a "pending free list"). For example, the pending free chunk list 703 may have different entries, each entry associated with a particular transaction and referencing a chunk that contains a node that was replaced during the particular transaction. For example, an entry may have a reference that points to a chain of chunks that contain nodes that were replaced by the transaction of that entry. The chain may be realized by a linked list, with the entry pointing to the first chunk of the list and each chunk pointing to the next chunk of the list (see "next chunk" of chunk 706). In one embodiment, as also shown in FIG. 7, when a chunk is added to the pending free chunk list 703, the transaction ID field is replaced by a pointer to the next chunk.
[0130] By keeping the chunk in the pending free chunk list 703, it is still possible to access the payload of the chunk with the "replaced node" since the payload (node) still contains valid information to support the pending transaction according to MVCC requirements, while at the same time keeping track of the node that needs to be deallocated in the near future.
[0131] When the replaced node is no longer needed by a pending transaction, the chunk containing the node is moved from the pending free chunks list 703 to the free chunks list 702 (also called the "free list bin"), and thus identified as a free chunk that can be reused to accommodate a new node (or as unused memory to be freed up).
[0132] In a preferred embodiment, such a determination of whether a node is still required by a pending transaction is not performed for each node individually, but rather for all nodes replaced by a particular transaction. In particular, such a determination may be accomplished by comparing the pending transaction identifier with the identifier of the particular transaction that replaced the node. Such a comparison requires that the pending transaction identifier is available and accessible by the memory management system. For example, the pending transaction identifier may be stored in a pending transaction list. The comparison may then be accomplished by determining whether the pending transaction list includes a transaction older than the particular transaction. The determination of whether an older transaction is included in the pending transaction list may be accomplished, for example, by using a monotonically increasing transaction identifier, i.e., a new transaction having a higher identifier number than the old transaction. Thus, it may be determined that the pending transaction list does not include a transaction with a lower transaction identifier than the transaction identifier of the particular transaction that replaced the node. If it is determined that there are no more pending transactions, all chunks associated with (or referenced by) the particular transaction are moved from the pending free chunk list 703 to the free chunk list 602. The corresponding chunks are added to the free chunk list 702 according to their size (when the chunks are organized into a linked list, as shown in FIG. 7).
[0133] A trie node created by the same transaction is updated. In this case, if the size of the corrected node is the same as the original node, the node may be overwritten or a new node may be created and the replaced node may be immediately returned to the free chunk list 702 since no other transactions can access it. This case may be detected by comparing the transaction ID of the chunk containing the node to be updated with the ID of the transaction updating it. If both IDs are the same, it is determined that the same transaction created the node.
[0134] When chunks are deallocated, they are distributed to the free chunk list 702 according to their size. If the free chunk list 702 does not have an entry (bin) for a particular chunk's size, the chunk's size may need to be corrected. If the chunk is larger than the available size, it is split into smaller chunks. If the chunk is smaller than the available size, it is combined with adjacent chunks. When combining with adjacent chunks (also called coalescing), the chunk flags of the adjacent chunks are evaluated to ensure that the chunks are unused and available for combining.
[0135] The embodiment shown in Figure 7 only describes memory management within a single array or epoch. However, as mentioned above, the size of arrays in programming languages is usually limited. Therefore, a solution is needed to efficiently perform garbage collection of multiple arrays and array files (epochs).
[0136] FIG. 8 illustrates one embodiment for efficiently garbage collecting multiple arrays in accordance with the present invention. FIG. 8 shows multiple arrays containing nodes from different tries. The multiple arrays arise from the fact that the size of the arrays is limited. Thus, if additional nodes need to be stored, a new array needs to be created. Such a new array is also called a new "epoch." Once a new array is created, it becomes the active array and is used to store new and modified nodes of the trie. Thus, the lists referred to above with respect to FIG. 7, free chunk list 702 and pending free chunk list 703, are maintained for the active array.
[0137] Arrays other than the active array are considered closed and will no longer be corrected. If nodes are modified or added during a transaction, copies of these nodes are stored in the active array.
[0138] In addition to the active array that holds the trie nodes, there are several other arrays, as shown in Figure 8. Each trie node is associated with a current trie root node corresponding to the current transaction and / or one or more previous trie root nodes corresponding to previous transactions. There are two trie root nodes in Figure 8: "old root" and "current root".
[0139] The array to be garbage collected must be determined in an eviction transaction to identify unused memory to be freed that is occupied by trie nodes of one or more tries that contain database indexes. Such determination may be based on one or more criteria. The criteria may be predefined or adapted at run time. The one or more criteria may include the number of transactions currently using the array and / or the number of nodes of one or more previous tries that are included in the array. Similar to the version store file, the candidate files representing trie arrays to be garbage collected may also be determined by tracking the amount and size of replaced nodes in the file.
[0140] If it is determined that one of the arrays meets the criteria, then said array is selected. In the next step, it is necessary to determine whether the selected array contains one or more nodes that are associated with the current trie root node (and therefore still in use). If the selected array contains such nodes, then in order to preserve them, the nodes must be copied to the active array.
[0141] Copying one or more nodes of the selected array associated with the current trie root node to the active array includes traversing the nodes associated with the current trie root node, and while traversing the nodes, copying nodes stored in the selected array and ignoring nodes not stored in the selected array.
[0142] To speed up the determination of whether a node needs to be copied, child nodes of nodes stored in arrays created before the selected array are ignored and therefore not traversed. Note that a node can only point to nodes within the same array or to a previous array, not to a node to an array allocated later. Thus, nodes from arrays created before the selected array cannot point to the selected array. Avoiding these branches improves performance since fewer nodes need to be evaluated (regardless of whether they are located in the selected array or not).
[0143] Also, while traversing the nodes associated with the current trie root node, nodes associated with previous trie root nodes created after the selected array became the active array may be simultaneously traversed, and the nodes associated with the current trie root node may be compared level by level from top to bottom with the nodes associated with the previous trie root node. If the comparison determines that a node is associated with the current trie root node but not with the previous trie root node, then the node and its child nodes are not traversed. Avoiding these nodes may significantly reduce the number of nodes traversed, since the nodes stored in the arrays between the current array and the selected array ("Array to GC" in FIG. 8) may be avoided.
[0144] In a preferred embodiment, the previous triroot node selected to perform the comparison may be the first triroot node created after the selected array becomes the active array, which means that the selected array is closed and is no longer corrected. The triroot node created immediately after this switch may be considered the best starting point, as it ensures that most nodes are not created between the selected array and the current / active array.
[0145] The aforementioned level-by-level comparison of the nodes associated with the current trie root node with the nodes associated with the previous trie root node from top to bottom includes comparing references to the nodes' child nodes. Such references may include bitmaps and pointers, as described in detail in International Patent Application PCT / EP2018 / 056592. In a preferred embodiment, the bitmaps are compared with a bitwise AND operator.
[0146] After copying the nodes, the memory occupied by the selected array may be identified as unused memory to be freed.
[0147] However, if there are pending transactions that still require access to nodes in the selected array, identification as unused memory to be released occurs only after all pending transactions have finished. The eviction (garbage collection) itself is performed within a transaction. The selected array needs to be held until all previously started transactions have finished. The determination of whether the pending transaction has finished can be performed by comparing the pending transaction with the eviction transaction, and determining that the pending transaction has finished if it is determined that the pending transaction does not contain any transactions older than the eviction transaction. In other words, there are no more pending transactions with transaction identifiers smaller than the transaction identifier of the eviction (garbage collection) that can discard the array.
[0148] If the array is stored in durable storage (e.g., a file), the durable storage can be destroyed only when the current array and the new root pointer after the garbage collection transaction have been flushed to durable storage reliably. Note that for performance reasons, flushing is not performed for each individual transaction.
[0149] FIG. 9 illustrates an example of garbage collection of multiple arrays according to FIG. 8. In a preferred embodiment, the trie is 32-variable, 64-variable. Thus, the bitmap referencing the pointer to the child node may contain 32 or 64 bits. For simplicity, FIG. 9 shows a 4-variable trie.
[0150] The example of Figure 9 includes three trie root nodes 901, 902, and 903. Trie root node 901 is the root to a first version of the trie, with the root node in "array 2" that is subject to garbage collection ("array 2" is the "selected array"). Trie root node 902 is the root node to a second version of the trie some later that results from a first transaction that occurs after switching from "array 2" to "array 3" as the current (active) array. Trie root node 903 is the current root of the trie.
[0151] For eviction of "Array 2", the trie nodes starting from trie root nodes 902 and 903 are compared. As mentioned above, with respect to Figure 8, the comparison may be performed (level-by-level and from top to bottom) by a bitwise AND of the node's bitmaps.
[0152] In the first step, bitmaps 904 and 905 are compared using a bitwise AND operation. The comparison shows that node 907 (key "2") is no longer in the current trie and does not need to be evicted (copied into the current array).
[0153] In the next step, the bitmaps on the next level 910, 911 of nodes 912 and 913 are compared and it is determined that node 906, which is part of key "012", is present in both tries but is stored in the array prior to "Array 2" ("Array 1"). Therefore, since "Array 1" is not subject to garbage collection, the node is not traversed (ignored) and does not need to be copied to the current array. No comparison of bitmaps is required to evaluate whether the node and its child nodes can be ignored because they are in an array stored prior to the selected array. This evaluation can also be performed, for example, when only one trie is traversed. As mentioned above, a node may be referenced by a pointer having two parts, a first part that points to an array using an index in a list of all arrays and a second part that holds an index within that particular array. Thus, the evaluation of whether the node is stored in the selected array or a previous array may be performed by evaluating the first part of the pointer.
[0154] Furthermore, by comparing the same bitmaps 910, 911, the path to node 914 is not followed because the key prefix "03" does not exist in the trie referenced by trie root node 902.
[0155] Furthermore, comparing the same bitmaps 910, 911 reveals that nodes 908 and 909, which are part of key "023", are still reachable from the current trie and therefore need to be evicted (copied) into the current array.
Claims
1. 1. A computer-implemented method performed by an electronic database application or information retrieval system for determining the storage location of a particular version of a database object, the method comprising: storing an index for each version of the database object in a trie having a root node corresponding to the particular version; the method comprising: determining a trie corresponding to the particular version by accessing the root node of the trie corresponding to the particular version; determining an object identifier for the database object by traversing the trie corresponding to the particular version using a secondary key associated with the database object as a search key; determining the storage location of the database object by traversing the trie corresponding to the particular version using the determined object identifier as a search key.
2. The method of claim 1 , wherein the search key includes information about whether the search key is an object identifier or a secondary key associated with a database object.
3. The method of any one of claims 1 to 2, wherein a secondary key comprises information about one or more properties encoded within said secondary key.
4. The method of claim 3 , wherein the one or more properties encoded in the secondary key include one of a name and an address.
5. The method of any one of claims 1 to 4, wherein an index is defined as having a key and a value.
6. 6. The method of claim 1, wherein a first index is defined by having the secondary key as a key and the object identifier as a value, and a second index is defined by having the object identifier as a key and the storage location of the database object as a value.
7. 7. The method of claim 1, wherein the trie having a root node corresponding to the particular version is created by: creating a new root node for the particular version; copying and modifying the corrected nodes with respect to nodes of a previous trie having a root node corresponding to a previous version; and creating a reference pointing to the nodes of the previous trie that have not been corrected.
8. 8. The method of claim 7, wherein creating the trie having a root node corresponding to the particular version is performed during a transaction, the particular version being associated with the transaction.
9. The method of claim 8 , wherein the transaction is identified by a transaction identifier.
10. A computer program comprising instructions for carrying out the method according to any one of claims 1 to 9.
11. A data processing device or system comprising one or more processors and a memory configured to perform the method of any one of claims 1 to 9.
12. A non-transitory computer readable medium having stored thereon the computer program of claim 10.
Citation Information
Patent Citations
Method and device for retrieving data, and recording medium
JP2000227921A
Memory allocation method and memory allocation program
JP2008065764A
Information generating device, information generating method, and information generating program
JP2012073943A
Program and version management method
JP2014191672A
Methods, systems, computer program products and computer programs for determining causes of external fragmentation of memory
JP2018509683A
