Cross-library data freezing method, device and equipment
By acquiring and utilizing the global process transaction identifier set and MVCC architecture of the database system, cross-database data freezing is achieved, solving the data visibility error problem in cross-database data freezing and improving the accuracy and efficiency of cross-database data freezing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CETC JINCANG (BEIJING) TECH CO LTD
- Filing Date
- 2025-12-08
- Publication Date
- 2026-04-17
AI Technical Summary
Existing technologies cannot effectively freeze cross-database data, leading to data visibility errors when accessing cross-databases.
By obtaining the set of transaction identifiers of all processes logged into the database system, the minimum transaction identifier is determined, and the data in the target database is frozen based on this identifier. Cross-database data freezing is performed using the global process array and the xmin and xmax fields of the MVCC architecture.
Ensure the integrity and correctness of cross-database data freezing logic, avoid data omissions, improve the efficiency of data visibility judgment, reduce computational overhead, and adapt to stability under complex load scenarios.
Smart Images

Figure CN121880433A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a method, apparatus and device for freezing cross-database data. Background Technology
[0002] For databases that support concurrent processing, data freezing is currently supported for only a single database. Data freezing is used to keep numerical data visible to all transactions.
[0003] With the increasing prevalence of cross-database (CRS) access scenarios, supporting data freezing in a single database is no longer sufficient to meet current needs. Therefore, how to implement cross-database data freezing has become a technical problem that urgently needs to be solved. Summary of the Invention
[0004] This application provides a method, apparatus, and device for cross-database data freezing, used to achieve cross-database data freezing.
[0005] In a first aspect, this application provides a cross-database data freezing method, comprising: for any target database in a database system that allows cross-database access: obtaining a set of transaction identifiers of all processes logged into the database system; determining a minimum transaction identifier based on the set of transaction identifiers; and freezing data in the target database based on the minimum transaction identifier.
[0006] In one possible embodiment, the transaction identifier in the transaction identifier set is a unique identifier for the current transaction of each process. If a process does not participate in a transaction, the corresponding transaction identifier is a preset value.
[0007] In one possible embodiment, all processes logging into the database system and their corresponding current transaction identifiers are represented by a global process array. Obtaining the transaction identifiers of all processes logging into the database system to obtain the transaction identifier set includes: traversing the transaction identifiers in the global process array to obtain the transaction identifier set.
[0008] In one possible embodiment, before traversing the transaction identifiers in the global process array to obtain the transaction identifier set, the cross-database data freezing method further includes: dynamically adjusting the update frequency of the global process array according to the transaction concurrency and / or the number of database connections of the database system.
[0009] In one possible embodiment, freezing data in the target database based on the minimum transaction identifier includes: scanning the data in the target database that has not been deleted, comparing the transaction identifier of the data in the target database that has not been deleted with the minimum transaction identifier; if the transaction identifier of the data in the target database that has not been deleted is less than the minimum transaction identifier, then setting a freeze identifier for the data in the target database that has not been deleted.
[0010] In one possible embodiment, after setting the freeze flag, the cross-database data freezing method further includes: determining data visibility based on the freeze flag.
[0011] In one possible embodiment, after setting a freeze flag for data that has not been deleted in the target database, the cross-database data freezing process further includes: storing the freeze flag in the metadata table of the target database; and determining data visibility based on the freeze flag includes: reading the freeze flag field in the metadata table to determine data visibility.
[0012] In one possible implementation, the cross-database data freeze method is performed on each database in the database system.
[0013] Secondly, this application provides a cross-database data freezing device, comprising: a transaction identifier set acquisition module, used to acquire the transaction identifier set of all processes logged into the database system for any target database in the database system; a minimum transaction identifier determination module, used to determine the minimum transaction identifier based on the transaction identifier set; and a data freezing module, used to freeze data in the target database based on the minimum transaction identifier.
[0014] Thirdly, this application provides an electronic device, including: a processor and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method as described in any of the first aspects.
[0015] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any of the first aspects.
[0016] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method of any one of the first aspects.
[0017] In this embodiment, for database systems that allow cross-database access, a minimum transaction identifier is determined by obtaining the transaction identifier set of all processes logged into the database system and then determining the minimum transaction identifier based on this set. The minimum transaction identifier is the minimum global transaction identifier value across multiple databases within the database system. Data freezing based on the minimum transaction identifier can cover data visible to all transactions globally within the database system. For example, databases in the database system that are not currently undergoing cross-database freezing may still support cross-database access. Therefore, during cross-database data freezing, the minimum transaction identifier needs to be determined from the transaction identifier set of all processes logged into the database system for subsequent data freezing. This ensures that the data freezing logic can achieve cross-database freezing, avoiding data visibility errors caused by missing cross-database data freezing.
[0018] In addition, the cross-database data freezing method in this application embodiment can reuse the xmin and xmax fields of the multi-version concurrency control (MVCC) architecture, thereby ensuring that cross-database freezing has good scalability. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0020] Figure 1 This is a schematic diagram illustrating an application scenario of the cross-database data freezing method according to an embodiment of this application;
[0021] Figure 2 This is a flowchart of a cross-database data freezing method according to an embodiment of this application;
[0022] Figure 3 This is a schematic diagram of a cross-database data freezing method according to an embodiment of this application;
[0023] Figure 4 This is a schematic diagram of a cross-database data freezing method according to another embodiment of this application;
[0024] Figure 5 This is a schematic diagram of a cross-database data freezing device according to an embodiment of this application;
[0025] Figure 6 This is a schematic diagram of an electronic device according to an embodiment of this application.
[0026] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation
[0027] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0028] With the increasing volume of database accesses, concurrency support has become a key performance indicator for databases. Concurrency refers to multiple processes simultaneously performing read and write operations on the database. Currently, some databases support concurrency, but this brings with it the issue of data visibility between different sessions or processes—a problem known as concurrency control.
[0029] Concurrency control methods include: Multi-Version Concurrency Control (MVCC), locks, optimistic locks, timestamp sorting, etc. Moreover, some concurrency control methods combine multiple of the above-mentioned multi-version concurrency control, locks, optimistic locks, and timestamp sorting for concurrency control.
[0030] Taking multi-version concurrency control as an example, determining whether a piece of data in the database is visible to the current transaction is achieved by comparing the version number of the data itself with the version number of the current transaction. Some databases use transaction identifiers as version numbers. For example, any piece of data Di in the database will have two additional fields, xmin and xmax, which store which transaction generated data Di and which transaction deleted it respectively. The value of xmin is the transaction identifier of the transaction that generated data Di, and the value of xmax is the transaction identifier of the transaction that deleted data Di. Whether data Di is visible to a certain transaction E is judged by comparing the transaction identifier of transaction E with xmin and xmax of data Di. Only when xmin < the transaction identifier of transaction E < xmax, data Di is visible to transaction E.
[0031] There are the following situations: The number of transaction identifiers is limited. When the data access volume is so large that all transaction identifiers are used up, the transaction identifiers will roll back. Based on the monotonically increasing characteristic of the transaction identifier, before the transaction identifier rolls back, the xmin of a certain data D1 is less than the current transaction identifier, and data D1 is visible to the current transaction; after the transaction identifier rolls back, the xmin of data D1 is greater than the current transaction identifier, and data D1 is not visible to the current transaction. Thus, due to the rollback of the transaction identifier, a situation of visibility contradiction of the same data to the current transaction occurs.
[0032] In the related art, data freezing for a single database is adopted to solve the visibility contradiction caused by the rollback of transaction identifiers. Specifically, assume that the database is a single database that cannot access across databases and the transaction identifiers are monotonically increasing. By periodically scanning the data in the database, when the gap between the xmin of data D1 and the current transaction identifier is too large, and the transaction identifiers of all currently running transactions are greater than the xmin of data D1, then freeze data D1 to make data D1 visible to all transactions.
[0033] The data freezing in the related art only targets a single database and cannot handle cross-database data freezing, which may lead to misjudgment of data visibility in cross-database access.
[0034] Based on this, the embodiments of the present application provide a cross-database data freezing method, device, equipment, storage medium, and program product.
[0035] Figure 1This is a schematic diagram illustrating an application scenario of the cross-database data freezing method according to an embodiment of this application.
[0036] like Figure 1 As shown, users 1 through X each initiate data processing requests through application 2 installed on their respective terminal devices, where X is an integer greater than or equal to 2. The X data processing requests from users 1 through X are sent to electronic device 3, which may be a server. Electronic device 3 is equipped with a database system 4 that allows cross-database access. Database system 4 includes multiple databases, for example, database system 4 includes databases db1 through dbN, where N is an integer greater than or equal to 2. The relevant data for the X data processing requests from users 1 through X is stored in database system 4. Electronic device 3 establishes processes for each of the X data processing requests from users 1 through X and executes the cross-database data freezing method of this embodiment.
[0037] The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0038] Figure 2 This is a flowchart illustrating a cross-database data freezing method according to an embodiment of this application. The cross-database data freezing method of this application embodiment can be executed by an electronic device, which can be a server.
[0039] like Figure 2 As shown, the cross-database data freezing method of this application embodiment includes: executing steps S110 to S130 for any target database in a database system that allows cross-database access. Unless otherwise specified below, the database system refers to a database system that allows cross-database access.
[0040] S110. Obtain the set of transaction identifiers for all processes that are logged into the database system.
[0041] For example, an electronic device can obtain multiple transaction identifiers that correspond one-to-one with all processes logging into the database system, and the multiple transaction identifiers constitute a transaction identifier set.
[0042] The process that logs into the database system refers to a process that has established a connection with the database system and is able to execute transactions, such as a user session or a background task process.
[0043] For all processes that log into the database system, the process is the initiator and executor of transactions, and a transaction is a logical unit of operation that a process executes on the logged-in database.
[0044] The transaction identifier in the transaction identifier set is a unique identifier for the current transaction of each process. That is, the transaction identifier is a globally unique identifier assigned to each transaction by the database system. Transaction identifiers are monotonically increasing and can represent the execution order of the current transaction for each process.
[0045] A process can only have one current transaction at a time. There are situations where a process is connected to the database but has no currently executing transaction, meaning the process is not participating in a transaction. When a process is not participating in a transaction, there is no current transaction for that process, meaning there is no transaction identifier for that process. This could lead to omissions in subsequent data freezing or errors in cross-database data freezing logic. To uniformly represent the transaction identifier for each process, in this embodiment, a preset value is set for the case where a process is not participating in a transaction. The preset value is a special value that identifies a process as not participating in a transaction; for example, the preset value is set to -1. The electronic device can exclude this preset value from the transaction identifier set, ensuring that the transaction identifier indicating a process is not participating in a transaction does not participate in the subsequent determination of the minimum transaction identifier. This ensures the logical integrity and correctness of cross-database data freezing, avoiding subsequent omissions in data freezing or errors in cross-database data freezing logic.
[0046] Figure 3 This is a schematic diagram of the cross-database data freezing method according to an embodiment of this application.
[0047] like Figure 3 As shown in the embodiments of this application, the processes for logging into the database system include process 1, process 2 to process Y, where Y is an integer greater than or equal to 3. Specifically, process 1 logs into database 1 (Database, db1), and process 1's current transaction identifier is i1, indicating that process 1 has established a connection with db1 and can execute the transaction indicated by the current transaction identifier i1. Similarly, process 2 logs into database db2, and process 2's current transaction identifier is i2; process Y logs into database dbN, and process Y's current transaction identifier is iY.
[0048] exist Figure 3 In the example, the set of transaction identifiers for all processes that log into the database system is (i1, i2, ..., iY).
[0049] S120. Determine the minimum transaction identifier based on the transaction identifier set.
[0050] For example, multiple transaction identifiers in the transaction identifier set are sorted and the minimum value among them is determined as the minimum transaction identifier.
[0051] Combination Figure 3 For example, the minimum transaction identifier minid is the minimum value in the set of transaction identifiers (i1, i2, ..., iY) of all processes logged into the database system.
[0052] S130. Freeze the data in the target database based on the minimum transaction identifier.
[0053] Freezing data means making the data visible to all transactions.
[0054] It is understood that the target database is any database in the database system. In this embodiment of the application, the electronic device can traverse the data of each database in the frozen database system.
[0055] exist Figure 3 In the example, freezing the data in the target database based on the minimum transaction identifier in step S130 can be achieved through a freeze process.
[0056] In this embodiment, the transaction identifier set of all processes logged into the database system is obtained, and a minimum transaction identifier is determined based on this set. The minimum transaction identifier is the minimum global transaction identifier value across multiple databases in the database system. Data freezing based on the minimum transaction identifier can cover data visible to all transactions in the global database system. For example, databases in the database system that have not yet undergone cross-database freezing still support cross-database data access. Therefore, during cross-database data freezing, the minimum transaction identifier needs to be determined from the transaction identifier set of all processes logged into the database system for subsequent data freezing. This ensures that the data freezing logic can achieve cross-database freezing, avoiding data visibility errors caused by missing cross-database data freezing.
[0057] Furthermore, the cross-database data freezing method in this application embodiment can reuse the xmin and xmax fields. This ensures that cross-database freezing has good scalability.
[0058] For example, process A, in transaction T1 of database db1, modifies data M in another database db2 of the same database system. Using the cross-database data freezing method of this application, when freezing data in database db2, the transaction identifiers of the entire database system are considered to determine the minimum global transaction identifier. Based on this minimum transaction identifier, it can be determined whether data M in database db2 can be frozen. It should be noted that this example only illustrates whether data M in database db2 can be frozen; in reality, the electronic device can determine whether every piece of data in database db2 can be frozen, and it can also determine whether data in every database within the database system can be frozen.
[0059] In one possible embodiment, all processes logging into the database system and their corresponding transaction identifiers are represented by a global process array. Step S110, obtaining the transaction identifiers of all processes logging into the database system to obtain a transaction identifier set, includes: traversing the transaction identifiers in the global process array to obtain the transaction identifier set.
[0060] A global process array is a data structure used to store information about all processes logged into the database system. The information for each process includes its current transaction identifier and the database it is logged into.
[0061] In this embodiment, a global process array is used to represent all processes logged into the database system and their corresponding current transaction identifiers. This global process array serves as a global process view of the database system. When obtaining the transaction identifier set of all processes logged into the database system, the transaction identifier set can be obtained simply by traversing the transaction identifiers in the global process array. This improves the speed and efficiency of obtaining the transaction identifier set of all processes logged into the database system.
[0062] In one possible embodiment, before traversing the transaction identifiers in the global process array to obtain the transaction identifier set, the cross-database data freezing method further includes: dynamically adjusting the update frequency of the global process array according to the transaction concurrency and / or the number of database connections of the database system.
[0063] Transaction concurrency refers to the number of transactions running simultaneously in a database system per unit of time. For example, during peak periods, a database system might run 1000 concurrent transactions per second, while during off-peak periods it might run 10 concurrent transactions per second. For instance, transaction concurrency can be calculated in real time using the database system's transaction statistics interface or a custom transaction counter.
[0064] A high number of database connections in a database system indicates a high potential level of transaction concurrency, such as the possibility of a large number of new transactions starting at any time. For example, the number of database connections can be obtained in real time through the database system's connection statistics interface.
[0065] For example, embodiments of this application can classify the load of a database system into low load, medium load, and high load. When determining the load of the database system using transaction concurrency and / or the number of database connections, load level thresholds corresponding to transaction concurrency and the number of database connections are preset.
[0066] Taking transaction concurrency as an example, if the transaction concurrency is less than the first threshold of 100, the database system is determined to be under low load; if the transaction concurrency is greater than or equal to the first threshold of 100 but less than the second threshold of 500, the database system is determined to be under medium load; and if the transaction concurrency is greater than or equal to the second threshold of 500, the database system is determined to be under high load. For instance, when the transaction concurrency of a database system is high, active transactions change rapidly. In this case, the update frequency of the global process array can be increased to ensure the accuracy of data such as the minimum transaction identifier, avoiding subsequent cross-database data freeze errors. Conversely, when the transaction concurrency of a database system is low, active transactions change less, and the global process array remains valid for a longer period. In this case, the update frequency of the global process array can be reduced to decrease unnecessary resource consumption.
[0067] Unlike determining the load of a database system using either transaction concurrency or database connection count, when using both, the electronic device can calculate multiple load levels corresponding to the transaction concurrency and database connection count, following the example above. The electronic device can then use the highest of the two load levels as the final load level.
[0068] For high-load database systems, electronic devices can increase the update frequency of the global process array. For medium-load database systems, electronic devices can maintain the current update frequency of the global process array. For low-load database systems, electronic devices can decrease the current update frequency of the global process array.
[0069] In this embodiment, by dynamically adjusting the update frequency of the global process array according to the transaction concurrency and / or database connection number of the database system, the accuracy of cross-database data freezing, the balance of resource consumption, and the improvement of database system stability can be taken into account, ensuring the stability and responsiveness of the cross-database data freezing process under complex load scenarios.
[0070] It should be noted that, in this embodiment of the application, in order to avoid cross-database data freezing delay caused by significantly reducing the update frequency of the global process array, a lower limit constraint on the update frequency or a constraint on the magnitude of the update frequency decrease can be set according to actual experience.
[0071] In one possible embodiment, step S130 of freezing data in the target database based on the minimum transaction identifier includes: scanning the data that has not been deleted in the target database, comparing the transaction identifier of the data that has not been deleted in the target database with the minimum transaction identifier; if the transaction identifier of the data that has not been deleted in the target database is less than the minimum transaction identifier, then setting a freeze identifier for the data that has not been deleted in the target database.
[0072] In the MVCC architecture, the xmin field of each data record in the database contains the transaction identifier of the transaction that created the data, and the xmax field contains the transaction identifier of the transaction that deleted the data. For data that has not been deleted, the xmax field is set to 0. This application embodiment can reuse the xmin and xmax fields of the MVCC architecture, but it uses different data freezing conditions than the MVCC architecture. It should be noted that data deletion refers to the data being marked for deletion, not physical deletion.
[0073] Based on the mechanism of automatically masking deleted data in the MVCC architecture, deleted data is considered an "expired version" and does not require visibility adjustment through data freezing. In this embodiment, when performing cross-database data freezing, the data freezing condition is as follows: Scanning the target database for non-deleted data, comparing the transaction identifier of the non-deleted data in the target database with the minimum transaction identifier to filter data that meets the data freezing condition. If the transaction identifier of the non-deleted data in the target database is less than the minimum transaction identifier, this indicates that the non-deleted data in the target database was generated before the current transaction of all processes logged into the database system. Furthermore, based on the monotonically increasing characteristic of transaction identifiers, the non-deleted data in the target database is also generated before future transactions. Therefore, the electronic device can set a freeze identifier for the non-deleted data in the target database. The freeze identifier indicates that the data is visible to all transactions, achieving correct cross-database data freezing.
[0074] Combination Figure 3 For example, taking the target database as db1 in the database system, db1 contains data from data 1 to data K, where K is an integer greater than or equal to 2. Figure 3 In the example, the transaction identifier xmin of data 1 is less than the minimum transaction identifier minid, and data 1 has not been deleted (xmax=0 for data 1 indicates that data 1 has not been deleted). A freeze flag is set for data 1, for example, setting the freeze flag of data 1 to true, where true indicates that data 1 is frozen. Figure 3 In the example, the transaction identifier xmin of data 2 is greater than or equal to the minimum transaction identifier minid, which does not meet the freezing condition. Therefore, the freeze identifier of data 2 is not set to true. Similarly, iterate through each piece of data in the target database db1, and set the freeze identifier to true for data that meets the freezing condition.
[0075] In one possible embodiment, after setting the freeze flag, the cross-database data freezing method further includes: determining data visibility based on the freeze flag.
[0076] For example, for any new transaction logging into the database system, if the data in the database system has a frozen tag, it indicates that the data has been frozen, meaning that the data is visible to all transactions. Therefore, in this embodiment, when determining data visibility, the electronic device does not need to compare the data's xmin and xmax fields with the transaction identifier; instead, it directly determines that the data is visible to the transaction based on the data's frozen tag. This reduces the computational overhead of determining data visibility and improves the efficiency of data visibility determination.
[0077] In one possible embodiment, after setting a freeze flag for the data that has not been deleted in the target database in step S130, the cross-database data freezing method further includes: storing the freeze flag in the metadata table of the target database. Determining data visibility based on the freeze flag includes: reading the freeze flag field from the metadata table to perform the data visibility determination.
[0078] The target database's metadata table is used to store metadata about the database system.
[0079] In this embodiment, after setting a freeze flag for data in the database system, the freeze flag is stored in the metadata table of the target database. This allows subsequent data visibility determination to directly access the freeze flag field in the metadata table without accessing the original database. This reduces the communication overhead for data visibility determination and improves the access performance of the database system.
[0080] In summary, the cross-database data freezing method of this application embodiment can perform cross-database data freezing on data in a target database. Since the database system of this application embodiment includes multiple databases, the cross-database data freezing method of this application embodiment can be executed on each database in the database system.
[0081] In this embodiment of the application, a cross-database data freezing method is performed on each of the multiple databases in the database system. For example, the cross-database data freezing method is performed on each database sequentially. At this time, the available resources of the database system can be concentrated on performing cross-database data freezing on any one of the databases (such as the target database) for which the cross-database data freezing method is being performed. Available resources include central processing unit resources, input / output resources, and network bandwidth resources, etc., to improve the cross-database data freezing speed of a single database.
[0082] Furthermore, this approach avoids the overhead associated with multiple databases collaboratively performing cross-database data freezes. For instance, if multiple databases collaboratively perform cross-database data freezes, an error might occur during the process of performing the freeze on one of the databases. This error would cause at least one database to roll back and retry, resulting in even greater overhead.
[0083] Of course, in this embodiment of the application, the cross-database data freezing method can also be executed simultaneously on multiple databases in the database system.
[0084] It should be noted that the data freezing method in this application embodiment can handle data visibility determination when transaction identifiers are rolled back. Specifically, the data visibility determination does not judge the absolute size of the transaction identifier, but rather the chronological relationship of the transaction identifiers on the timeline. By freezing the data, the old data is marked as visible to all transactions. For example, during the execution of the data freezing method in this application embodiment, if the transaction identifier is rolled back to the minimum value within its range, although the xmin of the data before the transaction identifier rollback is greater than the xmin of the new data, by executing the data freezing method in this application embodiment, the data that meets the freezing conditions has already been frozen before the transaction identifier rollback. At this time, after the transaction identifier rollback, the visibility determination of the new data does not depend on the xmin of the data before the transaction rollback, but is directly determined by the data's freeze identifier. Compared with related technologies that freeze data in a single database, this application embodiment can achieve cross-database data freezing to avoid data visibility conflicts caused by transaction identifier rollback.
[0085] Figure 4 This is a schematic diagram of a cross-database data freezing method according to another embodiment of this application.
[0086] like Figure 4 As shown, the cross-database data freezing method in this embodiment of the application is implemented by a freezing process running on an electronic device. Figure 4 In the example, the freeze process first freezes the data in database db1 in the database system. Specifically, the freeze process executes steps S211 to S213.
[0087] S211. Obtain the transaction identifier set of all processes currently logged into the database system and determine the minimum transaction identifier minid from the transaction identifier set.
[0088] S212. Determine the data in database db1 that has not been deleted and whose transaction ID is less than the minimum transaction ID minid.
[0089] S213. Set a freeze flag for data in database db1 that has not been deleted and whose transaction flag is less than the minimum transaction flag minid.
[0090] After freezing the data in database db1 in the database system, the freezing process freezes the data in databases db2 to dbN in a similar manner, which will not be described in detail here.
[0091] Figure 5 This is a schematic diagram of the cross-database data freezing device according to an embodiment of this application. Figure 5As shown, the cross-database data freezing device provided in this application embodiment includes: a transaction identifier set acquisition module 310, a minimum transaction identifier determination module 320, and a data freezing module 330.
[0092] The transaction identifier set acquisition module 310 is used to acquire the transaction identifier set of all processes that have logged into the database system for any target database in the database system.
[0093] The minimum transaction identifier determination module 320 is used to determine the minimum transaction identifier based on the transaction identifier set.
[0094] The data freeze module 330 is used to freeze data in the target database based on the minimum transaction identifier.
[0095] In one possible embodiment, the transaction identifier in the transaction identifier set is a unique identifier for the current transaction of each process. If a process does not participate in a transaction, the corresponding transaction identifier is a preset value.
[0096] In one possible embodiment, all processes logging into the database system and their corresponding current transaction identifiers are represented by a global process array. The transaction identifier set acquisition module is specifically used to traverse the transaction identifiers in the global process array to obtain the transaction identifier set.
[0097] In one possible embodiment, the cross-database data freezing device further includes: an adjustment module for dynamically adjusting the update frequency of the global process array based on the transaction concurrency and / or the number of database connections of the database system.
[0098] In one possible embodiment, the data freezing module is specifically used to: scan the data that has not been deleted in the target database, compare the transaction identifier of the data that has not been deleted in the target database with the minimum transaction identifier; if the transaction identifier of the data that has not been deleted in the target database is less than the minimum transaction identifier, then set a freeze identifier for the data that has not been deleted in the target database.
[0099] In one possible embodiment, the cross-database data freezing device further includes a judgment module for judging data visibility based on the freeze identifier.
[0100] In one possible embodiment, the cross-database data freezing device further includes: a storage module for storing freeze identifiers in the metadata table of the target database; and a judgment module specifically for reading the freeze identifier field in the metadata table to perform data visibility judgment.
[0101] In one possible embodiment, the cross-database data freezing device is applied to each database in the database system.
[0102] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 6 As shown, this application embodiment provides an electronic device including a processor 401 and a memory 402. Optionally, the device further includes a communication component 403. The processor 401, memory 402, and communication component 403 are connected via a bus 404.
[0103] In the specific implementation process, the memory 402 stores code, and the processor 401 runs the code stored in the memory 402 to execute the method of the above method embodiment.
[0104] The specific implementation process of processor 401 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0105] In the above Figure 6 In the illustrated embodiments, it should be understood that the processor 401 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0106] The memory 402 may include high-speed RAM memory, and may also include non-volatile memory (NVM), such as at least one disk storage.
[0107] Bus 404 can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Bus 404 can be divided into address bus, data bus, control bus, etc. For ease of illustration, the bus 404 in the accompanying drawings of this application is not limited to only one bus or one type of bus.
[0108] This application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the methods described in the above-described method embodiments.
[0109] The aforementioned computer-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0110] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0111] This application provides a computer program product, including a computer program that, when executed by a processor, implements the methods provided in any of the embodiments described above.
[0112] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.
[0113] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0114] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.
[0115] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.
[0116] When integrated units / modules are implemented in hardware, the hardware can be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc.
[0117] If the integrated unit / module is implemented as a software program module and sold or used as an independent financial product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software financial product. This computer software financial product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0118] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification.
[0119] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0120] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A cross-database data freezing method, characterized by, include: For any target database in a database system that allows cross-database access, Obtain the set of transaction identifiers for all processes logged into the database system; Determine the minimum transaction identifier based on the set of transaction identifiers; The data in the target database is frozen based on the minimum transaction identifier.
2. The method of claim 1, wherein, The transaction identifiers in the transaction identifier set are unique identifiers for the current transaction of each process. If a process does not participate in a transaction, the corresponding transaction identifier is a preset value.
3. The method of claim 2, wherein, All processes logging into the database system and their corresponding current transaction identifiers are represented by a global process array. Obtaining the transaction identifiers of all processes logging into the database system to obtain the transaction identifier set includes: The transaction identifiers in the global process array are traversed to obtain the transaction identifier set.
4. The method of claim 3, wherein, Before traversing the transaction identifiers in the global process array to obtain the transaction identifier set, the method further includes: The update frequency of the global process array is dynamically adjusted based on the transaction concurrency and / or database connection count of the database system.
5. The method according to any one of claims 1-4, characterized in that, Freezing the data in the target database based on the minimum transaction identifier includes: Scan the target database for data that has not been deleted, and compare the transaction identifier of the data that has not been deleted in the target database with the minimum transaction identifier; If the transaction identifier of the data that has not been deleted in the target database is less than the minimum transaction identifier, then a freeze identifier is set for the data that has not been deleted in the target database.
6. The method according to claim 5, characterized in that, After setting the freeze flag, the method further includes: Data visibility is determined based on the freeze flag.
7. The method according to claim 6, characterized in that, After setting a freeze flag for the data in the target database that has not been deleted, the method further includes: Store the freeze identifier in the metadata table of the target database; The step of determining data visibility based on the freeze identifier includes: reading the freeze identifier field in the metadata table to determine data visibility.
8. The method according to any one of claims 1-4, characterized in that, The cross-database data freezing method is executed for each database in the database system.
9. A cross-database data freezing device, characterized in that, include: The transaction identifier set acquisition module is used to acquire the transaction identifier set of all processes that log in to the database system for any target database in a database system that allows cross-database access. The minimum transaction identifier determination module is used to determine the minimum transaction identifier based on the set of transaction identifiers. The data freezing module is used to freeze data in the target database based on the minimum transaction identifier.
10. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 8.