Consistency test method and device, electronic equipment and storage medium

By obtaining business data of distributed databases, using SQL fuzzification algorithms and concurrent testing transactions, the customization needs of consistency testing in distributed databases are solved, and testing flexibility and coverage are improved.

CN119322743APending Publication Date: 2025-01-17DUXIAOMAN TECH (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411307915.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-19
Publication Date
2025-01-17

AI Technical Summary

Technical Problem

The prior art is difficult to meet the customized consistency testing needs of different users in distributed databases and cannot cover the testing requirements of most users.

Method used

By obtaining the business data of the target business, obtaining the library table structure based on the SQL fuzzification algorithm, creating a test table and inserting preset data, performing concurrent test transactions, and determining whether the test table meets the preset consistency conditions to determine the consistency test.

Benefits of technology

Customized consistency testing for different target businesses has been achieved, which improves testing flexibility and can cover more application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322743A_ABST
    Figure CN119322743A_ABST
Patent Text Reader

Abstract

The invention provides a consistency test method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining a target service, and obtaining a target library table structure of the target service based on an SQL fuzzification algorithm; and based on the target library table structure, creating test tables in each storage node, inserting preset data in each test table, concurrently executing a first preset test transaction, determining whether each test table meets a preset consistency condition, and if yes, enabling the target service to pass the consistency test. The method comprises the following steps: performing SQL fuzzification based on a real database for storing service data, determining an actual library table structure of a target service, creating a table based on the actual library table structure of the target service, inserting test data into the created table according to the structure of the target service data, and testing the target service. Different consistency tests are carried out for different target services, that is, consistency tests are carried out in a customized scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a consistency testing method, device, electronic equipment and storage medium. Background Art

[0002] A database is an organized collection of data used to store, manage, and retrieve information. The main function of a database is to efficiently store large amounts of data and to access that data quickly and reliably. In order to improve data access efficiency, distributed databases have emerged in related technologies.

[0003] A distributed database is a database system in which data is stored in multiple physical locations or nodes that are connected through a network and work together to provide data storage and access services. Distributed databases are designed to improve data availability, reliability, and performance, especially when dealing with large-scale data and high-concurrency requests.

[0004] Since data is stored in a distributed manner, there may be inconsistencies in the reading and writing of data stored in different nodes due to network anomalies, device anomalies, etc. Therefore, when using a distributed database, it is usually necessary to perform consistency testing on the distributed database.

[0005] In the related art, the consistency of a distributed database is usually tested through read and write tests between different nodes. Specifically, write and read operations are performed on different nodes of the distributed database respectively, and the final results are compared to see whether they meet expectations, so as to determine whether the distributed transaction is accurately executed.

[0006] However, each user's usage scenario is different, and the SQL to be executed is also different. This solution cannot cover the customized testing requirements of most users. Summary of the invention

[0007] In view of this, embodiments of the present invention provide a consistency test method, device, electronic device and storage medium to improve the flexibility of consistency testing.

[0008] According to one aspect of the present invention, a consistency testing method is provided, the method comprising:

[0009] Acquire a target business, wherein business data of the target business is stored in each storage node in a distributed manner;

[0010] Based on the SQL fuzzification algorithm, the target database table structure of the target business is obtained;

[0011] Based on the target library table structure, a test table is created in each of the storage nodes, and preset data is inserted into each of the test tables, wherein the fields included in the preset data are the same as the fields included in the business data stored in the corresponding storage node; and the sum of the data values ​​of the same fields corresponding to the same ID in the test table storing the same preset data is the first preset value;

[0012] Concurrently executing a first preset test transaction, the first preset test transaction comprising: exchanging data values ​​of preset fields corresponding to the random IDs in two test tables containing the same random ID, and inserting new data into the two test tables containing the same random ID, wherein the sum of data values ​​in the same fields in the new data in the two test tables is a second preset value;

[0013] After the first preset test transaction is executed, determine whether the two test tables meet the preset consistency conditions. If the two test tables meet the preset consistency conditions, determine that the target business has passed the consistency test, wherein the preset consistency conditions include: the sum of the data values ​​of the same fields of the preset data contained in the two test tables is the first preset value, the data value of the same field of the new data contained in the two test tables is the second preset value, and the number of times new data is inserted into the two test tables is the same as the number of successful executions of the first preset test transaction.

[0014] In a possible embodiment, the first preset value and the second preset value are preset by the following steps:

[0015] For each field, determine the data type of the field; the data type includes a numeric type, a datetime type, and a string type;

[0016] Determine that the data value preset for the data type is a first preset value or a second preset value, wherein the data value set for the numeric type is a preset number, the data value set for the datetime type is a preset timestamp, and the data value set for the string type is a number corresponding to an ASCII character.

[0017] In a possible embodiment, the method further includes:

[0018] When the number of test tables storing the same preset data exceeds 2, determining any two test tables among the test tables storing the same preset data as two target test tables;

[0019] Set the sum of the data values ​​in the same field corresponding to the same ID in the two target test tables to be the first preset value;

[0020] The first preset test transaction includes: exchanging data values ​​of preset fields corresponding to random IDs in the two target test tables, and inserting new data into the two target test tables, wherein the sum of data values ​​in the same fields in the new data in the two target test tables is a second preset value;

[0021] The method further comprises:

[0022] Determine whether all test tables storing the same preset data have been tested. If they have been tested, determine that the target service has passed the consistency test; if there are test tables that have not been tested, return to the step of concurrently executing the first preset test transaction.

[0023] In a possible embodiment, the method further includes:

[0024] Determine two storage nodes whose deployment distances meet a preset distance condition as a first preset node and a second preset node;

[0025] Creating a user balance table in the first preset node and the second preset node as a first user balance table and a second user balance table, wherein the user balance table includes a user ID, an initial balance, and a version identifier; the user ID included in the first user balance table and the second user balance table is the same;

[0026] Starting multiple coroutines to concurrently execute a second preset test transaction, wherein the second preset test transaction includes: reducing a first random value in a balance of a first random ID in a balance table of the first user, and increasing the first random value in a balance of a second random ID in a balance table of the second user, reducing a second random value in a balance of a third random ID in a balance table of the second user, and increasing the second random value in a balance of a fourth random ID in a balance table of the first user; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1;

[0027] After the second preset test transaction is executed, determine whether the first user balance table and the second user balance table meet the second preset test condition, wherein the second preset test condition includes: the sum of the balances of each user ID in the first user balance table is consistent with the sum of the initial balances in the first user balance table, the sum of the balances of each user ID in the second user balance table is consistent with the sum of the initial balances in the second user balance table, and the total number of versions in the first user balance table and the second balance table is four times the number of executions of the second preset test transaction.

[0028] In a possible embodiment, the second preset test transaction includes: reducing a third random value in the balance of the first preset ID in the first user balance table, and increasing the third random value in the balance of the second preset ID in the second user balance table, reducing a fourth random value in the balance of the second preset ID in the second user balance table, and increasing the fourth random value in the balance of the first preset ID in the first user balance table; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1.

[0029] According to another aspect of the present invention, there is provided a consistency testing device, the device comprising:

[0030] An acquisition module, used for acquiring a target business, wherein the business data of the target business is stored in each storage node in a distributed manner;

[0031] A fuzzy module, used to obtain the target library table structure of the target business based on the SQL fuzzification algorithm;

[0032] A creation module, configured to create a test table in each of the storage nodes based on the target library table structure, and insert preset data into each of the test tables, wherein the fields included in the preset data are the same as the fields included in the business data stored in the corresponding storage node; and the sum of the data values ​​of the same fields corresponding to the same ID in the test table storing the same preset data is a first preset value;

[0033] A test module, configured to concurrently execute a first preset test transaction, wherein the first preset test transaction includes: exchanging data values ​​of preset fields corresponding to the random IDs in two test tables containing the same random ID, and inserting new data into the two test tables containing the same random ID, wherein the sum of data values ​​in the same fields in the new data in the two test tables is a second preset value;

[0034] A verification module is used to determine whether the two test tables meet a preset consistency condition after the first preset test transaction is executed, and determine that the target business passes the consistency test when the two test tables meet the preset consistency condition, wherein the preset consistency condition includes: the sum of the data values ​​of the same field of the preset data contained in the two test tables is the first preset value, the data value of the same field of the new data contained in the two test tables is the second preset value, and the number of times new data is inserted into the two test tables is the same as the number of successful executions of the first preset test transaction.

[0035] In a possible embodiment, the test module is further used for:

[0036] Determine two storage nodes whose deployment distances meet a preset distance condition as a first preset node and a second preset node;

[0037] Creating a user balance table in the first preset node and the second preset node as a first user balance table and a second user balance table, wherein the user balance table includes a user ID, an initial balance, and a version identifier; the user ID included in the first user balance table and the second user balance table is the same;

[0038] Starting multiple coroutines to concurrently execute a second preset test transaction, wherein the second preset test transaction includes: reducing a first random value in a balance of a first random ID in a balance table of the first user, and increasing the first random value in a balance of a second random ID in a balance table of the second user, reducing a second random value in a balance of a third random ID in a balance table of the second user, and increasing the second random value in a balance of a fourth random ID in a balance table of the first user; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1;

[0039] After the second preset test transaction is executed, determine whether the first user balance table and the second user balance table meet the second preset test condition, wherein the second preset test condition includes: the sum of the balances of each user ID in the first user balance table is consistent with the sum of the initial balances in the first user balance table, the sum of the balances of each user ID in the second user balance table is consistent with the sum of the initial balances in the second user balance table, and the total number of versions in the first user balance table and the second balance table is four times the number of executions of the second preset test transaction.

[0040] In a possible embodiment, the second preset test transaction includes: reducing a third random value in the balance of the first preset ID in the first user balance table, and increasing the third random value in the balance of the second preset ID in the second user balance table, reducing a fourth random value in the balance of the second preset ID in the second user balance table, and increasing the fourth random value in the balance of the first preset ID in the first user balance table; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1.

[0041] According to another aspect of the present invention, there is provided an electronic device, comprising:

[0042] Processor; and

[0043] Memory for storing programs,

[0044] The program includes instructions, and when the instructions are executed by the processor, the processor executes any one of the above-mentioned consistency testing methods.

[0045] According to another aspect of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute any of the above-mentioned consistency testing methods.

[0046] One or more technical solutions provided in the embodiments of the present invention perform SQL fuzzification based on a database that actually stores business data, determine the actual library and table structure of the target business, create a table based on the actual library and table structure of the target business, insert test data into the created table according to the structure of the target business data, and test the target business, thereby implementing different consistency tests for different target businesses, that is, implementing consistency testing in customized scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Further details, features and advantages of the invention are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:

[0048] Figure 1 A schematic diagram of a flow chart of a consistency testing method provided by an embodiment of the present invention;

[0049] Figure 2 A schematic diagram of a flow chart of a consistency test device provided by an embodiment of the present invention;

[0050] Figure 3 A block diagram of an exemplary electronic device that can be used to implement an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0051] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.

