Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," "target," and "original," etc. in the description and claims of the present application and the above-described drawings are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be capable of executing sequences other than those illustrated or otherwise described. Furthermore, the terms "comprises," "comprising," and any variations thereof, are intended to cover a non-exclusive inclusion, 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 or inherent to such process, method, article, or apparatus.
Fig. 1 is a schematic flow chart of a data synchronization method according to an embodiment of the present application, where the embodiment may be applied to a scenario of synchronizing data in an original database and a target database in a process of migrating data in the original region to the target region. The data synchronization method provided by the embodiment of the application can be implemented by the data synchronization device provided by the embodiment of the application, and the device can be implemented in a software and/or hardware mode. In a specific embodiment, the data synchronization means may be integrated in an electronic device, which may be a computer or a server or the like, for example. The execution body for executing the method can be an electronic device. The migration of data from the original region to the target region is described in detail below as an example, and the electronic device may provide a data synchronization service by building a data integration platform (Apache SeaTunnel).
In smoothly migrating the data of the original region to the target region, the data integration tool may be used to synchronize the full amount of the data of the original database to the target database, and then split the user request from the original region to the target region in proportion and gradually increase the split proportion until the user request is 100% split to the target region, while in the gradual split process, incremental synchronization is started, if the user request is split to the original region and the user request involves data change operations of the original database, such as insertion, update and deletion, the data change operation of the original database is synchronized to the target database, and if the user request is split to the target region and the user request involves data change operation of the target database, the data change operation of the target database is synchronized to the original database.
By way of example, as shown in fig. 2, which is an example of data synchronization of an original area and a target area, the load balancing server in fig. 2 shunts 50% of user requests to the application server 1 of the original area and the remaining 50% of user requests to the application server 2 of the target area, the electronic device may synchronize the insertion operation of the original database into the target database when the user request 1 is shunted to the application server 1 of the original area and the user request 1 is to insert data into the original database, and the electronic device may synchronize the update operation of the target database into the original database when the user request 2 is shunted to the application server 2 of the target area and the user request 2 is to update data in the target database.
Referring to fig. 1, the data synchronization method of the present embodiment includes, but is not limited to, the following steps:
s110, when the first database is detected to execute the first data changing operation, setting a first distributed lock for the first data changing operation in the lock management database.
The first database is a database in which data change operation occurs, and the first database can be an original database of an original area or a target database of a target area.
The first data changing operation is an operation of changing data in the first database, and can change the data in the first database, and exemplary, the first data changing operation can comprise insertion, update, deletion and the like.
The lock management database is a database specially used for managing the distributed locks and is used for recording related information of the distributed locks, such as keys, values and the like of the distributed locks, wherein the keys of the distributed locks are unique identifiers of the distributed locks, and the values of the distributed locks are used for storing related information of data change operations corresponding to the distributed locks. By way of example, the lock management database may be a remote dictionary service (Remote Dictionary Server, redis) database.
The first distributed lock is a lock created for the first data change operation when the first data change operation is detected to be executed by the first database, and is used for judging whether the first data change operation of the first database needs to be synchronized to the second database or not, preventing the first data change operation from being synchronized between the first database and the second database for a plurality of times, indicating that the first data change operation of the first database is not synchronized to the second database if the first distributed lock is successfully set, and indicating that the first data change operation of the first database is synchronized to the second database if the first distributed lock is set to fail.
The second database is a database which needs to keep data consistency with the first database, and is an exemplary example when the first database is an original database, the second database is a target database, and when the first database is a target database, the second database is an original database. It should be noted that the database types of the first database and the second database may be the same or different.
Specifically, in the process of data synchronization, data in the first database may be batch-synchronized to the second database to align the data in the first database and the second database, and then whether the first database performs the first data change operation is detected in real time, that is, in one implementation, a database trigger may be created for the first database, and whether the first database performs the first data change operation is detected in real time through the database trigger. The database trigger is used for detecting whether the first database executes the data change operation or not in real time.
In another implementation manner, the log file of the first database can be detected in real time to obtain a detection result, whether the first database executes the first data change operation is determined according to the detection result, namely, the log file of the first database can be detected in real time, when a log record is newly added to the log file, the log record is determined to be the detection result, then the detection result is analyzed to obtain an operation corresponding to the detection result, if the operation corresponding to the detection result belongs to a preset operation type, the first database can be determined to execute the first data change operation, and if the operation corresponding to the detection result does not belong to the preset operation type, the first database can be determined to not execute the first data change operation. By detecting the log file, the data change operation can be detected rapidly, and the timeliness of data synchronization is improved. The detection result is a basis for judging whether the first database executes the first data change operation, and the preset operation type can comprise insertion, update, deletion and the like.
Then, when the first data change operation is detected to be executed by the first database, the first data change operation can be captured, for example, newly added log records in the log file can be analyzed to obtain change operation records presented in the form of structured query language (Structured Query Language, SQL) sentences, so as to obtain the first data change operation, then, a first distributed lock is set for the first data change operation in the lock management database, namely, a key of the first distributed lock and a value of the first distributed lock can be determined according to the first data change operation, and then, the first distributed lock is further set for the first data change operation in the lock management database according to the key of the first distributed lock and the value of the first distributed lock.
Further, setting a first distributed lock for a first data change operation in a lock management database, including Sa1-Sa3:
Sa1, analyzing the first data changing operation to obtain changing information corresponding to the first data changing operation.
The change information may include a first change table, a first change type, a first change field and first change field data, where the first change table is a database table related to a first data change operation, the first change type is a specific type of the first data change operation and may be insertion, update or deletion, the first change field is a specific field changed in the first change table when the first data change operation is performed on the first database, and the first change field data is new data (for insertion and update operations) or old data (for deletion operations) corresponding to the first change field.
Specifically, the first data change operation may be parsed to obtain change information, for example, an SQL statement corresponding to the first data change operation may be parsed by using a string processing function or a regular expression, a table name part may be extracted to obtain a first change table, then a key of a beginning part may be extracted from the SQL statement to obtain a change operation name, and a first change type may be determined according to the change operation name, for example, if the change operation name is INSERT, the first change type is UPDATE, if the change operation name is UPDATE, and if the change operation name is DELETE, a list name may be extracted from the SQL statement to obtain a first change field, a value may be extracted from the SQL statement to obtain first change field data, and if there are a plurality of first change fields, a mapping relationship between the first change field and the first change field data may be determined.
For example, if the SQL statement corresponding to the first data change operation is insert_1 (field 1_1, field 1_2) VALUES (value 1, value 2), the first change table is user_1, the first change type is INSERT, the first change field1 is field1_1, the first change field 2 is field1_2, the first change field data corresponding to the first change field1 is value1, and the first change field data corresponding to the first change field 2 is value2.
Sa2, determining the value of the first distributed lock and the key of the first distributed lock according to the change information.
Specifically, after obtaining the change information corresponding to the first data change operation, the change information may be analyzed, then a value of the first distributed lock is determined based on the first change field and the first change field data, and a key of the first distributed lock is determined based on the first change table, the first change type, and the value of the first distributed lock.
Further, determining a value of the first distributed lock based on the first change field and the first change field data, including Sb1-Sb3:
And Sb1, sequencing the first change fields based on a preset sequencing rule to obtain a sequencing result.
The preset ordering rule is a preset ordering rule and is used for ordering the first change fields. Illustratively, the preset ordering rule may be an ascending order according to a dictionary.
The sequencing result is a sequence obtained after sequencing the first change fields according to a preset sequencing rule.
Specifically, when there are multiple first change fields, the multiple first change fields may be ordered according to a preset ordering rule, and if the preset ordering rule is to order according to an ascending dictionary, and the first change field 1 is a username, the first change field 2 is an email, and the first change field 3 is a phone, the ordering result is [ "email", "phone", "username" ].
And Sb2, based on the sorting result, packaging the first change field and the corresponding first change field data according to a preset format to obtain change data.
The preset format is a preset format and is used for specifying how to combine the ordered first change fields with corresponding first change field data. Illustratively, the preset format is a JS key-value pair data (JavaScript Object Notation, JSON) format.
The change data is a result obtained after the ordered first change field and the corresponding first change field data are packaged according to a preset format.
For example, if the preset format is JSON format, the first change field data corresponding to the first change field 1 (i.e., username) is value1, the first change field data corresponding to the first change field 2 (i.e., email) is value2, the first change field data corresponding to the first change field 3 (i.e., phone) is value3, the sorting result of the first change field is [ "email," "phone," "username" ], the first change field and the corresponding first change field data are packaged according to the preset format, and the obtained change data is { "email": "value2," "phone": "value3," "username": "value1" }.
And Sb3, carrying out hash operation on the changed data to obtain the value of the first distributed lock.
Specifically, after obtaining the change data, a hash algorithm may be used to perform a hash operation on the change data, for example, a hash digest may be obtained by performing a hash operation on the change data using an SM3 algorithm, and the hash digest may be determined as the value of the first distributed lock.
According to the embodiment of the application, the first change fields are ordered based on the preset ordering rule, so that the same ordering result corresponding to the same data change operation can be ensured, further, different values are prevented from being generated due to different field sequences, the ordered first change fields and the corresponding first change field data are packaged according to the preset format, the organization form of the values is standardized, the same change data corresponding to the same data change operation can be determined, the value of the first distributed lock is obtained by carrying out hash operation on the change data, the privacy and the safety of the data are ensured, meanwhile, the different values corresponding to different data change operations are ensured, and the same value corresponding to the same data change operation is ensured, so that a judgment basis is provided for the follow-up prevention of cyclic synchronization.
After the value of the first distributed lock is obtained, the first change table, the first change type and the value of the first distributed lock can be spliced to obtain a key of the first distributed lock, and the representation form of the first change table at this time can be a table name or a table name with a database prefix. The key of the first distributed lock is generated in a splicing mode, so that the uniqueness of the key can be ensured, the key of each distributed lock can accurately correspond to a specific data change operation, and further a judgment basis is provided for the follow-up determination of whether the first distributed lock is successfully set or not, and further a judgment basis is provided for the follow-up prevention of circulation synchronization.
Illustratively, if the first change table is table1, the first change type is INSERT, and the value of the first distributed lock is sign, the key of the first distributed lock is table1 INSERT_sign, or if the first change table is db.table1, the first change type is INSERT, and the value of the first distributed lock is sign, the key of the first distributed lock is db.table1 INSERT_sign.
Sa3, setting the first distributed lock in the lock management database based on the value of the first distributed lock and the key of the first distributed lock.
Specifically, after obtaining the value of the first distributed lock and the key of the first distributed lock, the first distributed lock may be SET in the lock management database, that is, the lock management database may be connected, then the first distributed lock is SET based on the value of the first distributed lock and the key of the first distributed lock by using a lock setting command provided by the lock management database, such as a SET command in Redis, and it is determined whether the first distributed lock is SET successfully, specifically, when there is a lock identical to the key of the first distributed lock in the lock management database, the first distributed lock is SET failure, and when there is no lock identical to the key of the first distributed lock in the lock management database, the first distributed lock is SET successfully. It should be noted that, other reasons, such as a network problem or a failure of a server of the lock management database, may also cause the first distributed lock to fail to set.
If the first distributed lock is successfully set in the lock management database, the first distributed lock is indicated to be not in the lock management database, namely, the first data changing operation of the first database is not synchronized to the second database, and the S120 can be executed when the first data changing operation of the first database is needed to be synchronized, if the first distributed lock is failed to be set in the lock management database, the reason of the failure setting can be determined, when the reason of the failure setting is that the same lock of the first distributed lock exists in the lock management database, the first data changing operation of the first database is indicated to be synchronized to the second database, and the data changing operation of the first database can be continuously detected in real time without synchronizing again, and when the reason of the failure setting is other reasons, the first distributed lock can be repeatedly executed for the first data changing operation in the lock management database until the first distributed lock is successfully set.
In the embodiment of the application, the first distributed lock is arranged according to the change information corresponding to the first data change operation, so that the uniqueness of the first distributed lock can be ensured, a judgment basis is provided for the subsequent prevention of the cycle synchronization, and the cycle synchronization is further effectively prevented.
And S120, when the first distributed lock is successfully set, determining a second data changing operation corresponding to the second database according to the first data changing operation.
And, the second data change operation is to insert a new order record in the first database, if the first data change operation is to insert a new order record in the first database, the second data change operation is to perform a corresponding insert operation in the second database, in order to ensure that the order data in the two databases remain consistent.
Specifically, when the first distributed lock is determined to be successfully set, it indicates that the second database has not synchronized the first data change operation, at this time, the second data change operation corresponding to the second database may be determined according to the first data change operation, that is, the change information corresponding to the second data change operation may be determined based on the data mapping relationship between the first database and the second database and the change information corresponding to the first data change operation, and the second data change operation may be generated according to the change information corresponding to the second data change operation.
Further, determining a second data change operation corresponding to the second database according to the first data change operation, including Sc1-Sc2:
And Sc1, inquiring a preset data mapping relation based on the first change table and the first change field to obtain a second change table corresponding to the first change table and a second change field corresponding to the first change field.
The preset data mapping relationship is a preset mapping relationship, and is used for describing a corresponding relationship between a data structure and data content between the first database and the second database, and may include a table mapping relationship and a field mapping relationship.
The second change table is a table corresponding to the first change table in the second database. The second change field is a field in the second change table corresponding to the first change field in the first change table.
Specifically, a table mapping relation in a preset data mapping relation can be queried based on the first change table to obtain a second change table corresponding to the first change table, and then a field mapping relation in the preset data mapping relation is queried based on the first change field to obtain a second change field corresponding to the first change field.
Sc2, determining a second data change operation according to the first change type, the second change table, the second change field and the first change field data.
Specifically, after the second change table and the second change field are obtained, the second change type, that is, the specific operation type of the second data change operation, may be determined according to the first change type, where the second change type is the same as the first change type, then the first change field data is determined as the second change field data, and according to the mapping relationship between the first change field and the first change field data and the mapping relationship between the first change field and the second change field, the mapping relationship between the second change field and the second change field data is determined, and then the second data change operation is generated according to the second change type, the second change table, the second change field and the second change field data, where the second data change operation may be represented in an SQL statement.
For example, if the SQL statement corresponding to the first data modification operation is insert_1 (field 1_1, field 1_2) VALUES (field 1, value 2), the user_1 corresponding to user_2, the field1_1 corresponding to user_2 in user_1, the field2_2 corresponding to user_2 in user_1, the second modification table is user_2, the second modification type is INSERT, the second modification field1 is field2_1, the second modification field2 is field2_2, the second modification field data corresponding to second modification field1 is value1, the second modification field data corresponding to second modification field2 is value2, and the SQL statement corresponding to the second data modification operation is insert_2 (field 2_2, field2, value 2) is insert_2_1.
In the embodiment of the application, the error in the data conversion process across the databases can be effectively avoided by presetting the data mapping relation, so that the determination accuracy and the determination efficiency of the second data change operation are improved, the database types or the data structures of the first database and the second database can be allowed to be different, and the method is suitable for data synchronization between various isomorphic databases or heterogeneous databases, so that the flexibility of data synchronization is improved.
S130, setting a second distributed lock for a second data change operation in the lock management database, and controlling the second database to execute the second data change operation when the second distributed lock is successfully set.
Meanwhile, after the second database executes the second data change operation, the second distributed lock can also be used for judging whether the second data change operation of the second database needs to be synchronized to the first database or not, so that the second data change operation is prevented from being synchronized between the first database and the second database for a plurality of times, and the second data change operation is basically the same as the first data change operation.
Specifically, after the second data change operation is obtained, a second distributed lock may be set for the second data change operation in the lock management database, that is, a value of the second distributed lock may be determined based on the second change field and the second change field data, and a key of the second distributed lock may be determined based on the second change table, the second change type, and the value of the second distributed lock, and then the second distributed lock may be set in the lock management database based on the value of the second distributed lock and the key of the second distributed lock, and whether the second distributed lock is set successfully may be determined. Specific implementation details are the same as those of S110, and reference may be made to the description of S110, which is not repeated here.
Since the second database does not execute the second data change operation when the second distributed lock is set, the reason for the failure of the setting of the second distributed lock is not the same lock as the second distributed lock in the lock management database, but other reasons, therefore, when the failure of the setting of the second distributed lock is determined, the setting of the second distributed lock for the second data change operation in the lock management database is repeatedly executed until the setting of the second distributed lock is successful, and a decision basis is provided for determining whether to synchronize the second data change operation to the first database when the second data change operation is detected to be executed in the second database later, thereby effectively preventing the cycle synchronization.
If the second distributed lock is determined to be successfully set, the second database can be controlled to execute a second data change operation, for example, the second database is controlled to execute an SQL statement corresponding to the second data change operation, so as to synchronize the data in the second database and the first database.
Optionally, the electronic device may detect the log file of the second database in real time, and when detecting that the second database performs the second data modification operation, may set a corresponding distributed lock for the second data modification operation in the lock management database and record the second data modification operation as a third distributed lock, where a key of the third distributed lock is the same as a key of the second distributed lock, that is, the lock management database already has the same lock as the third distributed lock, so that it may be determined that the third distributed lock is set to fail, that is, the second data modification operation of the second database is already synchronized to the first database, without performing data synchronization again, and at this time, whether the second database performs the data modification operation may be continuously detected in real time.
An exemplary diagram of a data synchronization method provided by an embodiment of the present application is shown in fig. 3a, where a first database in fig. 3a is a database in an original area, a second database is a database in a target area, and a data synchronization process may be represented by controlling the first database to perform a first data change operation corresponding to a user request when the user request is shunted to the application server 1, where an electronic device may detect the first database in real time, set a first distributed lock for the first data change operation when the first database is detected to perform the first data change operation, then determining whether the first distributed lock is set successfully, determining a second data change operation corresponding to the second database according to the first data change operation if the first distributed lock is determined to be set successfully, and then controlling the second database to perform the second data change operation when the second distributed lock is determined to be set successfully, and preventing the synchronization process from being circulated if the first distributed lock is determined to be set to fail.
As shown in fig. 3b, which is an exemplary diagram of another data synchronization method provided by the embodiment of the present application, the first database in fig. 3b is a database in a target area, the second database is a database in an original area, and the data synchronization process may be represented by controlling the first database to perform a first data change operation corresponding to a user request by the application server 2 when the user request is shunted to the application server 2, where the electronic device may detect the first database in real time, set a first distributed lock for the first data change operation in the lock management database when the first data change operation is detected, determining a second data change operation corresponding to the second database according to the first data change operation if the first distributed lock is determined to be successful, and setting a second distributed lock for the second data change operation in the lock management database, and then controlling the second database to perform the second data change operation when the second distributed lock is determined to be successful, and ending the data synchronization process if the first distributed lock is determined to be failed.
According to the technical scheme, when the first data change operation is detected to be executed by the first database, the first distributed lock can be set for the first data change operation in the lock management database, then when the first distributed lock is determined to be set successfully, the second data change operation corresponding to the second database is determined according to the first data change operation, then the second distributed lock is set for the second data change operation in the lock management database, and when the second distributed lock is determined to be set successfully, the second data change operation is controlled to be executed by the second database, so that the data synchronization function is realized. According to the technical scheme, under the condition that the first database is detected to execute the first data change operation, when the first distributed lock is successfully set, the data synchronization process is executed, and an anti-cycle synchronization mechanism can be realized, namely, the data change operation which is basically the same is only synchronized once between the first database and the second database, so that cycle synchronization is effectively prevented, in the prior art, the anti-cycle synchronization mechanism is realized through the data synchronization log table and the combined unique index, additional data structures are required to be respectively created and maintained in the original database and the target database, storage resources and computing resources of the databases are occupied, and the anti-cycle synchronization mechanism is realized through the distributed lock, only the lock is required to be set and managed in the lock management database, so that the complex data synchronization log table and the combined unique index are prevented from being created and maintained in the first database and the second database, further, the storage pressure and the computing burden of the anti-cycle synchronization mechanism are reduced, the performance loss of the anti-cycle synchronization mechanism is reduced, and the data synchronization efficiency and the performance are improved.
Fig. 4 is a schematic structural diagram of a data synchronization device according to an embodiment of the present application, and referring to fig. 4, the data synchronization device may include:
A first setting module 410, configured to set a first distributed lock for a first data change operation in a lock management database when detecting that the first database performs the first data change operation;
A determining module 420, configured to determine, according to the first data change operation, a second data change operation corresponding to the second database when it is determined that the first distributed lock is successfully set;
The second setting module 430 is configured to set a second distributed lock for a second data change operation in the lock management database, and control the second database to execute the second data change operation when it is determined that the second distributed lock is set successfully.
In one embodiment, the first setting module 410 is specifically configured to:
Analyzing the first data changing operation to obtain changing information corresponding to the first data changing operation;
Determining a value of the first distributed lock and a key of the first distributed lock according to the change information;
The first distributed lock is set in the lock management database based on the value of the first distributed lock and the key of the first distributed lock.
In one embodiment, the change information includes a first change table, a first change type, a first change field, and first change field data, and the first setting module 410 determines a value of the first distributed lock and a key of the first distributed lock according to the change information, including:
determining a value of the first distributed lock based on the first change field and the first change field data;
A key of the first distributed lock is determined based on the first change table, the first change type, and the value of the first distributed lock.
In one embodiment, the first setting module 410 determines a value of the first distributed lock based on the first change field and the first change field data, including:
ordering the first change fields based on a preset ordering rule to obtain an ordering result;
based on the sorting result, the first change field and the corresponding first change field data are packaged according to a preset format to obtain change data;
and carrying out hash operation on the changed data to obtain the value of the first distributed lock.
In one embodiment, the first setup module 410 determines a key of the first distributed lock based on the first change table, the first change type, and the value of the first distributed lock, including:
and splicing the first change table, the first change type and the value of the first distributed lock to obtain a key of the first distributed lock.
In one embodiment, the determining module 420 is specifically configured to:
Inquiring a preset data mapping relation based on the first change table and the first change field to obtain a second change table corresponding to the first change table and a second change field corresponding to the first change field;
And determining a second data change operation according to the first change type, the second change table, the second change field and the first change field data.
In an embodiment, the data synchronization device further includes a detection module, where the detection module is specifically configured to:
Detecting a log file of the first database in real time before detecting that the first database executes a first data change operation, so as to obtain a detection result;
And determining whether the first database executes the first data change operation according to the detection result.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional modules is illustrated, and in practical application, the above-described functional allocation may be performed by different functional modules according to needs, i.e. the internal structure of the apparatus is divided into different functional modules to perform all or part of the functions described above. The specific working process of the functional module described above may refer to the corresponding process in the foregoing method embodiment, and will not be described herein.
The data synchronization device provided by the embodiment is applicable to the data synchronization method provided by any embodiment, and has corresponding functions and beneficial effects.
Fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application. Fig. 5 shows a block diagram of an exemplary electronic device 11 suitable for use in implementing embodiments of the application. The electronic device 11 shown in fig. 5 is only an example, and should not impose any limitation on the function and the range of use of the present embodiment.
As shown in fig. 5, the electronic device 11 is in the form of a general purpose computing electronic device. The components of the electronic device 11 may include, but are not limited to, one or more processors or processing units 16, a system memory 28, and a bus 18 that connects the various system components, including the system memory 28 and the processing units 16.
Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, and a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
The electronic device 11 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by electronic device 11 and includes both volatile and non-volatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and/or cache memory 32. The electronic device 11 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from or write to non-removable, nonvolatile magnetic media (not shown in FIG. 5, commonly referred to as a "hard disk drive"). Although not shown in fig. 5, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 18 through one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of the embodiments of the application.
A program/utility 40 having a set (at least one) of program modules 42 may be stored in, for example, system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 42 generally perform the functions and/or methods of the embodiments described herein.
The electronic device 11 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with the electronic device 11, and/or with any device (e.g., network card, modem, etc.) that enables the electronic device 11 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 22. Also, the electronic device 11 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, through a network adapter 20.
As shown in fig. 5, the network adapter 20 communicates with other modules of the electronic device 11 via the bus 18. It should be appreciated that although not shown in FIG. 5, other hardware and/or software modules may be used in connection with the electronic device 11, including, but not limited to, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processing unit 16 executes various functional applications and page displays by running programs stored in the system memory 28, for example, implementing a data synchronization method provided in the present embodiment, the method including:
Setting a first distributed lock for the first data change operation in the lock management database when the first database is detected to execute the first data change operation;
when the first distributed lock is successfully set, determining a second data changing operation corresponding to the second database according to the first data changing operation;
Setting a second distributed lock for a second data change operation in the lock management database, and controlling the second database to execute the second data change operation when the second distributed lock is determined to be set successfully.
Of course, those skilled in the art will understand that the processor may also implement the technical solution of the data synchronization method provided in any embodiment of the present application.
An embodiment of the present application provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a data synchronization method such as provided by the embodiment of the present application, the method including:
Setting a first distributed lock for the first data change operation in the lock management database when the first database is detected to execute the first data change operation;
when the first distributed lock is successfully set, determining a second data changing operation corresponding to the second database according to the first data changing operation;
Setting a second distributed lock for a second data change operation in the lock management database, and controlling the second database to execute the second data change operation when the second distributed lock is determined to be set successfully.
The computer storage media of the present embodiments may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium include an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
It will be appreciated by those of ordinary skill in the art that the modules or steps of the application described above may be implemented in a general purpose computing device, they may be centralized on a single computing device, or distributed over a network of computing devices, or they may alternatively be implemented in program code executable by a computer device, such that they are stored in a memory device and executed by the computing device, or they may be separately fabricated as individual integrated circuit modules, or multiple modules or steps within them may be fabricated as a single integrated circuit module. Thus, the present application is not limited to any specific combination of hardware and software.
In addition, the technical scheme of the application can acquire, store, use, process and the like the data, which accords with the relevant regulations of national laws and regulations.
Note that the above is only a preferred embodiment of the present application and the technical principle applied. It will be understood by those skilled in the art that the present application is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the application. Therefore, while the application has been described in connection with the above embodiments, the application is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit of the application, which is set forth in the following claims.