File migration method and storage layer system
By implementing an asynchronous file migration method in the storage layer system, the problem of limited storage resources in a single-machine database was solved, distributed management and control were achieved, and response speed and performance were improved.
Patent Information
- Application Number
- PCT/CN2024/137815
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-06-27
- Filing Date
- 2024-12-09
- Publication Date
- 2026-01-02
AI Technical Summary
Single-machine databases are limited by storage resources. How can we achieve better management and control in a distributed database environment, especially when the amount of data continues to grow?
By implementing a file migration method in the storage layer system and using a timer to trigger asynchronous file migration behavior, we can ensure that files are managed and controlled in a distributed manner across multiple storage modules, thus avoiding blocking critical operations.
It improves the response speed and performance of the storage layer system, enables better distributed management and control, and avoids blocking other operations by file migration behavior.
Smart Images

Figure CN2024137815_02012026_PF_FP_ABST
Abstract
Description
File migration method and storage layer system
[0001] The present application claims priority to the Chinese patent application No. 202410857415.4, filed on June 27, 2024 in the China Patent Office, and entitled "File migration method and storage layer system", the whole content of which is incorporated herein by reference. TECHNICAL FIELD
[0002] The present application relates to the technical field of computer, in particular to a file migration method and a storage layer system. BACKGROUND
[0003] Single-machine databases have the problem that storage resources are limited by the capacity of single-machine disks. To solve this problem, the current solution is mainly to replace the original single-machine database with a distributed database. For a distributed system environment, under the condition of continuous growth of data volume, how to better achieve distributed management and control is a problem that needs to be focused on. TECHNICAL PROBLEM
[0004] The present application provides a file migration method and a storage layer system, which can better achieve distributed management and control. TECHNICAL SOLUTION
[0005] In a first aspect, a file migration method is provided, which is applied to a storage layer system. The storage layer system includes a first device, one or more second devices, and a plurality of storage modules. Any one of the plurality of storage modules is located in the first device or the second device. Each storage module in the plurality of storage modules is used to store files. The plurality of storage modules can perform file migration. The method includes: when a timer expires, the first device determines file migration information of a new round of file migration behavior in the case that a previous round of file migration behavior has been completed. The file migration information is used to indicate files that any one of the plurality of storage modules needs to migrate to other storage modules. The file migration behavior is a background asynchronous behavior. The first device sends a migration request message to a device where each storage module in the plurality of storage modules is located. The migration request message carries the file migration information. After receiving the migration request message, a target device determines files that each storage module in the target device needs to send and files that each storage module in the target device needs to receive according to the file migration information. The target device is a device where at least one storage module in the plurality of storage modules is located. The target device performs file sending and receiving operations according to the files that each storage module in the target device needs to send and the files that each storage module in the target device needs to receive. After the file sending and receiving operations are completed, the target device sends a migration completion message to the first device. The first device determines whether the current round of file migration behavior is completed according to the received migration completion message.
[0006] In a second aspect, a storage layer system is provided, which includes a first device, one or more second devices, and a plurality of storage modules, any one of the plurality of storage modules is located in the first device or the second device, each of the plurality of storage modules is configured to store files, and file migration can be performed between the plurality of storage modules; the first device is configured to, when a timer expires, determine file migration information of a new round of file migration behavior in a case that a previous round of file migration behavior has been completed, the file migration information is used to indicate files that any one of the plurality of storage modules needs to migrate to other storage modules, and the file migration behavior is a background asynchronous behavior; the first device is further configured to send a migration request message to a device where each of the plurality of storage modules is located, the migration request message carries the file migration information; a target device is configured to, after receiving the migration request message, determine files that each of the storage modules in the target device needs to send and files that each of the storage modules in the target device needs to receive according to the file migration information, the target device is a device where at least one of the plurality of storage modules is located; the target device is further configured to perform file sending and receiving operations according to the files that each of the storage modules in the target device needs to send and the files that each of the storage modules in the target device needs to receive, and send a migration completion message to the first device after the file sending and receiving operations are completed; and the first device is further configured to determine whether the current round of file migration behavior is completed according to the received migration completion message.
[0007] In a third aspect, a computer device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is executed by the processor to implement operations performed by the first device or the second device in the file migration method of the first aspect.
[0008] In a fourth aspect, a computer readable storage medium is provided, which stores a computer program, and the computer program is executed by a processor to implement operations performed by the first device or the second device in the file migration method of the first aspect.
[0009] In a fifth aspect, a computer program product containing instructions is provided, which, when executed on a computer, causes the computer to perform operations performed by the first device or the second device in the file migration method of the first aspect. Advantages
[0010] In the present application, file migration is performed between the plurality of storage modules at a fixed time, which can achieve distributed storage of files. Moreover, the file migration behavior is a background asynchronous behavior, which can avoid blocking other key operations such as data storage operations, data query operations, etc., so as to improve the response speed and performance of the storage layer system. In this way, distributed management and control can be better achieved. BRIEF DESCRIPTION OF DRAWINGS
[0011] FIG. 1 is a schematic diagram of a storage layer system according to an embodiment of the present application;
[0012] FIG. 2 is a schematic diagram of a target tree according to an embodiment of the present application;
[0013] FIG. 3 is a schematic diagram of a key-value pair according to an embodiment of the present application;
[0014] FIG. 4 is a schematic diagram of another key-value pair according to an embodiment of the present application;
[0015] FIG. 5 is a flowchart of a file migration method according to an embodiment of the present application;
[0016] FIG. 6 is a schematic diagram of index information according to an embodiment of the present application;
[0017] FIG. 7 is a schematic diagram of a computer device according to an embodiment of the present application. Embodiments of the present application
[0018] The file migration method provided by the embodiments of the present application can be applied in a system with data processing requirements. In the embodiments of the present application, the system is referred to as a storage layer system, and the storage layer system is described below.
[0019] For example, after a blockchain system executes all transactions in a block, a series of ledger data is generated, which can include multiple key-value pairs. In this case, the file migration method provided by the embodiments of the present application can be used to store the ledger data in the storage layer system, and the ledger data can be migrated in the storage layer system according to the hotness of the ledger data.
[0020] The external system connected to the storage layer system is a system with data storage requirements. For example, the external system connected to the storage layer system can be a database system, a blockchain system, etc., which is not limited in the embodiments of the present application.
[0021] The storage layer system is used to receive, process and reply to various requests sent by the external system. For example, the requests sent by the external system can include data storage requests, data query requests, etc., which are not limited in the embodiments of the present application.
[0022] In some embodiments, the storage layer system can implement a database internal file storage mechanism that is characteristic of the blockchain system, can be horizontally expanded, and can realize cold and hot data statistics and separate storage. For example, this storage mechanism can be adapted to the underlying file storage engine of a continuous database with block granularity, and can also be used for the storage of final to-be-fallen disk files of a key-value (kv) type database such as a ledger.
[0023] FIG. 1 is a schematic diagram of a storage layer system according to an embodiment of the present application. Referring to FIG. 1, the storage layer system can include a first device 101, one or more second devices 102 (one second device 102 is shown in FIG. 1 as an example), and a plurality of storage modules (four storage modules are shown in FIG. 1 as an example). The plurality of storage modules are distributed in the first device 101 and the one or more second devices 102, and any one of the plurality of storage modules is located in the first device 101 or the second device 102.
[0024] The first device 101 and the second device 102 can communicate through wired connection or wireless connection. For example, the first device 101 and the second device 102 can establish a communication connection through a Google Remote Procedure Call (GRPC) protocol.
[0025] The first device 101 is configured to receive, process, and reply to various requests sent by an external system. The first device 101 can control file migration between the plurality of storage modules. The first device 101 runs management logic for overall management of the storage layer system. The first device 101 can selectively bind physical storage resources (such as disks) and directly interface with an upper-layer system (such as a blockchain system or a database system). The first device 101 can provide a file read-write interface to the upper-layer system. In this case, the first device 101 can receive requests (such as data query requests and data storage requests) sent by the upper-layer system and process the requests. The second device 102 is a device other than the first device 101, and the second device 102 can selectively bind physical storage resources (such as disks).
[0026] In some embodiments, the first device 101 can be referred to as a master device, and the second device 102 can be referred to as a slave device. For example, the first device 101 and the second device 102 can be physical machines. The first device 101 can carry and manage 0, 1, or more storage modules. Any one of the second devices 102 can carry and manage 0, 1, or more storage modules. The first device 101 and the one or more second devices 102 can collectively carry and manage a plurality of storage modules.
[0027] Each of the plurality of storage modules is configured to store files, and file migration can be performed between the plurality of storage modules. The file migration operation between the plurality of storage modules can be controlled and executed by the first device 101.
[0028] The file migration operation refers to the first device 101 migrating part of the files in one storage module to another storage module for storage.
[0029] The file migration operation has periodicity. Optionally, the first device 101 can migrate part of the files in one storage module to another storage module for storage every preset time length. The preset time length can be preset. For example, the preset time length can be set to 2 minutes, 3 minutes, 4 minutes, etc., and the embodiments of the present application do not limit this.
[0030] The files in the storage module include data such as key-value pairs, etc. sent by an external system and needing to be stored. For example, the storage module can be a disk, a storage area in the disk, or other devices that can be used for data storage, etc., and the embodiments of the present application do not limit this. For example, the plurality of storage modules can include a solid state drive (SSD), a hybrid hard drive (HHD), a traditional hard disk drive (HDD), etc., and the embodiments of the present application do not limit this.
[0031] Optionally, one storage module can correspond to one instance, and the instance can bind the path of the corresponding storage module, so that the first device 101 can store data in the corresponding storage module or read data from the corresponding storage module through the instance.
[0032] The storage module has an identifier, i.e., a module identifier. The module identifier of one storage module is used to identify the storage module.
[0033] In some embodiments, the storage layer system has a version number. One version number corresponds to one version, and the version corresponding to one version number can represent a file distribution state in the storage layer system, which indicates which files are stored in each storage module.
[0034] For example, storing a new file can trigger version updating, and migrating files between storage modules can also trigger version updating. The version updating is strictly serially executed in the storage layer system.
[0035] The storage layer system has a system version number, which can be a continuously increasing integer. The system version number is used to indicate the latest version number of the storage layer system. For example, the system version number can be 0, 1, 2, 3, 4, …, etc. For example, the updating of the system version number can be triggered by any one of the file storage operation or the file migration operation. Specifically, when the storage layer system performs the file storage operation or the file migration operation, a new version number is generated, and then the system version number can be updated to the new version number.
[0036] Optionally, each of the plurality of storage modules has a cold-hot priority score. The cold-hot priority score of each of the plurality of storage modules can be set according to the read-write performance (including but not limited to read-write efficiency) of each storage module. Specifically, the higher the read-write performance of a storage module, the higher the cold-hot priority score of the storage module, and the lower the read-write performance of a storage module, the lower the cold-hot priority score of the storage module.
[0037] The cold-hot priority score of each of the plurality of storage modules can be set in advance. For example, since the read-write efficiency of an SSD is higher than that of an HDD, the cold-hot priority score of an SSD can be set to be higher than that of an HDD.
[0038] In some embodiments, the cold-hot priority score of a storage module can indicate the priority of the storage module in storing hot data. Hot data refers to data with a higher access frequency by an external system, and cold data refers to data with a lower access frequency by an external system.
[0039] The higher the cold-hot priority score of a storage module, the higher the read-write performance of the storage module, and the higher the speed of the first device 101 in querying and storing files in the storage module. Therefore, hot data can be stored in a storage module with a higher cold-hot priority score. Conversely, the lower the cold-hot priority score of a storage module, the lower the read-write performance of the storage module, and the lower the speed of the first device 101 in querying and storing files in the storage module. Therefore, cold data can be stored in a storage module with a lower cold-hot priority score. The cold-hot priority scores of the plurality of storage modules are different, and the cold-hot priority scores of the plurality of storage modules have an order of magnitude. The plurality of storage modules are sorted in order of decreasing cold-hot priority score, i.e., the plurality of storage modules are sorted in order of decreasing read-write performance. Optionally, the files in any one of the plurality of storage modules except the last one in the order can be migrated to the next one in the order.
[0040] In some embodiments, each of the plurality of storage modules can have a first correspondence relationship, a second correspondence relationship, and a third correspondence relationship. Optionally, the first correspondence relationship, the second correspondence relationship, and the third correspondence relationship of each of the plurality of storage modules can be stored in the memory of the first device 101.
[0041] The first correspondence of a storage module can include the hit times of each file in the storage module. The first correspondence of a storage module can be a correspondence between the file identifiers of each file stored in the storage module and the hit times of the files. The hit time of a file can be the number of times the file is queried by an external system.
[0042] The first correspondence can include at least one file identifier and at least one hit time, the at least one file identifier and the at least one hit time corresponding one-to-one, and the hit time corresponding to a file identifier being the hit time of the file identified by the file identifier.
[0043] In some embodiments, the first correspondence can include a file identifier list and a hit time list, the number of elements in the file identifier list being the same as the number of elements in the hit time list, and the elements at the same index position in the file identifier list and the hit time list corresponding. In this way, the elements in the file identifier list and the elements in the hit time list correspond one-to-one.
[0044] The elements in the file identifier list are file identifiers. The file identifier list is a list recording the file identifier of each file in all files in the storage module. The elements in the hit time list are hit times. The hit time list is a list recording the hit time of each file in all files in the storage module.
[0045] It should be noted that the index of the element in the list is used to identify the element at a specific position in the list, and is usually incremented from 0. For example, in a list containing 5 elements, the index of the first element is 0, the index of the second element is 1, and so on, and the index of the fifth element is 4. Through the index, the element in the list can be quickly located and accessed or modified.
[0046] It should be noted that when the storage layer system has not yet started to store files, the first correspondence of each storage module in the plurality of storage modules is empty, i.e., there is no file identifier and no hit time in the first correspondence.
[0047] After the storage layer system starts to store files, such as after a new file is generated and stored in a storage module, the file identifier of the new file can be added to the first correspondence of the storage module, and the hit time corresponding to the file identifier is set to 0. Then, the first correspondence can be updated according to the received data query request. For example, if a file is queried in the storage module according to the data query request, the hit time corresponding to the file identifier of the file in the first correspondence of the storage module can be incremented by 1.
[0048] In addition, if a file in one storage module is migrated to another storage module, the file identifier of the migrated file and the corresponding hit count need to be added in the first correspondence relationship of the another storage module.
[0049] The second correspondence relationship of a storage module includes the number of files in the storage module whose hit counts are in each preset hit count interval of the plurality of preset hit count intervals. The second correspondence relationship of a storage module can be a correspondence relationship between each preset hit count interval and the number of files in the plurality of preset hit count intervals. The number of files corresponding to a preset hit count interval is the number of all files in the storage module whose hit counts are in the preset hit count interval.
[0050] The value ranges of each preset hit count interval in the plurality of preset hit count intervals are different. In addition, the plurality of preset hit count intervals are sorted in ascending order of value ranges. For example, the value ranges of the plurality of preset hit count intervals are consecutive on integers.
[0051] The plurality of preset hit count intervals can be set in advance. Alternatively, the plurality of preset hit count intervals can be obtained according to elements in a static hit count interval list. The hit count interval list can be a system configuration value, which can be set by a technician in advance and usually will not be modified during the running of the storage layer system.
[0052] The hit count interval list can include a plurality of elements, which can be sorted in ascending order in the hit count interval list. The plurality of elements in the hit count interval list correspond one-to-one to the plurality of preset hit count intervals. For example, for any element in the hit count interval list except the last element, the element can be taken as the minimum value of a preset hit count interval corresponding to the element, and the maximum integer less than the next element of the element can be taken as the maximum value of the preset hit count interval corresponding to the element. For the last element in the hit count interval list, the value range of a preset hit count interval corresponding to the element is from the element to positive infinity.
[0053] The third correspondence relationship of a storage module can include the total hit count of files in the storage module whose hit counts are in each preset hit count interval of the plurality of preset hit count intervals. The third correspondence relationship of a storage module can be a correspondence relationship between each preset hit count interval and the total hit count in the plurality of preset hit count intervals. The total hit count corresponding to a preset hit count interval is the sum of the hit counts of all files in the storage module whose hit counts are in the preset hit count interval.
[0054] As an example, the second correspondence relationship and the third correspondence relationship can be implemented in an array form. The hit frequency interval list is an array, and correspondingly, a corresponding file quantity array can be constructed as the second correspondence relationship, and a corresponding hit total frequency array can be constructed as the third correspondence relationship. The three arrays are one-dimensional arrays, and the lengths (i.e., the number of elements) of the three arrays are the same, and the elements at the same index positions in the three arrays correspond to each other.
[0055] In this case, the plurality of elements in the file quantity array correspond to the plurality of elements in the hit frequency interval list one by one, that is, correspond to the plurality of preset hit frequency intervals one by one. The plurality of elements in the hit total frequency array correspond to the plurality of elements in the hit frequency interval list one by one, that is, correspond to the plurality of preset hit frequency intervals one by one.
[0056] The first correspondence relationship, the second correspondence relationship, and the third correspondence relationship of each storage module in the plurality of storage modules can be managed by the first device 101. The first device 101 can manage the first correspondence relationship, the second correspondence relationship, and the third correspondence relationship of each storage module through the module identifier of each storage module in the plurality of storage modules.
[0057] In some embodiments, the first device 101 and each device in the one or more second devices 102 are configured with a globally unique device identifier, and each device needs to assume both the role of a server and the role of a client in the network.
[0058] As a server, different server processing logics can be started according to the device identity (such as a master device or a slave device) of the server. As a module that directly receives messages from other devices, the server will receive processing functions registered by upper modules when starting, so as to call these processing functions to perform corresponding processing when receiving messages sent by other devices, and then return the processing result to the sender.
[0059] As a client, because there is a scenario of data transmission between different storage modules in the same device in the storage layer system, the client needs to have the ability to distinguish the scenario of data transmission in the same device, and in this scenario, the packing and unpacking processing logics of the communication protocol (such as the grpc protocol) itself are omitted, and data transmission in the memory is directly performed.
[0060] In addition, the first device 101 maintains a mapping between the device identifier of the first device 101 and each device in the one or more second devices 102 and the storage module identifier. Each second device 102 maintains a mapping between its own device identifier and the storage module identifier. The device identifier to storage module identifier conversion can be implemented in each device. Therefore, the first device 101 can implement data transmission between any two storage modules.
[0061] In some embodiments, the storage layer system can interface with a database system. The database system can interface with other systems that have data storage needs, such as a blockchain system, and the like. Illustratively, when the blockchain system needs to store data, the data can be first sent to the database system, and then sent to the storage layer system by the database system. The storage layer system can store the data based on the target tree.
[0062] Optionally, the storage layer system and the database system can be independent systems, in which case the storage layer system and the database system can run on independent physical machines, respectively. Alternatively, the database system can include the storage layer system, in which case the database system includes a specific system that interfaces with the blockchain system and runs on the same physical machine as the storage layer system.
[0063] Next, the structure of the target tree provided by the embodiments of the present application is described.
[0064] The target tree is a tree structure. The target tree includes branch nodes and leaf nodes at the lowest level of the target tree, wherein a node with a number of child nodes of 0 is a leaf node, a node with a number of child nodes greater than or equal to 1 is a branch node, and the branch nodes and the leaf nodes are logical nodes. The branch node at the uppermost level of the target tree can be referred to as a root node, which is a branch node without a parent node in the target tree.
[0065] Optionally, the target tree can be an n-ary tree, that is, the number of child nodes of each branch node in the target tree is at most n, where n is an integer greater than or equal to 2. Any branch node in the n-ary tree can have at most n child nodes. Moreover, for branch nodes at the same level in the n-ary tree, a new branch node can be added after the last branch node at the same level only when the number of child nodes of the last branch node at the same level reaches n.
[0066] The leaf node stores a file identifier, a maximum key value, a minimum key value, and a mapping table.
[0067] The file identifier is used to identify a file stored in the storage layer system. For example, the file identifier can be a file identity (ID), a file name, or the like. The minimum key value in the leaf node is the minimum key value in the file identified by the file identifier in the leaf node. The maximum key value in the leaf node is the maximum key value in the file identified by the file identifier in the leaf node.
[0068] In the embodiments of the present application, the leaf nodes in the target tree correspond one-to-one to files. That is, a leaf node contains the file identifier of a file and the minimum key value and the maximum key value in the file.
[0069] The mapping table in the leaf node is used to indicate that the file identified by the file identifier in the leaf node is stored in the storage module under each version. The mapping table can include a mapping relationship between version numbers and storage module identifiers. One version number and its mapped storage module identifier in the mapping relationship are used to indicate that the file is stored in the storage module identified by the storage module identifier when the file is in the version corresponding to the version number.
[0070] In some embodiments, the mapping table can be a doubly linked list, and each node in the doubly linked list includes a version number and a storage module identifier. In this case, the doubly linked list can maintain two node pointers, one of which is a head pointer used to indicate the head node of the doubly linked list, and the other of which is a tail pointer used to indicate the tail node of the doubly linked list.
[0071] In the embodiments of the present application, the storage layer system can store one or more files, and each file can include one or more key-value pairs. The file identifiers of all the files stored in the storage layer system are globally ordered, that is, the file identifier of any file is ordered in all the files stored in the storage layer system. In addition, the key values in all the key-value pairs included in the files are also globally ordered, that is, the key value in any key-value pair included in any file is ordered in all the key-value pairs in all the files stored in the storage layer system.
[0072] Optionally, the global order of the key values in the key-value pairs can be in ascending order according to the lexicographical order.
[0073] In this case, the minimum key value in a file refers to the key value that is ranked first among the key values in all the key-value pairs in the file. The maximum key value in a file refers to the key value that is ranked last among the key values in all the key-value pairs in the file.
[0074] It should be noted that in the computer field, the lexicographical order can be used to indicate the size relationship between any two strings. The size relationship between two strings depends on the size relationship of the American Standard Code for Information Interchange (ASCII) codes of the characters in the strings from left to right.
[0075] Optionally, the global order of the file identifiers of the files can be in ascending order according to the lexicographical order.
[0076] For example, the file identifier of a file can start from 0 and increase by a preset value.
[0077] The preset value can be preset. For example, the preset value can be set as 1, 2, 3, etc., which is not limited in the embodiments of the present application.
[0078] In this case, the file identifiers of all the files are an arithmetic sequence. For example, assuming that the preset value is 1, the file identifiers of the first file, the second file, the third file, …, the kth file generated can be 0, 1, 2, …, k-1, respectively.
[0079] In some embodiments, a global continuously increasing counter can be maintained in the storage layer system, which is used to generate the file identifier. In this case, the storage layer system can take the current value of the counter as the file identifier of a new file each time a new file is generated, so that the files stored in the storage layer system are a batch of files with continuously increasing file identifiers.
[0080] The branch node includes a child node list, and the child node list includes the minimum key value and the maximum key value in each child node of the branch node. For example, the range from the minimum key value in a child node to the maximum key value in the child node can be referred to as the key range of the child node. The child nodes of a branch node can be branch nodes or leaf nodes in the next layer. The minimum key value in the branch node is the minimum key value in all the key values in the child node list in the branch node, that is, the key value with the earliest order in all the key values in the child node list; and the maximum key value in the branch node is the maximum key value in all the key values in the child node list in the branch node, that is, the key value with the latest order in all the key values in the child node list. The minimum key value and the maximum key value in a leaf node are the minimum key value and the maximum key value stored in the leaf node.
[0081] For example, FIG. 2 is a schematic diagram of a target tree provided by an embodiment of the present application. Referring to FIG. 2, the target tree is a 2-ary tree, and the target tree includes multiple leaf nodes (for example, node n4, node n5, and node n6 in FIG. 2) and multiple branch nodes (for example, node n1, node n2, and node n3 in FIG. 2). The child nodes of node n1 include node n2 and node n3, the child nodes of node n2 include node n4 and node n5, and the child nodes of node n3 include node n6. In the embodiments of the present application, the branch node in the uppermost layer of the target tree can be referred to as a root node, for example, node n1 in FIG. 2 is a root node.
[0082] Leaf node n4 in FIG. 2 stores file identifier 0, minimum key value 1, maximum key value 3, and mapping table 0. Leaf node n5 stores file identifier 1, minimum key value 4, maximum key value 6, and mapping table 1. Leaf node n6 stores file identifier 2, minimum key value 7, maximum key value 9, and mapping table 2. Branch node n2 in FIG. 2 stores a list of child nodes, which includes minimum key value 1 and maximum key value 3 in leaf node n4, and includes minimum key value 4 and maximum key value 6 in leaf node n5. Branch node n3 in FIG. 2 stores a list of child nodes, which includes minimum key value 7 and maximum key value 9 in leaf node n6. Branch node n1 in FIG. 2 stores a list of child nodes, which includes minimum key value 1 and maximum key value 6 in branch node n2, and includes minimum key value 7 and maximum key value 9 in branch node n3.
[0083] In an embodiment of the present application, the storage layer system can store the key-value pairs sent by the external system based on the target tree. The target tree can also be referred to as a solid branch tree. In some cases, the key values in the key-value pairs sent by the external system to the storage layer system are globally ordered. The concept of global order has been explained above and will not be repeated here.
[0084] In some embodiments, the storage layer system can interface with a database system, and the database system can interface with a blockchain system. In this case, the blockchain system can send the key-value pairs to be stored to the database system, and the database system can send a data storage request carrying the key-value pairs to the storage layer system after receiving the key-value pairs.
[0085] As an example, the key-value pairs to be stored sent by the blockchain system to the database system can be block data. Since the block data is strictly organized according to block numbers, i.e., the key values in the block data are block numbers, the key values in the block data are naturally globally ordered. In this case, the database system can directly send the block data to the storage layer system for storage in the data storage request.
[0086] As another example, the key-value pairs to be stored sent by the blockchain system to the database system can be account data within a block. The account data within a block includes multiple key-value pairs, and the key values in the multiple key-value pairs within the same block are different, but the key values in the key-value pairs within different blocks can be the same.
[0087] In this case, the database system can first process the account book data, specifically, the database system can introduce a block number in the account book data to construct key-value pairs with globally ordered keys, and then send the constructed key-value pairs to the storage layer system in a data storage request for storage. In this way, it can be ensured that the keys in the key-value pairs carried in the data storage request sent by the database system to the storage layer system are globally ordered.
[0088] Optionally, the key-value pair can be referred to as a target key-value pair in the embodiments of the present application, the key in the target key-value pair includes a block number and a key in a block identified by the block number (i.e. the key in the key-value pair in the account book data), and the value in the target key-value pair is the value in the block (i.e. the value in the key-value pair in the account book data).
[0089] In some embodiments, the key in the target key-value pair can be obtained by concatenating the block number and the key in the block, of course, the key in the target key-value pair can also be obtained by other ways, which are not limited in the embodiments of the present application.
[0090] Since the block number is naturally globally ordered, and the keys in a block are different, the key in the target key-value pair containing the block number and the key in the block identified by the block number is also globally ordered.
[0091] For example, the block with the block number 00000001 includes a plurality of key-value pairs, for each key-value pair in the plurality of key-value pairs, the block number 00000001 can be added before the key in the key-value pair to obtain a new key.
[0092] For example, as shown in (a) of FIG. 3, the block 1 with the block number 00000001 includes key-value pairs bbbb:{value1...}, bggg:{value2...}, caaa:{value3...}, xaab:{value4...}. As shown in (b) of FIG. 3, the block 2 with the block number 00000002 includes key-value pairs aabb:{value5...}, bggg:{value6...}, bcde:{value7...}.
[0093] Then, after the blockchain system sends the key-value pairs to the database system, the database system can introduce the block number 00000001 into the key-value pairs in block 1, specifically, concatenate 00000001 before the key value in each key-value pair in block 1 to obtain the target key-value pairs 00000001bbbb:{value1...}, 00000001bggg:{value2...}, 00000001caaa:{value3...}, and 00000001xaab:{value4...}. The block number 00000002 is introduced into the key-value pairs in block 2, specifically, 00000002 is concatenated before the key value in each key-value pair in block 2 to obtain the target key-value pairs 00000002aabb:{value5...}, 00000002bggg:{value6...}, and 00000002bcde:{value7...}. The key values in the target key-value pairs obtained in this way are globally ordered.
[0094] It should be noted that the storage layer system in the embodiments of the present application is not limited to storing the key-value pairs in the blockchain system proposed above, but can also store other key-value pairs, as long as the key values in the key-value pairs are globally ordered.
[0095] The process of constructing the initial target tree by the first device 101 will be described below, which can include the following steps (1) to (5):
[0096] (1) The first device 101 receives a data storage request carrying a key-value pair to be stored, the key value in the key-value pair being globally ordered. The data storage request is used to instruct the first device 101 to store the key-value pair to be stored. In some embodiments, the data storage request can be sent by an external system. For example, the blockchain system or the database system.
[0097] In this case, the key values in all key-value pairs to be stored sent by the external system to the first device 101 are ordered. After the first device 101 stores these key-value pairs, the key values in all key-value pairs stored in the storage layer system are also ordered.
[0098] (2) The first device 101 generates a new file containing one or more key-value pairs according to the order of the key values in the key-value pairs, and stores the new file in the first storage module; wherein the file identifiers of all files containing key-value pairs are globally ordered.
[0099] The first storage module is a storage module for storing the new file. For example, the first storage module is a storage module with the highest read-write performance among the plurality of storage modules, that is, the first storage module is a storage module ranked first among the plurality of storage modules.
[0100] The first storage module can be located at the first device 101, and of course, can also be located at the second device 102, and the embodiments of the present application do not limit this. If the first storage module is located at the first device 101, the first device 101 can directly store the new file to the first storage module; if the first storage module is located at the second device 102, the first device 101 can send the new file to the second device 102 where the first storage module is located, and the second device 102 can store the new file to the first storage module after receiving the new file.
[0101] The key values in the key-value pairs received by the first device 101 are in order. In this case, the first device 101 generates a new file according to the order of the key values in the key-value pairs, and the key values in the key-value pairs in the new file are also in order.
[0102] In some embodiments, the operation of step (2) can be that the first device 101 saves all key-value pairs carried by each data storage request in the memory of the first device 101 according to the order of the key values in the key-value pairs carried by the data storage request, every time the first device 101 receives a data storage request. If the difference between the total data amount of one or more key-value pairs saved in order in the memory and the preset data amount is less than or equal to the preset difference, the first device 101 generates a new file containing the one or more key-value pairs. The first device 101 stores the new file to the first storage module. The preset data amount can be set in advance. For example, the preset data amount can be set to 8 megabytes (MB), 9 MB, 10 MB, etc., and the embodiments of the present application do not limit this. Alternatively, the preset data amount can be set according to an integer multiple of the block size of the storage layer system. For example, if the block size is 4 MB, the preset data amount can be set to 4 MB, 8 MB, 12 MB, etc. The block size of the storage layer system refers to the smallest unit used by the storage layer system to organize and manage data storage. The preset difference can be set in advance. For example, the preset difference can be set to 100 kilobytes (KB), 200 KB, 300 KB, etc.
[0103] It should be noted that the data amount of each key-value pair is generally close, and the data amount of one key-value pair is usually within a predetermined range. In the embodiments of the present application, the preset data amount can be much larger than the data amount of one key-value pair. The preset difference can be close to the data amount of one key-value pair, such as equal to or slightly larger than the data amount of one key-value pair.
[0104] The first device 101 can save all the key-value pairs carried by each received data storage request in the memory in sequence. In this case, if the total data amount of one or more key-value pairs currently saved in the memory in sequence is close to the preset data amount (i.e., the difference between the total data amount and the preset data amount is less than or equal to the preset difference), all the key-value pairs currently saved in the memory can be stored in the first storage module in the form of a new file. In this way, batch storage of key-value pairs can be implemented, thereby improving the data storage efficiency. Moreover, in this case, the file size of each file stored in the first storage module is basically consistent, and is close to the preset data amount, thereby facilitating file management.
[0105] It should be noted that if the total data amount of all the key-value pairs currently saved in the memory is less than the preset data amount, and the difference between the total data amount and the preset data amount is greater than the preset difference, it indicates that the total data amount of the key-value pairs currently saved in the memory is greatly different from the preset data amount, and the condition for generating a new file is not met. In this case, the first device 101 can continue to receive the data storage request sent by the external system, and save the key-value pairs carried by the data storage request in the memory, until the difference between the total data amount of the key-value pairs saved in the memory in sequence and the preset data amount is less than or equal to the preset difference, and then generate a new file and store it.
[0106] The generated new file is stored in the first storage module, i.e., the persistence of the new file is implemented. Moreover, after the new file is stored in the first storage module, one or more key-value pairs in the new file are deleted from the memory.
[0107] It should be noted that the key values in the key-value pairs saved in the memory are in order. In this case, the new file is generated according to the key-value pairs saved in the memory, and the key values in all the key-value pairs in the new file are also in order. It should be noted that since one file can contain one or more key-value pairs, the key-value pairs in one file can cover the data of one block or multiple blocks.
[0108] For example, as shown in FIG. 4, the first device 101 receives a data storage request 1 carrying key-value pairs 00000001bbbb:{value1...}, 00000001bggg:{value2...}, 00000001caaa:{value3...}, and 00000001xaab:{value4...}. The first device 101 stores the key-value pairs carried in the data storage request 1 in the memory in order, and the key-value pairs currently stored in the memory include 00000001bbbb:{value1...}, 00000001bggg:{value2...}, 00000001caaa:{value3...}, and 00000001xaab:{value4...}. Since the total data amount of these key-value pairs is less than the preset data amount, and the difference between the total data amount and the preset data amount is greater than the preset difference, the condition for generating a new file is not met.
[0109] Then, the first device 101 receives a data storage request 2 carrying key-value pairs 00000002aabb:{value5...}, 00000002bggg:{value6...}, and 00000002bcde:{value7...}. The first device 101 stores the key-value pairs carried in the data storage request 2 in the memory in order. After storing the key-value pair 00000002bggg:{value6...} in the memory, the first device 101 finds that the difference between the total data amount of the key-value pairs 00000001bbbb:{value1...} to 00000002bggg:{value6...} currently stored in the memory and the preset data amount is less than or equal to the preset difference, and the condition for generating a new file is met. Therefore, a new file containing the key-value pairs 00000001bbbb:{value1...} to 00000002bggg:{value6...} is generated and stored in the first storage module. In addition, the first device 101 stores the key-value pair 00000002bcde:{value7...} carried in the data storage request 2 in the memory.
[0110] Afterwards, the first device 101 receives a data storage request 3 carrying a key-value pair 00000003bcbb:{value1...}. The first device 101 stores the key-value pair carried in the data storage request 3 in sequence in the memory, and the key-value pairs currently stored in the memory include 00000002bcde:{value7...} and 00000003bcbb:{value1...}. Since the total data amount of these key-value pairs is less than the preset data amount, and the difference between the total data amount and the preset data amount is greater than the preset difference, the new file generation condition is not met. The first device 101 continues to wait for the next data storage request.
[0111] (3) The first device 101 generates an initial version number.
[0112] The initial version number can be preset. For example, the initial version number can be 0.
[0113] Since the first device 101 stores the file for the first time, the first device 101 can generate the initial version number. After the first device 101 stores the new file in the first storage module and generates the initial version number, the first device 101 can determine the mapping relationship between the initial version number and the module identifier of the first storage module, which indicates that the new file is stored in the first storage module in the version corresponding to the initial version number.
[0114] (4) The first device 101 generates a new leaf node, and constructs an initial target tree according to the new leaf node. The new leaf node contains the file identifier of the new file, the minimum key value and the maximum key value in all key-value pairs in the new file, and a mapping table including the mapping relationship between the initial version number and the module identifier of the first storage module.
[0115] After generating the new leaf node, the first device 101 can create a branch node as the parent node of the new leaf node. The branch node contains a child node list including the minimum key value and the maximum key value in the new leaf node. Since the number of current leaf nodes is 1, the branch node is the root node, and thus the construction of the initial target tree is completed.
[0116] In some embodiments, a branch node in the target tree can include a child node list. The child node list in a branch node contains the node information of each child node of the branch node.
[0117] For example, the node information of a node can include the pointer of the node, the minimum key value and the maximum key value in the node.
[0118] The pointer of a node is used to point to the memory space where the node is located. The list of child nodes in a branch node includes node information of all child nodes of the branch node, and the node information of all child nodes is sequentially present in the list of child nodes.
[0119] In some cases, after the first device 101 completes the construction of the initial target tree, the first device 101 can also save the pointer of the root node of the target tree and the pointer of the last leaf node in the target tree in the memory of the first device 101. In this way, the first device 101 can subsequently quickly index to the root node in the target tree according to the pointer of the root node maintained in the memory, and quickly index to the last leaf node in the target tree according to the pointer of the leaf node maintained in the memory.
[0120] (5) The first device 101 creates a system version number, and updates the system version number to the initial version number.
[0121] After the first device 101 completes the construction of the initial target tree, the first device 101 can create a system version number in the memory of the first device 101, and update the system version number to the initial version number.
[0122] In some embodiments, for any data storage request, if all key-value pairs carried by the data storage request have been stored in the storage module in the form of a file, and the target tree has been constructed or updated and the system version number has been updated accordingly, the first device 101 can return a data storage success message to the external system that sent the data storage request. For example, the data storage success message can carry the file identifier of the file where the key-value pairs in the data storage request are located, and the like, which is not limited in the embodiments of the present application.
[0123] In some embodiments, after the first device 101 updates the system version number each time, the first device 101 can store the version information of the version corresponding to the updated system version number to the disk, the version information including the version number and version increment information, the version increment information being used to indicate the change of the files in the storage module under the version corresponding to the version number compared to the previous version. That is, the version increment information is used to indicate which storage module decreases which files and which storage module increases which files under the version compared to the previous version. It should be noted that the "file" referred to in the embodiments of the present application refers to the file containing key-value pairs referred to in the embodiments of the present application.
[0124] It should be noted that the reduction of the file in the storage module in the embodiments of the present application is caused by file migration, and the increase of the file in the storage module can be caused by file storage or file migration.
[0125] Optionally, the version information can further include the maximum file identifier (i.e., the file identifier with the last order) under the version.
[0126] In this case, each time the system version number is updated, the version information of the version corresponding to the updated system version number can be stored to the disk. Then, the first device 101 stores the version information of each version to the disk in order, i.e., the one or more version information stored in the disk is in order.
[0127] In some embodiments, the first device 101 can update the file distribution state stored in the disk according to the one or more version information stored in the disk, where the file distribution state contains the correspondence between the version number, the storage module identifier and the file identifier. The file distribution state is used to indicate the file stored in each storage module under the corresponding version. Wherein, the file identifier corresponding to any storage module identifier in the correspondence between the storage module identifier and the file identifier is the file identifier of each file stored in the storage module identified by the storage module identifier.
[0128] Since the one or more version information stored in the disk is in order, the first device 101 updates the file distribution state stored in the disk in order, i.e., sequentially according to the version order.
[0129] When the first device 101 updates the file distribution state stored in the disk according to a version information, the version number in the file distribution state can be updated to the version number in the version information, and the correspondence between the storage module identifier and the file identifier in the file distribution state can be updated according to the version increment information in the version information. Then, after updating the file distribution state according to the version information of a version, the updated file distribution state is used to indicate the file stored in each storage module under the version.
[0130] After the first device 101 updates the file distribution state according to a version information, the first device 101 can delete the version information from the disk.
[0131] In some cases, the file distribution state can be updated asynchronously by a thread. That is, the first device 101 records the version information each time a version update occurs, and then there are multiple version information after multiple version updates. There can be a thread that updates the file distribution state according to the recorded multiple version information in order.
[0132] For example, Table 1 below shows a plurality of version information and a file distribution state updated according to each of the plurality of version information in sequence. Specifically, when the first device 101 stores a new file 3 in the storage module 1 at the version corresponding to version number 2, obtains the version corresponding to version number 3, and the version information of this version is "version number: 3, version increment information: the storage module 1 adds the file 3". According to the version information, the file distribution state can be updated to "version number: 3, the correspondence between the storage module identifier and the file identifier: storage module 1: {file 2, file 3}, storage module 2: {file 1}". Then, when the first device 101 stores a new file 4 in the storage module 1 at the version corresponding to version number 3, obtains the version corresponding to version number 4, and the version information of this version is "version number: 4, version increment information: the storage module 1 adds the file 4". According to the version information, the file distribution state can be updated to "version number: 4, the correspondence between the storage module identifier and the file identifier: storage module 1: {file 2, file 3, file 4}, storage module 2: {file 1}". Then, when the first device 101 migrates the file 2 from the storage module 1 to the storage module 2 at the version corresponding to version number 4, obtains the version corresponding to version number 5, and the version information of this version is "version number: 5, version increment information: the storage module 1 reduces the file 2, and the storage module 2 adds the file 2". According to the version information, the file distribution state can be updated to "version number: 5, the correspondence between the storage module identifier and the file identifier: storage module 1: {file 3, file 4}, storage module 2: {file 1, file 2}".
[0133] Table 1
[0134] The above Table 1 is only an example for exemplarily illustrating the version information and the file distribution state, and does not limit the embodiments of the present application.
[0135] As an example, the target tree in the embodiments of the present application does not need to be persisted, that is, does not need to be stored in the disk, but can be saved in the memory of the first device 101, so that the storage resource can be saved.
[0136] In this case, if the first device 101 restarts due to a crash or the like, after the restart, the first device 101 can obtain the version number in the latest version information stored in the disk as the system version number, and save the system version number in the memory of the first device 101. After the restart, the first device 101 updates the file distribution state stored in the disk according to all the version information stored in the disk, and reconstructs the target tree in the memory of the first device 101 according to the updated file distribution state. In this case, the updated file distribution state is the file distribution state under the latest version (i.e., the version corresponding to the system version number), which can indicate the files stored in each storage module under the latest version.
[0137] Since the file identifiers are globally ordered and one-to-one corresponding to the leaf nodes, all the leaf nodes in the last layer of the target tree can be constructed according to all the file identifiers in the file distribution state and the minimum key value and the maximum key value in the file identified by each file identifier, and the mapping table in each leaf node can be constructed according to the version number (i.e., the version number of the latest version) in the file distribution state and the module identifier of the storage module where each file is located. At this time, the mapping table only contains the mapping relationship between the version number and the corresponding storage module identifier. Then, the branch nodes are constructed layer by layer upwards according to the leaf nodes in the last layer, until the root node is constructed, and thus the target tree is reconstructed. After the target tree is reconstructed, the pointer of the root node in the reconstructed target tree and the pointer of the last leaf node in the target tree are maintained in the memory.
[0138] It should be noted that after the target tree is constructed, the first device 101 can perform data processing based on the target tree, such as data storage, file migration, data query, etc.
[0139] Next, the process in which the first device 101 stores data and updates the target tree in the file migration method provided by the embodiment of the present application will be described, which can include the following steps A to E:
[0140] Step A: The first device 101 receives a data storage request, which carries a key-value pair to be stored, and the key value in the key-value pair is globally ordered. The operation of step A is similar to the operation of step (1) described above, and the embodiment of the present application will not be described again.
[0141] Step B: The first device 101 generates a new file containing one or more key-value pairs according to the order of the key value in the key-value pair, and stores the new file in the first storage module; wherein the file identifiers of all the files containing the key-value pairs are globally ordered.
[0142] The operation of Step B is similar to that of Step (2) described above, and will not be repeated here.
[0143] In some embodiments, after Step B, i.e., after the first device 101 stores the new file in the first storage module, the first device 101 can add the file identifier of the new file to the first correspondence relationship of the first storage module, and set the corresponding hit count of the file identifier of the new file in the first correspondence relationship to 0.
[0144] For example, the first device 101 can add the file identifier of the new file to the last element in the file identifier list in the first correspondence relationship of the first storage module. In addition, the first device 101 can add an element after the last element in the hit count list in the first correspondence relationship of the first storage module, and set the added element to 0.
[0145] It should be noted that in the case where the first correspondence relationship adopts the form of the file identifier list and the hit count list, the read-write efficiency of the first correspondence relationship is relatively high. In addition, since the file identifier list and the hit count list are static within a version range, the reading and modification of the internal elements thereof can use atomic operations without using lock structures, thereby reducing the overhead.
[0146] Step C: The first device 101 obtains a first version number, which is the sum of the latest system version number at the time when the storage of the new file is completed and 1. The first version number is the version number generated after the first device 101 stores the new file, i.e., the version number obtained by adding 1 to the latest system version number at the time when the storage of the new file is completed. For example, assuming that the latest system version number at the time when the storage of the new file is completed is 5, then the first version number is 6. In this case, the version update is strictly serially executed in the storage layer system.
[0147] The file distribution state indicated by the first version number is the file distribution state after the new file is stored in the first storage module on the basis of the file distribution state indicated by the last version number.
[0148] After the first device 101 obtains the first version number, the mapping relationship between the first version number and the module identifier of the first storage module can be determined, which is used to indicate that the new file is stored in the first storage module under the version corresponding to the first version number.
[0149] Step D: The first device 101 adds the first leaf node after the last leaf node in the target tree, updates the target tree according to the first leaf node, the first leaf node contains the file identifier of the new file, the minimum key value and the maximum key value in all key-value pairs in the new file, the first mapping table, and the first mapping table includes the mapping relationship between the first version number and the module identifier of the first storage module.
[0150] The first leaf node is a leaf node newly added after the last leaf node in the target tree, that is, a new leaf node.
[0151] Optionally, the first device 101 can first obtain the pointer of the last leaf node in the target tree in the memory, and then add the first leaf node after the leaf node according to the pointer of the leaf node.
[0152] For example, the last leaf node in the target tree can be located at the rightmost side of the last layer of the target tree, in which case the insertion order of the leaf node is from left to right. Then the first device 101 adds the first leaf node after the last leaf node in the target tree, that is, inserts the first leaf node at the rightmost side of the last layer of the target tree.
[0153] Alternatively, the last leaf node in the target tree can be located at the leftmost side of the last layer of the target tree, in which case the insertion order of the leaf node is from right to left. Then the first device 101 adds the first leaf node after the last leaf node in the target tree, that is, inserts the first leaf node at the leftmost side of the last layer of the target tree.
[0154] In the embodiments of the present application, when storing data, there is no need to index in the target tree, and a new file can be directly generated for storage, and accordingly a new leaf node can be directly added in the target tree to update the target tree, thereby improving the data storage efficiency.
[0155] It should be noted that the update logic of the target tree in the embodiments of the present application is only one, that is, a new leaf node is inserted after the last leaf node of the whole tree (such as the rightmost side or the leftmost side of the last layer). The traditional tree structure adopts a random insertion logic, which needs to index from the root node to the leaf node first, then insert and store data, and then backtrack to update or split the parent node. Compared with the random insertion logic in the traditional tree structure, the update logic of the target tree in the embodiments of the present application can avoid the indexing process from the root node to the leaf node, thereby improving the data storage efficiency.
[0156] It should be noted that since the file identifiers are globally ordered, and each leaf node stores a file identifier of a file, the file identifiers in all leaf nodes in the last layer of the target tree are ordered from left to right or from right to left.
[0157] It should be noted that, in the embodiments of the present application, the tree shape of the target tree is relatively fixed, and all the nodes except the nodes in the path from the root node to the last leaf node (i.e., the rightmost path or the leftmost path) are static nodes. The static node refers to a node that does not exist in a modification process and has a determined overall shape.
[0158] In some embodiments, the target tree is an n-ary tree, where n is an integer greater than or equal to 2. In the case where the target tree is an n-ary tree, no node splitting is required in the process of updating the target tree according to the first leaf node, thereby improving the updating efficiency.
[0159] Optionally, the operation of the first device 101 for updating the target tree according to the first leaf node can be that the first device 101 updates the nodes in the target tree layer by layer upwards according to the first leaf node until the root node is updated. In the process of updating the nodes layer by layer upwards, if an original node in the target tree needs to be updated, a write lock is added to the original node, and the write lock is released after the update is completed. In the process of updating the nodes layer by layer upwards, if a new node is added in the target tree, the new node does not need to be added with a write lock.
[0160] It should be noted that, in the embodiments of the present application, the tree shape of the target tree is relatively fixed, and all the nodes except the nodes in the path from the root node to the last leaf node (i.e., the rightmost path or the leftmost path) are static nodes. The static node refers to a node that does not exist in a modification process and has a determined overall shape.
[0161] The new node added in the updating process of the target tree does not need to be added with a write lock. This is because, before the updating of the target tree is completed, the new node is invisible to the outside, and then the data query process naturally does not pass through the new node, and there is no need to add a write lock.
[0162] In some embodiments, the operation of the first device 101 for updating the nodes in the target tree layer by layer upwards according to the first leaf node can include the following steps a to f.
[0163] Step a: let the first leaf node be the current node.
[0164] Step b: determine whether the current node is a new node or an original node in the target tree. If the current node is a new node, steps c to e are performed; if the current node is an original node, step f is performed.
[0165] Step c: if the current node is a new node, then determine whether the current node can be a child of the last node in the upper layer. If the current node can be a child of the last node in the upper layer, then execute the following step d; if the current node cannot be a child of the last node in the upper layer, then execute the following step e.
[0166] For example, in the case where the target tree is an n-ary tree, if the number of children of the last node in the upper layer is less than n, then the current node can be a child of the last node in the upper layer; if the number of children of the last node in the upper layer is equal to n, then the current node cannot be a child of the last node in the upper layer.
[0167] Step d: if the current node can be a child of the last node in the upper layer, then take the last node in the upper layer as the parent node of the current node, add a write lock to the parent node of the current node, update the parent node of the current node, release the write lock of the parent node of the current node after the update, take the parent node of the current node as the current node, and re-execute step b and the subsequent steps.
[0168] If the current node can be a child of the last node in the upper layer, then the last node in the upper layer can be taken as the parent node of the current node for updating. Here, the update is to add the node information of the current node to the child list in the last node in the upper layer.
[0169] Step e: if the current node cannot be a child of the last node in the upper layer, then add a new node to the upper layer as the parent node of the current node, take the parent node of the current node as the current node, and re-execute step b and the subsequent steps.
[0170] If the current node cannot be a child of the last node in the upper layer, then a new node can be added to the last node in the upper layer as the parent node of the current node. In this case, the parent node of the current node includes a child list, which includes the node information of the current node.
[0171] Step f: if the current node is an original node, then add a write lock to the parent node of the current node, update the parent node of the current node, release the write lock of the parent node of the current node after the update, take the parent node of the current node as the current node, and re-execute step b and the subsequent steps.
[0172] If the current node is an original node, then the parent node of the current node already exists in the target tree, and thus the parent node of the current node can be directly updated. Here, the update is to update the node information of the current node included in the child list in the parent node of the current node.
[0173] It should be noted that after the current node is re-determined in step d, step e or step f, before step b is re-executed, it can be determined whether the current node is the original root node of the target tree.
[0174] If the current node is not the original root node of the target tree, and is not a node at the same level as the original root node, then step b and the subsequent steps are re-executed. If the current node is the original root node of the target tree, it is determined that the update of the target tree is completed. If the current node is not the original root node of the target tree, and is a node at the same level as the original root node, then a new root node needs to be added at the upper level as the parent node of the original root node and the current node, and the new root node includes a child node list, which includes the node information of the original root node and the node information of the current node. In this way, the update of the target tree is completed. In this case, the height of the target tree will increase by one level.
[0175] It should be noted that the first device 101 can update the pointer of the root node in the target tree maintained in the memory and the pointer of the last leaf node in the target tree after updating the target tree. The behavior of updating the pointer of the root node in the memory cannot be concurrent with the behavior of obtaining the pointer of the root node in the memory. That is, if the pointer of the root node in the memory is being updated, the operation of obtaining the pointer of the root node in the memory needs to wait until the update is completed; if the pointer of the root node in the memory is being obtained, the operation of updating the pointer of the root node in the memory can be performed after the pointer of the root node is successfully obtained. This is because the pointer of the root node can be in a transitional state, such as being empty, during the process of updating the pointer of the root node, and in this case, an error will occur if the pointer of the root node is obtained.
[0176] Step E: The first device 101 updates the system version number to the first version number.
[0177] After the target tree is updated, the first device 101 can update the system version number to the first version number. In this way, the first device 101 updates the system version number after performing the file storage operation. In some embodiments, after updating the system version number, the first device 101 can store the version information of the version corresponding to the updated system version number in the disk.
[0178] Next, the process of the first device 101 querying data in the file migration method provided by the embodiments of the present application will be described, which can include the following steps A to E:
[0179] Step A: If the first device 101 receives a data query request, the target version number is obtained, and the data query request carries a target key value. The target version number is the latest system version number when the data query request is received.
[0180] The target key value is a key value in a key-value pair to which the value value to be queried belongs. The data query request is used to request to query the value value in the key-value pair to which the target key value belongs. The data query request can be sent by an external system. For example, it can be sent by a database system, a blockchain system, and the like, and the embodiments of the present application do not limit this.
[0181] In step B, the first device 101 determines a target leaf node to which the target key value is indexed in the target tree. The leaf node in the target tree contains a file identifier, minimum and maximum key values in all key-value pairs in the file identified by the file identifier, and a mapping table including a mapping relationship between version numbers and storage module identifiers. The mapping table is used to indicate the storage module in which the file identified by the file identifier is located at each version.
[0182] The target key value is greater than or equal to the minimum key value in the target leaf node and less than or equal to the maximum key value in the target leaf node.
[0183] For example, the target leaf node to which the target key value is indexed in the target tree can also be referred to as the target leaf node to which the target key value is distributed in the target tree.
[0184] Optionally, the first device 101 can index the target leaf node in the target tree according to the target key value by means of binary search, and of course, the target leaf node can also be indexed in the target tree by other means, and the embodiments of the present application do not limit this.
[0185] For example, if the target tree is an n-ary tree, the complexity of the indexing process satisfies O (logN) x log2branch. Wherein, the complexity of the tree indexing path is O (logN), and the complexity of specifying a child node in each node by means of binary search is a constant value log2branch, and the branch value is a fixed branch number constant n.
[0186] In some embodiments, the operation of step B can be that the first device 101 indexes nodes in the target tree from the root node layer by layer according to the target key value until the target leaf node is indexed.
[0187] As an example, in the process of indexing nodes layer by layer downward, a read lock is added to each node after indexing the node, the next node is indexed according to the node and the target key value, and the read lock of the node is released after the next node is indexed; the read lock of the target leaf node is released after the file identifier in the target leaf node and the mapping table are obtained.
[0188] Specifically, after obtaining the target version number, the first device 101 can first obtain the pointer of the root node in the memory, and then index the root node according to the pointer of the root node. The root node is read-locked after being indexed. Then, it is determined in which key range of the child node of the root node the target key value is located, and the next node is indexed. After determining that the target key value is located in the key range of a child node of the root node, the child node is the next node indexed, and the read lock of the root node is released and a read lock is added to the latest indexed node. If the node is a branch node, it can be determined in which key range of the child node of the node the target key value is located, that is, the next node is indexed. Until the indexed node is a leaf node. If the node is a leaf node, it can be determined that the node is the target leaf node, and the read lock of the target leaf node is released after obtaining the file identifier and the mapping table in the target leaf node.
[0189] As another example, in the process of indexing nodes layer by layer downwards, after indexing a node, in the case that the node is the last child node of all child nodes of its parent node, the node is read-locked, the next node is indexed according to the node and the target key value, and the read lock of the node is released after indexing the next node; and in the case that the node is not the last child node of all child nodes of its parent node, the node is not read-locked, and the next node is directly indexed according to the node and the target key value, and in this case, all the nodes indexed subsequently also do not need to be read-locked, so that the lock resource can be saved.
[0190] In the case that the target leaf node is read-locked in the indexing process, the read lock of the target leaf node is released after obtaining the file identifier and the mapping table in the target leaf node.
[0191] It should be noted that in the embodiments of the present application, the read lock and the read lock are shared locks, the read lock and the write lock are mutual exclusion locks, and the write lock and the write lock are mutual exclusion locks.
[0192] Optionally, the storage layer system in the embodiments of the present application can be a concurrent model of single-threaded writing and multi-threaded reading.
[0193] In this case, after one thread adds a read lock to a node, another thread can add a read lock to the node.
[0194] After a thread adds a read lock to a node, another thread cannot add a write lock to the node and has to wait until the read lock of the node is released, then add a write lock to the node and continue the operation (such as continuing to update the node).
[0195] In the embodiment of the application, the one-tree indexing process and the one-tree updating process will at most have one lock conflict (also referred to as lock preemption). That is, the tree structure of the target tree in the embodiment of the application can avoid path-level lock conflicts to the greatest extent, thereby maximizing the system concurrency and reducing the main business process latency.
[0196] It should be noted that all data query behaviors in the embodiment of the application can be concurrent, which is very friendly to the scene of concurrent reading of data in the system. For example, if the blockchain system supports concurrent execution of transactions, all behaviors of obtaining ledger data during the concurrent execution of transactions can also be completely concurrent in the system. In addition, the node insertion behavior in the embodiment of the application cannot be concurrent, that is, the next update can be performed only after the completion of the one-time update of the target tree.
[0197] Step C: The first device 101 obtains the specified storage module identifier from the mapping table in the target leaf node according to the target version number.
[0198] The storage module identified by the specified storage module identifier is the storage module in which the file identified by the file identifier in the target leaf node is stored under the version corresponding to the target version number.
[0199] Since the target version number is the latest system version number when the first device 101 receives the data query request, and the mapping relationship between the version number and the storage module identifier is saved in the mapping table in the target leaf node, the file in which the target key value is stored can be determined according to the target version number and the mapping table (i.e., the storage module identifier identified by the specified storage module identifier).
[0200] In some embodiments, the operation of step C can be: the first device 101 obtains, from the mapping table in the target leaf node, the storage module identifier to which the maximum version number in all version numbers less than or equal to the target version number is mapped as the specified storage module identifier.
[0201] That is, if the target version number is recorded in the mapping table, it can be determined that the storage module identifier to which the target version number is mapped is the module identifier of the storage module in which the file identified by the file identifier in the target leaf node is stored under the version corresponding to the target version number, and thus the storage module identifier can be taken as the specified storage module identifier.
[0202] If the target version number is not recorded in the mapping table, the maximum version number among all version numbers less than the target version number in the mapping table can be determined. The file identified by the file identifier in the target leaf node is not migrated from the version corresponding to the maximum version number to the version corresponding to the target version number, and thus the storage module in which the file is located at the version corresponding to the maximum version number is determined to be the storage module in which the file is located at the version corresponding to the target version number. Therefore, the storage module identifier to which the maximum version number is mapped can be taken as the specified storage module identifier.
[0203] In some embodiments, when the mapping table is a doubly linked list, the first device 101 can start searching from the tail of the doubly linked list to obtain the specified storage module identifier. This is because the latest system version number is usually used in data query, and thus searching from the tail of the doubly linked list can quickly find the corresponding node (i.e., the node containing the maximum version number among all version numbers less than or equal to the target version number and the specified storage module identifier).
[0204] It should be noted that, because the behavior of searching for a node is based on the tail node of the doubly linked list, the tail node (only a single node) needs a read lock to ensure its concurrent safety. That is, when a node needs to be searched, the tail node is first given a read lock, and then the tail node is searched forward, and the read lock is released after the corresponding node is found.
[0205] Step D: The first device 101 obtains, from the file identified by the file identifier in the storage module identified by the specified storage module identifier, the value in the key-value pair to which the target key value belongs.
[0206] Optionally, after obtaining the value, the first device 101 can return a data query result to an external system, and the data query result carries the value.
[0207] In some embodiments, the first device 101 can support concurrent reading, and thus multiple versions can coexist and run in the first device 101. Therefore, control and release of multiple versions are needed. In this case, after obtaining the target version number in step A, the first device 101 can increase the reference count of the target version number by 1. After obtaining the value in the key-value pair to which the target key value belongs in step D, the first device 101 can decrease the reference count of the target version number by 1.
[0208] As an example, the reference count has an initial value, and the initial value can be set to 0. That is, the first device 101 can set the reference count of the latest system version number to 0 after updating the system version number each time.
[0209] In this case, the reference count of the target version number indicates the total number of data query operations being performed on the version corresponding to the target version number.
[0210] In the process of multi-version management, the first device 101 needs to release historical versions (i.e., versions other than the version corresponding to the latest system version number), and thus can determine whether a historical version meets the release condition by using the reference count.
[0211] Specifically, if the reference count of a historical version number (i.e., any version number other than the latest system version number) is 0, it indicates that the first device 101 is not currently performing a data query operation based on the historical version corresponding to the historical version number, that is, the historical version is not currently in use and thus meets the release condition, and thus the historical version can be released. If the reference count of a historical version number is greater than 0, it indicates that the first device 101 is currently performing one or more data query operations based on the historical version corresponding to the historical version number, that is, the historical version is currently in use and thus does not meet the release condition, and thus the historical version is not released.
[0212] As another example, the reference count has an initial value, and the initial value can be set to 1. That is, the first device 101 can set the reference count of the latest system version number to 1 after updating the system version number each time, and in this case, the reference count of the previous version number of the latest system version number can also be decremented by 1.
[0213] In this case, the reference count of the target version number can indicate whether the version corresponding to the target version number is in use. For example, if the reference count of the target version number is 1, it indicates that the version corresponding to the target version number can be the current latest version (i.e., the version corresponding to the latest system version number), or the version corresponding to the target version number can be a historical version and a data query is being performed based on the historical version.
[0214] In the process of multi-version management, the first device 101 needs to release versions, and thus can determine whether a version meets the release condition by using the reference count. Specifically, if the reference count of a version number (whether it is a latest system version number or a historical version number) is 0, it indicates that the first device 101 is not currently using the version corresponding to the version number, and thus the version meets the release condition and can be released. If the reference count of a version number is greater than 0, it indicates that the first device 101 is currently using the version corresponding to the version number, and thus the version does not meet the release condition and is not released.
[0215] In some embodiments, the releasing of the version by the first device 101 can be: the first device 101 releases the version according to the version information of the next version of the version. Specifically, if the version information of the next version indicates that only the storage module adds files, and no storage module reduces files, the version is released, and only the reference count of the version number of the version is deleted. If the version information of the next version indicates that the storage module adds files, and the storage module (which can be referred to as the fifth storage module) reduces files (which can be referred to as the first file), the release of the version means that the first file is deleted from the fifth storage module, and all mapping relationships between the version number and the storage module identifier, whose version number is less than or equal to the version number of the version, are deleted from the mapping table in the leaf node of the file identifier of the first file contained in the target tree, and finally the reference count of the version number of the version is deleted.
[0216] Optionally, the operation of the first device 101 deleting the first file from the fifth storage module can be: if the fifth storage module is located in the first device 101, the first device 101 can directly delete the first file in the fifth storage module; if the fifth storage module is located in the second device 102, the first device 101 can send a file deletion message to the second device 102 where the fifth storage module is located, and the file deletion message can carry the module identifier of the fifth storage module and the file identifier of the first file, and further can carry the version number of the version. After receiving the file deletion message, the second device 102 can delete the first file in the fifth storage module.
[0217] In some embodiments, the mapping table in the leaf node is a double-linked list, and when the first device 101 needs to delete the mapping relationship in the double-linked list in the leaf node when releasing a version, it can directly delete a node from the head of the double-linked list. This is because when deleting, the oldest version is usually deleted.
[0218] It should be noted that, in the embodiments of the present application, the logic of lock-free deletion can be realized based on the double-linked list structure for the deletion scenario, because of the following two reasons: 1. The nodes corresponding to the same version in the double-linked list satisfy the logical clock order of being created first and then deleted. Moreover, for a certain version, the release of the version is triggered again in the case that there is no subsequent indexing behavior, that is, the deletion of the specified node in the double-linked list in the leaf node is triggered. Therefore, additional concurrent control logic is not required in the double-linked list. 2. The double-linked list can realize that the node deletion behavior is completely controlled within the scope of "only operating the node corresponding to the head pointer", so that the process can be lock-free. Based on the above reasons, the double-linked list in the embodiments of the present application can realize the maximum degree of safe concurrent read-write logic, thereby ensuring the throughput performance under high access frequency.
[0219] In some embodiments, after step D, that is, after the first device 101 identifies the value in the key-value pair to which the target key value belongs from the file identified in the identified storage module (which can be referred to as a target storage module) as the file in the target leaf node (which can be referred to as a second file), the first device 101 can update the first correspondence relationship and the second correspondence relationship of the target storage module.
[0220] As an example, the first device 101 can determine the hit count corresponding to the file identifier of the second file in the first correspondence relationship of the target storage module as a first hit count, add 1 to the hit count corresponding to the file identifier of the second file in the first correspondence relationship of the target storage module to obtain a second hit count; and the first device 101 updates the second correspondence relationship of the target storage module according to the first hit count and the second hit count.
[0221] The first hit count is the hit count corresponding to the file identifier of the second file in the first correspondence relationship of the target storage module before the update.
[0222] The second hit count is the hit count corresponding to the file identifier of the second file in the first correspondence relationship of the target storage module after the update.
[0223] For example, the first device 101 can first find the file identifier of the second file in the file identifier list in the first correspondence relationship of the target storage module according to the file identifier of the second file by using the binary search method, then obtain the index of the file identifier in the file identifier list, and then obtain the hit count at the same index position in the hit count list in the first correspondence relationship of the target storage module as the first hit count, and then add 1 to the hit count at the same index position in the hit count list to obtain the second hit count.
[0224] Optionally, the operation of updating, by the first device 101, the second correspondence relationship of the target storage module according to the first hit number and the second hit number can be: if the preset hit number interval in which the first hit number is located is different from the preset hit number interval in which the second hit number is located, the first device 101 decreases, by 1, the file quantity in the second correspondence relationship of the target storage module corresponding to the preset hit number interval in which the first hit number is located, and increases, by 1, the file quantity in the second correspondence relationship of the target storage module corresponding to the preset hit number interval in which the second hit number is located. If the preset hit number interval in which the first hit number is located is the same as the preset hit number interval in which the second hit number is located, the first device 101 does not update the second correspondence relationship of the target storage module.
[0225] In some embodiments, the first device 101 can also update a third correspondence relationship of the target storage module according to the first hit number and the second hit number. The third correspondence relationship includes the total hit number of the files in the target storage module that are in each of the preset hit number intervals.
[0226] Specifically, if the preset hit number interval in which the first hit number is located is different from the preset hit number interval in which the second hit number is located, the first device 101 can decrease, by the first hit number, the total hit number in the third correspondence relationship of the target storage module corresponding to the preset hit number interval in which the first hit number is located, and increase, by the second hit number, the total hit number in the third correspondence relationship of the target storage module corresponding to the preset hit number interval in which the second hit number is located. If the preset hit number interval in which the first hit number is located is the same as the preset hit number interval in which the second hit number is located, the first device 101 increases, by 1, the total hit number in the third correspondence relationship of the target storage module corresponding to the preset hit number interval in which the first hit number is located.
[0227] Next, the process of the storage layer system in the file migration method provided by the embodiments of the present application for migrating files among the plurality of storage modules will be explained in detail.
[0228] FIG. 5 is a flowchart of a file migration method provided by an embodiment of the present application. Referring to FIG. 5, the method can include the following steps:
[0229] Step 501: When the timer expires, the first device 101 determines file migration information of a new round of file migration behavior in the case that the file migration behavior of the previous round has been completed, the file migration information being used to indicate the files that any one of the plurality of storage modules needs to migrate to other storage modules, and the file migration behavior being a background asynchronous behavior.
[0230] The duration of the timer can be preset, for example, the duration of the timer can be a preset duration.
[0231] If the timer expires, it indicates that the time for performing a new round of file migration has arrived. In this case, if the previous round of file migration behavior has been completed, the first device 101 can directly determine the file migration information of the new round of file migration behavior. If the previous round of file migration behavior has not been completed, it indicates that the file migration is being performed in the background. In this case, the first device 101 can wait until the previous round of file migration behavior is completed, and then determine the file migration information of the new round of file migration behavior, and perform the new round of file migration according to the file migration information. After determining the file migration information of the new round of file migration behavior, the timer can be reset to restart the timing. Alternatively, the first device 101 can wait until the previous round of file migration behavior is completed, reset the timer to restart the timing, and then determine the file migration information of the new round of file migration behavior, and perform the new round of file migration according to the file migration information.
[0232] The file migration behavior refers to the behavior of performing file migration between the plurality of storage modules. For example, each round of file migration behavior can migrate files in a previous storage module to a next storage module.
[0233] It should be noted that, since file migration between storage modules needs to go through network transmission, and the amount of file data is large, the file migration behavior in the embodiments of the present application is performed asynchronously in the background. In this way, blocking of other key operations (such as data storage operations, data query operations, etc.) can be avoided, so that the response speed and performance of the storage layer system can be improved, and the call delay of the upper layer system to the storage layer system can be reduced.
[0234] In some embodiments, the file migration information can include at least one file migration list, and can also include a source storage module identifier and a target storage module identifier corresponding to each file migration list in the at least one file migration list, to indicate that the file identified by the file identifier in the file migration list is migrated from the storage module identified by the source storage module identifier to the storage module identified by the target storage module identifier.
[0235] In this case, the operation of the first device 101 to determine the file migration information of the new round of file migration behavior can be: the first device 101 determines a file migration list of a second storage module according to the first correspondence relationship and the second correspondence relationship of the second storage module, the second storage module being any one of the plurality of storage modules except the storage module ranked last, and the file migration list being used to indicate files that need to be migrated from the second storage module to a third storage module, the third storage module being the storage module ranked next to the second storage module in the plurality of storage modules.
[0236] The file migration list of the second storage module is used to record file identifiers of files in the second storage module that need to be migrated. The source storage module corresponding to the file migration list is the module identifier of the second storage module, and the target storage module corresponding to the file migration list is the module identifier of the storage module (i.e., the third storage module) that is arranged next to the second storage module.
[0237] Since the first correspondence relationship of the second storage module includes the hit times of each file in the second storage module, and the second correspondence relationship of the second storage module includes the number of files in the second storage module that have hit times in each preset hit time interval, the first correspondence relationship and the second correspondence relationship can reflect the file distribution of the second storage module in each preset hit time interval, and thus it can be analyzed which files with hit times in the second storage module belong to hot data compared with other files, and which files with hit times in the second storage module belong to cold data compared with other files, so that the file migration list of the second storage module can be determined, and the file migration list is used to indicate cold data that needs to be migrated to the next storage module.
[0238] In some embodiments, the operation of determining, by the first device 101, the file migration list of the second storage module according to the first correspondence relationship and the second correspondence relationship of the second storage module can include steps 5011 to 5013 as follows:
[0239] Step 5011: The first device 101 determines a first file quantity and a second file quantity according to the first correspondence relationship and the second correspondence relationship of the second storage module. The first file quantity is the number of files with a hit time of 0 in the second storage module, and the second file quantity is the largest file quantity in the second correspondence relationship of the second storage module.
[0240] The first device 101 can obtain the total file quantity of the second storage module according to the first correspondence relationship of the second storage module. Then, the total file quantity of the second storage module is subtracted from all the file quantities in the second correspondence relationship of the second storage module, and the number of files with a hit time of 0 in the second storage module is obtained, i.e., the first file quantity is obtained.
[0241] Step 5012: If the first file quantity is greater than or equal to the second file quantity, the first device 101 adds the file identifier of the file with a hit time of 0 in the first correspondence relationship of the second storage module to the file migration list of the second storage module.
[0242] If the first file quantity is greater than or equal to the second file quantity, it means that there are more files with a hit time of 0 in the second storage module, and the files with a hit time of 0 belong to cold data. Therefore, the file identifiers of these files are added to the file migration list. In this way, the cold data in the second storage module can be migrated to the next storage module according to the file migration list in the future.
[0243] The first device 101 can determine the files that need to be migrated by traversing the first correspondence relationship of the second storage module, i.e., determine the file identifiers of the files that need to be added to the file migration list of the second storage module.
[0244] In some embodiments, in the case where the current file migration is the first file migration of the second storage module, the first device 101 can start traversing from the first element in the hit frequency list in the first correspondence relationship, or can randomly select an element in the hit frequency list to start traversing. After starting the traversal, if the first device 101 determines that a certain element in the hit frequency list is 0, it can determine the index of the element, and add the element at the same index position in the file identifier list in the first correspondence relationship of the second storage module to the file migration list. In this case, the first device 101 can complete the traversal of all elements in the hit frequency list to add the file identifiers of all files with a hit frequency of 0 in the second storage module to the file migration list.
[0245] In some embodiments, in the case where the current file migration is not the first file migration of the second storage module, the first device 101 can estimate the number of files that need to be migrated this time (which can be referred to as the target migration number) according to the number of newly added files of the second storage module during the last file migration to the current file migration and / or the historical migration number of the second storage module (i.e., the number of files migrated by the second storage module to the third storage module each time before). For example, the second storage module can obtain the target migration number by weighted averaging the number of newly added files and the historical migration number, of course, the second storage module can also determine the target migration number by other ways according to the number of newly added files and / or the historical migration number, which is not limited in the embodiments of the present application.
[0246] The target migration number is the number of files that maintain the migration-in and migration-out balance of the second storage module, so that the second storage module can maintain good storage performance.
[0247] Optionally, if the first file quantity is greater than or equal to the target migration quantity, the first device 101 can start traversing from the first element in the hit frequency list in the first correspondence relationship of the second storage module, or can randomly select an element in the hit frequency list to start traversing, or can start traversing from the next element of the position where the last traversal ends in the hit frequency list. After starting the traversal, if the first device 101 determines that a certain element traversed in the hit frequency list is 0, it can determine the index of the element, and add the element at the same index position in the file identifier list in the first correspondence relationship of the second storage module to the file migration list of the second storage module. At the same time, if the first device 101 determines that the number of file identifiers added to the file migration list reaches the target migration quantity, the traversal is ended.
[0248] If the first file quantity is less than the target migration quantity, the first device 101 can start traversing from the first element in the hit frequency list in the first correspondence relationship of the second storage module, or can randomly select an element in the hit frequency list to start traversing, or can start traversing from the next element of the position where the last traversal ends in the hit frequency list. After starting the traversal, if the first device 101 determines that a certain element traversed in the hit frequency list is 0, it can determine the index of the element, and add the element at the same index position in the file identifier list in the first correspondence relationship of the second storage module to the file migration list of the second storage module. In this case, the first device 101 needs to complete the traversal of all elements in the hit frequency list to add the file identifiers of all files with a hit frequency of 0 in the second storage module to the file migration list.
[0249] Step 5013: If the first file quantity is less than the second file quantity, the first device 101 determines a first hit frequency interval, which is the preset hit frequency interval corresponding to the largest file quantity in the second correspondence relationship of the second storage module. The first device 101 determines at least one second hit frequency interval according to the first hit frequency interval, which is all preset hit frequency intervals before the first hit frequency interval in the second correspondence relationship of the second storage module. The first device 101 adds the file identifiers in the first correspondence relationship of the second storage module with corresponding hit frequencies in the at least one second hit frequency interval to the file migration list of the second storage module, and adds the file identifiers in the first correspondence relationship of the second storage module with a corresponding hit frequency of 0 to the file migration list.
[0250] If the number of files in the second storage module whose hit times are in the first hit time interval is relatively large, it can be determined that the files whose hit times are in the first hit time interval belong to hot data for the second storage module. Moreover, the hit times in the preset hit time intervals after the first hit time interval in the second correspondence of the second storage module are relatively large, so it can be determined that the files whose hit times are in these preset hit time intervals also belong to hot data. The hit times in the at least one second hit time interval are relatively small, and the number of files whose hit times are in each second hit time interval is also relatively small, so it can be determined that these files belong to cold data. Thus, the file identifiers of the files in the second storage module whose hit times are in the at least one second hit time interval can be added to the file migration list. Meanwhile, the files whose hit times are 0 also belong to cold data, so the file identifiers of these files are also added to the file migration list. In this way, the cold data in the second storage module can be migrated to the next storage module according to the file migration list in the subsequent process.
[0251] In some embodiments, if the current file migration is the first file migration of the second storage module, the first device 101 can directly determine the file migration list of the second storage module after determining the at least one second hit time interval.
[0252] For example, after the first device 101 determines the at least one second hit time interval, the first device 101 can determine the files that need to be migrated, i.e., the file identifiers that need to be added to the file migration list of the second storage module, by traversing the first correspondence of the second storage module. The first device 101 can start traversing from the first element in the hit time list in the first correspondence, or can randomly select an element in the hit time list to start traversing. After starting the traversal, if the first device 101 determines that a certain element in the hit time list is 0 or the element is in the at least one second hit time interval, the index of the element can be determined, and the element in the file identifier list in the first correspondence of the second storage module at the same index position can be added to the file migration list. In this case, the first device 101 can complete the traversal of all elements in the hit time list to add the file identifiers of all files in the second storage module whose hit times are 0 to the file migration list.
[0253] In some embodiments, in the case that the current file migration is not the first file migration of the second storage module, after the first device 101 determines the at least one second hit frequency interval, if the sum of the file quantities corresponding to each second hit frequency interval in the at least one second hit frequency interval is greater than or equal to the target migration quantity, the first device 101 can start traversing from the first element in the hit frequency list in the first correspondence relationship of the second storage module, or can randomly select an element in the hit frequency list to start traversing, or can start traversing from the next element of the position where the last traversal ends in the hit frequency list. After starting the traversal, if the first device 101 determines that a certain element in the hit frequency list is 0 or the element is in the at least one second hit frequency interval, the index of the element can be determined, and the element in the file identifier list in the first correspondence relationship of the second storage module at the same index position is added to the file migration list of the second storage module. At the same time, if the first device 101 determines that the number of file identifiers added to the file migration list reaches the target migration quantity, the traversal is ended.
[0254] Optionally, after the first device 101 determines the at least one second hit frequency interval, if the sum of the file quantities corresponding to each second hit frequency interval in the at least one second hit frequency interval is less than the target migration quantity, the first device 101 can divide the total hit frequency corresponding to the first hit frequency interval in the third correspondence relationship of the second storage module by the file quantity corresponding to the first hit frequency interval in the second correspondence relationship of the second storage module to obtain a target hit frequency, and add the file identifiers in the first correspondence relationship of the second storage module corresponding to the hit frequency in the first hit frequency interval and less than the target hit frequency to the file migration list of the second storage module.
[0255] The target hit frequency can reflect the average level of the hit frequency of the files in the second storage module corresponding to the hit frequency in the first hit frequency interval. Then, the files with the hit frequency less than the average level also belong to the relatively cold data to some extent, and thus the file identifiers of these files can also be added to the file migration list.
[0256] For example, after determining the at least one second hit count interval and the target hit count, the first device 101 can start traversing from the first element of the hit count list in the first correspondence of the second storage module, or it can randomly select an element from the hit count list to start traversing, or it can start traversing from the element after the last traversal position in the hit count list. After starting the traversal, if the first device 101 determines that an element traversed in the hit count list is 0, or that the element is in the at least one second hit count interval, or that the element is in the first hit count interval and is less than the target hit count, it can determine the index of the element and add the element at the same index position in the file identifier list in the first correspondence of the second storage module to the file migration list of the second storage module. At the same time, if the first device 101 determines that the number of file identifiers added to the file migration list reaches the target migration number, the traversal ends.
[0257] In some embodiments, when the first device 101 needs to determine the file migration list of the second storage module, it can first intercept the hit count update behavior by switching states, and then cancel the interception after the file migration list is determined. This ensures that the management data in the first, second, and third correspondences will not change during the process of determining the file migration list based on the first, second, and third correspondences of the second storage module. In this way, there is no need to consider the concurrent security issues of read and write behavior during this process.
[0258] In some embodiments, after determining the file migration list of the second storage module, the first device 101 may also update the first correspondence, the second correspondence, and the third correspondence of the second storage module.
[0259] Regarding the second and third correspondences of the second storage module, after determining the file migration list of the second storage module, the first device 101 can set the number of files corresponding to each preset hit count interval in the multiple preset hit count intervals in the second correspondence of the second storage module to 0, and set the total number of hits corresponding to each preset hit count interval in the multiple preset hit count intervals in the third correspondence of the second storage module to 0.
[0260] As an example, if the second storage module is the first storage module in the plurality of storage modules, the first device 101 can delete the file identifier (which may be referred to as the first specified file identifier) in the file migration list of the second storage module and the number of hits corresponding to the deletion of the first specified file identifier from the first correspondence of the second storage module.
[0261] For example, for the file identifier list in the first correspondence relationship, since the file identifiers in the file identifier list are in order, a new file identifier list can be quickly obtained by incrementally modifying the existing file identifier list. Specifically, the first device 101 can first apply for a memory space sufficient for the new file identifier list, and then for the old file identifier list, the position of the first specified file identifier that needs to be deleted can be located by a binary search method, and the remaining file identifiers are copied into the new file identifier list by segmenting. In this process, only one memory space needs to be applied for, so the memory overhead can be saved. Moreover, since the new file identifier list is completely ordered throughout the entire process, the complexity of the deletion operation is log(N), which is relatively low.
[0262] After obtaining the new file identifier list, a new hit count list is constructed, and the hit counts in the new hit count list are all 0. The number of elements in the new hit count list is the same as the number of elements in the new file identifier list, and the elements at the same index position in the new hit count list and the new file identifier list correspond to each other.
[0263] As another example, in the case where the second storage module is not the first storage module in the order of the plurality of storage modules, the second storage module can delete the file identifier (which can be referred to as a first specified file identifier) in the file migration list of the second storage module and the hit count corresponding to the first specified file identifier from the first correspondence relationship of the second storage module, and add the file identifier (which can be referred to as a second specified file identifier) in the file migration list of the fourth storage module and the hit count corresponding to the second specified file identifier in the first correspondence relationship, the fourth storage module being the storage module next to the second storage module in the order of the plurality of storage modules.
[0264] For example, for the file identifier list in the first correspondence relationship, the first device 101 can first apply for a memory space sufficient for the new file identifier list, and then for the old file identifier list, the position of the first specified file identifier that needs to be deleted can be located by a binary search method, and the remaining file identifiers are copied into the new file identifier list by segmenting. In this process, only one memory space needs to be applied for, so the memory overhead can be saved. Moreover, since the new file identifier list is completely ordered throughout the entire process, the complexity of the deletion and insertion operations is log(N), which is relatively low.
[0265] After obtaining the new file identifier list, a new hit count list is constructed, in which the hit counts are all 0. The number of elements in the new hit count list is the same as that in the new file identifier list, and the elements in the new hit count list correspond to the elements in the new file identifier list at the same index position.
[0266] In some embodiments, after determining the file migration information of the new round of file migration behavior, the first device 101 can further obtain a second version number, the second version number being the sum of the latest system version number at the time of determining the file migration information and 1, and then update the system version number to the second version number.
[0267] The second version number is a version number generated at the beginning of the current round of file migration, that is, a version number obtained by adding 1 to the latest system version number at the beginning of the current round of file migration.
[0268] The file distribution state indicated by the second version number is the file distribution state obtained after the previous round of file migration behavior based on the file distribution state indicated by the previous version number. Since the file migration information of the new round of file migration behavior has been determined, the first device 101 can directly update the system version number after determining the file migration information of the new round of file migration behavior, and further update the target tree according to the file migration information of the previous round of file migration behavior.
[0269] For example, if the file migration list of the second storage module included in the file migration information of the previous round of file migration behavior indicates that the third file in the second storage module is migrated to the third storage module, the first device 101 can determine the mapping relationship between the second version number and the identifier of the third storage module after obtaining the second version number, the mapping relationship being used to indicate that the third file is stored in the third storage module under the version corresponding to the second version number. Then, the first device 101 can perform the following steps A to B to update the target tree.
[0270] Step A: The first device 101 indexes the second leaf node in the target tree according to the file identifier of the third file, the second leaf node being a leaf node containing the file identifier of the third file.
[0271] In some embodiments, the operation of step A can include the following steps a to b:
[0272] Step a: In the case where the target tree is an n-ary tree, the first device 101 determines the index information in the target tree according to the file identifier of the third file, n, and the height of the target tree.
[0273] The index information in the target tree is information needed when indexing the leaf nodes in the target tree.
[0274] Optionally, assuming that the height of the target tree is m, m is an integer greater than or equal to 2. The index information in the target tree can include the index information of each layer in the target tree, that is, can include the index information of each layer from the 2nd layer to the mth layer.
[0275] The index information of the ith layer is used to indicate the order number of the node of the ith layer to be indexed in all child nodes of the parent node, where i is greater than or equal to 2 and less than or equal to m.
[0276] That is, after indexing a node in the (i-1)th layer, it is necessary to continue to index the node in the ith layer. In this case, the next node can be indexed from all child nodes of the node in the (i-1)th layer according to the index information of the ith layer. For example, the index information of the 2nd layer is 0, and after indexing the node in the 1st layer, that is, the root node, the child node with the order number 0 in all child nodes of the root node can be taken as the next node to be indexed, and the next node is the node in the 2nd layer.
[0277] As an example, the first device 101 can obtain the file identifier in the last leaf node in the target tree according to the pointer of the last leaf node in the target tree maintained in the memory, add 1 to the target value corresponding to the file identifier to obtain the number of leaf nodes of the target tree. In the case where the number of leaf nodes of the target tree and the number of branches n of the target tree are known, the height m of the target tree can be determined.
[0278] The target value corresponding to a file identifier is the order number of the file identified by the file identifier in all files. The order number starts from 0 and increases by 1. That is, the order number can be 0, 1, 2, 3, ….
[0279] The file identifier and the target value have a corresponding relationship. The first device 101 can take the order number of a new file in all files as the target value corresponding to the file identifier of the new file every time a new file is added.
[0280] Since the file identifiers are globally ordered, for any file identifier, the corresponding target value can be determined.
[0281] For example, if the file identifiers start from 0 and increase by 1, that is, the file identifiers are 0, 1, 2, 3, …, then a file identifier and the target value corresponding thereto are the same.
[0282] For example, if the file identifiers are sequentially increased by a fixed value starting from 0, and the fixed value is j, where j is an integer greater than or equal to 2, then the file identifiers are 0, j, 2j, 3j, …. In this case, the target value corresponding to a file identifier is the value obtained by dividing the file identifier by j.
[0283] Of course, the file identifiers can also be sequentially arranged in other forms. For example, the file identifiers can be a, b, c, …. In this case, the file identifiers can be converted into corresponding target values according to certain rules. For example, the target value corresponding to the file identifier a is 0, the target value corresponding to the file identifier b is 1, and the target value corresponding to the file identifier c is 2.
[0284] Optionally, the height of the target tree is m, where m is an integer greater than or equal to 2. The operation of step a can be as follows: the first device 101 adds a read lock to the root node of the target tree. The target value corresponding to the file identifier of the third file is determined, and the target value corresponding to the file identifier of the third file is the sequential number of the third file among all files. Let i be m, and let the specified parameter be the target value corresponding to the file identifier of the third file. Divide the specified parameter by n to obtain a quotient and a remainder, and use the remainder as the index information of the i-th layer. If i is not 2, let i = i-1, let the specified parameter be the quotient, and re-execute the above step of dividing the specified parameter by n to obtain a quotient and a remainder, and the subsequent steps, until i is 2. If i is 2, index the root node, and release the read lock of the root node after indexing the root node.
[0285] It should be noted that the embodiments of the present application need to add a read lock to the root node in the process of determining the index information in the target tree. This is because if a new root node appears in the process of determining the index information in the target tree, the index information determined according to the old root node will start from the new root node, which will cause errors. Therefore, the embodiments of the present application add a read lock to the root node before determining the index information in the target tree, so as to avoid modification of the root node by other threads. After the index information in the target tree is determined, the root node is indexed, and the read lock of the root node is released after indexing the root node. In this way, the root node at the beginning of the indexing process is consistent with the root node when the index information is determined, thereby ensuring the correctness of the indexing process.
[0286] In addition, the embodiments of the present application add a read lock to the root node in the process of determining the index information of the target tree, which does not affect other data indexing processes. That is, different processes of indexing leaf nodes through file identifiers can be completely concurrent.
[0287] It should be noted that the specified parameter is divided by n to obtain a quotient and a remainder. The quotient represents the order number of the parent node of the node to be indexed in the i-th layer in all nodes in the i-1-th layer. The remainder is the order number of the node to be indexed in the i-th layer among all child nodes of the parent node. Accordingly, the indexing of the node in the i-th layer can be continued after the node in the i-1-th layer is indexed.
[0288] In the embodiment of the present application, the index information in the target tree is determined from the index information in the m-th layer, and then the index information in the m-1-th layer, the index information in the m-2-th layer, and so on, until the index information in the second layer is determined. When indexing, the root node is indexed first, and then the nodes in the second layer, the third layer, and so on, to the leaf node according to the index information in the second layer, the index information in the third layer, and so on, the index information in the m-th layer.
[0289] Step b: The first device 101 indexes the second leaf node in the target tree according to the index information in the target tree.
[0290] It should be noted that the index path from the root node to the second leaf node can be directly determined according to the index information in the target tree, and the node data does not need to be read in this process, so the process of indexing the second leaf node according to the index information in the target tree does not need to add a read lock.
[0291] In the embodiment of the present application, only m-1 times of calculation is needed to determine the index information in the target tree, and the index path can be directly determined according to the index information in the target tree. In this way, the complexity of the indexing process is low, and the indexing efficiency is high.
[0292] The process of determining the index information in the target tree is described below with reference to FIG. 6.
[0293] As shown in (b) of FIG. 6, the target tree is a binary tree, and the height of the target tree is 4.
[0294] Suppose that the target value corresponding to the file identifier of the third file is 6, as shown in (a) of FIG. 6, first, the index information in the fourth layer is determined. Specifically, the specified parameter is 6, 6 is divided by 2 to obtain a quotient of 3 and a remainder of 0, and then the index information in the fourth layer is determined to be 0.
[0295] Then, the index information in the third layer is determined. Specifically, the specified parameter is 3, 3 is divided by 2 to obtain a quotient of 1 and a remainder of 1, and then the index information in the third layer is determined to be 1.
[0296] Then, the index information in the second layer is determined. Specifically, the specified parameter is 1, 1 is divided by 2 to obtain a quotient of 0 and a remainder of 1, and then the index information in the second layer is determined to be 1.
[0297] At this point, the index information of each layer from the second layer to the fourth layer in the target tree is determined.
[0298] Subsequently, when indexing according to the index information of each layer from the second layer to the fourth layer, as shown in (b) of FIG. 6, after indexing to the node of the first layer, i.e., the root node, according to the index information of the second layer, it can be determined that the node of the second layer to be indexed is the child node with the sequence number 1 among all child nodes of the root node. After indexing to a node of the second layer, according to the index information of the third layer, it can be determined that the node of the third layer to be indexed is the child node with the sequence number 1 among all child nodes of the node of the second layer. After indexing to a node of the third layer, according to the index information of the fourth layer, it can be determined that the node of the fourth layer to be indexed is the child node with the sequence number 0 among all child nodes of the node of the third layer. In this way, the corresponding leaf node, i.e., the second leaf node, is indexed.
[0299] Step B: The first device 101 adds a mapping relationship between the second version number and the identifier of the third storage module in the mapping table in the second leaf node.
[0300] In some embodiments, the mapping table is a doubly linked list. Each node in the doubly linked list contains a version number and a storage module identifier.
[0301] In this case, the operation of step B can be that the first device 101 adds a node containing the second version number and the identifier of the third storage module to the tail of the doubly linked list in the second leaf node.
[0302] It should be noted that, because the above node adding behavior during file migration is based on the tail node of the doubly linked list, the tail node (only a single node) needs a write lock to ensure its concurrent safety. That is, when a node needs to be added, the tail node is first locked with a write lock, then a node is added after the tail node, and then the write lock is released.
[0303] It should be noted that, after the first device 101 determines the file migration information of a new round of file migration behavior, the file migration behavior of this round can be performed. The file migration behavior can include the following steps 502 to 505. Because the file migration behavior is a background asynchronous behavior, steps 502 to 505 can be executed in the background asynchronously, in which case the execution of steps 502 to 505 will not affect other key operations such as data storage operations, data query operations, etc.
[0304] Step 502: The first device 101 sends a migration request message to each device where each storage module in the plurality of storage modules is located, the migration request message carrying the file migration information.
[0305] The migration request message is used to instruct the file migration between the storage modules according to the file migration information carried in the migration request message.
[0306] It should be noted that the first device 101 can include a first module and a second module. The first module can perform steps 501 and 502.
[0307] For any one of the plurality of storage modules, if the device where the storage module is located is the second device 102, the first device 101 sends the migration request message to the second device 102, which belongs to network communication; if the device where the storage module is located is the first device 101, the first module in the first device 101 sends the migration request message to the second module, which belongs to local inter-thread communication.
[0308] Step 503: After receiving the migration request message, the target device determines the files to be sent and the files to be received by each storage module in the target device according to the file migration information. The target device is the device where at least one of the plurality of storage modules is located.
[0309] If the target device is the second device 102, the second device 102 can determine the files to be sent and the files to be received by each storage module in the second device 102 according to the file migration information carried in the migration request message sent by the first device 101 after receiving the migration request message. Alternatively, after receiving the migration request message sent by the first device 101, the second device 102 can send an acknowledgement (ACK) message to the first device 101 to indicate that the second device 102 has received the migration request message.
[0310] If the target device is the first device 101, the second module in the first device 101 can determine the files to be sent and the files to be received by each storage module in the first device 101 according to the file migration information carried in the migration request message sent by the first module after receiving the migration request message. Alternatively, after receiving the migration request message sent by the first module, the second module can send an ACK message to the first module to indicate that the second module has received the migration request message.
[0311] Since the file migration information is used to indicate the files that any one of the plurality of storage modules needs to migrate to other storage modules, the target device can know the files that each storage module in the target device needs to migrate to the next storage module and the files that each storage module in the target device needs to receive from the previous storage module according to the file migration information, that is, the files to be sent and the files to be received by each storage module in the target device can be determined.
[0312] For example, the file migration information includes at least one file migration list and a source storage module identifier and a target storage module identifier corresponding to each file migration list. In this case, for any one of the at least one file migration list, if the source storage module identifier corresponding to the file migration list is the same as the module identifier of a certain storage module in the target device, each file identifier in the file migration list identifies a file that needs to be sent by the storage module to the target storage module identified by the target storage module identifier corresponding to the file migration list. If the target storage module identifier corresponding to the file migration list is the same as the module identifier of a certain storage module in the target device, each file identifier in the file migration list identifies a file that needs to be received by the storage module from the storage module identified by the source storage module identifier corresponding to the file migration list.
[0313] Step 504: The target device performs file transmission and reception operations according to the files that need to be sent and the files that need to be received by each storage module in the target device, and sends a migration completion message to the first device 101 after the file transmission and reception operations are completed.
[0314] If the target device is the second device 102, the second device 102 can perform step 504 to perform file transmission and reception operations, and then send a migration completion message to the first device 101. Optionally, after the first device 101 receives the migration completion message sent by the second device 102, the first device 101 can send an ACK message to the second device 102 in response to the migration completion message, to indicate that the first device 101 has received the migration completion message.
[0315] If the target device is the first device 101, the second module of the first device 101 can perform step 504 to perform file transmission and reception operations, and then send a migration completion message to the first module of the first device 101. Optionally, after the first module receives the migration completion message sent by the second module, the first module can send an ACK message to the second module in response to the migration completion message, to indicate that the first module has received the migration completion message.
[0316] The migration completion message is used to indicate that each storage module in the target device has completed the file sending and receiving required in the current round of file migration behavior.
[0317] In some embodiments, for any one storage module in the target device, if the storage module (which can be referred to as the sixth storage module) is the storage module identified by the source storage module identifier corresponding to a certain file migration list, the target device obtains the files indicated by the file migration list from the sixth storage module; if the storage module identified by the target storage module identifier corresponding to the file migration list (which can be referred to as the seventh storage module) is located in the target device, the target device stores the files to the seventh storage module; if the seventh storage module is located in another device, the target device sends the files and the module identifier of the seventh storage module to the device where the seventh storage module is located in a file migration request, and the device receiving the file migration request can store the files carried by the file migration request to the seventh storage module. In this way, the file sending operation for the sixth storage module is completed.
[0318] For any one storage module in the target device, if the storage module (which can be referred to as the eighth storage module) is the storage module identified by the target storage module identifier corresponding to a certain file migration list, if the storage module identified by the source storage module identifier corresponding to the file migration list (which can be referred to as the ninth storage module) is located in the target device, the target device obtains the files indicated by the file migration list from the ninth storage module and stores the files to the eighth storage module; if the ninth storage module is located in another device, the target device receives the file migration request sent by the other device and carrying at least one file and the module identifier of the eighth storage module, and then stores the at least one file to the eighth storage module. In this way, the file receiving operation for the eighth storage module is completed.
[0319] If each storage module in the target device has sent the files to be sent to the target storage module and has received the files to be received from the source storage module, the target device can determine that the file sending and receiving operation is completed, and then can send a migration completion message to the first device 101.
[0320] In some embodiments, during the file sending and receiving operation of the target device, for the received files to be stored to the storage module of the target device (which can be referred to as target files), the effective version number of the target files can be set to a preset version number. The preset version number can be set in advance, and the preset version number is the maximum value in the value range of the effective version number.
[0321] The version corresponding to the effective version number of the target file is a version at which the target file starts to take effect, i.e., a version at which the target file can be used. Since the target device is in the process of file migration and the current round of file migration has not been completed, the effective version number of the target file received by the target device has not been updated to the version number of the version corresponding to the current round of file migration. Therefore, the target device can temporarily set the effective version number of the target file to a preset version number, so as to avoid the target file being mistakenly deleted during the current round of file migration.
[0322] As an example, if the first device 101 sends a file deletion message carrying the third version number and the file identifier of the first file (which can be the target file or can not be the target file) to the target device when releasing the version corresponding to the third version number, the target device can ignore the file deletion message, i.e., not delete the first file, when the third version number is less than the effective version number of the first file. This is because the third version number is less than the effective version number of the first file, which means that the version corresponding to the third version number is an old version compared to the version corresponding to the effective version number of the first file. When releasing the old version, the file stored in the new version should not be deleted. In this way, the first file can be prevented from being lost in the new version.
[0323] For example, in some cases, the cold and hot priority scores of the plurality of storage modules can be adjusted, and / or new storage modules can be added to the storage layer system, which can cause the order of the plurality of storage modules to change. In this case, a file can be continuously migrated between two storage modules, which can cause the file migrated in the high version to be mistakenly deleted in the release of the low version, resulting in file loss.
[0324] For example, assume that file 3 in storage module 2 is migrated to storage module 3 at version 8. Then, file 3 is migrated from storage module 3 to storage module 2 at version 10. Then, the device where storage module 2 is located receives the release message of version 8 (i.e., the file deletion message carrying the version number of version 8 and the file identifier of file 3) sent by the first device 101, and requires deleting file 3. If file 3 is directly deleted, file 3 will be lost at version 10. Therefore, in the embodiments of the present application, the effective version number is set. After file 3 is migrated from storage module 3 to storage module 2 at version 10, the effective version number of file 3 is set to a preset version number or the version number of version 10. Therefore, even if the release message of version 8 is received, file 3 in storage module 2 will not be deleted because the version number of version 8 is less than the preset version number or the version number of version 10, so that file 3 can be prevented from being lost at version 10.
[0325] Step 505: The first device 101 determines whether the current file migration behavior is completed according to the received migration completion message.
[0326] After the first device 101 sends the migration request message to the device where each of the plurality of storage modules is located in step 502, the first device 101 can receive the migration completion message returned by each device and determine whether the current file migration behavior is completed according to the migration completion message.
[0327] If the first device 101 has received the migration completion message sent by the device where each of the plurality of storage modules is located, it can be determined that the current file migration behavior is completed. If the first device 101 has not received the migration completion message sent by the device where at least one of the plurality of storage modules is located, it can be determined that the current file migration behavior is not completed.
[0328] If the timer expires after it is determined that the current file migration behavior is completed, the above steps 501 to 505 can be continued to perform a new round of file migration behavior.
[0329] If the current file migration behavior (herein the current file migration behavior is the previous round of file migration behavior described in step 501) is not completed when the timer expires, the first device 101 can wait until the current file migration behavior is completed, i.e., until the migration completion message sent by the device where each of the plurality of storage modules is located is received, and then determine the file migration information of the new round of file migration behavior, and then continue to perform steps 502 to 505 to perform the new round of file migration behavior, and the timer can be reset to restart the timing after the file migration information of the new round of file migration behavior is determined; or the first device 101 can wait until the current file migration behavior is completed, i.e., until the migration completion message sent by the device where each of the plurality of storage modules is located is received, and then reset the timer to restart the timing, and then determine the file migration information of the new round of file migration behavior, and then continue to perform steps 502 to 505 to perform the new round of file migration behavior.
[0330] In some embodiments, the first device 101 can send a version update message to the device where each of the plurality of storage modules is located when it is determined that the current file migration behavior is completed, and the version update message carries the latest system version number and target file information, and the target file information is used to indicate the target file that each of the plurality of storage modules needs to receive in the current file migration behavior. After the target device receives the version update message, the effective version number of the target file in each storage module of the target device can be updated to the version number carried by the version update message according to the version update message.
[0331] The version corresponding to the latest system version number at the completion of the current file migration behavior is the version at the completion of the current file migration behavior, and since the target file is migrated to other storage modules in the current file migration behavior, the effective version number of the target file can be updated to the current latest system version number at the completion of the current file migration behavior, so that the target file starts to take effect from the version corresponding to the system version number.
[0332] For example, the target file information can include a plurality of storage module identifiers (i.e., the module identifier of each storage module in the plurality of storage modules) and the target file identifier corresponding to each storage module identifier.
[0333] After the target device receives the version update message, if the module identifier of a storage module in the target device is the same as a storage module identifier in the target file information, the target device can obtain the target file identifier corresponding to the storage module identifier from the target file information, and update the effective version number of the target file identified by the target file identifier in the storage module to the version number carried by the version update message.
[0334] As an example, if the first device 101 sends a file deletion message carrying the third version number and the file identifier of the first file (which can be the target file or not) to the target device when releasing the version corresponding to the third version number, the target device can delete the first file after receiving the file deletion message and in the case that the third version number is greater than or equal to the effective version number of the first file.
[0335] It should be noted that in some embodiments, the plurality of storage modules are sorted in order of read-write performance from high to low, and the storage layer system can store the generated new file to the first storage module with the highest read-write performance, which can ensure that the delay of the storage layer system processing write requests is relatively low. In addition, the storage layer system can perform file migration behavior asynchronously in the background to continuously migrate the files in each storage module in the plurality of storage modules to the next storage module, so as to ensure that the first storage module always has capacity to store new files. Moreover, since the file migration is performed according to the file migration list of each storage module, and the files indicated by the file migration list of a storage module are cold data in the storage module, the cold and hot data separation can be achieved through file migration, so that the hot data is kept in the storage module with higher read-write performance, and the cold data is migrated to the storage module with lower read-write performance. In this way, the read-write efficiency of the hot data can be improved and the read-write delay of the hot data can be reduced while achieving distributed storage of files.
[0336] In some cases, a large number of file writes in a short time can occur, causing the first storage device to be occupied or even exhausted in a large amount of time for a round of file migration behavior. To solve this problem, the first device 101 can determine the remaining storage space of the first storage module after storing a new file in the first storage module each time. If the remaining storage space of the first storage module is less than or equal to a preset storage space, it indicates that the remaining storage space of the first storage module is small, and then the target mode is entered, in which the storage of files to the first storage module is stopped. That is, in the target mode, the first device 101 can normally generate new files, but temporarily does not store the generated new files to the first storage module, but waits until it exits the target mode, and then stores all new files generated during this period to the first storage module.
[0337] In addition, when the first device 101 is in the target mode, it can determine whether the current round of file migration behavior is completed, that is, whether the migration completion message sent by the device where each of the plurality of storage modules is located is received after sending the migration request message to the device where each of the plurality of storage modules is located. Until the migration completion message sent by the device where each of the plurality of storage modules is located has been received, it is determined that the current round of file migration behavior has been completed, at which time the next round of file migration behavior is directly performed, that is, the operation of determining the file migration information of the new round of file migration behavior in step 501 and steps 502 to 504 are performed. After the first device 101 determines that the current round of file migration behavior is completed in step 504, the target mode is exited, and the timer is reset.
[0338] It should be noted that the file migration behavior is usually triggered by the timer, that is, when the timer is up, the first device 101 allows a new round of file migration behavior. After entering the target mode due to the small remaining storage space of the first storage module, in order to reduce the number of files in the first storage module, after the current round of file migration behavior is completed, the timer does not need to be waited for, but a file migration behavior is directly triggered. The operation of this file migration behavior triggered here is the same as that of the file migration behavior triggered by the timer. After this file migration behavior is completed, the target mode is exited and the timer is reset, and the original file migration logic is restored.
[0339] In addition, since the old version is released when the new version takes effect, in order to delete the migrated files in the file migration behavior from the source storage module, the first device 101 can update the system version number, i.e., add 1 to the system version number, after the file migration behavior is completed, so that the version obtained after the file migration behavior is completed takes effect, and then the old version is released, i.e., the migrated files in the old version can be truly deleted from the source storage module. In this way, the files migrated to other storage modules in the file migration behavior can be truly deleted from the first storage module, so that the remaining storage space of the first storage module can be increased, and the normal operation of the system can be ensured.
[0340] In the embodiment of the present application, the first device 101 determines the file migration information of the new round of file migration behavior when the timer expires, in the case that the file migration behavior of the previous round is completed, the file migration information is used to indicate the files that need to be migrated from any one of the plurality of storage modules to other storage modules, and the file migration behavior is a background asynchronous behavior. Then, the first device 101 sends a migration request message to the device where each of the plurality of storage modules is located, and the migration request message carries the file migration information. After any one or more target devices where the storage modules are located receive the migration request message, the target device determines the files that need to be sent and the files that need to be received according to the file migration information, performs file transmission and reception operations according to the files that need to be sent and the files that need to be received, and sends a migration completion message to the first device 101 after the file transmission and reception operations are completed. The first device 101 determines whether the file migration behavior of this round is completed according to the received migration completion message. The embodiment of the present application can realize distributed storage of files by periodically migrating files between the plurality of storage modules. Moreover, the file migration behavior is a background asynchronous behavior, so it can avoid blocking other key operations such as data storage operations, data query operations, etc., so as to improve the response speed and performance of the storage layer system. In this way, the distributed management and control can be better realized.
[0341] FIG. 7 is a structural schematic diagram of a computer device according to an embodiment of the present application. As shown in FIG. 7, the computer device 7 includes a processor 70, a memory 71, and a computer program 72 stored in the memory 71 and executable on the processor 70, and the processor 70 implements the operations performed by the first device or the second device in the file migration method in the above-mentioned embodiments when executing the computer program 72.
[0342] The computer device 7 can be a general purpose computer device or a special purpose computer device. In specific implementations, the computer device 7 can be a desktop computer, a laptop computer, a network server, a palmtop computer, a mobile phone, a tablet computer, a wireless terminal device, a communication device or an embedded device, and the embodiments of the present application do not limit the type of the computer device 7. Those skilled in the art can understand that FIG. 7 is only an example of the computer device 7, and does not limit the computer device 7, which can include more or less components, or combine certain components, or different components, such as also including input / output devices, network access devices, etc.
[0343] The processor 70 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic components, discrete hardware components, etc. The general-purpose processor can be a microprocessor or can also be any conventional processor.
[0344] The memory 71 can be an internal storage unit of the computer device 7, such as a hard disk or a memory of the computer device 7 in some embodiments. The memory 71 can also be an external storage device of the computer device 7, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 7 in other embodiments. Further, the memory 71 can include both the internal storage unit and the external storage device of the computer device 7. The memory 71 is used to store an operating system, application programs, a boot loader, data and other programs, etc. The memory 71 can also be used to temporarily store data that has been output or will be output.
[0345] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the above method embodiments can be completed by a computer program instructing related hardware, and the computer program can be stored in a computer readable storage medium. When the computer program is executed by a processor, the steps of each method embodiment described above can be implemented. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or some intermediate forms. The computer readable medium at least includes any entity or device capable of carrying the computer program code to the photographing device / terminal equipment, recording medium, computer memory, ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage device, etc. The computer readable storage medium mentioned in the present application can be a non-volatile storage medium, in other words, a non-transitory storage medium.
[0346] It should be understood that all or part of the steps of the above embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, it can be implemented in the form of a computer program product in whole or in part. The computer program product includes one or more computer instructions. The computer instructions can be stored in the computer readable storage medium described above.
Claims
1. A file migration method, characterized in that, The method is applied to a storage layer system, which includes a first device, one or more second devices, and multiple storage modules. Any one of the multiple storage modules is located on the first device or a second device. Each of the multiple storage modules is used to store files, and file migration is possible between the multiple storage modules. The method includes: When the timer expires, the first device determines the file migration information for the new round of file migration, assuming the previous round of file migration has been completed. The file migration information is used to indicate the files that need to be migrated from any one of the plurality of storage modules to other storage modules. The file migration is an asynchronous background process. The first device sends a migration request message to the device where each of the plurality of storage modules is located, and the migration request message carries the file migration information. After receiving the migration request message, the target device determines the files to be sent and received by each storage module in the target device according to the file migration information. The target device is the device where at least one of the multiple storage modules is located. The target device performs file sending and receiving operations according to the files to be sent and received by each storage module in the target device. After the file sending and receiving operations are completed, the target device sends a migration completion message to the first device. The first device determines whether the current file migration is complete based on the received migration completion message.
2. The method as described in claim 1, characterized in that, The multiple storage modules are ordered in descending order of read / write performance, and files in any of the storage modules other than the last one are allowed to be migrated to the next storage module.
3. The method as described in claim 2, characterized in that, The method further includes: the first device receiving a data storage request, the data storage request carrying key-value pairs to be stored, the key values in the key-value pairs being globally ordered; the first device generating a new file containing one or more key-value pairs according to the order of the key values in the key-value pairs, storing the new file in a first storage module, the first storage module being the first among the plurality of storage modules; wherein, the file identifiers of all files containing the key-value pairs are globally ordered.
4. The method as described in claim 3, characterized in that, After the first device stores the new file in the first storage module, the method further includes: the first device obtaining a first version number, which is the sum of the latest system version number when the new file is stored and 1; the first device adding a first leaf node after the last leaf node in the target tree, and updating the target tree according to the first leaf node; wherein, the leaf node in the target tree contains a file identifier, the minimum and maximum key values among all key-value pairs in the file identified by the file identifier, and a mapping table, the mapping table including the mapping relationship between the version number and the storage module identifier, the mapping table being used to indicate the storage module where the file identified by the file identifier is located under each version; the first leaf node contains the file identifier of the new file, the minimum and maximum key values among all key-value pairs in the new file, and a first mapping table, the first mapping table including the mapping relationship between the first version number and the module identifier of the first storage module; the first device updating the system version number to the first version number.
5. The method as described in claim 3, characterized in that, After the first device stores the new file in the first storage module, the method further includes: if the first device determines that the remaining storage space of the first storage module is less than or equal to the preset storage space, it enters the target mode, in which the storage of files to the first storage module is stopped; when the first device is in the target mode, after the current round of file migration is completed, the first device performs the next round of file migration, and after the next round of file migration is completed, it exits the target mode and resets the timer.
6. The method as described in claim 2, characterized in that, Each of the plurality of storage modules has a first correspondence and a second correspondence. The first correspondence includes the number of hits for each file in the storage module, and the second correspondence includes the number of files in the storage module whose hit count falls within each of the plurality of preset hit count intervals. The file migration information includes at least one file migration list. The first device determines the file migration information for a new round of file migration behavior, including: the first device determines the file migration list of the second storage module according to the first correspondence and the second correspondence of the second storage module, wherein the second storage module is any one of the plurality of storage modules except the last one in the order, and the file migration list is used to indicate the files that the second storage module needs to migrate to the third storage module, wherein the third storage module is the storage module that is next in the order of the second storage module in the order of the plurality of storage modules.
7. The method as described in claim 6, characterized in that, The first device determines the file migration list of the second storage module based on the first and second correspondences of the second storage module, including: the first device determines the number of first files and the number of second files based on the first and second correspondences of the second storage module, wherein the number of first files is the number of files in the second storage module with a hit count of 0, and the number of second files is the largest number of files in the second correspondence of the second storage module; if the number of first files is greater than or equal to the number of second files, the first device adds the file identifiers with a hit count of 0 corresponding to the first correspondence of the second storage module to the file migration list.
8. The method as described in claim 7, characterized in that, After the first device determines the number of first files and the number of second files based on the first correspondence and the second correspondence of the second storage module, the method further includes: if the number of first files is less than the number of second files, the first device determines a first hit count interval, which is a preset hit count interval corresponding to the largest number of files in the second correspondence of the second storage module; the first device determines at least one second hit count interval based on the first hit count interval, which is all preset hit count intervals in the second correspondence of the second storage module that are located before the first hit count interval; the first device adds file identifiers whose hit counts in the first correspondence of the second storage module are within the at least one second hit count interval to the file migration list, and adds file identifiers whose hit counts are 0 in the first correspondence of the second storage module to the file migration list.
9. The method as described in claim 8, characterized in that, Each of the plurality of storage modules has a third correspondence relationship, which includes the total number of hits of files in the storage module that are within each of the plurality of preset hit count intervals; After the first device determines at least one second hit count interval based on the first hit count interval, the method further includes: if the sum of the number of files corresponding to each second hit count interval in the at least one second hit count interval is less than the target migration number, then the first device divides the total number of hits corresponding to the first hit count interval in the third correspondence of the second storage module by the number of files corresponding to the first hit count interval in the second correspondence of the second storage module to obtain the target hit count, and adds the file identifiers whose hit counts in the first correspondence of the second storage module are within the first hit count interval and less than the target hit count to the file migration list.
10. The method according to any one of claims 1 to 9, characterized in that, Before the first device sends a migration request message to the device where each of the plurality of storage modules is located, the method further includes: after the first device determines the file migration information, it obtains a second version number, wherein the second version number is the sum of the latest system version number when the file migration information is determined and 1; and the first device updates the system version number to the second version number.
11. The method as described in claim 10, characterized in that, The method further includes: when the first device has completed the current round of file migration, it sends a version update message to the device where each of the plurality of storage modules is located. The version update message carries the latest system version number and target file information. The target file information is used to indicate the target file that each of the plurality of storage modules needs to receive in the current round of file migration. After receiving the version update message, the target device updates the effective version number of the target file in each storage module of the target device to the version number carried in the version update message according to the version update message.
12. The method as described in claim 11, characterized in that, Before the target device sends a migration completion message to the first device after the file sending and receiving operation is completed, the method further includes: during the file sending and receiving operation, the target device sets the effective version number of the received target file to a preset version number, where the preset version number is the maximum value within the range of the effective version number; the method further includes: the first device sending a file deletion message to the target device, the file deletion message carrying a third version number and a file identifier of the first file; after receiving the file deletion message, the target device deletes the first file if the third version number is greater than or equal to the effective version number of the first file.
13. A storage layer system, characterized in that, The storage layer system includes a first device, one or more second devices, and multiple storage modules. Any one of the multiple storage modules is located on the first device or the second device. Each of the multiple storage modules is used to store files, and file migration is possible between the multiple storage modules. The first device is configured to determine file migration information for a new round of file migration when a timer expires, provided that the previous round of file migration has been completed. The file migration information is used to indicate files that need to be migrated from any one of the plurality of storage modules to other storage modules. The file migration is a background asynchronous operation. The first device is also configured to send a migration request message to the device where each of the plurality of storage modules is located. The migration request message carries the file migration information. The target device is configured to, upon receiving the migration request message, determine, based on the file migration information, the files to be sent and the files to be received by each storage module in the target device, wherein the target device is the device containing at least one of the plurality of storage modules; the target device is further configured to perform file sending and receiving operations based on the files to be sent and the files to be received by each storage module in the target device, and after the file sending and receiving operations are completed, send a migration completion message to the first device; The first device is further configured to determine whether the current round of file migration has been completed based on the received migration completion message.
Citation Information
Patent Citations
Method and system for dynamic data synchronization
CN101446972A
Method and device of data migration trigger
CN102521138A
Method and device for migration of data in integrated storage systems
CN108874311A
Multi-node load balancing cold and hot data migration device and method, terminal and medium
CN115079958A
Method for processing user-defined strategy migration by computer
CN115185882A