Data backup, restoration and query methods and apparatuses for distributed database
By building an index tree on the backup media, the metadata of the distributed database can be quickly restored, solving the problem that the distributed database can only be queried after recovery, and achieving faster recovery and lower resource consumption.
Patent Information
- Application Number
- PCT/CN2025/088818
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-05-11
- Filing Date
- 2025-04-14
- Publication Date
- 2025-11-20
AI Technical Summary
In existing technologies, distributed databases can only support data queries after data recovery, resulting in excessively long recovery times and resource consumption.
By building an index tree on the backup media, including a first index tree and a second index tree, the metadata of the distributed database can be quickly recovered, allowing users to perform queries without restoring the data to the local database node.
It enables faster deployment of distributed databases, reduces the time and resource consumption required for overall recovery, and improves response speed and disaster recovery capabilities.
Smart Images

Figure CN2025088818_20112025_PF_FP_ABST
Abstract
Description
Data backup, recovery and query method and device of distributed database
[0001] The present application claims priority to the Chinese patent application No. 202410585845.5, filed on May 11, 2024, and entitled "Data backup, recovery and query method and device of distributed database", the whole content of which is incorporated herein by reference. TECHNICAL FIELD
[0002] Embodiments of the present specification relate to the technical field of database, in particular, to a data backup, recovery and query method and device of distributed database. BACKGROUND
[0003] Physical backup recovery in a distributed database is an important technical means for disaster recovery, which usually recovers all data from backup media to local database nodes. At present, distributed databases generally support data queries after all data is completely recovered.
[0004] There is an urgent need for a reasonable and reliable solution to make the distributed database available more quickly and reduce the time and resource consumption required for overall recovery. SUMMARY
[0005] Embodiments of the present specification provide a data backup, recovery and query solution of distributed database, which can make the distributed database available more quickly and reduce the time and resource consumption required for overall recovery.
[0006] In a first aspect, the embodiments of the present specification provide a data backup method of distributed database, comprising: writing a plurality of first data blocks to be backed up in a database node of the distributed database to a backup medium, the plurality of first data blocks being derived from a plurality of ordered string table (SST) files corresponding to a plurality of data shards managed by the database node; for each target SST file in the plurality of SST files, constructing a first index tree based on the first metadata of each first data block and the first address on the backup medium, and writing the first index tree to the backup medium, and writing the second metadata of the target SST file to the backup medium, the second metadata comprising the root node address of the first index tree; and constructing a second index tree based on the second address of each second metadata on the backup medium, and writing the second index tree to the backup medium for data recovery.
[0007] In some embodiments, the writing the plurality of first data blocks to be backed up in the database node of the distributed database into the backup medium comprises: generating a plurality of backup tasks for the plurality of first data blocks; wherein a single backup task comprises an identification of a number of first data blocks in the plurality of first data blocks, and an identification of the backup medium; and writing the plurality of first data blocks into the backup medium by executing the plurality of backup tasks in parallel.
[0008] In some embodiments, the method further comprises: caching the plurality of first data blocks into a memory of the database node; and the writing the plurality of first data blocks into the backup medium by executing the plurality of backup tasks in parallel comprises: for each backup task in the plurality of backup tasks, in response to an occupied space of a first data block cached in the memory and responsible for backup by the backup task reaching a preset threshold, writing the first data block cached in the memory into the backup medium by executing the backup task.
[0009] In some embodiments, the constructing the first index tree based on the first metadata of each first data block and the first address on the backup medium comprises: for each backup task in the plurality of backup tasks and related to the target SST file, in response to each first data block in the target SST file and responsible for backup by the backup task being written into the backup medium, constructing an intermediate layer index tree of the target SST file based on the first metadata of each first data block and the first address on the backup medium; and aggregating each intermediate layer index tree of the target SST file into the first index tree.
[0010] In some embodiments, the method further comprises: writing third metadata of the number of data shards into the backup medium; and the constructing the second index tree based on the second address of each second metadata on the backup medium comprises: constructing the second index tree based on the second address of each second metadata on the backup medium and the third address of each third metadata on the backup medium.
[0011] In some embodiments, the writing the plurality of first data blocks into the backup medium by executing the plurality of backup tasks in parallel comprises: for each backup task in the plurality of backup tasks, writing each first data block responsible for backup by the backup task into a data backup file corresponding to the backup task in the backup medium by executing the backup task.
[0012] In some embodiments, after the second metadata of the target SST file is written to the backup medium, the method further comprises: writing address information comprising a second address of the second metadata of the target SST file at a target position in a data backup file corresponding to a backup task related to the target SST file; and constructing the second index tree based on the second addresses of the second metadata on the backup medium comprises: aggregating the address information recorded at the target positions in the data backup files corresponding to the plurality of backup tasks respectively, and constructing the second index tree based on the aggregation result.
[0013] In a second aspect, the embodiments of the present specification provide a data recovery method of a distributed database, comprising: for a plurality of data shards to be recovered by a database node of the distributed database, obtaining second addresses of second metadata of ordered string table (SST) files corresponding to the plurality of data shards respectively on a backup medium from a second index tree stored in the backup medium; the second metadata comprises a root node address of a first index tree on the backup medium, and the first index tree is constructed based on first metadata of a plurality of first data blocks of the SST files and first addresses on the backup medium; for each target address in the obtained second addresses, obtaining target second metadata stored at the target address from the backup medium, and constructing a first SST file comprising the target second metadata in the database node; so that the root node address in the first SST file is used for remote data query.
[0014] In some embodiments, the method further comprises: generating a plurality of recovery tasks for the plurality of data shards, the plurality of recovery tasks comprising identifications of different data shards in the plurality of data shards and an identification of the backup medium; and performing data recovery on the database node by executing the plurality of recovery tasks in parallel.
[0015] In some embodiments, the constructing the first SST file comprising the target second metadata in the database node comprises: constructing an empty second SST file in the database node; writing the target second metadata to the second SST file, and taking the updated second SST file as the first SST file.
[0016] In a third aspect, the embodiments of the present specification provide a data query method of a distributed database, executed by a database node of the distributed database, comprising: receiving a data query request, wherein the data query request comprises a table name and a primary key range of a data table; determining, based on the data query request, a target SST file to be accessed, which corresponds to a target data shard of the data table, and the target data shard comprises row data whose primary keys are within the primary key range; in response to the target SST file comprising second metadata, determining, based on the primary key range and a target first index tree in a backup medium, a target first data block to be accessed; the second metadata corresponds to an original SST file of the database node and comprises a root node address of the target first index tree, and the target first index tree is constructed based on first metadata of a plurality of first data blocks of the original SST file and a first address on the backup medium; acquiring the target first data block from the backup medium based on a first address of the target first data block, and determining a query result based on the target first data block.
[0017] In some embodiments, a single first data block comprises a plurality of second data blocks; the method further comprises: determining, based on the primary key range, a target second data block to be accessed in the target first data block; and the determining the query result based on the target first data block comprises: determining the query result based on the target second data block.
[0018] In some embodiments, the method further comprises: determining whether the target first data block is cached locally by the database node; and the acquiring the target first data block from the backup medium based on the first address of the target first data block comprises: in response to a determination result being no, acquiring the target first data block from the backup medium based on the first address of the target first data block.
[0019] In some embodiments, the method further comprises: in response to the determination result being yes, acquiring the target first data block cached locally.
[0020] In some embodiments, after acquiring the target first data block from the backup medium, the method further comprises: caching the target first data block locally.
[0021] In a fourth aspect, the embodiments of the present specification provide a data backup apparatus of a distributed database, comprising: a first backup unit configured to write a plurality of first data blocks to be backed up in a database node of the distributed database to a backup medium, the plurality of first data blocks being derived from a plurality of sequential string table (SST) files corresponding to a plurality of data shards managed by the database node; a second backup unit configured to, for each target SST file in the plurality of SST files, based on first metadata of each first data block and a first address on the backup medium, construct a first index tree and write the first index tree to the backup medium, and write second metadata of the target SST file to the backup medium, the second metadata comprising a root node address of the first index tree; and a third backup unit configured to, based on a second address on the backup medium of each second metadata, construct a second index tree and write the second index tree to the backup medium for data recovery.
[0022] In a fifth aspect, the embodiments of the present specification provide a data recovery apparatus of a distributed database, comprising: an acquisition unit configured to, for a plurality of data shards to be recovered by a database node of the distributed database, acquire, from a second index tree stored in a backup medium, a second address on the backup medium of second metadata of a sequential string table (SST) file corresponding to each of the plurality of data shards; the second metadata comprising a root node address on the backup medium of a first index tree, the first index tree being constructed based on first metadata of a plurality of first data blocks of the SST file and first addresses on the backup medium; and a data recovery unit configured to, for each target address in each acquired second address, acquire, from the backup medium, target second metadata stored at the target address, and construct, in the database node, a first SST file comprising the target second metadata; so that the root node address in the first SST file is used for remote data query.
[0023] In a sixth aspect, an embodiment of the present specification provides a database node of a distributed database, comprising: a receiving unit configured to receive a data query request, wherein the data query request comprises a table name of a data table and a primary key range; a first determining unit configured to determine, based on the data query request, a target SST file of ordered strings to be accessed, which corresponds to a target data shard of the data table, and the target data shard comprises row data whose primary keys are within the primary key range; a second determining unit configured to determine, based on the primary key range and a target first index tree in a backup medium, a target first data block to be accessed, in response to the target SST file comprising second metadata; the second metadata corresponds to an original SST file of the database node and comprises a root node address of the target first index tree, and the target first index tree is constructed based on first metadata of a plurality of first data blocks of the original SST file and a first address on the backup medium; an obtaining unit configured to obtain the target first data block from the backup medium based on a first address of the target first data block; and a third determining unit configured to determine a query result based on the target first data block.
[0024] In a seventh aspect, an embodiment of the present specification provides a computer readable storage medium having a computer program stored thereon, wherein when the computer program is executed in a computer, the computer is caused to perform the method described in any implementation manner of the first aspect to the third aspect.
[0025] In an eighth aspect, an embodiment of the present specification provides a computing device comprising a memory and a processor, wherein the memory has executable code stored therein, and the processor implements the method described in any implementation manner of the first aspect to the third aspect when executing the executable code.
[0026] In a ninth aspect, an embodiment of the present specification provides a computer program product comprising computer programs / instructions, which, when executed by a processor, implement the method described in any implementation manner of the first aspect to the third aspect.
[0027] The above-mentioned embodiments of the present specification provide a scheme, in the data backup phase, a plurality of first data blocks to be backed up in the database nodes of the distributed database can be written to the backup medium, and for each target SST file in the plurality of first data blocks corresponding to a plurality of SST files, a first index tree is constructed based on the first metadata of each first data block and the first address on the backup medium, and the second metadata of the target SST file is written to the backup medium, and the second metadata includes the root node address of the first index tree. Then, based on the second address of each second metadata on the backup medium, a second index tree is constructed and written to the backup medium for data recovery. By using this data backup process, when subsequent recovery of the SST file is required, only the second metadata of the SST file can be recovered, so that the root node address in the second metadata is used for remote data query, so that the user can perform query operations without restoring the backup data to the local database node. Therefore, the scheme can make the distributed database available more quickly, and reduce the time and resource consumption required for overall recovery. BRIEF DESCRIPTION OF DRAWINGS
[0028] In order to more clearly illustrate the technical solutions of the multiple embodiments disclosed in the present specification, the drawings required in the embodiment description will be briefly introduced below. Obviously, the drawings in the following description are only multiple embodiments disclosed in the present specification, and other drawings can also be obtained by those skilled in the art without creative labor.
[0029] FIG. 1 is a schematic diagram of a data backup process of a distributed database in an embodiment of the present specification;
[0030] FIG. 2 is a schematic diagram of a data recovery and query process of a distributed database in an embodiment of the present specification;
[0031] FIG. 3 is a flowchart of a data backup method of a distributed database in an embodiment of the present specification;
[0032] FIG. 4 is a flowchart of a data backup method of a distributed database in an embodiment of the present specification;
[0033] FIG. 5 is a flowchart of a data recovery method of a distributed database in an embodiment of the present specification;
[0034] FIG. 6 is a flowchart of a data query method of a distributed database in an embodiment of the present specification;
[0035] FIG. 7 is a flowchart of a data query method of a distributed database in an embodiment of the present specification;
[0036] FIG. 8 is a structural schematic diagram of a data backup device of a distributed database in an embodiment of the present specification;
[0037] FIG. 9 is a structural diagram of a data recovery apparatus of a distributed database according to an embodiment of the present specification;
[0038] FIG. 10 is a structural diagram of a database node of a distributed database according to an embodiment of the present specification. DETAILED DESCRIPTION
[0039] The present specification will be further described below in conjunction with the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein merely serve to explain the related application, and are not a limitation on the application. The described embodiments are only a part of the embodiments of the present specification, rather than all the embodiments. Based on the embodiments in the present specification, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.
[0040] It should be noted that, for the convenience of description, only the parts related to the application are shown in the accompanying drawings. The embodiments in the present specification and the features in the embodiments can be combined with each other without conflict. In addition, the words "first", "second", "third" and the like in the embodiments of the present specification are only for information differentiation, and do not have any limiting effect.
[0041] As described above, the physical backup recovery in the distributed database is an important technical means for disaster recovery, which generally restores all data from the backup medium to the local database node. At present, the distributed database generally supports data query after all data is completely restored.
[0042] The embodiments of the present specification provide a data backup, recovery and query scheme for the distributed database, which can make the distributed database available more quickly and reduce the time and resource consumption required for overall recovery.
[0043] FIG. 1 is a schematic diagram of a data backup process of a distributed database according to an embodiment of the present specification. As shown in FIG. 1, the data backup process involves a distributed database 101, a data backup and recovery system 102, and a backup medium 103. The distributed database 101 includes a plurality of database nodes, such as the database nodes Node1, Node2, …, Node n , where subscript n is the total number of the plurality of database nodes. The distributed database 101 can communicate with the data backup and recovery system 102 and the backup medium 103. The data backup and recovery system 102 is configured to perform data backup and data recovery on the database nodes of the distributed database 101. The backup medium 103 is configured to store the data to be backed up in the database nodes of the distributed database 101. The backup medium 103 can be a physical machine or a cloud storage service independent of the distributed database 101, which is not limited here.
[0044] The distributed database 101 can employ a LSM Tree (Log Structured Merge Tree) architecture. The LSM Tree is a data structure that can improve the speed of disk write operations by converting a large number of random disk write operations into batch sequential write operations. In addition, the distributed database 101 can employ a shared nothing architecture. The shared nothing architecture is a distributed system architecture that separates the components of the system so that there is no shared resource between them, thereby avoiding the competition and conflict caused by shared resources and improving the reliability and scalability of the system.
[0045] Data table management can be performed in the distributed database 101. For example, a data table can be horizontally split to divide the data table into a plurality of data shards, and the plurality of data shards can be allocated to a plurality of database nodes of the distributed database 101 for management. Each database node of the distributed database 101 can be responsible for managing different data shards. A single data shard can include part of the row data in the data table. In an example, a data shard can be referred to as a Tablet. A Tablet is a logical data shard unit that has its own unique identifier and range definition (such as a primary key range), which is used to determine which row data the Tablet is responsible for managing. By dividing a data table into a plurality of Tablets according to certain rules (such as primary key hashing, range, etc.), balanced storage of data in the cluster and balanced query load can be achieved.
[0046] For each data shard managed by each database node of the distributed database 101, the database node can store an SST (Sorted String Table) file corresponding to the data shard, and the SST file includes a plurality of row data of the data shard. Taking the database node Node1 shown in FIG. 1 as an example, Node1 stores a plurality of SST files corresponding to a plurality of data shards managed by Node1, such as the SST files File1, File2, …, Filem shown in FIG. 1. The subscript m is the total number of the plurality of SST files. Each data shard in the plurality of data shards corresponds to one or more files in the plurality of SST files. m
[0047] In practice, SST can also be referred to as SSTable, which is a file format for storing and managing data, capable of sorting key-value pairs by key, and being divided into multiple fixed-size blocks when writing. The fixed size may include, but is not limited to, 64KB (Kilobyte). Each SST file includes several such blocks (as shown in the first data block in FIG. 1). In one example, the block can be referred to as a macro block. SST, as one of the core components of the underlying storage engine, has the characteristics of efficient reading, fast lookup, and persistence, and can provide better performance and reliability in massive data scenarios. In addition, the distributed database 101 can optimize the write operation of SST by using the LSM-Tree structure to achieve high throughput and low latency.
[0048] To ensure that the distributed database 101 can quickly recover and continue to provide services when failures or errors occur, during the data backup phase, for the database nodes in the distributed database 101 that need to perform data backup, such as the database node Node1 shown in FIG. 1, the data backup recovery system 102 can write each first data block to be backed up in Node1 to the backup medium 103, and construct a first index tree for each SST file corresponding to the first data block to the backup medium 103, and write the second metadata of each SST file to the backup medium 103. Wherein, the first index tree is constructed based on the first metadata of each first data block of the corresponding SST file and the first address on the backup medium 103. The first metadata may include, for example, the identification and primary key range of the corresponding first data block. The second metadata includes the root node address of the first index tree of the corresponding SST file. Then, the data backup recovery system 102 can construct a second index tree based on the second address of each second metadata on the backup medium 103, and write it to the backup medium 103 for data recovery.
[0049] When Node1 fails or data is damaged and needs to be recovered, during the data recovery phase, the data backup recovery system 102 can quickly recover Node1 based on the second index tree stored in the backup medium 103. Taking the backup of the first data block of each SST file File1, File2, …, File m For example, after completing the data backup of Node1, the backup medium 103 will store the second index tree, and File1, File2, …, File m Each first data block, first index tree, and second metadata. Wherein, FIG. 2 is a schematic diagram of the data recovery and query process of the distributed database in the embodiment of the present specification.
[0050] As shown in Figure 2, when data recovery is required for several data fragments of Node1, the data backup and recovery system 102 can obtain the second address of the second metadata of the SST files corresponding to each of the several data fragments on the backup medium 103 from the second index tree stored in the backup medium 103. For example, it can obtain the second address of File1, File2, ..., File... m Each second metadata location is located at a second address on backup medium 103. Then, data backup and recovery system 102 can retrieve the second metadata stored at each second address from backup medium 103. Then, for each retrieved second metadata location, data backup and recovery system 102 can construct an SST file in Node 1 that includes the second metadata location, so that the root node address in the SST file can be used for remote data retrieval. For example, SST files File′1, File′2, ..., File′ can be constructed in Node 1. m , where File′ i Including File i The second metadata element, with index i being a natural number in the range [1, m]. By employing the fast recovery process described herein, it is not necessary for the distributed database to support data queries only after all data has been fully recovered. This allows the distributed database to become available more quickly and reduces the overall recovery time and resource consumption. Fast recovery enables users to continue executing queries while the restoration process is in progress, thereby improving the response speed and efficiency of the distributed database, enhancing its disaster recovery capabilities, and providing users with a better user experience and performance optimization.
[0051] During the data query phase, Node1, having completed data recovery, can perform remote data queries based on received data query requests. These requests can include the table name and primary key range. Specifically, as shown in Figure 2, Node1 can determine the target SST file to access based on the query request. This target SST file corresponds to the target data shard of the table, and the shard includes rows whose primary keys fall within the specified range. Then, in response to the target SST file including second metadata, Node1 can read the target first index tree corresponding to the root node address in the second metadata from the backup medium 103, and determine the target first data block to access based on the primary key range and the target first index tree. Next, Node1 can retrieve the target first data block from the backup medium 103 based on the first address of the target first data block recorded in the target first index tree, and determine the query result based on the target first data block.
[0052] The following sections, using specific examples, will describe the data backup process, data recovery process, and data query process of a distributed database.
[0053] FIG. 3 is a flow chart of a data backup method of a distributed database according to an embodiment of the present specification, which can be performed by a data backup recovery system (e.g., the data backup recovery system 102 shown in FIG. 1 and FIG. 2). The method comprises steps S301-S305 as shown below.
[0054] As shown in FIG. 3, in step S301, a plurality of first data blocks to be backed up in a database node of a distributed database are written to a backup medium, the plurality of first data blocks being derived from a plurality of SST files corresponding to a plurality of data shards managed by the database node.
[0055] The plurality of data shards can be all or part of the data shards managed by the database node. The plurality of SST files comprises all or part of the SST files corresponding to each data shard in the plurality of data shards. The plurality of first data blocks comprises all or part of the first data blocks included in each SST file in the plurality of SST files.
[0056] It should be noted that in step S301, the plurality of first data blocks can be copied from the database node to the backup medium in response to receiving a data backup request for the plurality of first data blocks. The data backup request can comprise the respective identifiers of the plurality of first data blocks, the identifiers of the SST files in which the respective first data blocks are located, and the identifiers of the data shards corresponding to the SST files. Further, the data backup request can further comprise the node identifier of the database node and / or the identifier of the backup medium.
[0057] Next, in step S303, for each target SST file in the plurality of SST files, a first index tree is constructed based on the first metadata of the respective first data blocks and the first addresses on the backup medium, and the second metadata of the target SST file is written to the backup medium, the second metadata comprising the root node address of the first index tree.
[0058] Specifically, for each target SST file in the plurality of SST files, after each first data block included in the target SST file in the plurality of first data blocks is written to the backup medium, first metadata of the first data block stored locally by the database node can be acquired, a first index tree is constructed based on the first metadata of the first data block and the first address on the backup medium, and the first index tree is written to the backup medium. The first metadata and the first address of the first data block are included in the first index tree. Then, second metadata of the target SST file stored locally by the database node can be acquired, a root node address of the first index tree is added to the second metadata, and the updated second metadata is written to the backup medium. Further, when the updated second metadata is written to the backup medium, the updated second metadata can be serialized, and the serialized second metadata is written to the backup medium.
[0059] It should be noted that the first address of the first data block on the backup medium can be the same size as the address of the first data block on the database node, but in different formats and can be distinguished by bits whether it belongs to the address on the backup medium or the address on the database node.
[0060] Then, in step S305, a second index tree is constructed based on the second address of each second metadata on the backup medium and written to the backup medium for data recovery.
[0061] Specifically, after the second metadata of the plurality of SST files is written to the backup medium, a second index tree can be constructed based on the second address of the second metadata of the plurality of SST files on the backup medium, and the second index tree is written to the backup medium. The second index tree includes the second address.
[0062] Further, the identifier of each data shard in the plurality of data shards can be recorded in a certain intermediate node of the second index tree, and the second address of the second metadata of each SST file corresponding to the data shard in the plurality of SST files can be recorded in a certain leaf node related to the intermediate node. Further, the root node of the second index tree can record the node identifier of the database node where the plurality of SST files are located. Thus, when subsequent recovery of the data shard of the database node is required, the second index tree corresponding to the database node can be queried in the backup medium based on the node identifier of the database node, and the second address of the second metadata of the SST file corresponding to the data shard is queried in the second index tree based on the identifier of the data shard, so that the SST file is executed based on the queried second address. fast recovery process.
[0063] In an embodiment, third metadata of the plurality of data shards stored locally by the database node can also be acquired, and each acquired third metadata can be written to the backup medium, so as to construct a second index tree based on the second address of each second metadata on the backup medium and the third address of each third metadata on the backup medium. The second index tree comprises the second address and the third address.
[0064] The scheme provided by the corresponding embodiment of FIG. 3 can write the plurality of first data blocks to be backed up in the database node of the distributed database to the backup medium in the data backup phase, and for each target SST file in the plurality of SST files corresponding to the plurality of first data blocks, construct a first index tree based on the first metadata and the first address on the backup medium of each first data block of the target SST file and write the first index tree to the backup medium, and write the second metadata of the target SST file to the backup medium, the second metadata comprising the root node address of the first index tree. Then, a second index tree can be constructed based on the second address of each second metadata on the backup medium and written to the backup medium for data recovery. By using this data backup process, when the SST file needs to be recovered subsequently, the second metadata of the SST file can be queried on the backup medium based on the second index tree, and then the second metadata of the SST file is recovered to the database node locally, so that the root node address in the second metadata is used for remote data query, so that the user can perform the query operation without restoring the backup data to the database node locally. Therefore, the scheme can make the distributed database available more quickly and reduce the time and resource consumption required for overall recovery.
[0065] In an embodiment, in order to improve the data backup efficiency, a plurality of backup tasks can be generated for each first data block to be backed up in the database node, and the plurality of backup tasks are executed in parallel to write each first data block to the backup medium.
[0066] Specifically, referring to FIG. 4, which is a flowchart of a data backup method of a distributed database in an embodiment of the present specification. The method can be executed by a data backup and recovery system (for example, the data backup and recovery system 102 shown in FIG. 1 and FIG. 2). The method comprises the following steps S401-S407.
[0067] As shown in FIG. 4, in step S401, a plurality of backup tasks are generated for a plurality of first data blocks to be backed up in a database node of a distributed database; wherein a single backup task comprises the identification of a plurality of first data blocks in the plurality of first data blocks, and the identification of a backup medium.
[0068] Specifically, the plurality of first data blocks can be divided into a plurality of data block groups based on the number of the plurality of first data blocks and a first preset value, and one backup task can be generated for each data block group in the plurality of data block groups. At least part of the data block groups in the plurality of data block groups each include the first preset value of first data blocks.
[0069] Then, in step S403, the plurality of first data blocks are written into the backup medium by executing the plurality of backup tasks in parallel.
[0070] Specifically, the plurality of backup tasks can be assigned to a plurality of task execution threads, so that the plurality of task execution threads execute the assigned backup tasks. For each backup task in the plurality of backup tasks, the first data blocks responsible for backup by the backup task can be written into a data backup file corresponding to the backup task in the backup medium.
[0071] In an implementation, in order to reduce the number of accesses to the backup medium, thereby improving the data backup efficiency, the plurality of first data blocks can be cached in the memory of the database node, and for each backup task in the plurality of backup tasks, the first data blocks responsible for backup by the backup task cached in the memory can be written into the backup medium by executing the backup task in response to the cache space of the first data blocks reaching a preset threshold.
[0072] In step S405, for each target SST file in the plurality of SST files, the following sub-steps S4051-S4055 are executed.
[0073] In sub-step S4051, for each backup task in the plurality of backup tasks related to the target SST file, in response to each first data block responsible for backup by the backup task in the target SST file being written into the backup medium, an intermediate layer index tree of the target SST file is constructed based on the first metadata of the first data block and the first address on the backup medium.
[0074] As an example, after each backup task is generated, for each SST file involved in the backup task, an index block builder corresponding to the SST file can be created for the backup task. In such a case, for each backup task related to the target SST file, in response to each first data block responsible for backup by the backup task in the target SST file being written into the backup medium, an intermediate layer index tree of the target SST file is constructed by the index block builder corresponding to the target SST file of the backup task based on the first metadata of the first data block and the first address on the backup medium. The intermediate layer index tree includes the first metadata and the first address.
[0075] Then, in sub-step S4053, each intermediate layer index tree of the target SST file is aggregated into the first index tree and written to the backup medium.
[0076] As an example, after learning that the above plurality of first data blocks are to be backed up, an index builder can be created for each of the above SST files, so that each intermediate layer index tree of an SST file is aggregated into a first index tree by the index builder created for the SST file.
[0077] It should be noted that by first generating the intermediate layer index tree of the target SST file and then aggregating each intermediate layer index tree of the target SST file into the first index tree, it is not necessary to wait until each first data block of the target SST file is completed before performing the index tree construction process for the target SST file, which can shorten the overall construction time of the first index tree and thus effectively improve the data backup efficiency.
[0078] Then, in sub-step S4055, the second metadata of the target SST file is written to the backup medium, and the second metadata includes the root node address of the first index tree.
[0079] The second metadata of the target SST file can be serialized, and the serialized second metadata can be written to the backup medium.
[0080] After writing the second metadata of each of the above SST files to the backup medium by performing step S405, step S407 can be performed to construct a second index tree.
[0081] Specifically, in step S407, based on the second address of each second metadata on the backup medium, a second index tree is constructed and written to the backup medium for data recovery.
[0082] As an example, after performing sub-step S4055, address information including the second address of the second metadata of the target SST file can also be written to a target position in the data backup file corresponding to the backup task related to the target SST file. The target position includes but is not limited to the tail of the data backup file. Based on this, the address information recorded at the target position in the data backup file corresponding to each of the above plurality of backup tasks can be summarized, and a second index tree can be constructed based on the summary result. The construction process of the second index tree can be performed by a thread responsible for establishing an index.
[0083] Further, the third metadata of the data slices can also be written into the backup medium. In this case, the address information written at the target position in the data backup file corresponding to the backup task of the target SST file can include the third address of the third metadata of the data slices corresponding to the target SST file on the backup medium, in addition to the second address of the second metadata of the target SST file.
[0084] The scheme provided by the corresponding embodiments of FIG. 4 can generate a plurality of backup tasks for the plurality of first data blocks to be backed up in the database node of the distributed database, and write the plurality of first data blocks into the backup medium by executing the plurality of backup tasks in parallel, so as to improve the backup efficiency of the plurality of first data blocks. In addition, the scheme can first generate the intermediate layer index trees of the SST file, and then aggregate the intermediate layer index trees of the SST file into the first index tree, so that the index tree construction process for the SST file does not need to wait until all the first data blocks of the SST file are completed. Thus, the overall construction time of the first index tree can be shortened, thereby further improving the data backup efficiency.
[0085] The foregoing describes the data backup process of the distributed database provided by the embodiments of the present specification in combination with FIG. 3 and FIG. 4. Next, the data recovery process of the distributed database is described.
[0086] Referring to FIG. 5, it is a flowchart of the data recovery method of the distributed database in the embodiments of the present specification. The method can be executed by a data backup recovery system (for example, the data backup recovery system 102 shown in FIG. 1 and FIG. 2). The method includes the following steps S501-S503.
[0087] As shown in FIG. 5, in step S501, for a plurality of data slices to be recovered in the database node of the distributed database, the second address of the second metadata of the SST file corresponding to each of the plurality of data slices on the backup medium is obtained from the second index tree stored in the backup medium; the second metadata includes the root node address of the first index tree on the backup medium, and the first index tree is constructed based on the first metadata of the plurality of first data blocks of the SST file and the first address on the backup medium.
[0088] As an example, the root node of the second index tree corresponding to the database node can record the node identification of the database node, the identification of each data shard of the data shards completed by the database node can be recorded in an intermediate node of the second index tree, and the second address of the second metadata of the SST file corresponding to the data shard can be recorded in a leaf node related to the intermediate node. In such a case, for a database node in the distributed database that needs to be data restored, the second index tree corresponding to the database node can be queried in the backup medium based on the node identification of the database node, and then the second address of the second metadata of the SST file corresponding to each of the data shards to be restored by the database node can be obtained from the second index tree based on the identification of the data shards.
[0089] Next, in step S503, for each target address in the obtained second addresses, the target second metadata stored at the target address is obtained from the backup medium, and a first SST file including the target second metadata is constructed in the database node; so that the root node address in the first SST file is used for remote data query.
[0090] In constructing the first SST file, an empty second SST file can be first constructed in the database node, and then the target second metadata is written into the second SST file, and the updated second SST file is taken as the first SST file. Further, in the case that the target second metadata is serialized second metadata, in writing the target second metadata into the second SST file, the target second metadata can be first deserialized, and then the deserialized target second metadata is written into the second SST file. Taking the data restoration of the SST file File1 shown in FIG. 2 as an example, after obtaining the serialized second metadata of File1 from the backup medium 103, an empty SST file File'1 can be first constructed in the database node Node1, then the second metadata is deserialized, and the deserialized second metadata is written into File'1. File'1 containing the second metadata acts as a restored file of File1.
[0091] In an embodiment, in order to further improve the data restoration efficiency, a plurality of restoration tasks can be generated for the above-mentioned plurality of data shards, and the database node is data restored by parallel execution of the plurality of restoration tasks. Wherein the plurality of restoration tasks include the identification of different data shards in the above-mentioned plurality of data shards, and the identification of the backup medium.
[0092] It should be noted that when the plurality of recovery tasks are generated for the plurality of data shards, the plurality of data shards can be divided into a plurality of shard groups based on the number of the plurality of data shards and the second preset value, and one recovery task is generated for each of the divided shard groups. At least some of the plurality of shard groups include the second preset number of data shards. In addition, for each of the plurality of recovery tasks, the second address of the second metadata of the SST file corresponding to the data shard to be recovered by the recovery task can be obtained from the second index tree stored in the backup medium by executing the recovery task, and then the target second metadata stored at the second address can be obtained from the backup medium, and the first SST file including the target second metadata can be constructed in the database node.
[0093] In an implementation, in order to improve the overall data query efficiency, after the first SST file is constructed, a target mark can be configured for the first SST file, the target mark being used to represent that the first data block of the first SST file references from the backup medium. If the first SST file is accessed in the subsequent data query stage, based on the target mark configured for the first SST file, it can be quickly known that the first SST file includes the second metadata, and the first data block thereof references from the backup medium, so it is not necessary to read and identify the file content of the first SST file to determine whether the first data block of the SST file references from the backup medium, thereby helping to improve the overall data query efficiency.
[0094] The scheme provided by the embodiment corresponding to FIG. 5 can make the root node address in the second metadata of the SST file corresponding to the data shard to be recovered used to implement remote data query, so that the first data block of the SST file does not need to be recovered. Therefore, the scheme can realize fast recovery, can make the distributed database available more quickly, and can reduce the time and resource consumption required for overall recovery.
[0095] Next, in combination with FIG. 6, the data query process of the distributed database provided by the embodiment of the present specification will be introduced. FIG. 6 is a flowchart of a data query method of a distributed database in the embodiment of the present specification, the method is executed by a database node of the distributed database, and includes steps S601-S607 as follows.
[0096] As shown in FIG. 6, in step S601, a data query request is received, which includes the table name and the primary key range of the data table.
[0097] The data query request can be sent by a user through a user device or sent by another device, which is not limited herein. The data query request can further include other information, such as a field name of a field to be queried, etc.
[0098] In step S603, based on the data query request, a target SST file to be accessed is determined, which corresponds to a target data shard of the data table and includes row data whose primary keys are within the primary key range.
[0099] As an example, based on the data query request, a target data shard to be accessed can be determined in each data shard of the data table, which includes row data whose primary keys are within the primary key range. For example, each data shard is configured with a primary key range, and based on the primary key range of each data shard and the primary key range in the data query request, the target data shard can be determined. The intersection between the primary key range of the target data shard and the primary key range in the data query request is not empty. Then, based on the primary key range of each SST file corresponding to the target data shard and the primary key range in the data query request, the target SST file can be determined in each SST file. The intersection between the primary key range of the target SST file and the primary key range in the data query request is not empty.
[0100] After the target SST file to be accessed is determined, it can be further determined whether the target SST file includes the second metadata. For example, by reading and identifying the file content of the target SST file, it can be determined whether the target SST file includes the second metadata. For another example, if a target mark is configured for the file to be recovered (such as the first SST file mentioned above) in the data recovery phase, it can be determined whether the target SST file includes the second metadata by determining whether the target SST file is configured with the target mark. If it is determined that the target SST file does not include the second metadata, it can be known that the target SST file is an SST file originally local to the database node, and local data query can be performed based on the target SST file. If it is determined that the target SST file includes the second metadata, it can be known that the target SST file is a file constructed when data recovery is performed, and remote data query can be performed by executing steps S605 and S607.
[0101] In step S605, in response to the target SST file including the second metadata, a target first data block to be accessed is determined based on the primary key range and the target first index tree in the backup medium; the second metadata corresponds to an SST file originally local to the database node and includes a root node address of the target first index tree, and the target first index tree is constructed based on the first metadata of a plurality of first data blocks of the original SST file and the first addresses on the backup medium.
[0102] Specifically, the target first index tree can be queried in the backup medium based on the root node address in the second metadata, and then the target first data block to be accessed can be determined based on the primary key range in the data query request and each first metadata recorded in the target first index tree. The target first data block includes row data whose primary key is in the primary key range.
[0103] In step S607, the target first data block is obtained from the backup medium based on the first address of the target first data block, and the query result is determined based on the target first data block.
[0104] In practice, in order to better support data compression, fast reading and writing, etc., a single first data block can be split into several second data blocks. The second data block can be referred to as a microblock. In the case where a single first data block includes several second data blocks, after the target first data block is obtained from the backup medium, the target second data block to be accessed can be determined in the target first data block based on the primary key range in the data query request, and the query result is determined based on the target second data block. In addition, after the query result is determined, the query result can be returned.
[0105] The scheme provided by the embodiment corresponding to FIG. 6 can achieve fast remote data query by determining the target first data block to be accessed based on the primary key range in the data query request and the target first index tree in the backup medium corresponding to the root node address included in the second metadata in response to the target SST file including the second metadata, then obtaining the target first data block from the backup medium based on the first address of the target first data block on the backup medium recorded in the target first index tree, and determining the query result based on the target first data block. In addition, the root node address included in the second metadata restored to the local of the database node is used for remote data query, so that users can perform query operations without restoring the backup data to the local of the database node. Thus, the scheme can make the distributed database available faster and reduce the time and resource consumption required for overall recovery.
[0106] In an embodiment, in order to further improve the data query efficiency, a data query process as shown in FIG. 7 can be used. FIG. 7 is a flowchart of a data query method of a distributed database according to an embodiment of the present specification. The method is performed by a database node of the distributed database, and includes steps S701-S715 as follows.
[0107] As shown in FIG. 7, in step S701, a data query request is received, which includes the table name of a data table and a primary key range.
[0108] At step S703, based on the data query request, a target SST file to be accessed is determined, which corresponds to a target data shard of the data table, and the shard includes row data whose primary keys are within the primary key range.
[0109] At step S705, in response to the target SST file including the second metadata, a target first data block to be accessed is determined based on the primary key range and the target first index tree in the backup medium; the second metadata corresponds to an original SST file of the database node and includes a root node address of the target first index tree, and the target first index tree is constructed based on the first metadata of the first data blocks of the original SST file and the first addresses on the backup medium.
[0110] Wherein, for the explanation of steps S701-S705, please refer to the related description of steps S601-S605 in the foregoing, which will not be repeated here.
[0111] At step S707, it is determined whether the target first data block is cached locally in the database node.
[0112] As an example, the database node can cache the first data block associated with the first address of the first data block on the backup medium locally after obtaining the first data block from the backup medium each time. In such a case, based on the first address of the target first data block, the first data block associated with the first address can be searched in the locally cached first data block, and based on the search result, it is determined whether the target first data block is cached locally. If it is determined that the target first data block is not cached locally, step S709 can be performed. If it is determined that the target first data block is cached locally, step S711 can be performed.
[0113] At step S709, in response to the determination result of step S707 being no, the target first data block is obtained from the backup medium based on the first address of the target first data block.
[0114] Wherein, after obtaining the target first data block from the backup medium, steps S713 and S715 can be performed.
[0115] At step S711, in response to the determination result of step S707 being yes, the target first data block cached locally is obtained.
[0116] Wherein, after obtaining the target first data block cached locally, step S713 can be performed subsequently.
[0117] At step S713, the query result is determined based on the target first data block.
[0118] At step S715, the target first data block obtained from the backup medium is cached to the database node locally.
[0119] The scheme provided by the corresponding embodiment of FIG. 7 can not only achieve the technical effects of the scheme provided by the corresponding embodiment of FIG. 6, but also accelerate the performance of remote query by caching the first data blocks obtained from the backup medium.
[0120] According to the foregoing description, the scheme provided by the embodiments of the present specification can improve key indicators such as data recovery, index establishment and query performance, and has wide application potential in a distributed system environment. The scheme can provide a fast recovery function under a distributed shared nothing database architecture, and ensure that the distributed database can quickly recover and continue to provide services when a fault or error occurs.
[0121] FIG. 8 is a data backup device of a distributed database in an embodiment of the present specification, which can be applied to a data backup and recovery system. The device comprises: a first backup unit 801 configured to write a plurality of first data blocks to be backed up in a database node of a distributed database into a backup medium, the plurality of first data blocks being derived from a plurality of SST files corresponding to a plurality of data shards managed by the database node; a second backup unit 802 configured to, for each target SST file in the plurality of SST files, construct a first index tree based on first metadata of each first data block of the target SST file and a first address of the first data block on the backup medium, and write the first index tree into the backup medium, and write second metadata of the target SST file into the backup medium, the second metadata comprising a root node address of the first index tree; and a third backup unit 803 configured to construct a second index tree based on a second address of each second metadata on the backup medium, and write the second index tree into the backup medium for data recovery.
[0122] In an implementation, the first backup unit 801 can be further configured to: generate a plurality of backup tasks for the plurality of first data blocks; wherein a single backup task comprises an identifier of a plurality of first data blocks in the plurality of first data blocks, and an identifier of the backup medium; and write the plurality of first data blocks into the backup medium by executing the plurality of backup tasks in parallel.
[0123] In an implementation, the device can further comprise: a cache unit (not shown in the figure) configured to cache the plurality of first data blocks in a memory of the database node; and the first backup unit 801 can be further configured to: for each backup task in the plurality of backup tasks, in response to an occupied space of the first data block cached in the memory and responsible for backup by the backup task reaching a preset threshold, write the first data block cached in the memory into the backup medium by executing the backup task.
[0124] In an embodiment, the second backup unit 802 can be further configured to, for each backup task of the plurality of backup tasks related to the target SST file, in response to each first data block responsible for backup by the backup task being written into the backup medium, construct an intermediate layer index tree of the target SST file based on the first metadata of the first data block and the first address on the backup medium; and aggregate each intermediate layer index tree of the target SST file into the first index tree.
[0125] In an embodiment, the apparatus can further comprise a fourth backup unit (not shown in the figure) configured to write the third metadata of the plurality of data shards into the backup medium; and the third backup unit 803 can be further configured to construct the second index tree based on the second address of each second metadata on the backup medium and the third address of each third metadata on the backup medium.
[0126] In an embodiment, the first backup unit 801 can be further configured to, for each backup task of the plurality of backup tasks, write each first data block responsible for backup by the backup task into a data backup file corresponding to the backup task in the backup medium by executing the backup task.
[0127] In an embodiment, the second backup unit 802 can be further configured to write address information comprising the second address of the second metadata of the target SST file at a target position in the data backup file corresponding to the backup task related to the target SST file; and the third backup unit 803 can be further configured to aggregate the address information recorded at the target position in the data backup file corresponding to each of the plurality of backup tasks, and construct the second index tree based on the aggregation result.
[0128] FIG. 9 is a data recovery apparatus of a distributed database in an embodiment of the present specification, which can be applied to a data backup recovery system. The apparatus comprises: an acquisition unit 901 configured to, for a plurality of data shards to be recovered by a database node of a distributed database, acquire the second address of the second metadata of an SST file corresponding to each of the plurality of data shards on the backup medium from the second index tree stored in the backup medium; the second metadata comprises a root node address of a first index tree on the backup medium, the first index tree being constructed based on the first metadata of a plurality of first data blocks of the SST file and the first address on the backup medium; and a data recovery unit 902 configured to, for each target address in the acquired second addresses, acquire target second metadata stored at the target address from the backup medium, and construct a first SST file comprising the target second metadata in the database node; so that the root node address in the first SST file is used for remote data query.
[0129] In an implementation, the apparatus can further comprise a generating unit (not shown in the figure) configured to generate a plurality of recovery tasks for the plurality of data shards, the plurality of recovery tasks comprising an identification of different data shards in the plurality of data shards and an identification of the backup medium; and perform data recovery on the database node by executing the plurality of recovery tasks in parallel.
[0130] In an implementation, the data recovery unit 902 can be further configured to: construct an empty second SST file in the database node; write the target second metadata into the second SST file, and use the updated second SST file as the first SST file.
[0131] FIG. 10 is a database node of a distributed database in an embodiment of the present specification. The database node comprises: a receiving unit 1001 configured to receive a data query request comprising a table name of a data table and a primary key range; a first determining unit 1002 configured to determine, based on the data query request, a target SST file to be accessed, which corresponds to a target data shard of the data table and comprises row data whose primary keys are within the primary key range; a second determining unit 1003 configured to determine, in response to the target SST file comprising second metadata, a target first data block to be accessed based on the primary key range and the target first index tree in the backup medium; the second metadata corresponds to an original SST file of the database node and comprises a root node address of the target first index tree, which is constructed based on first metadata of a plurality of first data blocks of the original SST file and first addresses on the backup medium; an obtaining unit 1004 configured to obtain the target first data block from the backup medium based on the first addresses of the target first data block; and a third determining unit 1005 configured to determine a query result based on the target first data block.
[0132] In an implementation, a single first data block comprises a plurality of second data blocks; the second determining unit 1003 can be further configured to determine, based on the primary key range, a target second data block to be accessed in the target first data block; and the third determining unit 1005 can be further configured to determine the query result based on the target second data block.
[0133] In an implementation, the second determining unit 1003 can be further configured to determine whether the target first data block is cached locally in the database node; and the obtaining unit 1004 can be further configured to obtain the target first data block from the backup medium based on the first addresses of the target first data block in response to a determination result being no.
[0134] In an implementation, the obtaining unit 1004 can be further configured to obtain the target first data block cached locally in the database node in response to the determination result being yes.
[0135] In an embodiment, the apparatus can further include a cache unit (not shown in the figure) configured to cache the target first data block locally to the database node after the obtaining unit 1004 obtains the target first data block from the backup medium.
[0136] The embodiments of the present disclosure further provide a computer readable storage medium, which stores a computer program, and the computer program causes a computer to execute the method shown in FIG. 3 to FIG. 7 when the computer program is executed in the computer.
[0137] The embodiments of the present disclosure further provide a computing device, which includes a memory and a processor, wherein the memory stores executable code, and the processor executes the executable code to implement the method shown in FIG. 3 to FIG. 7.
[0138] The embodiments of the present disclosure further provide a computer program product, which includes a computer program / instruction, and the computer program / instruction is executed by a processor to implement the method shown in FIG. 3 to FIG. 7.
[0139] Those skilled in the art should be aware that the functions described in the above one or more examples can be implemented in hardware, software, firmware, or any combination thereof. When implemented in software, the functions can be stored in or transmitted over as one or more instructions or code on a computer-readable medium.
[0140] In some cases, the actions or steps recited in the claims can be performed in a different order and still achieve desirable results. Additionally, the processes depicted in the figures do not necessarily require the particular order shown or sequential order in order to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous.
[0141] The above detailed description merely describes specific implementations, which are not intended to limit the scope of the embodiments disclosed in the present specification. The above detailed description sets forth what is considered to be the important or novel technical solutions of the embodiments disclosed in the present specification, and makes the best effort possible to describe the embodiments disclosed in the present specification accurately and completely. It should be appreciated that the description is merely described for the purposes of clear and complete explanation of the embodiments disclosed in the present specification and conveniently communicating the technical solutions of the embodiments disclosed in the present specification to those skilled in the art. Thus, for those skilled in the art, as long as the technical solutions disclosed in the present specification are not deviated from, various modifications and changes in form and detail can be made to the embodiments disclosed in the present specification. In summary, any and all modifications, equivalent replacements, improvements, and the like made to the embodiments disclosed in the present specification should be included in the scope of the embodiments disclosed in the present specification.
Claims
1. A method for data backup of a distributed database, comprising: writing, to a backup medium, a plurality of first data blocks to be backed up in a database node of the distributed database, the plurality of first data blocks being derived from a plurality of SST files corresponding to a plurality of data shards managed by the database node; for each target SST file of the plurality of SST files, constructing a first index tree based on first metadata of each first data block of the target SST file and a first address of the first data block on the backup medium, and writing the first index tree to the backup medium, and writing second metadata of the target SST file to the backup medium, the second metadata comprising a root node address of the first index tree; constructing a second index tree based on second addresses of the second metadata on the backup medium, and writing the second index tree to the backup medium for data recovery.
2. The method of claim 1, wherein, The writing, to a backup medium, a plurality of first data blocks to be backed up in a database node of the distributed database, comprises: generating a plurality of backup tasks for the plurality of first data blocks, wherein a single backup task comprises an identifier of a plurality of first data blocks of the plurality of first data blocks, and an identifier of the backup medium; writing, to the backup medium, the plurality of first data blocks by executing the plurality of backup tasks in parallel. 3.The method of claim 2, further comprising: caching the plurality of first data blocks in a memory of the database node; The writing, to the backup medium, the plurality of first data blocks by executing the plurality of backup tasks in parallel, comprises: for each backup task of the plurality of backup tasks, in response to an occupied space of each first data block cached in the memory and responsible for backup by the backup task reaching a preset threshold, writing, to the backup medium, the first data block cached in the memory by executing the backup task.
4. The method of claim 2, wherein, The constructing a first index tree based on first metadata of each first data block of the target SST file and a first address of the first data block on the backup medium, comprises: for each backup task of the plurality of backup tasks related to the target SST file, in response to each first data block of the target SST file and responsible for backup by the backup task being written to the backup medium, constructing an intermediate layer index tree of the target SST file based on first metadata of each first data block and a first address of the first data block on the backup medium; aggregating each intermediate layer index tree of the target SST file into a first index tree. 5.The method of claim 1, further comprising: writing third metadata of the plurality of data shards to the backup medium; The constructing a second index tree based on second addresses of the second metadata on the backup medium, comprises: constructing a second index tree based on second addresses of the second metadata on the backup medium and third addresses of the third metadata on the backup medium.
6. The method of claim 2, wherein, The writing, to the backup medium, the plurality of first data blocks by executing the plurality of backup tasks in parallel, comprises: For each backup task in the plurality of backup tasks, by executing the backup task, write each first data block of which the backup task is responsible for backup, into a data backup file corresponding to the backup task in the backup medium.
7. The method of claim 6, wherein, After writing the second metadata of the target SST file into the backup medium, further comprising: writing address information including the second address of the second metadata of the target SST file, at a target location in the data backup file corresponding to the backup task related to the target SST file; constructing a second index tree based on the second addresses of the second metadata on the backup medium, comprising: summarizing the address information recorded at the target locations in the data backup files corresponding to the plurality of backup tasks respectively, and constructing a second index tree based on the summary result.
8. A data recovery method of a distributed database, comprising: For a plurality of data shards to be recovered by a database node of the distributed database, obtaining, from a second index tree stored in a backup medium, second addresses of second metadata of ordered string table (SST) files corresponding to the plurality of data shards respectively; the second metadata includes a root node address of a first index tree on the backup medium, and the first index tree is constructed based on first metadata of a plurality of first data blocks of the SST files and first addresses on the backup medium; For each target address in the obtained second addresses, obtaining target second metadata stored at the target address from the backup medium, and constructing a first SST file including the target second metadata in the database node; so that the root node address in the first SST file is used for remote data query.
9. The method of claim 8, further comprising: generating a plurality of recovery tasks for the plurality of data shards, the plurality of recovery tasks including identifications of different data shards in the plurality of data shards and an identification of the backup medium; so that the database node is data-recovered by executing the plurality of recovery tasks in parallel.
10. The method of claim 8 or 9, wherein, The constructing, in the database node, of the first SST file including the target second metadata, comprises: constructing an empty second SST file in the database node; writing the target second metadata into the second SST file, and taking the updated second SST file as the first SST file.
11. A data query method of a distributed database, executed by a database node of the distributed database, the method comprising: receiving a data query request, which includes a table name of a data table and a primary key range; based on the data query request, determining a target ordered string table (SST) file to be accessed, which corresponds to a target data shard of the data table including row data with primary keys in the primary key range; in response to the target SST file including second metadata, determining a target first data block to be accessed based on the primary key range and a target first index tree in a backup medium; The second metadata corresponds to an original SST file of the database node and includes a root node address of the target first index tree, which is constructed based on first metadata of a plurality of first data blocks of the original SST file and first addresses on the backup medium; Based on the first address of the target first data block, the target first data block is obtained from the backup medium, and a query result is determined based on the target first data block.
12. The method of claim 11, wherein, A single first data block includes a plurality of second data blocks; The method further includes: Based on the primary key range, a target second data block to be accessed is determined in the target first data block; The determination of the query result based on the target first data block includes: The query result is determined based on the target second data block.
13. The method of claim 11 or 12, further comprising: determining whether the target first data block is cached locally at the database node; The obtaining of the target first data block from the backup medium based on the first address of the target first data block includes: in response to a determination result being no, the target first data block is obtained from the backup medium based on the first address of the target first data block.
14. The method of claim 13, further comprising: in response to the determination result being yes, the target first data block cached locally is obtained.
15. The method of claim 13, wherein, After the target first data block is obtained from the backup medium, the method further includes: caching the target first data block locally at the database node.
16. A data backup apparatus of a distributed database, comprising: a first backup unit configured to write a plurality of first data blocks to be backed up in a database node of the distributed database to a backup medium, the plurality of first data blocks originating from a plurality of ordered string table (SST) files corresponding to a plurality of data shards managed by the database node; a second backup unit configured to, for each target SST file of the plurality of SST files, construct a first index tree based on first metadata of first data blocks of the target SST file and first addresses on the backup medium, and write the second metadata of the target SST file to the backup medium, the second metadata including a root node address of the first index tree; a third backup unit configured to construct a second index tree based on second addresses on the backup medium of the second metadata, and write the second index tree to the backup medium for data recovery.
17. A data recovery apparatus of a distributed database, comprising: an obtaining unit configured to, for a plurality of data shards of a database node of the distributed database to be recovered, obtain, from a second index tree stored in a backup medium, second addresses on the backup medium of second metadata of ordered string table (SST) files corresponding to the plurality of data shards respectively; the second metadata including a root node address on the backup medium of a first index tree constructed based on first metadata of a plurality of first data blocks of the SST files and first addresses on the backup medium. a data recovery unit configured to, for each target address in the obtained second addresses, obtain target second metadata stored at the target address from the backup medium, and construct a first SST file including the target second metadata in the database node; so that the root node address in the first SST file is used for remote data query.
18. A database node of a distributed database, comprising: a receiving unit configured to receive a data query request including a table name of a data table and a primary key range; a first determining unit configured to determine, based on the data query request, a target SST file to be accessed, which corresponds to a target data shard of the data table including row data with primary keys within the primary key range; a second determining unit configured to, in response to the target SST file including second metadata, determine, based on the primary key range and a target first index tree in a backup medium, a target first data block to be accessed; the second metadata corresponding to an original SST file of the database node and including a root node address of the target first index tree, the target first index tree being constructed based on first metadata of a plurality of first data blocks of the original SST file and first addresses on the backup medium; a retrieving unit configured to retrieve, based on first addresses of the target first data block, the target first data block from the backup medium; a third determining unit configured to determine a query result based on the target first data block.
19. A computing device comprising a memory and a processor, wherein, the memory stores executable code, and the processor executes the executable code to implement the method in any one of claims 1-15.
20. A computer program product, comprising computer programs / instructions, which, when executed by a processor, implement the method in any one of claims 1-15.
Citation Information
Patent Citations
Incremental backup and recovery method and system based on shared SST file
CN115617580A
Data backup method and device, data recovery method and device, medium and electronic equipment
CN116107811A
Multi-node concurrent mass file backup recovery method and system
CN117806873A
Data backup, recovery and query method and device for distributed database
CN118519827A
Data block based backup
US20160110258A1
Cited By
Metadata repair method and electronic device
CN122387753A