[0052] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.

[0053] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc. mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0054] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0055] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.

[0056] In order to improve the flexibility of consistency testing so that consistency testing can cover more application scenarios, the embodiments of the present invention provide a consistency testing method, device, electronic device and storage medium. The consistency testing method provided by the embodiments of the present invention can be applied to any electronic device with a consistency testing function, which can be a server, a computer or a mobile terminal, etc. Specifically, the consistency testing method can be applied to a distributed database. The following describes the scheme of the present invention with reference to the accompanying drawings:

[0057] Figure 1 A flow chart of a consistency test method provided by an embodiment of the present invention may include the following steps:

[0058] S101, acquiring a target business, wherein business data of the target business is stored in each storage node in a distributed manner;

[0059] S102, based on the SQL fuzzification algorithm, obtaining the target library table structure of the target business;

[0060] S103: Based on the target library table structure, create a test table in each storage node, and insert preset data into each test table, wherein the fields included in the preset data are the same as the fields included in the business data stored in the corresponding storage node; and the sum of the data values ​​of the same fields corresponding to the same ID in the test table storing the same preset data is a first preset value;

[0061] S104, concurrently executing a first preset test transaction, the first preset test transaction comprising: exchanging data values ​​of preset fields corresponding to the random IDs in two test tables containing the same random ID, and inserting new data into the two test tables containing the same random ID, the sum of data values ​​in the same fields in the new data in the two test tables being a second preset value;

