Data management method and device, program product, equipment and storage medium
By dynamically adjusting the merge mode and freezing strategy of database partitions and using statistical information to optimize the merge operation of data tables, the problem of data query performance degradation in the LSM-Tree storage engine is solved and a balance between resources and performance is achieved.
Patent Information
- Application Number
- CN202410947484.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-10-01
Smart Images

Figure CN118733635A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a data management method and apparatus, program product, device, and storage medium. Background Art
[0002] With the rapid development of the Internet and informatization, the generation of data is growing explosively, so the requirements for databases and their management are getting higher and higher. Distributed databases based on the LSM-Tree storage engine can insert, update, delete and other operations on data during the execution of the Data Manipulation Language (DML), but the deletion operation is only a logical mark deletion, and the data item will not be physically deleted until the merge operation is performed. This will seriously affect the performance of data queries when there are a large number of insertion and deletion operations in the database.
[0003] Although the merging of data items can reduce or overcome the degradation of data query performance caused by the above factors, the merging of data items will cause the consumption of computing resources and transmission resources. Therefore, it is critical to find a balance between resource consumption and query performance improvement. In related technologies, the merging operation of data items in the database is performed periodically, or started according to fixed indicators such as the number of ordered string tables, which only avoids resource consumption but does not improve data query performance. Summary of the invention
[0004] In view of this, one or more embodiments of the present specification provide a data management method and apparatus, a program product, a device, and a storage medium.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a data management method is proposed, the method comprising:
[0007] Obtain disk statistics information of a partition, wherein the disk statistics information is used to record relevant information of data of the partition in the disk;
[0008] Determining whether the partition meets the adaptive merging condition according to a merging threshold function in a merging mode of a data table to which the partition belongs and disk statistics of the partition;
[0009] If the partition meets the adaptive merging condition, a merging operation is performed on the partition according to a merging strategy in a merging mode of the data table to which the partition belongs.
[0010] In one or more embodiments of the present specification, the method further includes:
[0011] Obtain memory statistics information of the partition, wherein the memory statistics information is used to record relevant information of the data of the partition in the memory;
[0012] Determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the memory statistics information of the partition, or determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the disk statistics information and the memory statistics information of the partition;
[0013] If the partition meets the quick freezing condition, the data of the partition in the memory is frozen and dumped to the disk.
[0014] In one or more embodiments of this specification, obtaining disk statistics of a partition includes:
[0015] If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is obtained.
[0016] In one or more embodiments of the present specification, the method further includes:
[0017] If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is updated.
[0018] In one or more embodiments of the present specification, the disk statistics information includes at least one of the following:
[0019] The number of deleted rows, the number of updated rows, the ratio of update operations within a preset time, the number of ordered string tables, the number of slow queries, and the ratio of slow queries, where the slow query is a data query operation whose execution time exceeds a time threshold, and the slow query ratio is the ratio of the number of slow queries to the number of all data query operations;
[0020] The memory statistics information includes at least one of the following:
[0021] Active time of the memory data table, number of rolled back transactions, number of deleted rows, number of updated rows, ratio of update operations within the preset time, number of slow queries, and ratio of slow queries.
[0022] In one or more embodiments of the present specification, the disk statistics information is stored in the memory, the memory statistics information is stored in the memory; and / or,
[0023] The disk statistics information includes the latest disk statistics information within a preset time period and all disk statistics information after the last merge operation was performed.
[0024] In one or more embodiments of this specification, obtaining disk statistics of a partition includes:
[0025] If the partition meets the iteration requirements, disk statistics of the partition are obtained.
[0026] In one or more embodiments of the present specification, the merge mode of the data table to which the partition belongs is one of a plurality of preset merge modes, wherein, among the plurality of preset merge modes, the merge threshold functions, freeze threshold functions, and merge strategies of different merge modes are all different.
[0027] In one or more embodiments of the present specification, among the multiple preset merging modes, at least one of the following merging strategies is provided: a basic merging strategy, an advanced merging strategy, and an aggressive merging strategy;
[0028] The basic merging strategy only performs partition merging, and the partition merging is merging the baseline ordered string table and the incremental ordered string table at the same position in all database instances involved in the partition;
[0029] The advanced merge strategy performs partition merge when the time from the current time to the last partition merge reaches a preset period, and performs basic merge when the time from the current time to the last partition merge does not reach the preset period, wherein the basic merge is to merge the baseline ordered string table and the incremental ordered string table in the database instance;
[0030] The aggressive merge strategy includes performing only the basic merge.
[0031] In one or more embodiments of the present specification, the method further includes:
[0032] Taking the distributed database as the environment, the disk statistics information and the memory statistics information of the partition as the state, the merging mode change of the partition as the action, and the preset reward function, reinforcement learning training is performed until the convergence condition is met, so as to obtain the merging mode of each data table in the distributed database.
[0033] In one or more embodiments of the present specification, the partition merging mode change includes:
[0034] changing the merging mode of the partitions from one preset merging mode to another preset merging mode; and,
[0035] At least one of a merge threshold function, a freeze threshold function and a merge strategy in a merge mode of the partition is adjusted.
[0036] In one or more embodiments of the present specification, the reward function is used to characterize at least one of the following:
[0037] If the execution time of the data query operation decreases after the action is performed, a positive reward is given; if the execution time of the data query operation increases after the action is performed, a negative reward is given;
[0038] If the proportion of slow queries decreases after the action is executed, a positive reward is given; if the proportion of slow queries increases after the action is executed, a negative reward is given;
[0039] If the ratio between the logical rows scanned and the physical rows scanned in the data query operation increases after the action is executed, a positive reward is given; if the ratio between the logical rows scanned and the physical rows scanned in the data query operation decreases after the action is executed, a negative reward is given;
[0040] If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, or the number of ordered string tables decreases after the action is performed, a positive reward will be given. If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, and the number of ordered string tables increase after the action is performed, a negative reward will be given.
[0041] According to a second aspect of one or more embodiments of this specification, a data management device is provided, the device comprising:
[0042] An acquisition module, used for acquiring disk statistics information of a partition, wherein the disk statistics information is used for recording relevant information of data of the partition in the disk;
[0043] A determination module, used to determine whether the partition meets the adaptive merging condition according to a merge threshold function in a merge mode of a data table to which the partition belongs and disk statistics of the partition;
[0044] The merging module is used to perform a merging operation on the partition according to a merging strategy in a merging mode of the data table to which the partition belongs if the partition meets the adaptive merging condition.
[0045] In one or more embodiments of the present specification, the device further comprises a quick freezing module, configured to:
[0046] Obtain memory statistics information of the partition, wherein the memory statistics information is used to record relevant information of the data of the partition in the memory;
[0047] Determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the memory statistics information of the partition, or determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the disk statistics information and the memory statistics information of the partition;
[0048] If the partition meets the quick freezing condition, the data of the partition in the memory is frozen and dumped to the disk.
[0049] In one or more embodiments of this specification, the acquisition module is used to:
[0050] If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is obtained.
[0051] In one or more embodiments of the present specification, the device further includes an updating module, configured to:
[0052] If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is updated.
[0053] In one or more embodiments of the present specification, the disk statistics information includes at least one of the following:
[0054] The number of deleted rows, the number of updated rows, the ratio of update operations within a preset time, the number of ordered string tables, the number of slow queries, and the ratio of slow queries, where the slow query is a data query operation whose execution time exceeds a time threshold, and the slow query ratio is the ratio of the number of slow queries to the number of all data query operations;
[0055] The memory statistics information includes at least one of the following:
[0056] Active time of the memory data table, number of rolled back transactions, number of deleted rows, number of updated rows, ratio of update operations within the preset time, number of slow queries, and ratio of slow queries.
[0057] In one or more embodiments of the present specification, the disk statistics information is stored in the memory, the memory statistics information is stored in the memory; and / or,
[0058] The disk statistics information includes the latest disk statistics information within a preset time period and all disk statistics information after the last merge operation was performed.
[0059] In one or more embodiments of this specification, the acquisition module is used to:
[0060] If the partition meets the iteration requirements, disk statistics of the partition are obtained.
[0061] In one or more embodiments of the present specification, the merge mode of the data table to which the partition belongs is one of a plurality of preset merge modes, wherein, among the plurality of preset merge modes, the merge threshold functions, freeze threshold functions, and merge strategies of different merge modes are all different.
[0062] In one or more embodiments of the present specification, among the multiple preset merging modes, at least one of the following merging strategies is provided: a basic merging strategy, an advanced merging strategy, and an aggressive merging strategy;
[0063] The basic merging strategy only performs partition merging, and the partition merging is merging the baseline ordered string table and the incremental ordered string table at the same position in all database instances involved in the partition;
[0064] The advanced merge strategy performs partition merge when the time from the current time to the last partition merge reaches a preset period, and performs basic merge when the time from the current time to the last partition merge does not reach the preset period, wherein the basic merge is to merge the baseline ordered string table and the incremental ordered string table in the database instance;
[0065] The aggressive merge strategy includes performing only the basic merge.
[0066] In one or more embodiments of the present specification, the device further includes a training module for:
[0067] Taking the distributed database as the environment, the disk statistics information and the memory statistics information of the partition as the state, the merging mode change of the partition as the action, and the preset reward function, reinforcement learning training is performed until the convergence condition is met, so as to obtain the merging mode of each data table in the distributed database.
[0068] In one or more embodiments of the present specification, the partition merging mode change includes:
[0069] changing the merging mode of the partitions from one preset merging mode to another preset merging mode; and,
[0070] At least one of a merge threshold function, a freeze threshold function and a merge strategy in a merge mode of the partition is adjusted.
[0071] In one or more embodiments of the present specification, the reward function is used to characterize at least one of the following:
[0072] If the execution time of the data query operation decreases after the action is performed, a positive reward is given; if the execution time of the data query operation increases after the action is performed, a negative reward is given;
[0073] If the proportion of slow queries decreases after the action is executed, a positive reward is given; if the proportion of slow queries increases after the action is executed, a negative reward is given;
[0074] If the ratio between the logical rows scanned and the physical rows scanned in the data query operation increases after the action is executed, a positive reward is given; if the ratio between the logical rows scanned and the physical rows scanned in the data query operation decreases after the action is executed, a negative reward is given;
[0075] If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, or the number of ordered string tables decreases after the action is performed, a positive reward will be given. If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, and the number of ordered string tables increase after the action is performed, a negative reward will be given.
[0076] According to a third aspect of one or more embodiments of this specification, a computer program product is provided, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.
[0077] According to a fourth aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0078] processor;
[0079] a memory for storing processor-executable instructions;
[0080] The processor implements the method as described in the first aspect by running the executable instructions.
[0081] According to a fifth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.
[0082] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0083] The data management method provided in the embodiment of this specification obtains the disk statistics of the partition, and determines whether the partition meets the adaptive merge condition according to the merge threshold function in the merge mode of the data table to which the partition belongs and the disk statistics of the partition. If the partition meets the adaptive merge condition, the partition is merged according to the merge strategy in the merge mode of the data table to which the partition belongs. In this method, different merge modes can be set for the data table, so that the merge conditions of the data items in the data table are set by the merge threshold function in the merge mode, and the merge mode of the data items in the data table is set by the merge strategy in the merge mode; then the method can adapt to different data tables and start the data item merge under different conditions, and perform the data item merge in different ways. Different conditions lead to different data information concerned by the data item merge, different thresholds, etc., and different methods lead to different resources consumed by the data item merge. Therefore, the method can find a balance between resource consumption and query performance improvement to a certain extent, thereby significantly improving the data query performance of the database without increasing more resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0084] Figure 1 It is a schematic diagram of the structure of a distributed database provided by an exemplary embodiment.
[0085] Figure 2 It is a flowchart of a data management method provided by an exemplary embodiment.
[0086] Figure 3 It is a schematic flow chart of a rapid freezing method provided by an exemplary embodiment.
[0087] Figure 4 It is a control logic diagram of a data management method provided by an exemplary embodiment.
[0088] Figure 5 It is a structural schematic diagram of a device provided by an exemplary embodiment.
[0089] Figure 6 is a block diagram of a data management device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0090] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0091] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0092] First, some concepts involved in this specification are explained.
[0093] Log Structure Merge-Tree (LSM-Tree).
[0094] Memory data table: Memory Table (MemTable), usually in the form of B-Tree and Hash Table, is often used to represent the data structure organization of key-value storage in memory.
[0095] Sorted String Table: Sorted String Table, SSTable, represents static read-only data in the LSM-Tree storage engine.
[0096] Freeze: Convert the active MemTable to a frozen MemTable and prohibit new writes.
[0097] Dump: Organize the frozen MemTable data into an SSTable structure and write it to disk.
[0098] Compaction: Merge multiple SSTable files, delete duplicate keys, delete keys, update expired keys, and generate new SSTable files.
[0099] Buffer table: refers specifically to a type of table with frequent insertion and deletion (including update, which can be abstracted as deletion followed by insertion) under the LSM-Tree architecture, similar to the replacement of buffer data items; it is also commonly seen in the scenario of continuous dequeueing and queuing in the message queue, so it is also called Queuing table.
[0100] Baseline SSTable (Major SSTable): The SSTable on disk that stores the merged committed data.
[0101] Incremental SSTable (Mini SSTable): An SSTable on disk that stores unmerged incremental data, obtained by freezing and dumping a MemTable or merging multiple incremental SSTables.
[0102] SQL execution plan: A sequence of steps designed by a database to execute a SQL (Structured Query Language) query statement.
[0103] With the rapid development of the Internet and informatization, the generation of data is exploding, so the requirements for databases and their management are getting higher and higher. In the process of executing the data manipulation language (DML), the database can insert, update, delete and other operations on data, while the deletion operation is only a logical mark deletion. The data item will not be physically deleted until the merge operation is performed. This will seriously affect the performance of data query when there are a large number of insertion and deletion operations in the database, that is, the buffer table effect is generated: a table may have only dozens of rows of data items, but in fact millions of insertion and deletion operations have been performed, generating multiple versions of incremental data, which will lead to serious space amplification and read amplification, making the data query speed very slow. At the same time, the serious mismatch between the number of physical rows and the number of logical rows will affect the SQL execution plan obtained by the optimizer based on the cost calculation model, thereby causing a significant decline in SQL performance.
[0104] Although the merging of data items can reduce or overcome the degradation of data query performance caused by the above factors, namely the buffer table effect, the merging of data items will cause the consumption of computing resources and transmission resources. Therefore, it is critical to find a balance between resource consumption and query performance improvement. In related technologies, the merging operation of data items in the database is performed periodically, or started according to fixed indicators such as the number of ordered string tables, which only avoids resource consumption but does not improve data query performance.
[0105] Based on this, at least one embodiment of the present specification provides a data management method, which can configure a merge mode suitable for each data table in the database, so that the partitions of these data tables can start the merge operation at the timing specified by their merge mode, and perform the merge operation in the manner or strategy specified by the merge mode. For example, a balance can be found between resource consumption and query performance improvement, so that each data table can optimize the query performance through merge operations in a timely manner when the impact of the decline in query performance is greater than the resource consumption impact caused by the merge operation of the data table, and without causing excessive resource consumption.
[0106] This method can be applied to database management systems, such as Figure 1 The management system run by each database instance in the distributed database based on the LSM-Tree storage engine is shown.
[0107] Please refer to the attached Figure 2 , which exemplarily shows the process of the data management method, including steps S201 to S203.
[0108] In step S201, disk statistics information of a partition is obtained, wherein the disk statistics information is used to record relevant information of data of the partition in the disk.
[0109] The partition is any partition of any data table in the database. For example, the method can be for each partition of each data table in the database, and this step can obtain the disk statistics of each partition of each data table. Of course, if there is a start condition for obtaining the disk statistics of the partition, the disk statistics of the partition will be obtained only when the partition meets the start condition.
[0110] Exemplarily, the disk statistics information can be stored in the memory for easy access. For example, in a distributed database based on the LSM-Tree storage engine, during the execution of the Data Manipulation Language (DML), operations such as INSERT, DELETE, UPDATE, and SELECT on the memory data table, as well as the number of physical rows, the number of logical rows, and the number of minimum storage units (such as microblocks or pages) scanned for each query are recorded in the memory, and added to the disk statistics information when the memory data table is frozen and dumped as an ordered string table.
[0111] In another exemplary embodiment, the disk statistics include the latest disk statistics within a preset time period and all disk statistics after the last merge operation. The latest disk statistics within a preset time period can be called a recent value, and all disk statistics after the last merge operation can be called a cumulative value.
[0112] In another exemplary embodiment, the disk statistics are at least used to record the statistical results of data operations performed in the partition; for example, the disk statistics include at least one of the following: the number of deleted rows, the number of updated rows, the proportion of update operations within a preset time, the number of ordered string tables, the number of slow queries, and the proportion of slow queries. Among them, the number of deleted rows refers to the number of data rows deleted by all delete operations, the number of updated rows refers to the number of data rows updated by all update operations, the proportion of update operations refers to the proportion of the number of update operations in the number of all data operations, the slow query is a data query operation whose execution time exceeds a time threshold, and the slow query proportion is the proportion of the number of slow queries in the number of all data query operations.
[0113] As another example, if the data of the partition in the memory is frozen and dumped to the disk, the disk statistics of the partition are updated. In other words, after the memory data table in the memory is frozen and dumped to the disk to form an ordered string table, the data of the partition in the disk will change, so the disk statistics can be updated according to these changes.
[0114] In step S202, it is determined whether the partition meets the adaptive merging condition according to the merge threshold function in the merge mode of the data table to which the partition belongs and the disk statistical information of the partition.
[0115] The database is preset with multiple merge modes (Table Mode), and the merge mode at least includes a merge threshold function, which is used to set the conditions for merging data items in the data table. Different conditions lead to different data information concerned with the data item merge, different thresholds, etc. Among the preset multiple merge modes, the merge threshold functions of different merge modes are different, that is, the conditions for merging data items are different. The merge mode of the data table to which the partition belongs is one of the multiple preset merge modes.
[0116] For example, the merge threshold function is expressed as Among them, m is used to identify the merge mode, for example, it can be m1, m2, m3, m4, m5, etc. For disk statistics; when , determining that the partition meets the adaptive merging condition.
[0117] For example, the merge threshold function can characterize the scenarios that trigger adaptive merges, such as the tombstone scenario, that is, the ratio of updated and deleted rows within a preset time exceeds a certain range, or the inefficient read scenario, that is, the number of logical rows scanned within a preset time is lower than a certain percentage of the number of physical rows scanned.
[0118] In step S203, if the partition meets the adaptive merging condition, a merging operation is performed on the partition according to the merging strategy in the merging mode of the data table to which the partition belongs.
[0119] The merge mode at least includes a merge strategy, which is used to set the way to merge data items in the data table. Different ways will consume different resources for merging data items. Among the preset multiple merge modes, different merge modes have different merge strategies, that is, different ways to merge data items. The merge mode of the data table to which the partition belongs is one of the multiple preset merge modes.
[0120] Among the multiple preset merge modes, at least one of the following merge strategies is provided: a basic merge strategy, an advanced merge strategy and an aggressive merge strategy; wherein the basic merge strategy only performs partition merge (MediumCompaction), and the partition merge is to merge the baseline ordered string table and the incremental ordered string table at the same position in all database instances (i.e., database instances) involved in the partition; the advanced merge strategy performs partition merge when the duration from the current time to the last execution of the partition merge reaches a preset period, and performs basic merge (Meta Compaction) when the duration from the current time to the last execution of the partition merge does not reach the preset period, and the basic merge is to merge the baseline ordered string table and the incremental ordered string table in the database instance to generate a temporary basic ordered string table (Meta SSTable), which replaces the baseline ordered string table when querying; the aggressive merge strategy includes only performing the basic merge.
[0121] In the multiple preset merge modes, the difficulty of the conditions represented by the merge threshold function is adapted to the merge strategy, that is, when the conditions represented by the merge threshold function are difficult, the merge strategy is a basic merge strategy, when the conditions represented by the merge threshold function are moderately difficult, the merge strategy is an advanced merge strategy, and when the conditions represented by the merge threshold function are easy, the merge strategy is an aggressive merge strategy. For example, the difficulty of the conditions represented by the merge threshold function in merge modes m1, m2, m3, m4, and m5 decreases in sequence, the merge strategy in merge modes m1 and m2 is a basic merge strategy, the merge strategy in merge mode m3 is an advanced merge strategy, and the merge strategy in merge modes m4 and m5 is an aggressive merge strategy.
[0122] Based on the above content, if the merge strategy in the merge mode of the data table to which the partition belongs is a merge strategy, then in this step, a partition merge is performed on the partition; if the merge strategy in the merge mode of the data table to which the partition belongs is an advanced merge strategy, and the time length from the current time to the last execution of the partition merge reaches a preset period, then in this step, a partition merge is performed on the partition; if the merge strategy in the merge mode of the data table to which the partition belongs is an advanced merge strategy, and the time length from the current time to the last execution of the partition merge does not reach the preset period, then in this step, a basic merge is performed on the partition; if the merge strategy in the merge mode of the data table to which the partition belongs is an aggressive merge strategy, then in this step, a basic merge is performed on the partition.
[0123] In this method, different merge modes can be set for the data table, so that the conditions for merging data items in the data table are set with the merge threshold function in the merge mode, and the way of merging data items in the data table is set with the merge strategy in the merge mode; then the method can adapt to different data tables and start data item merging under different conditions, and execute data item merging in different ways. Different conditions lead to different data information concerned with data item merging, different thresholds, etc., and different ways lead to different resources consumed by data item merging. Therefore, this method can find a balance between resource consumption and query performance improvement to a certain extent, thereby significantly improving the data query performance of the database without increasing resource consumption.
[0124] In some embodiments of the present disclosure, Figure 2 The method flow shown can be started in at least one of the following ways:
[0125] Method 1: If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is obtained. That is, each time the memory data table of the partition in the memory is frozen and dumped to the disk to form an ordered string table, the disk statistics information of the partition is updated first, and then the attached operations are performed based on the updated disk statistics information. Figure 2 The method flow shown is used to determine whether the partitions need to be merged.
[0126] Method 2: If the partition meets the iteration requirements, obtain the disk statistics of the partition. Figure 2 The thread of the method process shown can continuously traverse each partition, and when traversing to a partition, the partition meets the iteration requirement, and then the attached partition is executed. Figure 2 The method flow shown is used to determine whether the partitions need to be merged.
[0127] In this embodiment, the attached program is started by at least one of the above methods. Figure 2 The method flow shown is used to determine whether partitions need to be adaptively merged at an appropriate time, thereby further improving the accuracy and pertinence of the merge operation and further improving the data query performance of the database.
[0128] In some embodiments of the present disclosure, the method further comprises: Figure 3 The quick freezing process shown includes steps S301 to S303.
[0129] In step S301, memory statistics information of a partition is obtained, wherein the memory statistics information is used to record relevant information of data of the partition in the memory.
[0130] The partition is any partition of any data table in the database. For example, the method may be for each partition of each data table in the database. Then, this step may obtain memory statistics information of each partition of each data table.
[0131] Exemplarily, the memory statistics information is stored in the memory for easy retrieval.
[0132] As another example, the memory statistics information includes at least one of the following: the active duration of the memory data table, the number of rolled back transactions, the number of deleted rows, the number of updated rows, the proportion of update operations within a preset duration, the number of slow queries, and the proportion of slow queries. Among them, the number of deleted rows refers to the number of data rows deleted by all delete operations, the number of updated rows refers to the number of data rows updated by all update operations, the proportion of update operations refers to the proportion of the number of update operations in the number of all data operations, the slow query is a data query operation whose execution time exceeds a time threshold, and the slow query proportion is the proportion of the number of slow queries in the number of all data query operations.
[0133] In step S302, whether the partition meets the quick freezing condition is determined based on the freezing threshold function in the merge mode of the data table to which the partition belongs and the memory statistics of the partition, or whether the partition meets the quick freezing condition is determined based on the freezing threshold function in the merge mode of the data table to which the partition belongs and the disk statistics and memory statistics of the partition.
[0134] The database is preset with a plurality of merge modes (Table Mode), and the merge mode at least includes a freezing threshold function, which is used to set the freezing condition of the memory data table in the memory. Different conditions lead to different data information concerned with freezing the memory data table (for example, some merge modes only concern data information in the memory statistics, while some merge modes concern data information including disk statistics in addition to the memory statistics), and different thresholds, etc. Among the preset multiple merge modes, the freezing threshold functions of different merge modes are different, that is, the freezing conditions of the memory data table are different. The merge mode of the data table to which the partition belongs is one of the multiple preset merge modes.
[0135] For example, the merge threshold function is expressed as Among them, m is used to identify the merge mode, for example, it can be m1, m2, m3, m4, m5, etc. For memory statistics; when When the partition meets the quick freezing condition, it is determined that the partition meets the quick freezing condition.
[0136] In step S303, if the partition meets the quick freezing condition, the data of the partition in the memory is frozen and dumped to the disk.
[0137] For example, after the memory data table of the partition in the memory is frozen and dumped to the disk, an ordered string table is formed.
[0138] This embodiment can adapt to different data tables and start fast freezing under different conditions, so that the memory data table that is prone to cause the buffer table effect can be frozen and dumped to the disk in time, so that it can be merged into the baseline ordered string table as soon as possible during the merge process, thereby reducing the degradation of data query performance caused by too many deletion operations from the source.
[0139] Of course, it is understandable that this method can also freeze and dump the memory data table when it reaches the memory threshold.
[0140] In some embodiments of the present disclosure, a merge mode can be configured for each data table in a database in the following manner: taking the distributed database as the environment, the disk statistics information and the memory statistics information of the partition as the state, changing the merge mode of the partition as the action, and performing reinforcement learning training with a preset reward function until the convergence condition is met, so as to obtain the merge mode of each data table in the distributed database.
[0141] Among them, the change of the partition merge mode may include: changing the partition merge mode from a preset merge mode to another preset merge mode; and adjusting at least one of the merge threshold function, the freeze threshold function and the merge strategy in the partition merge mode, for example, lowering / raising the merge cooling time threshold, lowering / raising the deletion row number threshold, lowering / raising the statistical information validity period, elimination rate, buffer pool size, raising / lowering the ratio of triggering basic merge during merge, etc., which is actually adjusting the freeze threshold function. and merge threshold function The execution strategy selects the point walk, but the direction is random.
[0142] The reward function is used to represent at least one of the following:
[0143] If the execution time of the data query operation is reduced after the action is executed, a positive reward is given; if the execution time of the data query operation is increased after the action is executed, a negative reward is given; preferably, the reward is calculated for data query operations with a higher execution frequency (for example, operations that account for more than 80% of the execution).
[0144] If the proportion of slow queries decreases after the action is executed, a positive reward is given; if the proportion of slow queries increases after the action is executed, a negative reward is given;
[0145] If the ratio between the logical rows scanned and the physical rows scanned in the data query operation increases after the action is executed, a positive reward is given; if the ratio between the logical rows scanned and the physical rows scanned in the data query operation decreases after the action is executed, a negative reward is given;
[0146] If the amount of data read and written by the disk (IO quantity) within the preset time, the number of write operations on the disk within the preset time, or the number of ordered string tables decreases after the action is performed, a positive reward will be given. If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, and the number of ordered string tables increase after the action is performed, a negative reward will be given.
[0147] Exemplarily, an intelligent agent is preset to generate actions according to the state in the environment; in reinforcement learning, actions can be generated according to the state in each iteration, and the reward value can be determined by using a reward function based on the impact of the action on the state, and the parameters of the intelligent agent are adjusted according to the reward value until the obtained reward value meets the convergence requirements. The merge mode changed by the action corresponding to the reward value that meets the convergence requirements is determined as the merge mode of the data table.
[0148] This embodiment determines the merging mode of each data table in the database by means of reinforcement learning, thereby improving the accuracy of the merging mode of the data tables, so that the method can be adapted to different databases and different data tables to achieve better results, thereby improving the scope of application of the method.
[0149] Of course, it is understandable that in this method, the user can also determine and configure the merging mode of each data table.
[0150] Please refer to the attached Figure 4 , which exemplarily shows the data management method obtained by combining the above multiple embodiments.
[0151] Among them, the frozen memory check thread can freeze the active MemTable and dump the Mini SSTable when the memory data table reaches the memory threshold, update the disk statistics of the partition, and then try to initiate a merge. Figure 2 The process shown determines whether to perform an adaptive merge on the partition.
[0152] The fast freezing scheduling thread can determine whether the partition meets the freezing condition based on the memory statistics and the freezing threshold function. Figure 3 The process shown in the figure determines whether to perform a quick freeze on the partition; if it is satisfied, the active MemTable is frozen, the Mini SSTable is dumped, the disk statistics of the partition are updated, and then an attempt is made to initiate a merge, that is, by attaching Figure 2 The process shown determines whether to perform an adaptive merge on the partition.
[0153] The partition merge scheduling thread can, when iterating to each partition, use the attached Figure 2 The process shown determines whether to perform an adaptive merge on the partition.
[0154] Figure 5 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 5 At the hardware level, the device includes a processor 502, an internal bus 504, a network interface 506, a memory 508, and a non-volatile memory 510, and may also include hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 502 reading the corresponding computer program from the non-volatile memory 510 into the memory 508 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0155] Please refer to Figure 6 , the data management device can be used for Figure 5 The device shown in the figure can realize the technical solution of this specification. The data management device can include:
[0156] An acquisition module 601 is used to acquire disk statistics information of a partition, wherein the disk statistics information is used to record relevant information of data of the partition in the disk;
[0157] A determination module 602 is used to determine whether the partition meets the adaptive merging condition according to a merge threshold function in a merge mode of the data table to which the partition belongs and disk statistics of the partition;
[0158] The merging module 603 is configured to perform a merging operation on the partition according to a merging strategy in a merging mode of the data table to which the partition belongs if the partition meets the adaptive merging condition.
[0159] In one or more embodiments of the present specification, the device further comprises a quick freezing module, configured to:
[0160] Obtain memory statistics information of the partition, wherein the memory statistics information is used to record relevant information of the data of the partition in the memory;
[0161] Determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the memory statistics information of the partition, or determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the disk statistics information and the memory statistics information of the partition;
[0162] If the partition meets the quick freezing condition, the data of the partition in the memory is frozen and dumped to the disk.
[0163] In one or more embodiments of this specification, the acquisition module is used to:
[0164] If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is obtained.
[0165] In one or more embodiments of the present specification, the device further includes an updating module, configured to:
[0166] If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is updated.
[0167] In one or more embodiments of the present specification, the disk statistics information includes at least one of the following:
[0168] The number of deleted rows, the number of updated rows, the ratio of update operations within a preset time, the number of ordered string tables, the number of slow queries, and the ratio of slow queries, where the slow query is a data query operation whose execution time exceeds a time threshold, and the slow query ratio is the ratio of the number of slow queries to the number of all data query operations;
[0169] The memory statistics information includes at least one of the following:
[0170] Active time of the memory data table, number of rolled back transactions, number of deleted rows, number of updated rows, ratio of update operations within the preset time, number of slow queries, and ratio of slow queries.
[0171] In one or more embodiments of the present specification, the disk statistics information is stored in the memory, the memory statistics information is stored in the memory; and / or,
[0172] The disk statistics information includes the latest disk statistics information within a preset time period and all disk statistics information after the last merge operation was performed.
[0173] In one or more embodiments of this specification, the acquisition module is used to:
[0174] If the partition meets the iteration requirements, disk statistics of the partition are obtained.
[0175] In one or more embodiments of the present specification, the merge mode of the data table to which the partition belongs is one of a plurality of preset merge modes, wherein, among the plurality of preset merge modes, the merge threshold functions, freeze threshold functions, and merge strategies of different merge modes are all different.
[0176] In one or more embodiments of the present specification, among the multiple preset merging modes, at least one of the following merging strategies is provided: a basic merging strategy, an advanced merging strategy, and an aggressive merging strategy;
[0177] The basic merging strategy only performs partition merging, and the partition merging is merging the baseline ordered string table and the incremental ordered string table at the same position in all database instances involved in the partition;
[0178] The advanced merge strategy performs partition merge when the time from the current time to the last partition merge reaches a preset period, and performs basic merge when the time from the current time to the last partition merge does not reach the preset period, wherein the basic merge is to merge the baseline ordered string table and the incremental ordered string table in the database instance;
[0179] The aggressive merge strategy includes performing only the basic merge.
[0180] In one or more embodiments of the present specification, the device further includes a training module for:
[0181] Taking the distributed database as the environment, the disk statistics information and the memory statistics information of the partition as the state, the merging mode change of the partition as the action, and the preset reward function, reinforcement learning training is performed until the convergence condition is met, so as to obtain the merging mode of each data table in the distributed database.
[0182] In one or more embodiments of the present specification, the partition merging mode change includes:
[0183] changing the merging mode of the partitions from one preset merging mode to another preset merging mode; and,
[0184] At least one of a merge threshold function, a freeze threshold function and a merge strategy in a merge mode of the partition is adjusted.
[0185] In one or more embodiments of the present specification, the reward function is used to characterize at least one of the following:
[0186] If the execution time of the data query operation decreases after the action is performed, a positive reward is given; if the execution time of the data query operation increases after the action is performed, a negative reward is given;
[0187] If the proportion of slow queries decreases after the action is executed, a positive reward is given; if the proportion of slow queries increases after the action is executed, a negative reward is given;
[0188] If the ratio between the logical rows scanned and the physical rows scanned in the data query operation increases after the action is executed, a positive reward is given; if the ratio between the logical rows scanned and the physical rows scanned in the data query operation decreases after the action is executed, a negative reward is given;
[0189] If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, or the number of ordered string tables decreases after the action is performed, a positive reward will be given. If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, and the number of ordered string tables increase after the action is performed, a negative reward will be given.
[0190] One or more embodiments of the present specification also provide a computer program product, including a computer program / instruction, which implements the steps of the method provided in any of the above embodiments when executed by a processor.
[0191] One or more embodiments of the present specification also provide a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method provided in any of the above embodiments.
[0192] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0193] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0194] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0195] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0196] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0197] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0198] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0199] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0200] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0201] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A data management method, the method include: Obtain disk statistics information of a partition, wherein the disk statistics information is used to record relevant information of data of the partition in the disk; Determining whether the partition meets the adaptive merging condition according to a merging threshold function in a merging mode of a data table to which the partition belongs and disk statistics of the partition; If the partition meets the adaptive merging condition, a merging operation is performed on the partition according to a merging strategy in a merging mode of the data table to which the partition belongs.
2. The data management method according to claim 1, further comprising: include: Obtain memory statistics information of the partition, wherein the memory statistics information is used to record relevant information of the data of the partition in the memory; Determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the memory statistics information of the partition, or determining whether the partition meets the quick freezing condition according to the freezing threshold function in the merge mode of the data table to which the partition belongs and the disk statistics information and the memory statistics information of the partition; If the partition meets the quick freezing condition, the data of the partition in the memory is frozen and dumped to the disk.
3. The data management method according to claim 2, wherein the obtaining of disk statistics of a partition comprises: include: If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is obtained.
4. The data management method according to claim 2 or 3, further comprising: include: If the data of the partition in the memory is frozen and dumped to the disk, the disk statistics information of the partition is updated.
5. The data management method according to claim 2, wherein the disk statistics information includes at least one of the following: The number of deleted rows, the number of updated rows, the ratio of update operations within the preset time, the number of ordered string tables, the number of slow queries, and the ratio of slow queries. in, The slow query is a data query operation whose execution time exceeds a time threshold, and the slow query ratio is the ratio of the number of slow queries to the number of all data query operations; The memory statistics information includes at least one of the following: Active time of the memory data table, number of rolled back transactions, number of deleted rows, number of updated rows, ratio of update operations within the preset time, number of slow queries, and ratio of slow queries.
6. The data management method according to claim 2, wherein the disk statistics information is stored in the memory, and the memory statistics information is stored in the memory; and / or, The disk statistics information includes the latest disk statistics information within a preset time period and all disk statistics information after the last merge operation was performed.
7. The data management method according to claim 1, wherein the obtaining of disk statistics of a partition comprises: include: If the partition meets the iteration requirements, disk statistics of the partition are obtained.
8. The data management method according to claim 1, wherein the merging mode of the data table to which the partition belongs is one of a plurality of preset merging modes, in, In the plurality of preset merging modes, different merging modes have different merging threshold functions, freezing threshold functions, and merging strategies.
9. The data management method according to claim 1, wherein among the plurality of preset merging modes, at least one of the following merging strategies is provided: a basic merging strategy, an advanced merging strategy, and an aggressive merging strategy; in, The basic merge strategy only performs partition merge, and the partition merge is to merge the baseline ordered string table and the incremental ordered string table at the same position in all database instances involved in the partition; The advanced merge strategy performs partition merge when the time from the current time to the last partition merge reaches a preset period, and performs basic merge when the time from the current time to the last partition merge does not reach the preset period, wherein the basic merge is to merge the baseline ordered string table and the incremental ordered string table in the database instance; The aggressive merge strategy performs only the basic merge.
10. The data management method according to claim 8, further comprising: include: Taking the distributed database as the environment, the disk statistics information and the memory statistics information of the partition as the state, the merging mode change of the partition as the action, and the preset reward function, reinforcement learning training is performed until the convergence condition is met, so as to obtain the merging mode of each data table in the distributed database.
11. The data management method according to claim 10, wherein the partition merging mode is changed include: Changing the merging mode of the partitions from one preset merging mode to another preset merging mode; as well as, At least one of a merge threshold function, a freeze threshold function and a merge strategy in a merge mode of the partition is adjusted.
12. The data management method according to claim 11, wherein the reward function is used to characterize at least one of the following: If the execution time of the data query operation decreases after the action is performed, a positive reward is given; if the execution time of the data query operation increases after the action is performed, a negative reward is given; If the proportion of slow queries decreases after the action is executed, a positive reward is given; if the proportion of slow queries increases after the action is executed, a negative reward is given; If the ratio between the logical rows scanned and the physical rows scanned in the data query operation increases after the action is executed, a positive reward is given; if the ratio between the logical rows scanned and the physical rows scanned in the data query operation decreases after the action is executed, a negative reward is given; If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, or the number of ordered string tables decreases after the action is performed, a positive reward will be given. If the amount of data read and written by the disk within the preset time, the number of write operations on the disk within the preset time, and the number of ordered string tables increase after the action is performed, a negative reward will be given.
13. A data management device, the device include: An acquisition module, used for acquiring disk statistics information of a partition, wherein the disk statistics information is used for recording relevant information of data of the partition in the disk; A determination module, used to determine whether the partition meets the adaptive merging condition according to a merging threshold function in a merging mode of a data table to which the partition belongs and disk statistics of the partition; The merging module is used to perform a merging operation on the partition according to a merging strategy in a merging mode of the data table to which the partition belongs if the partition meets the adaptive merging condition.
14. A computer program product comprising a computer program / instructions, which when executed by a processor implement the steps of the method according to any one of claims 1 to 12.
15. An electronic device, include: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 12 by running the executable instructions.
16. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Data processing method and device
CN117806567A
Cited By
Storage architecture optimization method and device based on reinforcement learning, medium and product
CN119377448A
Storage architecture optimization methods, equipment, media and products based on reinforcement learning
CN119377448B
Data management method and apparatus, program product, device, and storage medium
WO2026017054A1
