CN112307124A - Database synchronization verification method, device, equipment and storage medium - Google Patents

Database synchronization verification method, device, equipment and storage medium Download PDF

Info

Publication number
CN112307124A
CN112307124A CN202011207860.4A CN202011207860A CN112307124A CN 112307124 A CN112307124 A CN 112307124A CN 202011207860 A CN202011207860 A CN 202011207860A CN 112307124 A CN112307124 A CN 112307124A
Authority
CN
China
Prior art keywords
source
target
synchronization
field
name
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011207860.4A
Other languages
Chinese (zh)
Inventor
刘刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202011207860.4A priority Critical patent/CN112307124A/en
Publication of CN112307124A publication Critical patent/CN112307124A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages

Abstract

The invention relates to the field of big data and discloses a database synchronization verification method, a device, equipment and a storage medium. The method comprises the following steps: receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode; analyzing the GG synchronization request to obtain the owner names and the table names of the source table and the target table; verifying whether the table structure definitions of the source table and the target table are correct; then verifying whether each record of the source table is correctly synchronized to the target table; then when GG synchronization is finished, verifying whether the number of records of the source table and the target table is consistent; and finally outputting a GG synchronous verification result between the source database and the target database. The invention also relates to blockchain techniques, the source and target tables being stored in blockchains. The invention realizes the automatic detection of GG synchronous data and improves the detection accuracy and the detection efficiency.

Description