[0062] S105. After the first preset test transaction is executed, determine whether the two test tables meet the preset consistency conditions. If the two test tables meet the preset consistency conditions, determine that the target business passes the consistency test, wherein the preset consistency conditions include: the sum of the data values ​​of the same fields of the preset data contained in the two test tables is the first preset value, the data value of the same field of the new data contained in the two test tables is the second preset value, and the number of times new data is inserted into the two test tables is the same as the number of successful executions of the first preset test transaction.

[0063] By applying the embodiments of the present invention, SQL fuzzification is performed based on a real database that stores business data, the actual library and table structure of the target business is determined, and a table is created based on the actual library and table structure of the target business. Test data is inserted into the created table according to the structure of the target business data, and the target business is tested, thereby implementing different consistency tests for different target businesses, that is, implementing consistency testing in customized scenarios.

[0064] The above S101-S105 are exemplarily described below:

[0065] The target business in S101 may be externally input or determined according to a preset detection order. In a possible embodiment, the target business may be input by a user on a preset detection page. For example, the preset detection page may include a target business selection box, and the user may determine the target business by checking or inputting the target business using a keyboard. In a possible embodiment, the consistency detection order of the business data of each business may be preset, and the target business to be detected may be determined according to the order.

[0066] In S102, the business database information of the target business can be obtained. The business data can be determined based on the actual business functions. For example, the business data can include fields contained in the user data of using the business. The user data can include user identification, personal information, operation behavior records, etc. The above-mentioned user identification can be a user name or user ID, etc. The above-mentioned personal information can include information filled in by the user, such as the user's age and gender. The operation behavior record can include the user's use of the business and the corresponding usage time. The above-mentioned operation behavior can include opening, browsing, purchasing, etc.

[0067] In order to avoid leakage of business data during the test process, the business SQL cannot be directly provided to the outside for use, so it is necessary to fuzzify the business data before passing it to the outside. In a possible embodiment, after obtaining the above business data, the above business data can be fuzzified. Specifically, the business data can be subjected to SQL fuzzification. SQL fuzzification refers to mapping the characters in SQL into random strings to ensure that the SQL statement before mapping cannot be inferred based on the results after mapping. Through SQL fuzzification, the library table structure actually used by the business database of the target business can be obtained. The library table structure may include the fields and data quantity contained in the business database. The above fields are determined based on the specific business, such as user identification, age, gender and other information.

[0068] Afterwards, the target business can be tested for consistency based on the library table. As mentioned above, in the related art, business data is usually stored in a distributed database, specifically, it is stored in a distributed database in the form of sharding, wherein sharding is a strategy for horizontally partitioning data storage, which is used to divide data into multiple fragments (or shards) according to certain rules, and store different shards on different physical nodes or database instances. This sharding method is intended to improve the performance, scalability and availability of the system. In an embodiment of the present invention, a data table can be established in each shard and data can be inserted into the data table. The structure of the data table established in each shard is the same as the library table structure of the business itself, and the data inserted into the data table is consistent with the field of the business data.

[0069] Exemplarily, the library table structure of the target business is that Table A in the A shard stores the user identifier of the target business, Table B in the B shard stores the user information of the user identifier within the first preset range, and Table C in the C shard stores the user information of the user identifier within the second preset range. Accordingly, during the test process, a data table can be established in the A shard, and the data table is used to store the user identifier, and the user identifier can be randomly generated, a data table can be established in the B shard, and the data table is used to store the user information of the user identifier within the first preset range, and a data table can be established in the C shard, and the data table is used to store the user information of the user identifier within the second preset range. The above-mentioned first preset range and second preset range can be flexibly defined according to the actual application scenario, such as setting the first preset range as user ID in [1,500], and setting the second preset range as user ID in [500,1000]. The above-mentioned user information may include multiple fields, such as name, age, and gender fields.

[0070] In practical applications, in order to ensure the stability of distributed storage, multiple copies are usually established for a data table, and the multiple copies are stored in different nodes to avoid a major impact on data query and other services when a storage node fails. Accordingly, when performing consistency testing, different copies of the same data table can be stored in different storage nodes according to the library table structure of the business data. Based on the above example, a data table can also be established in the D shard, and the data table is used to store user information whose user identifier is within the first preset range, and a data table can be established in the E shard, and the data table is used to store user information whose user identifier is within the second preset range.

[0071] In a possible embodiment, after creating a table in each shard, 1,000 pieces of data can be inserted into each table. The fields contained in the 1,000 pieces of data are the same as the fields contained in the business data of the target business, and the sum of each field in the records of the same ID in the tables of different shards is a preset value, that is, the sum of the values ​​under the same field in the different copies of the user information storing the same ID is the preset value. Based on the above example, the sum of the data values ​​under the same field in shards B and D is a preset value, and the sum of the data under the same field in shards C and E is a preset value. As a possible implementation method, when there are more than two copies of the same data table, the sum of the same fields in the sharded data table can be set to a preset value.

[0072] The above preset values ​​can be set for different data types. For example, the int type can make the sum of the data with the same ID in the two tables be 100 (the two numbers are randomly generated, and you can generate a number first, and then subtract the first number from 100 to get the second number); the datetime type is similar, and the sum of the data with the same ID in the two tables can be a specific Unix timestamp, which is converted into a datetime type and inserted into the data table; the string type (var char&blob) can insert a byte type ASCII character (converted to a number with a maximum value of 127), so that the sum of the data with the same ID in the two tables is 127.

[0073] After that, you can test the transaction based on the created table and the inserted data. Specifically, you can submit a distributed transaction, where a distributed transaction refers to a transaction operation involving multiple independent nodes or databases in a distributed system. These operations need to be executed as a whole to ensure data consistency and integrity. The purpose of a distributed transaction is to ensure that in a distributed environment, the system can still maintain a consistent state even in the event of network failures, node failures, etc.

[0074] The above transaction may include the following: randomly generate a target ID, determine the data table containing the target ID based on the target ID, and swap the values ​​of preset fields in the data table containing the target ID. If the number of data tables containing the target ID is greater than 2, tests can be performed on every two data table shards.

[0075] Secondly, two new data pieces can be inserted into the two tables in pieces. The new data has a different ID from the original data in the data table, but contains the same fields. For the two new data pieces, the data values ​​of the second preset fields are swapped.

[0076] The above distributed transactions can be executed concurrently. After the transaction is executed, it can be verified whether the amount of data in the two data tables is the same, whether the sum of the same fields in the two tables with the same ID is the preset value, and whether the new records inserted into a single table are equal to the number of successful transaction executions. If the verification result meets the above three conditions, it is determined that the target business database has passed the consistency test.

[0077] Through the above steps, the consistency of the distributed database is tested in combination with the data table information of the specific business, which realizes the consistency testing of distributed transactions in customized scenarios and improves the flexibility of testing.

[0078] In a possible embodiment, for a target service with a high latency scenario, the target service may be tested by the following steps:

[0079] S201, determining that two storage nodes whose deployment distances meet a preset distance condition are a first preset node and a second preset node;

[0080] S202: Create a user balance table in the first preset node and the second preset node as a first user balance table and a second user balance table, wherein the user balance table includes a user ID, an initial balance, and a version identifier; the user ID included in the first user balance table and the second user balance table is the same;

[0081] S203, starting multiple coroutines to concurrently execute a second preset test transaction, wherein the second preset test transaction includes: reducing a first random value in a balance of a first random ID in the first user balance table, and increasing the first random value in a balance of a second random ID in the second user balance table, reducing a second random value in a balance of a third random ID in the second user balance table, and increasing the second random value in a balance of a fourth random ID in the first user balance table; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1;

[0082] S204: After the second preset test transaction is executed, determine whether the first user balance table and the second user balance table meet a second preset test condition, wherein the second preset test condition includes: the sum of the balances of the user IDs in the first user balance table is consistent with the sum of the initial balances in the first user balance table, the sum of the balances of the user IDs in the second user balance table is consistent with the sum of the initial balances in the second user balance table, and the total number of versions in the first user balance table and the second balance table is four times the number of executions of the second preset test transaction.

[0083] The above-mentioned preset shards can be any two storage nodes included in the target business, or two storage nodes whose deployment distance meets the preset distance condition. The above-mentioned deployment distance refers to the physical distance between the machines or computer rooms where the two storage nodes are located. The above-mentioned preset distance condition can be set according to the actual business scenario, and can cross cities, provinces, etc.

[0084] During the test, a data table with the same structure can be created in two preset shards according to the table creation statement. The structure of the data table can be arbitrarily defined, and the present invention does not specifically limit this. Afterwards, test data can be added to the two preset tables. The amount of the test data can be set according to actual needs, such as 5000, 10000, etc. The test data may include a user identifier, an initial amount, and a version identifier, wherein the user identifier may specifically be a user ID, and the initial value of the version identifier is 0.

[0085] After inserting the test data, the sum of the initial amounts of each test data in the first amount table and the second amount table can be determined. After that, multiple coroutines can be started to perform transfer operations concurrently, wherein the coroutine is a program component that allows the lessee to pause and resume during execution. As a possible implementation method, a distributed transaction is started in each coroutine, and its initial balance is read from a table (denoted as table a) according to a randomly generated ID (denoted as the first random ID), and a random number is generated according to the read balance, the random number is less than the balance, the random number is subtracted from the initial amount of the ID in table a, and the version identifier of the corresponding ID record is increased by 1, and a piece of data of the second random ID is read from another table (denoted as table b), and the above random number is added, that is, the first random ID in table a transfers the above random number amount to the second random ID in table b, and the version identifier of the second random ID in table b is increased by 1; then a piece of data is randomly selected from table b and transferred to table a, the process is the same as above, a transfer behavior is generated, and the version identifier of the corresponding ID is increased by 1.

[0086] After each transaction is executed, it can be determined whether the two test tables included in the transaction meet the preset consistency conditions. If the two test tables meet the preset consistency conditions, it is determined that the target business has passed the consistency test, wherein the preset consistency conditions include: the sum of the data values ​​of the same fields of the preset data included in the two test tables is the first preset value, the data value of the same field of the new data included in the two test tables is the second preset value, and the number of times new data is inserted into the two test tables is the same as the number of successful executions of the first preset test transaction.

