[ summary of the invention ]
In view of this, the present invention provides a data consistency detection method, apparatus, storage medium and server, which can detect the consistency of data, thereby improving the accuracy of data.
In one aspect, an embodiment of the present invention provides a data consistency detection method, where the method is based on a data consistency detection system, the system includes multiple detection areas, and each detection area includes a master node and a slave node;
the method comprises the following steps:
selecting a current detection area from the plurality of detection areas;
acquiring first remaining ticket information from the main node in the current detection area, and performing hash calculation on current main node detection section data extracted from the first remaining ticket information through a hash algorithm to generate a first hash value;
acquiring second remaining ticket information from the slave node of the current detection area, and performing hash calculation on the current slave node detection section data extracted from the second remaining ticket information through a hash algorithm to generate a second hash value;
and judging whether the first hash value is consistent with the second hash value or not, and acquiring a data consistency detection result.
Optionally, the acquiring first remaining ticket information from the master node in the current detection area, and performing hash calculation on current detection segment data extracted from the first remaining ticket information by using a hash algorithm to generate a first hash value includes:
acquiring first surplus ticket information from a main node in the current detection area, wherein the first surplus ticket information comprises a plurality of main node detection section data, and the main node detection section data comprises a plurality of main node detection fields;
extracting current main node detection section data from the first remaining ticket information, and extracting a specified main node detection field from the current main node detection section data;
and carrying out hash calculation on the specified main node detection field through a hash algorithm to generate a first hash value.
Optionally, the obtaining second remaining ticket information from the slave node of the current detection area, and performing hash calculation on current detection segment data extracted from the second remaining ticket information by using a hash algorithm to generate a second hash value includes:
acquiring second remaining ticket information from a slave node of the current detection area, wherein the second remaining ticket information comprises a plurality of slave node detection section data;
extracting current slave node detection segment data from the second remaining ticket information, and extracting a specified slave node detection field from the current slave node detection segment data;
and carrying out hash calculation on the specified slave node detection field through a hash algorithm to generate a second hash value.
Optionally, the determining whether the first hash value is consistent with the second hash value, and obtaining a data consistency detection result includes:
judging whether the first hash value is consistent with the second hash value;
and if the first hash value is consistent with the second hash value, judging whether next host node detection segment data can be extracted from the first remaining ticket information, if so, taking the next host node detection segment data as current host node detection segment data, continuing to execute the current host node detection segment data extracted from the first remaining ticket information, and extracting a specified host node detection field from the current host node detection segment data.
Optionally, the method further comprises:
and if the next main node detection section data is not extracted from the first remaining ticket information, selecting a next detection area from the plurality of detection areas, taking the next detection area as a current detection area, and continuing to execute the step of obtaining the first remaining ticket information from the main node in the current detection area, wherein the first remaining ticket information comprises the plurality of main node detection section data, and the main node detection section data comprises the plurality of main node detection fields.
Optionally, the detection segment data comprises a plurality of detection data, and the detection data comprises a plurality of detection fields; the method further comprises the following steps:
if the first hash value is judged to be inconsistent with the second hash value, extracting current main node detection data from the current main node detection section data;
performing hash calculation on the current main node detection data through a hash algorithm to generate a third hash value;
extracting current slave node detection data from the current slave node detection section data;
performing hash calculation on the current slave node detection data through a hash algorithm to generate a fourth hash value;
and judging whether the third hash value is consistent with the fourth hash value or not, and acquiring a data consistency detection result.
Optionally, the determining whether the third hash value is consistent with the fourth hash value, and acquiring a data consistency detection result includes:
judging whether the third hash value is consistent with the fourth hash value;
if the third hash value is consistent with the fourth hash value, extracting next host node detection data from the current host node detection segment data, taking the next host node detection data as the current host node detection data, and continuously executing the step of performing hash calculation on the current host node detection data through a hash algorithm to generate a third hash value;
and if the third hash value is judged to be inconsistent with the fourth hash value, generating alarm information.
On the other hand, the embodiment of the invention provides a device for detecting data consistency, wherein the device is based on a system for detecting data consistency, the system comprises a plurality of detection areas, and each detection area comprises a master node and a slave node;
the device comprises:
the selection module is used for selecting a current detection area from the plurality of detection areas; acquiring first remaining ticket information from a main node of the current detection area; acquiring second remaining ticket information from a slave node of the current detection area;
the calculation module is used for performing hash calculation on the data of the current main node detection section extracted from the first remaining ticket information through a hash algorithm to generate a first hash value; performing hash calculation on the data of the current slave node detection section extracted from the second remaining ticket information through a hash algorithm to generate a second hash value;
and the judging module is used for judging whether the first hash value is consistent with the second hash value or not and acquiring a data consistency detection result.
On the other hand, the embodiment of the present invention provides a storage medium, where the storage medium includes a stored program, and when the program runs, a device in which the storage medium is located is controlled to execute the above-mentioned data consistency detection method.
In another aspect, an embodiment of the present invention provides a server, including a memory and a processor, where the memory is used to store information including program instructions, and the processor is used to control execution of the program instructions, and the program instructions are loaded by the processor and execute the steps of the data consistency detection method described above.
In the technical scheme provided by the embodiment of the invention, a current detection area is selected from a plurality of detection areas, first surplus ticket information is obtained from a main node of the current detection area, and hash calculation is carried out on data of a current main node detection section extracted from the first surplus ticket information through a hash algorithm to generate a first hash value; and acquiring second remaining ticket information from the slave node of the current detection area, performing hash calculation on the data of the current slave node detection section extracted from the second remaining ticket information through a hash algorithm to generate a second hash value, judging whether the first hash value is consistent with the second hash value, and acquiring a data consistency detection result, so that the data consistency can be detected, and the data accuracy is improved.
[ detailed description ] embodiments
For better understanding of the technical solutions of the present invention, the following detailed descriptions of the embodiments of the present invention are provided with reference to the accompanying drawings.
It should be understood that the described embodiments are only some embodiments of the invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be understood that the term "and/or" as used herein is merely one type of associative relationship that describes an associated object, meaning that three types of relationships may exist, e.g., A and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
Fig. 1 is an architecture diagram of a data consistency detection system according to an embodiment of the present invention, as shown in fig. 1, the system includes a plurality of detection areas. For example, the plurality of detection areas may include detection area 1, detection area 2, detection area 3, detection area 4, and detection area 5, wherein each detection area includes a master node and a slave node.
In the embodiment of the present invention, as shown in fig. 1, the system includes a source database, a plurality of target databases, and a cache database cluster, where a master node includes the source database or the target database, and a slave node includes the target database or the cache database cluster corresponding to the target database. For example, the detection area 1 includes a source database 11 and a target database 12, where the source database 11 is a master node and the target database 12 is a slave node; the detection area 2 comprises a source database 11 and a target database 13, wherein the source database 11 is a master node, and the target database 13 is a slave node; the detection area 3 comprises a source database 11 and a target database 14, wherein the source database 11 is a master node, and the target database 14 is a slave node; the detection area 4 comprises a target database 13 and a cache database cluster 13 'corresponding to the target database, wherein the target database 13 is a master node, and the cache database cluster 13' corresponding to the target database is a slave node; the detection area 5 includes a target database 14 and a cache database cluster 14 'corresponding to the target database, where the target database 14 is a master node and the cache database cluster 14' corresponding to the target database is a slave node.
The source database may be 18 road bureau node databases, and the target database 12, the target database 13, and the target database 14 are node databases at a head office level, for example, the target database 12 is a central transit database of a railroad department, the target database 13 is a central transit database, and the target database 14 is a two-central transit database. The target database 13 is connected to the cache database cluster 13' corresponding to the target database 13 through the database snooping component 131, the data transmission component 132 and the warehousing component (not shown in the figure). The target database 14 is connected to the cache database cluster 14' corresponding to the target database 14 through the database snooping component 141, the data transmission component 142, and the warehousing component (not shown). Where, for example, the database listening component may comprise CTMSX, the data transfer component may comprise RabbitMQ, the invention is not particularly limited with respect to the type of component, e.g., the data transfer component may also comprise other MQ components.
In the embodiment of the present invention, the source database 11 is used to store the first remaining ticket information. The target database is used for storing the second remaining ticket information corresponding to the source database 11. The target database cluster is used for calculating the surplus ticket number in the surplus ticket information and providing an interface for the application program to call the interface to acquire the surplus ticket number.
Fig. 2 is a flowchart of a data consistency detection method according to an embodiment of the present invention, as shown in fig. 2, the method is based on a data consistency detection system, the system includes a plurality of detection areas, and each detection area includes a master node and a slave node; the method comprises the following steps:
step 101, selecting a current detection area from a plurality of detection areas.
102, acquiring first remaining ticket information from a main node in a current detection area, and performing hash calculation on data of a current main node detection section extracted from the first remaining ticket information through a hash algorithm to generate a first hash value.
And 103, acquiring second remaining ticket information from the slave node of the current detection area, and performing hash calculation on the current slave node detection section data extracted from the second remaining ticket information through a hash algorithm to generate a second hash value.
And 104, judging whether the first hash value is consistent with the second hash value or not, and acquiring a data consistency detection result.
In the technical scheme provided by the embodiment of the invention, a current detection area is selected from a plurality of detection areas, first surplus ticket information is obtained from a main node of the current detection area, and hash calculation is carried out on data of a current main node detection section extracted from the first surplus ticket information through a hash algorithm to generate a first hash value; and acquiring second remaining ticket information from the slave node of the current detection area, performing hash calculation on the data of the current slave node detection section extracted from the second remaining ticket information through a hash algorithm to generate a second hash value, judging whether the first hash value is consistent with the second hash value, and acquiring a data consistency detection result, so that the data consistency can be detected, and the data accuracy is improved.
Fig. 3 is a flowchart of a data consistency detection method according to another embodiment of the present invention, as shown in fig. 3, the method is based on a data consistency detection system, the system includes a plurality of detection areas, and each detection area includes a master node and a slave node; the method comprises the following steps:
step 201, selecting a current detection area from a plurality of detection areas.
In the embodiment of the present invention, as shown in fig. 1, the plurality of detection regions include a detection region 1, a detection region 2, a detection region 3, a detection region 4, and a detection region 5. For example, from among 5 detection areas, the detection area 1 is selected as the current detection area.
Step 202, obtaining first remaining ticket information from the master node in the current detection area, wherein the first remaining ticket information comprises a plurality of master node detection section data, and the master node detection section data comprises a plurality of master node detection fields.
In the embodiment of the present invention, the detection area includes a master node and a slave node, for example, the detection area 1 includes a source database 11 and a target database 12, where the source database 11 is the master node and the target database 12 is the slave node.
The master node includes the first remaining ticket information and other information. For example, first remaining ticket information is obtained from the source database 1, where the first remaining ticket information may include a plurality of remaining ticket tables. Since the data volume of the first remaining ticket information is large, the first remaining ticket information is divided into a plurality of master node detection segment data, for example, one master node detection segment data includes 100 master node detection data, and the specific number can be set according to the requirement. And each master node detection data comprises a plurality of master node detection fields, so that the master node detection section data can be determined to comprise a plurality of master node detection fields. The main node detection fields comprise fields of an initial station, a passing station, a destination station, a train number, a departure date, a seat level, the number of remaining tickets, a train number long-distance rule, a train number driving rule, a remaining ticket sharing rule, a scheduling judgment rule and the like, wherein the seat level, the remaining ticket data, the seat long-distance rule, the train number driving rule, the remaining ticket sharing rule and the scheduling judgment rule are fields related to a remaining ticket calculation rule. The train number long and short distance rule is used for representing train number types, wherein the train number types comprise long distance trains or short distance trains. The long distance of the train number refers to whether the train number purchases long distance or short distance, for example, a certain train passes through Beijing, Tianjin, Jinan, Nanjing, Suzhou and Shanghai, the long distance train refers to a ticket for purchasing a station after Beijing to Nanjing, and the short distance train refers to a ticket for purchasing Beijing to Tianjin or Beijing to Jinan. The driving rule of the train number is used for representing the driving state of the train number, and the driving state of the train number comprises daily operation or alternate-day operation and the like. The surplus ticket sharing rule is used for representing available stations of seats, and the available stations of the seats comprise available stations in the driving route or available stations specified in the route. The dispatching judgment rule is used for indicating whether a station running state and the train number are additionally hung or not, wherein the station running state comprises normal operation or stop operation, and whether the train number is additionally hung or not comprises whether the train number is increased or not. In addition, the detection field of the master node also includes other fields related to the remaining ticket calculation rule, which is not limited in the present invention.
And 203, extracting the data of the current main node detection segment from the first remaining ticket information, and extracting a specified main node detection field from the data of the current main node detection segment.
In the embodiment of the present invention, the first remaining ticket information includes a plurality of master node detection segment data, one master node detection segment data includes a plurality of master node detection data, and one master node detection data includes a plurality of master node detection fields. The designated main node detection fields comprise main fields related to the remaining ticket calculation rule, such as the number of remaining tickets, seat level, train number long and short distance rule, train number driving rule, remaining ticket sharing rule, scheduling judgment rule and other detection fields.
For example, the first remaining ticket information includes 100 pieces of master node detection segment data, one piece of master node detection segment data is extracted as current master node detection segment data, one piece of master node detection segment data includes a plurality of pieces of master node detection data, and each piece of master node detection data includes a plurality of identical master node detection fields, so that the master node detection end data also includes identical master node detection fields, and thus, a specified master node detection field can be extracted from the current master node detection segment data. The designated main node detection fields comprise detection fields such as the number of remaining tickets, seat levels, train number long and short distance rules, train number driving rules, remaining ticket sharing rules, scheduling judgment rules and the like. In the embodiment of the invention, the current main node detection segment data is locked from the first remaining ticket information, and the step of locking the current main node detection segment data is used for temporarily forbidding the change and deletion of the current main node detection segment data under the condition that the system allows the query of the current main node detection segment data without influencing the query, change and deletion of other data except the current main node detection segment data, thereby realizing the dynamic detection of data consistency, improving the flexibility of data detection and avoiding the problem that the service operation needs to be suspended because of the detection of the data consistency.
And 204, performing hash calculation on the specified main node detection field through a hash algorithm to generate a first hash value.
In the embodiment of the present invention, the hash algorithm includes CRC32, MD5, SHA1, a custom hash algorithm, and the like. The first hash value includes a character string or a numerical value, and is calculated according to an adopted hash algorithm. The embodiment of the invention performs hash calculation on the specified main node detection field.
For example, as shown in table 1 below, each row of data is master node detection data, and each 100 pieces of master node detection data are master node detection segment data. For example, one master node detection data includes 12 master node detection fields, where the master node detection fields are respectively an origin station, an approach station, a destination station, a train number, an departure date, a seat level, surplus ticket data, a train number long and short distance rule, a train number driving rule, a surplus ticket sharing rule, and a scheduling judgment rule, and thus one master node detection field data also includes 12 master node detection fields, where the detection fields such as the surplus ticket number, the seat level, the train number long and short distance rule, the train number driving rule, the surplus ticket sharing rule, the scheduling judgment rule, and the like are main fields related to the surplus ticket calculation rule, and thus the detection fields such as the surplus ticket number, the seat level, the train number long and short distance rule, the train number driving rule, the surplus ticket sharing rule, the scheduling judgment rule, and the like are used as specified master node detection fields.
After extracting the designated master node detection fields from the current master node detection segment data, each designated master node detection field also includes 100 pieces of data. For example, the specified detection fields of the master node are detection fields such as the number of remaining tickets, seat level, train number long and short distance rule, train number driving rule, remaining ticket sharing rule, and scheduling judgment rule, and the detection fields such as the number of remaining tickets, seat level detection field, train number long and short distance rule detection field, train number driving rule detection field, remaining ticket sharing rule detection field, and scheduling judgment rule detection field each include 100 data, and 100 data included in the detection fields such as the number of remaining tickets detection field, seat level detection field, train number long and short distance rule detection field, train number driving rule detection field, remaining ticket sharing rule detection field, and scheduling judgment rule detection field are subjected to hash calculation to generate a hash value.
TABLE 1
In other embodiments, for example, when there are few ticket purchasing services, every 500 pieces of master node detection data may be regarded as one piece of master node detection segment data, so that the detection rate may be increased. The number of the main node detections contained in the main node detection segment data is not specifically limited, and can be set according to requirements.
And step 205, acquiring second remaining ticket information from the slave node of the current detection area, wherein the second remaining ticket information comprises a plurality of slave node detection segment data, and the slave node detection segment data comprises a plurality of slave node detection fields.
In the embodiment of the invention, the slave node comprises second surplus ticket information corresponding to the first surplus ticket information in the master node and other information, wherein the second surplus ticket information also comprises a plurality of surplus ticket tables. And each surplus ticket table in the second surplus ticket information and each surplus ticket table in the first surplus ticket information have a one-to-one corresponding relation. Since the data amount of the second remaining ticket information is large, the second remaining ticket information is divided into a plurality of slave node detection segment data, for example, one slave node detection segment data includes 100 slave node detection data, and the specific number can be set according to the requirement. And each slave node test data includes a plurality of slave node test fields, so that it can be determined that the slave node test data includes a plurality of slave node test fields. The slave node detection fields comprise fields of an initial station, a passing station, a destination station, a train number, a departure date, a seat level, the number of remaining tickets, a train number long-distance rule, a train number driving rule, a remaining ticket sharing rule, a scheduling judgment rule and the like, wherein the seat level, the remaining ticket data, the seat long-distance rule, the train number driving rule, the remaining ticket sharing rule and the scheduling judgment rule are fields related to a remaining ticket calculation rule. The train number long and short distance rule is used for representing train number types, wherein the train number types comprise long distance trains or short distance trains. The long distance of the train number refers to whether the train number purchases long distance or short distance, for example, a certain train passes through Beijing, Tianjin, Jinan, Nanjing, Suzhou and Shanghai, the long distance train refers to a ticket for purchasing a station after Beijing to Nanjing, and the short distance train refers to a ticket for purchasing Beijing to Tianjin or Beijing to Jinan. The driving rule of the train number is used for representing the driving state of the train number, and the driving state of the train number comprises daily operation or alternate-day operation and the like. The surplus ticket sharing rule is used for representing available stations of seats, and the available stations of the seats comprise available stations in the driving route or available stations specified in the route. The dispatching judgment rule is used for indicating whether a station running state and the train number are additionally hung or not, wherein the station running state comprises normal operation or stop operation, and whether the train number is additionally hung or not comprises whether the train number is increased or not. In addition, the slave node detection field also includes other fields related to the remaining ticket calculation rule, which is not limited by the present invention.
And step 206, extracting the current slave node detection segment data from the second remaining ticket information, and extracting the specified slave node detection field from the current slave node detection segment data.
In the embodiment of the present invention, the second remaining ticket information includes a plurality of slave node detection segment data, one slave node detection segment data includes a plurality of slave node detection data, and one slave node detection data includes a plurality of slave node detection fields. The designated slave node detection fields comprise main fields related to the remaining ticket calculation rule, such as detection fields of the number of remaining tickets, seat levels, train number long and short distance rules, train number driving rules, remaining ticket sharing rules, scheduling judgment rules and the like.
For example, the second remaining ticket information includes 100 pieces of slave node gage segment data, one piece of slave node gage segment data is extracted as the current slave node gage segment data, and one piece of slave node gage segment data includes a plurality of pieces of slave node gage data, and since each piece of slave node gage data includes the same plurality of slave node gage fields, the slave node gage end data also includes the same slave node gage field, so that the specified slave node gage field can be extracted from the current slave node gage segment data. The designated slave node detection fields comprise main fields related to the remaining ticket calculation rule, such as the number of remaining tickets, seat level, train number long and short distance rule, train number driving rule, remaining ticket sharing rule, scheduling judgment rule and other detection fields. In the embodiment of the invention, the current slave node detection segment data is locked from the second remaining ticket information, and the step of locking the current slave node detection segment data temporarily prohibits the change and deletion of the current slave node detection segment data under the condition that the system allows the query of the current slave node detection segment data without influencing the query, change and deletion of other data except the current slave node detection segment data, thereby realizing the dynamic detection of data consistency, improving the flexibility of data detection and avoiding the problem that the service operation needs to be suspended because of the detection of the data consistency.
And step 207, performing hash calculation on the specified slave node detection field through a hash algorithm to generate a second hash value.
In the embodiment of the present invention, the hash algorithm includes CRC32, MD5, SHA1, a custom hash algorithm, and the like. The first hash value includes a character string or a numerical value, and is calculated according to an adopted hash algorithm. The embodiment of the invention performs Hash calculation on the specified slave node detection field.
For example, as shown in table 2 below, each line of data is one slave node probe data, and each 100 slave node probe data is one slave node probe segment data. For example, one slave node detection data includes 12 slave node detection fields, wherein the slave node detection fields are respectively an origin station, an approach station, a destination station, a train number, an departure date, a seat level, surplus ticket data, a train number long and short distance rule, a train number driving rule, a surplus ticket sharing rule, and a scheduling judgment rule, and therefore one slave node detection field data also includes 12 slave node detection fields, wherein the surplus ticket number, the seat level, the train number long and short distance rule, the train number driving rule, the surplus ticket sharing rule, and the scheduling judgment rule are main fields related to the surplus tickets, and therefore the surplus ticket number, the seat level, the train number long and short distance rule, the train number driving rule, the surplus ticket sharing rule, and the scheduling judgment rule are used as specified slave node detection fields.
After extracting the designated slave node sense fields from the current slave node sense segment data, each designated slave node sense field also includes 100 data. For example, the specified slave node detection fields are detection fields such as the number of remaining tickets, seat level, train number long and short distance rule, train number driving rule, remaining ticket sharing rule, and scheduling judgment rule, and the detection fields such as the number of remaining tickets detection field, seat level detection field, train number long and short distance rule detection field, train number driving rule detection field, remaining ticket sharing rule detection field, and scheduling judgment rule detection field each include 100 data, and 100 data included in the detection fields such as the number of remaining tickets detection field, seat level detection field, train number long and short distance rule detection field, train number driving rule detection field, remaining ticket sharing rule detection field, and scheduling judgment rule detection field are subjected to hash calculation to generate a hash value.
TABLE 2
In other embodiments, for example, when there is less ticket purchasing services, every 500 slave nodes may detect data as one slave node detection segment data, so that the detection rate may be increased. The number of slave node detections included in the slave node detection segment data is not particularly limited, and can be set according to requirements.
Step 208, judging whether the first hash value is consistent with the second hash value, if so, executing step 209; if not, go to step 212.
In the embodiment of the present invention, if it is determined that the first hash value is consistent with the second hash value, indicating that the data in the host node detection field corresponding to the first hash value is the same as the data in the slave node detection field corresponding to the second hash value, step 209 may be executed to continue determining the data in the next host node detection segment; if the first hash value is determined to be inconsistent with the second hash value, it indicates that the data in the designated master node detection field corresponding to the first hash value is different from the data in the designated slave node detection field corresponding to the second hash value, step 212 is performed.
Step 209, judging whether the next host node detection section data can be extracted from the first remaining ticket information, if so, executing step 210; if not, go to step 211.
In the embodiment of the invention, if the next main node detection segment data can be extracted from the first remaining ticket information, the fact that the undetected main node detection segment data still exists in the first remaining ticket information indicates that the data consistency needs to be continuously detected; if the next main node detection section data is judged not to be extracted from the first remaining ticket information, the main node detection section data in the first remaining ticket information is detected completely, and the detection of the data consistency of the main node detection end data in the next detection area can be continued.
And step 210, taking the next master node detection segment data as the current master node detection segment data, and continuing to execute step 203.
In the embodiment of the invention, as the undetected main node detection segment data still exists in the first remaining ticket information, the next main node detection segment data is used as the current main node detection segment data, and the detection of the data consistency is continuously carried out.
Step 211 is to select the next detection area from the plurality of detection areas, and continue to execute step 202 with the next detection area as the current detection area.
In the embodiment of the invention, as the detection of the data of the main node detection section in the first remaining ticket information is finished, the detection of the data consistency of the data of the main node detection section in the next detection area can be continuously detected.
And step 212, extracting the current main node detection data from the current main node detection section data.
In the embodiment of the present invention, as shown in table 1 above, the data of one master node detection segment includes a plurality of master node detection data, that is, each row of data is one master node detection data.
Step 213, performing hash calculation on the current host node detection data through a hash algorithm to generate a third hash value.
In the embodiment of the present invention, hash calculation is performed on the detection data of the host node by using a hash algorithm, as shown in table 1 above, that is, hash calculation is performed on data in each detection field of the host node in the detection data of the host node, so as to generate a third hash value.
And step 214, extracting the current slave node detection data from the current slave node detection segment data.
In the embodiment of the present invention, as shown in table 2 above, one slave node sensing section data includes a plurality of slave node sensing data, that is, each line of data is one slave node sensing data.
Step 215, performing hash calculation on the current slave node detection data through a hash algorithm to generate a fourth hash value.
In the embodiment of the present invention, the hash calculation is performed on the slave node detection data through a hash algorithm, as shown in table 1 above, that is, the hash calculation is performed on the data in each slave node detection field in the slave node detection data, so as to generate a third hash value.
Step 216, judging whether the third hash value is consistent with the fourth hash value, if so, executing step 217; if not, go to step 218.
In the embodiment of the present invention, if it is determined that the third hash value is consistent with the fourth hash value, it indicates that the host node detection data corresponding to the third hash value is the same as the slave node detection data corresponding to the second hash value, step 217 may be executed, and the next host node detection data may be continuously determined; if the third hash value is determined to be inconsistent with the fourth hash value, it indicates that the detection data of the master node corresponding to the third hash value is different from the detection field of the slave node corresponding to the fourth hash value, go to step 218, and generate an alarm message.
Step 217, extracting next host node detection data from the current host node detection segment data, taking the next host node detection data as the current host node detection data, and continuing to execute step 213.
In the embodiment of the invention, as the undetected main node detection data still exists in the current main node detection section data, the next main node detection data is taken as the current main node detection data, and the detection of the data consistency is continued.
Step 218, generating alarm information.
In the embodiment of the invention, if the third hash value is detected to be inconsistent with the fourth hash value, the result indicates that the detection data of the main node corresponding to the third hash value is different from the detection field of the slave node corresponding to the fourth hash value, that is, the remaining ticket information of the main node and the slave node is inconsistent, so that the alarm information is generated according to the different data in the detection fields of the main node corresponding to the third hash value and the slave node corresponding to the fourth hash value, the subsequent data synchronization processing is facilitated, the remaining ticket information can be consistent, the problem that the ticket cannot be purchased on a user network due to the inconsistency of the remaining ticket information is solved, and the accuracy of the data is improved.
In the embodiment of the present invention, the above steps 201 to 218 are a data dynamic detection process, and data consistency is detected by extracting data in detection segments, so that service is not interrupted, and data consistency is detected in real time while influence on service is reduced.
Optionally, in an embodiment of the present invention, the method further includes: and locking the first remaining ticket information of the master node and the second remaining ticket information of the slave node, and performing the steps 201 to 218 to detect the data consistency of the first remaining ticket information of the master node and the second remaining ticket information of the slave node.
An alternative scheme in the embodiment of the present invention is different from the above steps 201 to 208 in that the above steps 201 to 208 lock the current master node detection segment data or the current slave node detection segment data so as not to affect the change and deletion of other data. And in the alternative, the first remaining ticket information of the master node and the second remaining ticket information of the slave node are locked, namely, the change and deletion of all data are suspended, and the data consistency is detected. In the alternative, the method can be performed without ticket purchase service, and compared with the scheme of the step 201 to the step 208, since the alternative does not need to extract the detection segment for data consistency detection, the detection rate of the alternative is greater than that of the scheme.
In the technical scheme provided by the embodiment of the invention, a current detection area is selected from a plurality of detection areas, first surplus ticket information is obtained from a main node of the current detection area, and hash calculation is carried out on data of a current main node detection section extracted from the first surplus ticket information through a hash algorithm to generate a first hash value; and acquiring second remaining ticket information from the slave node of the current detection area, performing hash calculation on the data of the current slave node detection section extracted from the second remaining ticket information through a hash algorithm to generate a second hash value, judging whether the first hash value is consistent with the second hash value, and acquiring a data consistency detection result, so that the data consistency can be detected, and the data accuracy is improved.
Fig. 4 is a schematic structural diagram of an apparatus for detecting data consistency according to an embodiment of the present invention, as shown in fig. 4, the apparatus includes: a selecting module 11, a calculating module 12 and a detecting module 13.
The selecting module 11 is configured to select a current detection area from the multiple detection areas; acquiring first remaining ticket information from a main node of the current detection area; and acquiring second remaining ticket information from the slave node of the current detection area.
The calculation module 12 is configured to perform hash calculation on data of a current host node detection segment extracted from the first remaining ticket information through a hash algorithm to generate a first hash value; and performing hash calculation on the data of the current slave node detection section extracted from the second remaining ticket information through a hash algorithm to generate a second hash value.
The detection module 13 is configured to determine whether the first hash value is consistent with the second hash value, and obtain a data consistency detection result.
In the embodiment of the present invention, the computing module 12 of the apparatus specifically includes: an acquisition submodule 121 and a calculation submodule 122.
The obtaining submodule 121 is configured to obtain first remaining ticket information from a master node in a current detection area, where the first remaining ticket information includes a plurality of master node detection segment data, and the master node detection segment data includes a plurality of master node detection fields; and extracting current main node detection segment data from the first remaining ticket information, and extracting a specified main node detection field from the current main node detection segment data.
The calculating submodule 122 is configured to perform hash calculation on the specified main node detection field through a hash algorithm, so as to generate a first hash value.
In this embodiment of the present invention, the computing module 12 of the apparatus further includes:
the obtaining sub-module 121 is further configured to obtain second remaining ticket information from a slave node in the current detection area, where the second remaining ticket information includes a plurality of slave node detection segment data, and the slave node detection segment data includes a plurality of slave node detection fields; current slave node detection segment data extracted from the second remaining ticket information, and a specified slave node detection field extracted from the current slave node detection segment data.
The calculating sub-module 122 is further configured to perform a hash calculation on the specified slave node detection field through a hash algorithm, so as to generate a second hash value.
In this embodiment of the present invention, the detection module 13 of the apparatus further includes: a detection submodule 131, a judgment submodule 132 and a processing submodule 133.
The detection submodule 131 is configured to determine whether the first hash value is consistent with the second hash value; if the first hash value is determined to be consistent with the second hash value, the triggering determination sub-module 132 determines whether the next host node detection segment data can be extracted from the first remaining ticket information.
The judging sub-module 132 is configured to judge whether the next host node detection segment data can be extracted from the first remaining ticket information.
The processing sub-module 133 is configured to, if the determining sub-module 132 determines that the next host node detection segment data is extracted from the first remaining ticket information, take the next host node detection segment data as the current host node detection segment data, and trigger the obtaining sub-module 121 to continue executing the current host node detection segment data extracted from the first remaining ticket information, and extract a specified host node detection field from the current host node detection segment data.
In this embodiment of the present invention, the detection module 13 of the apparatus further includes:
the processing sub-module 133 is further configured to, if the determining sub-module 132 determines that the next host node detection segment data is not extracted from the first remaining ticket information, select a next detection area from the multiple detection areas, and use the next detection area as the current detection area, trigger the obtaining sub-module 121 to continue to execute the step of obtaining the first remaining ticket information from the host node in the current detection area, where the first remaining ticket information includes the multiple host node detection segment data, and the host node detection segment data includes the multiple host node detection fields.
In this embodiment of the present invention, the detection module 13 of the apparatus further includes: an extraction sub-module 134 and a calculation sub-module 135.
The extracting submodule 134 is configured to extract current host node detection data from the current host node detection segment data if the detecting submodule 131 determines that the first hash value is inconsistent with the second hash value.
The calculating sub-module 135 is configured to perform a hash calculation on the current host node detection data through a hash algorithm, so as to generate a third hash value.
The extracting sub-module 134 is further configured to extract current slave node detection data from the current slave node detection segment data;
the calculating sub-module 135 is further configured to perform a hash calculation on the current slave node detection data through a hash algorithm, so as to generate a fourth hash value.
The detection submodule 131 is further configured to determine whether the third hash value is consistent with the fourth hash value, and obtain a data consistency detection result.
In this embodiment of the present invention, the detection sub-module 131 of the apparatus further includes: a detection sub-module 1311, an extraction sub-module 1312, and a generation sub-module 1313.
The detecting sub-module 1311 is further configured to determine whether the third hash value is consistent with the fourth hash value.
The extracting submodule 1312 is configured to, if the detecting submodule 1311 determines that the third hash value is consistent with the fourth hash value, extract next host node detection data from the current host node detection segment data, use the next host node detection data as the current host node detection data, and trigger the calculating submodule 135 to continue to perform the step of performing hash calculation on the current host node detection data through a hash algorithm to generate a third hash value;
the generating sub-module 1313 is configured to generate alarm information if the detecting sub-module 1311 determines that the third hash value is inconsistent with the fourth hash value.
In the technical scheme provided by the embodiment of the invention, a current detection area is selected from a plurality of detection areas, first surplus ticket information is obtained from a main node of the current detection area, and hash calculation is carried out on data of a current main node detection section extracted from the first surplus ticket information through a hash algorithm to generate a first hash value; and acquiring second remaining ticket information from the slave node of the current detection area, performing hash calculation on the data of the current slave node detection section extracted from the second remaining ticket information through a hash algorithm to generate a second hash value, judging whether the first hash value is consistent with the second hash value, and acquiring a data consistency detection result, so that the data consistency can be detected, and the data accuracy is improved.
An embodiment of the present invention provides a storage medium, where the storage medium includes a stored program, where, when the program runs, a device on which the storage medium is located is controlled to execute each step of the above embodiment of the data consistency detection method, and for a specific description, reference may be made to the above embodiment of the data consistency detection method.
An embodiment of the present invention provides a server, including a memory and a processor, where the memory is used to store information including program instructions, and the processor is used to control execution of the program instructions, and the program instructions are loaded and executed by the processor to implement the steps of the data consistency detection method. For a detailed description, reference may be made to the above-described embodiments of the data consistency detection method.
Fig. 5 is a schematic diagram of a server according to an embodiment of the present invention. As shown in fig. 5, the server 3 of this embodiment includes: the processor 31, the memory 32, and the computer program 33 stored in the memory 32 and capable of running on the processor 31, where the computer program 33 is executed by the processor 31 to implement the method for detecting data consistency in the embodiments, and in order to avoid repetition, the details are not repeated herein. Alternatively, the computer program is executed by the processor 31 to implement the functions of each model/unit in the data consistency detection apparatus in the embodiment, which are not described herein for avoiding redundancy.
The server 3 includes, but is not limited to, a processor 31, a memory 32. Those skilled in the art will appreciate that fig. 5 is merely an example of the server 3 and is not intended to be limiting of the server 3, and may include more or fewer components than shown, or some components in combination, or different components, e.g., the server 3 may also include input output devices, network access devices, buses, etc.
The Processor 31 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 32 may be an internal storage unit of the server 3, such as a hard disk or a memory of the server 3. The memory 32 may also be an external storage device of the server 3, such as a plug-in hard disk provided on the server 3, a Smart Memory Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Further, the memory 32 may also include both an internal storage unit of the server 3 and an external storage device. The memory 32 is used for storing computer programs and other programs and data required by the server 3. The memory 32 may also be used to temporarily store data that has been output or is to be output.
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.
In the embodiments provided in the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
The integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) or a Processor (Processor) to execute some steps of the methods 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 above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.