Database synchronization verification method, device, equipment and storage medium
Technical Field
The present invention relates to big data, and in particular, to a method, an apparatus, a device, and a storage medium for database synchronization verification.
Background
In some application scenarios, database synchronization is required, for example, a test scenario generally employs a GG (Golden Gate, a log-based structured data replication backup software) synchronization process to implement data synchronization, but the entire synchronization process cannot be suspended, and the source database is synchronized to the target database whenever there is a data change.
Generally, data differences between a source database and a target database do not occur if the GG synchronization process is not interrupted, and therefore, the existing GG synchronization process does not have data difference verification. When data difference occurs in the database synchronization process, a tester is required to manually check the data difference, the workload is high, errors are easy to occur, and the testing work efficiency is low.
Disclosure of Invention
The invention mainly aims to solve the problem that the difference of synchronous data cannot be automatically detected in the database synchronization process.
The invention provides a database synchronization verification method in a first aspect, which comprises the following steps:
receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode;
analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
verifying whether the table structure definitions of the source table and the target table are correct or not according to the owner name and the table name of the source table and the owner name and the table name of the target table;
if the table structure definitions of the source table and the target table are correct, verifying whether each record of the source table is correctly synchronized to the target table;
if all records of the source table are correctly synchronized to the target table, verifying whether the number of the records of the source table is consistent with that of the records of the target table when GG synchronization is finished;
and outputting a GG synchronous verification result between the source database and the target database.
Optionally, in a first implementation manner of the first aspect of the present invention, the verifying whether the table structure definitions of the source table and the target table are correct according to the owner name and the table name of the source table and the owner name and the table name of the target table includes:
judging whether the field types of each field in the source table and the target table are consistent and whether the field length of the target table is larger than or equal to the field length of the source table according to the owner name and the table name of the source table and the owner name and the table name of the target table;
if the field type and the field length of each field in the source table and the target table are correct, the unique index name and each list name of the target table are searched for whether to exist in the source table;
and if the unique index name and each list name of the target table exist in the source table, determining that the table structures of the source table and the target table are defined correctly.
Optionally, in a second implementation manner of the first aspect of the present invention, if the table structure definitions of the source table and the target table are correct, verifying whether each record of the source table is correctly synchronized to the target table includes:
if the table structure definitions of the source table and the target table are correct, acquiring a field value corresponding to each field from a preset configuration table according to the field type and the field length of each field in the source table;
executing a preset SQL inserting statement, and writing the obtained field value of each field into a source table;
executing a preset first query SQL statement, and judging whether the target table has a field value inserted in the source table and the corresponding field names are the same;
if the field value inserted in the source table exists in the target table and the corresponding field names are the same, executing a preset SQL updating statement and updating the field value inserted in the source table;
executing a preset second query SQL statement, and judging whether the updated field value in the source table exists in the target table and whether the corresponding field names are the same;
if the updated field value in the source table exists in the target table and the corresponding field names are the same, executing a preset SQL deleting statement and deleting the updated field value in the source table;
and executing a preset third query SQL statement, and judging whether the field value updated in the synchronous source table in the target table is deleted and the field names corresponding to the deleted field values are the same.
Optionally, in a third implementation manner of the first aspect of the present invention, if each record of the source table is correctly synchronized to the target table, when GG synchronization ends, verifying whether the number of records of the source table and the number of records of the target table are consistent includes:
if all records of the source table are correctly synchronized to the target table, respectively acquiring a first number of records of the source table and a second number of records of the target table when GG synchronization is finished, and judging whether the first number of records is consistent with the second number of records.
Optionally, in a fourth implementation manner of the first aspect of the present invention, after verifying whether the number of records in the source table is consistent with that in the target table when GG synchronization ends if each record in the source table is correctly synchronized to the target table, the method further includes:
when the GG synchronization process detects data difference, recording the check point of the data difference and generating data difference description.
Optionally, in a fifth implementation manner of the first aspect of the present invention, the source table and the target table are stored in a block chain.
The second aspect of the present invention provides a database synchronization verification apparatus, including:
the system comprises a receiving module, a synchronization module and a synchronization module, wherein the receiving module is used for receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, and the GG synchronization is a log-based structured data synchronization mode;
the analysis module is used for analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
the first verification module is used for verifying whether the table structure definitions of the source table and the target table are correct or not according to the owner name and the table name of the source table and the owner name and the table name of the target table;
the second verification module is used for verifying whether each record of the source table is correctly synchronized to the target table or not if the table structure definitions of the source table and the target table are correct;
the third verification module is used for verifying whether the number of records of the source table is consistent with that of the target table when GG synchronization is finished if all records of the source table are correctly synchronized to the target table;
and the output module is used for outputting the GG synchronous verification result between the source database and the target database.
Optionally, in a first implementation manner of the second aspect of the present invention, the first verification module includes:
the first judging unit is used for judging whether the field types of each field in the source table and the target table are consistent and whether the field length of the target table is larger than or equal to the field length of the source table according to the owner name and the table name of the source table and the owner name and the table name of the target table;
the searching unit is used for searching whether the unique index name and each list name of the target table exist in the source table or not if the field type and the field length of each field in the source table and the target table are correct;
and the determining unit is used for determining that the table structure definitions of the source table and the target table are correct if the unique index name and each list name of the target table exist in the source table.
Optionally, in a second implementation manner of the second aspect of the present invention, the second verification module includes:
the device comprises an acquisition unit, a configuration unit and a processing unit, wherein the acquisition unit is used for acquiring a field value corresponding to each field from a preset configuration table according to the field type and the field length of each field in a source table if the table structures of the source table and a target table are defined correctly;
the second judging unit is used for executing preset inserting SQL sentences and writing the obtained field value of each field into the source table; executing a preset first query SQL statement, and judging whether the target table has a field value inserted in the source table and the corresponding field names are the same;
a third judging unit, configured to execute a preset update SQL statement to update the field value inserted in the source table if the field value inserted in the source table exists in the target table and corresponding field names are the same; executing a preset second query SQL statement, and judging whether the updated field value in the source table exists in the target table and whether the corresponding field names are the same;
the fourth judging unit is used for executing the preset deleting SQL statement and deleting the updated field value in the source table if the updated field value in the source table exists in the target table and the corresponding field names are the same; and executing a preset third query SQL statement, and judging whether the field value updated in the synchronous source table in the target table is deleted and the field names corresponding to the deleted field values are the same.
Optionally, in a third implementation manner of the second aspect of the present invention, the third verification module is further configured to:
if all records of the source table are correctly synchronized to the target table, respectively acquiring a first number of records of the source table and a second number of records of the target table when GG synchronization is finished, and judging whether the first number of records is consistent with the second number of records.
Optionally, in a fourth implementation manner of the second aspect of the present invention, the database synchronization verification apparatus further includes:
and the recording module is used for recording a check point of data difference and generating data difference description when the GG synchronization process detects the data difference.
Optionally, in a fifth implementation manner of the second aspect of the present invention, the source table and the target table are stored in a block chain.
A third aspect of the present invention provides a database synchronization verification apparatus, including: a memory and at least one processor, the memory having instructions stored therein; the at least one processor invokes the instructions in the memory to cause the database synchronization verification apparatus to perform the database synchronization verification method described above.
A fourth aspect of the present invention provides a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to execute the above-mentioned database synchronization verification method.
According to the technical scheme provided by the invention, GG synchronization verification is carried out after a GG synchronization request is received; whether the table structure definition of the source table and the target table is correct or not is verified through the attribute name and the table name of the source table and the owner name and the table name of the target table in the GG synchronization request; then verifying whether each record of the source table is correctly synchronized to the target table; then, whether the record numbers of the source table and the target table are consistent is verified; and finally, all GG synchronous verification results of the source table and the target table are output by the methods, so that automatic GG synchronous data detection is realized, and the detection accuracy and detection efficiency are improved.
Drawings
FIG. 1 is a schematic diagram of a first embodiment of a database synchronization verification method according to an embodiment of the present invention;
FIG. 2 is a diagram of a database synchronization verification method according to a second embodiment of the present invention;
FIG. 3 is a diagram of a database synchronization verification method according to a third embodiment of the present invention;
FIG. 4 is a diagram illustrating a fourth embodiment of a database synchronization verification method according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of an embodiment of a database synchronization verification apparatus according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of another embodiment of a database synchronization verification apparatus according to an embodiment of the present invention;
fig. 7 is a schematic diagram of an embodiment of a database synchronization verification apparatus in an embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a database synchronization verification method, a database synchronization verification device and a storage medium, wherein the method comprises the steps of receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode; analyzing the GG synchronization request to obtain the owner names and the table names of the source table and the target table; firstly, verifying whether the table structure definitions of a source table and a target table are correct; then verifying whether each record of the source table is correctly synchronized to the target table; then when GG synchronization is finished, verifying whether the number of records of the source table and the target table is consistent; and finally outputting a GG synchronous verification result between the source database and the target database. The invention also relates to blockchain techniques, the source and target tables being stored in blockchains. The invention realizes the automatic detection of GG synchronous data and improves the detection accuracy and the detection efficiency.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein. Furthermore, the terms "comprises," "comprising," or "having," and any variations thereof, are intended to cover non-exclusive inclusions, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
For convenience of understanding, a detailed flow of the embodiment of the present invention is described below, and referring to fig. 1, a first embodiment of the database synchronization verification method in the embodiment of the present invention includes:
101. receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode;
it is to be understood that the execution subject of the present invention may be a database synchronization verification apparatus, and may also be a terminal or a server, which is not limited herein. The embodiment of the present invention is described by taking a server as an execution subject. It is emphasized that the source table and the target table may also be stored in nodes of a blockchain in order to further ensure privacy and security of the source table and the target table.
In this embodiment, after receiving the GG synchronization request, the source database performs GG synchronization data on the target database, and then simultaneously triggers verification of the synchronization data in the source database and the target database. In addition, the method and the device perform six-aspect verification on the synchronous data in the source database and the target database.
102. Analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
in this embodiment, when the source database performs GG synchronization on the target database, a GG synchronization request is initiated, where the GG synchronization request includes a principal name and a table name for identifying each source table in the source database, and a principal name and a table name of each target table in the corresponding target database, so as to determine a storage format and storage space content of the GG synchronization data.
103. Verifying whether the table structure definitions of the source table and the target table are correct or not according to the owner name and the table name of the source table and the owner name and the table name of the target table;
in this embodiment, the first aspect of GG synchronization is verified: the field types and field lengths of each field in the source table and the target table are compared to ensure that the field types are consistent, and the field length of the target table is greater than or equal to the field length of the source table. The method specifically comprises the following steps:
connecting fields, field types and field lengths in each source table in a source database and each corresponding target table in a target database according to the main name, wherein the database can be an SQL (Structured Query Language) database;
judging whether the table names of the source tables in the source database contain the table names of all target tables in the target database;
if yes, circularly comparing field types in the source table and the target table with the same table name, judging whether the field types are consistent and judging whether the field lengths meet preset conditions;
if the fields are consistent and in accordance with each other, determining that all the fields pass the check, and if the fields are inconsistent or not in accordance with each other, determining that the fields which are inconsistent or not in accordance with each other do not pass the check, and outputting notification information that the check does not pass;
if not, it is determined that GG synchronization fails the check and notification information indicating that the check fails is output.
In this embodiment, the second aspect in GG synchronization is verified: whether the index value of each data in the source table contains the index values of all data in the target table. The method specifically comprises the following steps:
connecting each source table in the source database with the index name in each corresponding target table in the target database;
determining all index values in the source table and the target table based on the index name;
comparing the index values in the source table and the target table, and judging whether the source table contains all the index values of the target table;
if the fields are not included, the fields which are not included are determined not to pass the check, and notification information that the check is not passed is output.
104. If the table structure definitions of the source table and the target table are correct, verifying whether each record of the source table is correctly synchronized to the target table;
in this embodiment, through the previous verification of the first aspect and the second aspect of GG synchronization, we obtain the field index, the field type, and the field length of each field in the source table. Here, the third, fourth and fifth aspects of GG synchronization are verified. The third aspect is used for verifying whether the insertion fields of the source table and the target table in the GG synchronization are the same, the fourth aspect is used for verifying whether the update fields of the source table and the target table in the GG synchronization are the same, the fifth aspect is used for verifying whether the deletion fields of the source table and the target table in the GG synchronization are the same, and the specific verification steps are as follows:
sequentially assigning values to fields in each source table, each target table and each source table and each target table to obtain corresponding field values;
splicing SQL sentences corresponding to the fields inserted, updated or deleted in the source table based on the field values of the source table, the target tables and the fields, and executing the SQL sentences in the source database;
and checking whether the target library has corresponding copied records and the same assigned content, if so, determining that all fields pass the check, otherwise, determining that the fields with the coded records do not pass the check, and outputting notification information that the check does not pass.
105. If all records of the source table are correctly synchronized to the target table, verifying whether the number of the records of the source table is consistent with that of the records of the target table when GG synchronization is finished;
in this embodiment, a sixth aspect of GG synchronization is verified: whether the number of records in the fields of the source table and the target table are consistent. And different types of databases can adopt corresponding field counting commands. Specifically, verifying whether the record numbers of the source table and the target table are consistent may be performed by respectively obtaining a first record number of the source table and a second record number of the target table, and determining whether the first record number is consistent with the second record number.
106. And outputting a GG synchronous verification result between the source database and the target database.
In this embodiment, the verification results of the first to sixth aspects in GG synchronization are output according to a display rule (for example, a front-end display model), where the display rule defines a display area of each verification result in a manner of displaying a template.
In the embodiment of the invention, GG synchronization verification is carried out after a GG synchronization request is received; verifying whether the table structure definitions of the source table and the target table are correct or not through the attribute name and the table name of the source table and the owner name and the table name of the target table in the GG synchronization request; then verifying whether each record of the source table is correctly synchronized to the target table; then, whether the record numbers of the source table and the target table are consistent is verified; and finally, outputting all GG synchronous verification results of the source table and the target table so as to realize automatic detection of GG synchronous data and improve the detection accuracy and detection efficiency.
Referring to fig. 2, a second embodiment of the database synchronization verification method according to the embodiment of the present invention includes:
201. receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode;
202. analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
203. judging whether the field types of each field in the source table and the target table are consistent and whether the field length of the target table is larger than or equal to the field length of the source table according to the owner name and the table name of the source table and the owner name and the table name of the target table;
in this embodiment, first, whether the field types of the fields in the source table and the target table are consistent is compared: the table names and the field types of the source table and the target table are respectively taken out according to the main names, and then the difference between the table names and the field types is compared, so that the method can be directly executed through a database command line. For example, for an Oracle database, field type consistency verification can be performed by the following commands:
select.owner,T.TABLE_NAME,T.COLUMN_NAME,T.DATA_TYPE,T.DAT A_LENGTH
from all _ tab _ columns t where t, inner ═ UPPER ('owner NAME') AND T, TABLE _ NAME ═ UPPER ('table NAME')
Verifying whether the field length of the target table is larger than or equal to the field length of the source table, sorting the field lengths according to the ASCII code values of the fields at the same positions, and comparing the field lengths according to the sorting number, for example, the field lengths of the source table are aceb and acebd, and the sorting order of the ASCII code values: b is more than a and c is more than d and e are less than a, and the field length abce is less than abcde.
204. If the field type and the field length of each field in the source table and the target table are correct, the unique index name and each list name of the target table are searched for whether to exist in the source table;
205. and if the unique index name and each list name of the target table exist in the source table, determining that the table structures of the source table and the target table are defined correctly.
In the embodiment, an index view corresponding to a storage field is obtained according to the owner name and the table name of the source table and the owner name and the table name of the target table; creating a corresponding index table according to the index view, and filtering according to the index name in the index table; according to the index names left after the filtering of the corresponding index names of the target table, whether the unique index name and each list name of the target table exist in the source table or not and the index names which do not exist in the source table can be determined. The specific execution command line is as follows:
select t.table_owner,t.table_name,t.index_name,
t.column_name from all_ind_columns t,
all_indexes i where t.table_owner=i.table_owner and
t.index_name=i.index_name and
t.table_name=i.table_name and
i.uniqueness='UNIQUE'and
table _ name UPPER ('table name') and
table _ owner ═ UPPER ('owner name').
206. If the table structure definitions of the source table and the target table are correct, verifying whether each record of the source table is correctly synchronized to the target table;
207. if all records of the source table are correctly synchronized to the target table, verifying whether the number of the records of the source table is consistent with that of the records of the target table when GG synchronization is finished;
208. and outputting a GG synchronous verification result between the source database and the target database.
In the embodiment of the invention, the detailed description is given to the verification of whether the table structure definitions of the source table and the target table are correct, and if the table names and the main attribute names of the source table and the target table are consistent with the field types, the field lengths and the index names of the fields, the table structure definitions of the source table and the target table can be determined to be correct, so that the first round of GG synchronization verification is realized.
Referring to fig. 3, a third embodiment of the database synchronization verification method according to the embodiment of the present invention includes:
301. receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode;
302. analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
303. verifying whether the table structure definitions of the source table and the target table are correct or not according to the owner name and the table name of the source table and the owner name and the table name of the target table;
304. if the table structure definitions of the source table and the target table are correct, acquiring a field value corresponding to each field from a preset configuration table according to the field type and the field length of each field in the source table;
in this embodiment, a preset configuration table specifies field value assignment rules for each field type and field length, and performs field value configuration on each field, for example, for fields in the range of the a type and the B length, a fixed value a + a fixed value B + a sequence number (for example, 1, 2, and 3 … …) is used, so as to obtain a field value corresponding to each field. In addition, each source table is sequentially numbered and inserted into the field values, and then the final field value of each field is: sequence number + fixed value a + fixed value b + sequence number.
305. Executing a preset SQL inserting statement, and writing the obtained field value of each field into a source table;
in this embodiment, for the SQL database, a command line for inserting a field is configured to be a preset inserted SQL statement, which may be an insert table _ name value, and each corresponding field is assigned by inserting the SQL statement, that is, an action of writing in the source table is performed.
306. Executing a preset first query SQL statement, and judging whether the target table has a field value inserted in the source table and the corresponding field names are the same;
in this embodiment, when the first query SQL statement in the source data is executed, the field to which the field value is assigned is still synchronized to the target database, so that it is only necessary to query whether each field in the target database corresponding to the target table is also assigned, and it is determined whether GG synchronization is normal.
It should be noted that, here, the SQL statement and the first query SQL statement are inserted to verify whether the data synchronization function after the field value is inserted in the GG synchronization is normal.
307. If the field value inserted in the source table exists in the target table and the corresponding field names are the same, executing a preset SQL updating statement and updating the field value inserted in the source table;
in this embodiment, for the SQL database, the command line for updating the field is configured to serve as a preset update SQL statement, which may be update table _ name set a (field name) ═ new-value (new field value), and the field value of each corresponding field is updated by updating the SQL statement, that is, the action for updating the field value in the source table is performed.
308. Executing a preset second query SQL statement, and judging whether the updated field value in the source table exists in the target table and whether the corresponding field names are the same;
in this embodiment, when the second query SQL statement in the source data is executed, the field to which the field value is reassigned is still synchronized to the target database, so that it is only necessary to query whether each field in the target database corresponding to the target table also updates the field value, and it is determined whether the GG synchronization is normal.
It should be noted that, here, the SQL statement and the second query SQL statement are updated to verify whether the data synchronization function after the field value is updated in the GG synchronization is normal.
309. If the updated field value in the source table exists in the target table and the corresponding field names are the same, executing a preset SQL deleting statement and deleting the updated field value in the source table;
in this embodiment, for the SQL database, the command line for deleting a field is configured to serve as a preset delete SQL statement, which may be a delete from table _ name _ word value, and by deleting the SQL statement, each corresponding field is deleted, that is, an action for deleting a field value in the source table is performed.
310. Executing a preset third query SQL statement, and judging whether the field value updated in the synchronous source table in the target table is deleted and the field names corresponding to the deleted field values are the same;
in this embodiment, when the third query SQL statement in the source data is executed, the field value after the field value is deleted is still synchronized to the target database, so that it is only necessary to query whether the field value of each field in the target table in the target database is also deleted, and it is determined whether the GG synchronization is normal.
It should be noted that, here, by deleting the SQL statement and the third query SQL statement, it is verified whether the data synchronization function after deleting the field value in the GG synchronization is normal.
311. If all records of the source table are correctly synchronized to the target table, verifying whether the number of the records of the source table is consistent with that of the records of the target table when GG synchronization is finished;
312. and outputting a GG synchronous verification result between the source database and the target database.
In the embodiment of the invention, the verification of whether each record of a source table is correctly synchronized into a target table is described in detail, firstly, each field in the source table is assigned, then, field value insertion, field value updating and field value deletion are sequentially carried out, after GG synchronization, whether the field value of each corresponding field in the target table is inserted, updated and deleted is respectively judged, whether the three synchronization functions of the GG synchronization are correct is detected, and the second-layer verification of the GG synchronization is realized.
Referring to fig. 4, a fourth embodiment of the database synchronization verification method according to the embodiment of the present invention includes:
401. receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode;
402. analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
403. verifying whether the table structure definitions of the source table and the target table are correct or not according to the owner name and the table name of the source table and the owner name and the table name of the target table;
404. if the table structure definitions of the source table and the target table are correct, verifying whether each record of the source table is correctly synchronized to the target table;
405. if all records of the source table are correctly synchronized to the target table, respectively acquiring a first record number of the source table and a second record number of the target table when GG synchronization is finished, and judging whether the first record number is consistent with the second record number;
in this embodiment, for an Oracle (Oracle) database, a select count () from COLUMN _ NAME (i.e., table NAME) is used to execute the database statement, so that the record number of fields in the source table and the target table corresponding to the table NAME can be obtained, if the record number of the fields is the same as that of the source table and that of the target table, all the fields can be determined to pass the check, otherwise, it is determined that the fields corresponding to the source table fail to be synchronized, the fields cannot pass the check, and notification information indicating that the check fails is output.
406. When the GG synchronization process detects data difference, recording the check point of the data difference and generating data difference description;
in this embodiment, for the verification results of the first to sixth aspects in the GG synchronization process, when data is abnormal in the GG synchronization process, a checkpoint at which the data is abnormal is recorded and corresponding data difference descriptions, such as table structure abnormality, field synchronization error, field record number error, and the like, are generated, where specific data abnormality descriptions, including field value insertion abnormality, field value update abnormality, and field value deletion abnormality, are also described after the table structure abnormality. And the data difference description can be output as a G data synchronization verification result between the source database and the target database.
407. And outputting a GG synchronous verification result between the source database and the target database.
In the embodiment of the invention, the verification of whether the record numbers of the source table and the target table are consistent is described in detail, the first record number of the source table and the second record number of the target table are obtained respectively and compared to directly obtain whether the record numbers are consistent, and if the record numbers are not consistent, data difference description needs to be generated to realize GG synchronous third-layer verification.
In the above description of the database synchronization verification method in the embodiment of the present invention, the following description of the database synchronization verification apparatus in the embodiment of the present invention refers to fig. 5, and an embodiment of the database synchronization verification apparatus in the embodiment of the present invention includes:
a receiving module 501, configured to receive a GG synchronization request between a source database and a target database and perform GG synchronization, where GG synchronization is a log-based structured data synchronization manner;
an analyzing module 502, configured to analyze the GG synchronization request, obtain an owner name and a table name of the source table, and obtain an owner name and a table name of the target table;
a first verifying module 503, configured to verify whether the table structure definitions of the source table and the target table are correct according to the owner name and the table name of the source table and the owner name and the table name of the target table;
a second verifying module 504, configured to verify whether each record of the source table is correctly synchronized to the target table if the table structure definitions of the source table and the target table are correct;
a third verifying module 505, configured to verify, if each record of the source table is correctly synchronized to the target table, whether the number of records of the source table is consistent with that of records of the target table when GG synchronization ends;
an output module 506, configured to output a GG synchronization verification result between the source database and the target database.
In the embodiment of the invention, GG synchronization verification is carried out after a GG synchronization request is received; verifying whether the table structure definitions of the source table and the target table are correct or not through the attribute name and the table name of the source table and the owner name and the table name of the target table in the GG synchronization request; verifying whether each record of the source table is correctly synchronized to the target table; then, whether the record numbers of the source table and the target table are consistent is verified; and finally, outputting all GG synchronous verification results of the source table and the target table so as to realize automatic detection of GG synchronous data and improve the detection accuracy and detection efficiency.
Referring to fig. 6, another embodiment of the database synchronization verification apparatus according to the embodiment of the present invention includes:
a receiving module 501, configured to receive a GG synchronization request between a source database and a target database and perform GG synchronization, where GG synchronization is a log-based structured data synchronization manner;
an analyzing module 502, configured to analyze the GG synchronization request, obtain an owner name and a table name of the source table, and obtain an owner name and a table name of the target table;
a first verifying module 503, configured to verify whether the table structure definitions of the source table and the target table are correct according to the owner name and the table name of the source table and the owner name and the table name of the target table;
a second verifying module 504, configured to verify whether each record of the source table is correctly synchronized to the target table if the table structure definitions of the source table and the target table are correct;
a third verifying module 505, configured to verify, if each record of the source table is correctly synchronized to the target table, whether the number of records of the source table is consistent with that of records of the target table when GG synchronization ends;
an output module 506, configured to output a GG synchronization verification result between the source database and the target database.
Specifically, the first verification module includes:
a first determining unit 5031, configured to determine, according to the owner name and the table name of the source table and the owner name and the table name of the target table, whether field types of each field in the source table and the target table are consistent, and whether a field length of the target table is greater than or equal to a field length of the source table;
a searching unit 5032, configured to, if the field type and the field length of each field in the source table and the target table are correct, search whether the unique index name and each list name of the target table exist in the source table;
a determining unit 5033, configured to determine that the table structures of the source table and the target table are defined correctly if the unique index name and the respective list names of the target table exist in the source table.
Specifically, the second verification module includes:
an obtaining unit 5041, configured to obtain, if the table structures of the source table and the target table are defined correctly, a field value corresponding to each field from a preset configuration table according to a field type and a field length of each field in the source table;
a second judging unit 5042, configured to execute a preset insert SQL statement, and write the obtained field value of each field into the source table; the system comprises an acquisition unit, a search unit and a search unit, wherein the acquisition unit is used for executing a preset first query SQL statement and judging whether field values inserted in a source table exist in a target table or not and corresponding field names are the same;
a third judging unit 5043, configured to execute a preset update SQL statement to update the field value inserted in the source table if the field value inserted in the source table exists in the target table and corresponding field names are the same; executing a preset second query SQL statement, and judging whether the updated field value in the source table exists in the target table and whether the corresponding field names are the same;
a fourth judging unit 5044, configured to execute a preset delete SQL statement to delete the updated field value in the source table if the updated field value in the source table exists in the target table and corresponding field names are the same; and executing a preset third query SQL statement, and judging whether the field value updated in the synchronous source table in the target table is deleted and the field names corresponding to the deleted field values are the same.
Specifically, the third verification module is further configured to:
if all records of the source table are correctly synchronized to the target table, respectively acquiring a first number of records of the source table and a second number of records of the target table when GG synchronization is finished, and judging whether the first number of records is consistent with the second number of records.
Specifically, the database synchronization verification apparatus further includes:
and a recording module 507, configured to record a checkpoint at which a data difference occurs and generate a data difference description when a data difference is detected in the GG synchronization process.
Specifically, the source table and the target table are stored in a block chain.
In the embodiment of the invention, three layers of verification of GG synchronization are introduced in detail, if the table names and the main attribute names of a source table and a target table, and the field types, the field lengths and the index names of all fields are consistent, the table structures of the source table and the target table can be determined to be correctly defined, and the first round of verification of GG synchronization is realized; assigning values to fields in the source table, sequentially performing field value insertion, field value update and field value deletion, respectively judging whether the field values of corresponding fields in the target table are inserted, updated and deleted after GG synchronization, checking whether the three synchronous functions of the GG synchronization are correct, and realizing second-layer verification of the GG synchronization; and finally, respectively obtaining the first record number of the source table and the second record number of the target table, comparing, directly obtaining whether the two are consistent, and if not, generating data difference description to realize GG synchronization third-layer verification.
Fig. 5 and fig. 6 describe the database synchronization verification apparatus in the embodiment of the present invention in detail from the perspective of the modular functional entity, and the database synchronization verification apparatus in the embodiment of the present invention is described in detail from the perspective of hardware processing.
Fig. 7 is a schematic structural diagram of a database synchronization verification apparatus 700 according to an embodiment of the present invention, where the database synchronization verification apparatus 700 may generate relatively large differences due to different configurations or performances, and may include one or more processors (CPUs) 710 (e.g., one or more processors) and a memory 720, one or more storage media 730 (e.g., one or more mass storage devices) for storing applications 733 or data 732. Memory 720 and storage medium 730 may be, among other things, transient storage or persistent storage. The program stored in the storage medium 730 may include one or more modules (not shown), each of which may include a series of instruction operations on the database synchronization verification apparatus 700. Further, the processor 710 may be configured to communicate with the storage medium 730 to execute a series of instruction operations in the storage medium 730 on the database synchronization verification apparatus 700.
Database synchronization verification apparatus 700 may also include one or more power supplies 740, one or more wired or wireless network interfaces 750, one or more input-output interfaces 760, and/or one or more operating systems 731, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, and the like. Those skilled in the art will appreciate that the database synchronization verification device configuration shown in FIG. 7 does not constitute a limitation of database synchronization verification devices, and may include more or fewer components than shown, or some components in combination, or a different arrangement of components.
The invention further provides a database synchronization verification device, which includes a memory and a processor, where the memory stores computer readable instructions, and the computer readable instructions, when executed by the processor, cause the processor to execute the steps of the database synchronization verification method in the foregoing embodiments.
The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium, and which may also be a volatile computer-readable storage medium, having stored therein instructions, which, when run on a computer, cause the computer to perform the steps of the database synchronization verification method.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A database synchronization verification method is characterized by comprising the following steps:
receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, wherein the GG synchronization is a log-based structured data synchronization mode;
analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
verifying whether the table structure definitions of the source table and the target table are correct or not according to the owner name and the table name of the source table and the owner name and the table name of the target table;
if the table structure definitions of the source table and the target table are correct, verifying whether each record of the source table is correctly synchronized to the target table;
if all records of the source table are correctly synchronized to the target table, verifying whether the number of the records of the source table is consistent with that of the records of the target table when GG synchronization is finished;
and outputting a GG synchronous verification result between the source database and the target database.
2. The database synchronization verification method according to claim 1, wherein the verifying whether the table structure definitions of the source table and the target table are correct according to the owner name and the table name of the source table and the owner name and the table name of the target table comprises:
judging whether the field types of each field in the source table and the target table are consistent and whether the field length of the target table is larger than or equal to the field length of the source table according to the owner name and the table name of the source table and the owner name and the table name of the target table;
if the field type and the field length of each field in the source table and the target table are correct, the unique index name and each list name of the target table are searched for whether to exist in the source table;
and if the unique index name and each list name of the target table exist in the source table, determining that the table structures of the source table and the target table are defined correctly.
3. The database synchronization verification method of claim 2, wherein if the table structure definitions of the source table and the target table are correct, verifying whether the records of the source table are correctly synchronized to the target table comprises:
if the table structure definitions of the source table and the target table are correct, acquiring a field value corresponding to each field from a preset configuration table according to the field type and the field length of each field in the source table;
executing a preset SQL inserting statement, and writing the obtained field value of each field into a source table;
executing a preset first query SQL statement, and judging whether the target table has a field value inserted in the source table and the corresponding field names are the same;
if the field value inserted in the source table exists in the target table and the corresponding field names are the same, executing a preset SQL updating statement and updating the field value inserted in the source table;
executing a preset second query SQL statement, and judging whether the updated field value in the source table exists in the target table and whether the corresponding field names are the same;
if the updated field value in the source table exists in the target table and the corresponding field names are the same, executing a preset SQL deleting statement and deleting the updated field value in the source table;
and executing a preset third query SQL statement, and judging whether the field value updated in the synchronous source table in the target table is deleted and the field names corresponding to the deleted field values are the same.
4. The database synchronization verification method according to claim 1, wherein if each record of the source table is correctly synchronized to the target table, verifying whether the number of records of the source table and the number of records of the target table are consistent at the end of the GG synchronization comprises:
if all records of the source table are correctly synchronized to the target table, respectively acquiring a first number of records of the source table and a second number of records of the target table when GG synchronization is finished, and judging whether the first number of records is consistent with the second number of records.
5. The database synchronization verification method according to any one of claims 1 to 4, wherein after verifying whether the number of records of the source table and the target table are consistent at the end of GG synchronization if the records of the source table are correctly synchronized to the target table, the method further comprises:
when the GG synchronization process detects data difference, recording the check point of the data difference and generating data difference description.
6. The database synchronization verification method of claim 1, wherein the source table and the target table are in a blockchain.
7. A database synchronization verification apparatus, comprising:
the system comprises a receiving module, a synchronization module and a synchronization module, wherein the receiving module is used for receiving a GG synchronization request between a source database and a target database and carrying out GG synchronization, and the GG synchronization is a log-based structured data synchronization mode;
the analysis module is used for analyzing the GG synchronization request to obtain an owner name and a table name of a source table and an owner name and a table name of a target table;
the first verification module is used for verifying whether the table structure definitions of the source table and the target table are correct or not according to the owner name and the table name of the source table and the owner name and the table name of the target table;
the second verification module is used for verifying whether each record of the source table is correctly synchronized to the target table or not if the table structure definitions of the source table and the target table are correct;
the third verification module is used for verifying whether the number of records of the source table is consistent with that of the target table when GG synchronization is finished if all records of the source table are correctly synchronized to the target table;
and the output module is used for outputting the GG synchronous verification result between the source database and the target database.
8. The database synchronization verification apparatus according to claim 7, wherein the second verification module comprises:
the device comprises an acquisition unit, a configuration unit and a processing unit, wherein the acquisition unit is used for acquiring a field value corresponding to each field from a preset configuration table according to the field type and the field length of each field in a source table if the table structures of the source table and a target table are defined correctly;
the first judging unit is used for executing a preset inserting SQL statement and writing the obtained field value of each field into the source table; the system comprises an acquisition unit, a search unit and a search unit, wherein the acquisition unit is used for executing a preset first query SQL statement and judging whether field values inserted in a source table exist in a target table or not and corresponding field names are the same;
the second judging unit is used for executing a preset SQL updating statement and updating the field value inserted in the source table if the field value inserted in the source table exists in the target table and the corresponding field names are the same; executing a preset second query SQL statement, and judging whether the updated field value in the source table exists in the target table and whether the corresponding field names are the same;
a third judging unit, configured to execute a preset delete SQL statement to delete the updated field value in the source table if the updated field value in the source table exists in the target table and corresponding field names are the same; and executing a preset third query SQL statement, and judging whether the field value updated in the synchronous source table in the target table is deleted and the field names corresponding to the deleted field values are the same.
9. A database synchronization verification apparatus, characterized in that the database synchronization verification apparatus comprises: a memory and at least one processor, the memory having instructions stored therein;
the at least one processor invoking the instructions in the memory to cause the database synchronization verification apparatus to perform the database synchronization verification method of any of claims 1-6.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a database synchronization verification method according to any one of claims 1 to 6.
CN202011207860.4A 2020-11-03 2020-11-03 Database synchronization verification method, device, equipment and storage medium Pending CN112307124A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011207860.4A CN112307124A (en) 2020-11-03 2020-11-03 Database synchronization verification method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011207860.4A CN112307124A (en) 2020-11-03 2020-11-03 Database synchronization verification method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112307124A true CN112307124A (en) 2021-02-02