[0087] In a possible embodiment, when the number of test tables storing the same preset data exceeds 2, any two test tables among the test tables storing the same preset data are determined as two target test tables;

[0088] Set the sum of the data values ​​in the same field corresponding to the same ID in the two target test tables to be the first preset value;

[0089] The first preset test transaction includes: exchanging data values ​​of preset fields corresponding to random IDs in the two target test tables, and inserting new data into the two target test tables, wherein the sum of data values ​​in the same fields in the new data in the two target test tables is a second preset value;

[0090] The method further comprises:

[0091] Determine whether all test tables storing the same preset data have been tested. If they have been tested, determine that the target service has passed the consistency test; if there are test tables that have not been tested, return to the step of concurrently executing the first preset test transaction.

[0092] By executing the above transactions concurrently, you can test data consistency in high-latency scenarios and at different concurrency levels.

[0093] In a possible embodiment, consistency testing may be performed only on some IDs, that is, the second preset test transaction includes: reducing the third random value in the balance of the first preset ID in the first user balance table, and increasing the third random value in the balance of the second preset ID in the second user balance table, reducing the fourth random value in the balance of the second preset ID in the second user balance table, and increasing the fourth random value in the balance of the first preset ID in the first user balance table; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1.

[0094] The above preset ID may be one or more, which can be determined according to the actual application scenario. For example, the above test can be performed on each ID that uses a certain function in the service. That is, the synchronous transfer test can be performed on one or more IDs, and it can be determined whether the test table after the transfer meets the above consistency conditions.

[0095] By applying the embodiments of the present invention, the consistency of distributed transactions in a high-latency environment is tested by deploying shards in different computer rooms that are far away from each other; the consistency of distributed transactions in a high-concurrency scenario is tested by concurrently executing the above test cases; and the consistency of distributed transactions in a customized scenario is tested by combining business data table information.

[0096] Based on the same inventive concept, the embodiment of the present invention also provides a consistency testing device, such as Figure 2 As shown, the device 200 may include:

[0097] An acquisition module 201 is used to acquire a target business, wherein the business data of the target business is stored in each storage node in a distributed manner;

[0098] A fuzzy module 202 is used to obtain the target library table structure of the target business based on the SQL fuzzification algorithm;

[0099] A creation module 203 is used to create a test table in each of the storage nodes based on the target library table structure, and insert preset data into each of the test tables, wherein the fields included in the preset data are the same as the fields included in the business data stored in the corresponding storage node; and the sum of the data values ​​of the same fields corresponding to the same ID in the test table storing the same preset data is the first preset value;

[0100] The test module 204 is used to concurrently execute a first preset test transaction, wherein the first preset test transaction includes: exchanging data values ​​of preset fields corresponding to the random IDs in two test tables containing the same random ID, and inserting new data into the two test tables containing the same random ID, wherein the sum of data values ​​in the same fields in the new data in the two test tables is a second preset value;

[0101] The verification module 205 is used to determine whether the two test tables meet the preset consistency conditions after the first preset test transaction is executed. If the two test tables meet the preset consistency conditions, it is determined that the target business has passed the consistency test, wherein the preset consistency conditions include: the sum of the data values ​​of the same fields of the preset data contained in the two test tables is the first preset value, the data value of the same field of the new data contained in the two test tables is the second preset value, and the number of times new data is inserted into the two test tables is the same as the number of successful executions of the first preset test transaction.

[0102] In a possible embodiment, the test module is further used for:

[0103] Determine two storage nodes whose deployment distances meet a preset distance condition as a first preset node and a second preset node;

[0104] Creating a user balance table in the first preset node and the second preset node as a first user balance table and a second user balance table, wherein the user balance table includes a user ID, an initial balance, and a version identifier; the user ID included in the first user balance table and the second user balance table is the same;

[0105] Starting multiple coroutines to concurrently execute a second preset test transaction, wherein the second preset test transaction includes: reducing a first random value in a balance of a first random ID in a balance table of the first user, and increasing the first random value in a balance of a second random ID in a balance table of the second user, reducing a second random value in a balance of a third random ID in a balance table of the second user, and increasing the second random value in a balance of a fourth random ID in a balance table of the first user; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1;

[0106] After the second preset test transaction is executed, determine whether the first user balance table and the second user balance table meet the second preset test condition, wherein the second preset test condition includes: the sum of the balances of each user ID in the first user balance table is consistent with the sum of the initial balances in the first user balance table, the sum of the balances of each user ID in the second user balance table is consistent with the sum of the initial balances in the second user balance table, and the total number of versions in the first user balance table and the second balance table is four times the number of executions of the second preset test transaction.

[0107] In a possible embodiment, the second preset test transaction includes: reducing a third random value in the balance of the first preset ID in the first user balance table, and increasing the third random value in the balance of the second preset ID in the second user balance table, reducing a fourth random value in the balance of the second preset ID in the second user balance table, and increasing the fourth random value in the balance of the first preset ID in the first user balance table; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1.

[0108] Among them, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the present invention are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0109] The exemplary embodiment of the present invention further provides an electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication. The memory stores a computer program that can be executed by the at least one processor, and the computer program is used to enable the electronic device to perform a method according to an embodiment of the present invention when executed by the at least one processor.

[0110] Exemplary embodiments of the present invention also provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform a method according to an embodiment of the present invention.

[0111] An exemplary embodiment of the present invention further provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor of a computer, the computer is used to enable the computer to perform a method according to an embodiment of the present invention.

[0112] refer to Figure 3 , a block diagram of an electronic device 300 that can be used as a server or client of the present invention will now be described, which is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0113] like Figure 3 As shown, the electronic device 300 includes a computing unit 301, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 302 or a computer program loaded from a storage unit 308 into a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the electronic device 300 can also be stored. The computing unit 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0114] A plurality of components in the electronic device 300 are connected to the I / O interface 305, including: an input unit 306, an output unit 307, a storage unit 308, and a communication unit 309. The input unit 306 may be any type of device capable of inputting information to the electronic device 300, and the input unit 306 may receive input digital or character information, and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 307 may be any type of device capable of presenting information, and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 308 may include, but is not limited to, a disk, an optical disk. The communication unit 309 allows the electronic device 300 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0115] The computing unit 301 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 301 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 301 performs the various methods and processes described above. For example, in some embodiments, the above-mentioned consistency test method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 308. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 300 via the ROM 302 and / or the communication unit 309. In some embodiments, the computing unit 301 may be configured to perform the above-mentioned consistency test method in any other appropriate manner (e.g., by means of firmware).

[0116] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.

[0117] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0118] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.

[0119] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0120] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0121] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.

Claims

1. A consistency testing method, characterized in that: The method comprises: Acquire a target business, wherein business data of the target business is stored in each storage node in a distributed manner; Based on the SQL fuzzification algorithm, the target database table structure of the target business is obtained; Based on the target library table structure, a test table is created in each of the storage nodes, and preset data is inserted into each of the test tables, wherein the fields included in the preset data are the same as the fields included in the business data stored in the corresponding storage node; and the sum of the data values ​​of the same fields corresponding to the same ID in the test table storing the same preset data is the first preset value; Concurrently executing a first preset test transaction, the first preset test transaction comprising: exchanging data values ​​of preset fields corresponding to the random IDs in two test tables containing the same random ID, and inserting new data into the two test tables containing the same random ID, wherein the sum of data values ​​in the same fields in the new data in the two test tables is a second preset value; After the first preset test transaction is executed, determine whether the two test tables meet the preset consistency conditions. If the two test tables meet the preset consistency conditions, determine that the target business has passed the consistency test, wherein the preset consistency conditions include: the sum of the data values ​​of the same fields of the preset data contained in the two test tables is the first preset value, the data value of the same field of the new data contained in the two test tables is the second preset value, and the number of times new data is inserted into the two test tables is the same as the number of successful executions of the first preset test transaction.

2. The method according to claim 1, characterized in that: The first preset value and the second preset value are preset by the following steps; For each field, determine the data type of the field; the data type includes a numeric type, a datetime type, and a string type; Determine that the data value preset for the data type is a first preset value or a second preset value, wherein the data value set for the numeric type is a preset number, the data value set for the datetime type is a preset timestamp, and the data value set for the string type is a number corresponding to an ASCII character.

3. The method according to claim 1, characterized in that The method further comprises: When the number of test tables storing the same preset data exceeds 2, determining any two test tables among the test tables storing the same preset data as two target test tables; Set the sum of the data values ​​in the same field corresponding to the same ID in the two target test tables to be the first preset value; The first preset test transaction includes: exchanging data values ​​of preset fields corresponding to random IDs in the two target test tables, and inserting new data into the two target test tables, wherein the sum of data values ​​in the same fields in the new data in the two target test tables is a second preset value; The method further comprises: Determine whether all test tables storing the same preset data have been tested. If they have been tested, determine that the target service has passed the consistency test; if there are test tables that have not been tested, return to the step of concurrently executing the first preset test transaction.

4. The method according to claim 1, characterized in that The method further comprises: Determine two storage nodes whose deployment distances meet a preset distance condition as a first preset node and a second preset node; Creating a user balance table in the first preset node and the second preset node as a first user balance table and a second user balance table, wherein the user balance table includes a user ID, an initial balance, and a version identifier; the user ID included in the first user balance table and the second user balance table is the same; Starting multiple coroutines to concurrently execute a second preset test transaction, wherein the second preset test transaction includes: reducing a first random value in a balance of a first random ID in a balance table of the first user, and increasing the first random value in a balance of a second random ID in a balance table of the second user, reducing a second random value in a balance of a third random ID in a balance table of the second user, and increasing the second random value in a balance of a fourth random ID in a balance table of the first user; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1; After the second preset test transaction is executed, determine whether the first user balance table and the second user balance table meet the second preset test condition, wherein the second preset test condition includes: the sum of the balances of each user ID in the first user balance table is consistent with the sum of the initial balances in the first user balance table, the sum of the balances of each user ID in the second user balance table is consistent with the sum of the initial balances in the second user balance table, and the total number of versions in the first user balance table and the second balance table is four times the number of executions of the second preset test transaction.

5. The method according to claim 4, characterized in that The second preset test transaction includes: reducing a third random value in the balance of the first preset ID in the first user balance table, and increasing the third random value in the balance of the second preset ID in the second user balance table, reducing a fourth random value in the balance of the second preset ID in the second user balance table, and increasing the fourth random value in the balance of the first preset ID in the first user balance table; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1.

6. A consistency testing device, characterized in that: The device comprises: An acquisition module, used for acquiring a target business, wherein the business data of the target business is stored in each storage node in a distributed manner; A fuzzy module, used to obtain the target library table structure of the target business based on the SQL fuzzification algorithm; A creation module, configured to create a test table in each of the storage nodes based on the target library table structure, and insert preset data into each of the test tables, wherein the fields included in the preset data are the same as the fields included in the business data stored in the corresponding storage node; and the sum of the data values ​​of the same fields corresponding to the same ID in the test table storing the same preset data is a first preset value; A test module, configured to concurrently execute a first preset test transaction, wherein the first preset test transaction includes: exchanging data values ​​of preset fields corresponding to the random IDs in two test tables containing the same random ID, and inserting new data into the two test tables containing the same random ID, wherein the sum of data values ​​in the same fields in the new data in the two test tables is a second preset value; A verification module is used to determine whether the two test tables meet a preset consistency condition after the first preset test transaction is executed, and determine that the target business passes the consistency test when the two test tables meet the preset consistency condition, wherein the preset consistency condition includes: the sum of the data values ​​of the same field of the preset data contained in the two test tables is the first preset value, the data value of the same field of the new data contained in the two test tables is the second preset value, and the number of times new data is inserted into the two test tables is the same as the number of successful executions of the first preset test transaction.

7. The device according to claim 6, characterized in that The test module is also used to: Determine two storage nodes whose deployment distances meet a preset distance condition as a first preset node and a second preset node; Creating a user balance table in the first preset node and the second preset node as a first user balance table and a second user balance table, wherein the user balance table includes a user ID, an initial balance, and a version identifier; the user ID included in the first user balance table and the second user balance table is the same; Starting multiple coroutines to concurrently execute a second preset test transaction, wherein the second preset test transaction includes: reducing a first random value in a balance of a first random ID in a balance table of the first user, and increasing the first random value in a balance of a second random ID in a balance table of the second user, reducing a second random value in a balance of a third random ID in a balance table of the second user, and increasing the second random value in a balance of a fourth random ID in a balance table of the first user; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1; After the second preset test transaction is executed, determine whether the first user balance table and the second user balance table meet the second preset test condition, wherein the second preset test condition includes: the sum of the balances of each user ID in the first user balance table is consistent with the sum of the initial balances in the first user balance table, the sum of the balances of each user ID in the second user balance table is consistent with the sum of the initial balances in the second user balance table, and the total number of versions in the first user balance table and the second balance table is four times the number of executions of the second preset test transaction.

8. The device according to claim 7, characterized in that The second preset test transaction includes: reducing a third random value in the balance of the first preset ID in the first user balance table, and increasing the third random value in the balance of the second preset ID in the second user balance table, reducing a fourth random value in the balance of the second preset ID in the second user balance table, and increasing the fourth random value in the balance of the first preset ID in the first user balance table; each time the balance is changed, the version identifier corresponding to the user ID whose balance is changed is increased by 1.

9. An electronic device, comprising: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 5.

10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to make a computer execute the method according to any one of claims 1-5.