Family

ID=74333845

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011207860.4A Pending CN112307124A (en) 2020-11-03 2020-11-03 Database synchronization verification method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112307124A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113204598A (en) * 2021-05-28 2021-08-03 平安科技(深圳)有限公司 Data synchronization method, system and storage medium
CN114817410A (en) * 2022-06-23 2022-07-29 心鉴智控(深圳)科技有限公司 Service data processing method, device, equipment and storage medium
CN116089537A (en) * 2023-04-07 2023-05-09 江西省智能产业技术创新研究院 Incremental data synchronization method, system, computer and storage medium
CN117667951A (en) * 2024-01-31 2024-03-08 杭州海康威视数字技术股份有限公司 Data processing method and device for characteristic data of camera

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102231161A (en) * 2011-06-30 2011-11-02 北京新媒传信科技有限公司 Method for synchronously verifying and monitoring databases
US20120030172A1 (en) * 2010-07-27 2012-02-02 Oracle International Corporation Mysql database heterogeneous log based replication
CN109885614A (en) * 2019-01-04 2019-06-14 平安科技(深圳)有限公司 A kind of method and apparatus that data are synchronous
US20190197174A1 (en) * 2017-12-22 2019-06-27 Warevalley Co., Ltd. Method and system for replicating data to heterogeneous database and detecting synchronization error of heterogeneous database through sql packet analysis
CN110162461A (en) * 2019-04-16 2019-08-23 平安科技(深圳)有限公司 Data synchronize verification method, device and computer equipment
CN110263032A (en) * 2019-05-13 2019-09-20 平安科技(深圳)有限公司 Table structure control methods, device, computer equipment and storage medium in database
CN111143470A (en) * 2019-12-27 2020-05-12 中国银行股份有限公司 Cross-platform database data synchronization comparison method and device

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120030172A1 (en) * 2010-07-27 2012-02-02 Oracle International Corporation Mysql database heterogeneous log based replication
CN102231161A (en) * 2011-06-30 2011-11-02 北京新媒传信科技有限公司 Method for synchronously verifying and monitoring databases
US20190197174A1 (en) * 2017-12-22 2019-06-27 Warevalley Co., Ltd. Method and system for replicating data to heterogeneous database and detecting synchronization error of heterogeneous database through sql packet analysis
CN109885614A (en) * 2019-01-04 2019-06-14 平安科技(深圳)有限公司 A kind of method and apparatus that data are synchronous
CN110162461A (en) * 2019-04-16 2019-08-23 平安科技(深圳)有限公司 Data synchronize verification method, device and computer equipment
CN110263032A (en) * 2019-05-13 2019-09-20 平安科技(深圳)有限公司 Table structure control methods, device, computer equipment and storage medium in database
CN111143470A (en) * 2019-12-27 2020-05-12 中国银行股份有限公司 Cross-platform database data synchronization comparison method and device

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113204598A (en) * 2021-05-28 2021-08-03 平安科技(深圳)有限公司 Data synchronization method, system and storage medium
CN113204598B (en) * 2021-05-28 2023-05-09 平安科技(深圳)有限公司 Data synchronization method, system and storage medium
CN114817410A (en) * 2022-06-23 2022-07-29 心鉴智控(深圳)科技有限公司 Service data processing method, device, equipment and storage medium
CN116089537A (en) * 2023-04-07 2023-05-09 江西省智能产业技术创新研究院 Incremental data synchronization method, system, computer and storage medium
CN117667951A (en) * 2024-01-31 2024-03-08 杭州海康威视数字技术股份有限公司 Data processing method and device for characteristic data of camera
CN117667951B (en) * 2024-01-31 2024-05-03 杭州海康威视数字技术股份有限公司 Data processing method and device for characteristic data of camera

Similar Documents

Publication Publication Date Title
CN112307124A (en) Database synchronization verification method, device, equipment and storage medium
KR101149994B1 (en) External metadata processing
US8019795B2 (en) Data warehouse test automation framework
CN107807982B (en) Consistency checking method and device for heterogeneous database
CN108132957B (en) Database processing method and device
CN110134694B (en) Rapid comparison device and method for table data in double-activity database
JP3201945B2 (en) How to compare database tables
US5579515A (en) Method of checking index integrity in a DB2 database
CN111259004B (en) Method for indexing data in storage engine and related device
US20060026199A1 (en) Method and system to load information in a general purpose data warehouse database
US20080091742A1 (en) System and method for detecting and updating geographical information dataset versions
CN112579586A (en) Data processing method, device, equipment and storage medium
EP2797001B1 (en) System and method for creating variants in a test database during various test stages
CN111324781A (en) Data analysis method, device and equipment
CN112579604A (en) Test system number making method, device, equipment and storage medium
CN115422180A (en) Data verification method and system
US11693834B2 (en) Model generation service for data retrieval
CN114443625A (en) Database processing method and device
CN113778997B (en) Database version management method, system and equipment
CN112559195B (en) Database deadlock detection method and device, test terminal and medium
CN114282260A (en) Method and device for auditing and executing Clickhouse DDLSQL semantic grammar
Bindal et al. Etl life cycle
CN116150264A (en) Database replica data master-slave consistency verification method, device, equipment and medium
CN116340430A (en) Data synchronization verification method and related equipment
CN114996240A (en) Data table verification method, device, equipment, storage medium and program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination