Data synchronization method and device
By using the reception time and event time in data synchronization to determine the synchronization time and determining the target synchronization time based on the time window, the problem of high pressure on the database in the prior art is solved, and the data synchronization efficiency is improved.
Patent Information
- Application Number
- CN202311188449.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-14
- Publication Date
- 2025-03-14
AI Technical Summary
In the prior art, data synchronization is under great pressure to treat synchronous databases, with many synchronization times and low efficiency.
The first synchronization time is determined by the reception time and event time of the data to be synchronized. When the first synchronization time is outside the current time window, the target synchronization time is determined based on the current time window, and data synchronization is performed according to the corresponding target synchronization data.
Reduces the number of synchronization times to the database, reduces the pressure on the database, and improves the efficiency of data synchronization.
Smart Images

Figure CN119621837A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data synchronization method and device. Background Art
[0002] Data synchronization is usually required in business systems to improve the real-time performance of data. The current data synchronization solution is to parse the data log in MySQL (relational database management system) and push the data to be synchronized to the database to be synchronized. Since each add, delete, and modify operation will generate data to be synchronized, for operations with the same primary key, there will be multiple data to be synchronized, and all the data to be synchronized needs to be stored in the database.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] The number of synchronizations for the database to be synchronized is large, the pressure on the database to be synchronized is high, and the data synchronization efficiency is low. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a data synchronization method and device, which determines a first synchronization time through the reception time and event time of the data to be synchronized. When the first synchronization time is outside the current time window, a target synchronization time is determined based on the current time window, and data synchronization is performed according to the corresponding target data to be synchronized. This can reduce the number of synchronization times for the database, reduce the pressure on the database, and improve data synchronization efficiency.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a data synchronization method is provided.
[0007] A data synchronization method comprises: in response to a data synchronization request, obtaining data to be synchronized, the data to be synchronized having an event time and a receiving time; generating a first synchronization time according to the receiving time and the event time in accordance with a preset synchronization time generation strategy; obtaining a current time window, and when the first synchronization time is outside the current time window, obtaining a target synchronization time of the current time window, the target synchronization time being the latest event time in the current time window; using the data to be synchronized corresponding to the target synchronization time as target data to be synchronized, and performing data synchronization through the target data to be synchronized.
[0008] Optionally, the method further includes: when the first synchronization time is within the current time window, updating the target synchronization time of the current time window according to the event time of the data to be synchronized.
[0009] Optionally, the current time window has a second synchronization time; before updating the target synchronization time of the current time window according to the event time of the data to be synchronized, it also includes: comparing the first synchronization time and the second synchronization time, and determining that the first synchronization time is after the second synchronization time.
[0010] Optionally, after updating the target synchronization time of the current time window according to the event time of the data to be synchronized, the method further includes: updating the second synchronization time according to the first synchronization time.
[0011] Optionally, the first synchronization time is generated according to the receiving time and the event time in accordance with a preset synchronization time generation strategy, including: calculating a first difference between the receiving time and a preset delay duration, and a second difference between the event time and the delay duration; and taking the larger value of the first difference and the second difference as the first synchronization time.
[0012] Optionally, after obtaining the target synchronization time of the current time window, it also includes: closing the current time window; determining the next time window based on the first synchronization time, and opening the next time window; updating the target synchronization time of the next time window according to the event time of the data to be synchronized.
[0013] Optionally, the current time window has an opening time; the method also includes: obtaining the current system time, and calculating the opening duration of the current time window based on the current system time and the opening time; in response to the opening duration being greater than or equal to a preset opening duration threshold, closing the current time window and opening the next time window.
[0014] According to another aspect of an embodiment of the present invention, a data synchronization device is provided.
[0015] A data synchronization device comprises: a module for acquiring data to be synchronized, for acquiring data to be synchronized in response to a data synchronization request, wherein the data to be synchronized has an event time and a receiving time; a first synchronization time generation module, for generating a first synchronization time according to the receiving time and the event time in accordance with a preset synchronization time generation strategy; a target synchronization time acquisition module, for acquiring a current time window, and when the first synchronization time is outside the current time window, acquiring a target synchronization time of the current time window, wherein the target synchronization time is the latest event time in the current time window; a data synchronization module, for taking the data to be synchronized corresponding to the target synchronization time as target data to be synchronized, and performing data synchronization through the target data to be synchronized.
[0016] Optionally, the device further comprises a target synchronization time updating module, configured to update the target synchronization time of the current time window according to the event time of the data to be synchronized when the first synchronization time is within the current time window.
[0017] Optionally, the current time window has a second synchronization time; the target synchronization time update module is further used to: compare the first synchronization time and the second synchronization time, and determine that the first synchronization time is after the second synchronization time.
[0018] Optionally, the target synchronization time updating module is further used to: update the second synchronization time according to the first synchronization time.
[0019] Optionally, the first synchronization time generation module is also used to: calculate a first difference between the receiving time and a preset delay duration, and a second difference between the event time and the delay duration; and use the larger value of the first difference and the second difference as the first synchronization time.
[0020] Optionally, the device also includes a window opening module, which is used to: close the current time window; determine the next time window according to the first synchronization time, and open the next time window; update the target synchronization time of the next time window according to the event time of the data to be synchronized.
[0021] Optionally, the current time window has an opening time; the device also includes a window opening module, which is used to: obtain the current system time, and calculate the opening duration of the current time window based on the current system time and the opening time; in response to the opening duration being greater than or equal to a preset opening duration threshold, close the current time window and open the next time window.
[0022] According to yet another aspect of the embodiments of the present invention, an electronic device is provided.
[0023] An electronic device includes: one or more processors; and a memory for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the data synchronization method provided in an embodiment of the present invention.
[0024] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0025] A computer-readable medium stores a computer program, which, when executed by a processor, implements a data synchronization method provided in an embodiment of the present invention.
[0026] An embodiment of the above invention has the following advantages or beneficial effects: by responding to a data synchronization request, obtaining the data to be synchronized, the data to be synchronized has an event time and a receiving time; according to a preset synchronization time generation strategy, generating a first synchronization time according to the receiving time and the event time; obtaining the current time window, and when the first synchronization time is outside the current time window, obtaining the target synchronization time of the current time window, the target synchronization time is the latest event time in the current time window; using the data to be synchronized corresponding to the target synchronization time as the target data to be synchronized, and performing data synchronization through the target data to be synchronized. The technical solution determines the first synchronization time through the receiving time and the event time of the data to be synchronized. When the first synchronization time is outside the current time window, the target synchronization time is determined based on the current time window, and data synchronization is performed according to the corresponding target data to be synchronized, which can reduce the number of synchronizations on the database, reduce the pressure on the database, and improve the efficiency of data synchronization.
[0027] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0029] Figure 1 is a schematic diagram of main steps of a data synchronization method according to an embodiment of the present invention;
[0030] Figure 2 is a schematic diagram of processing data to be synchronized according to an embodiment of the present invention;
[0031] Figure 3 is a flow chart of a data synchronization method according to an embodiment of the present invention;
[0032] Figure 4 is a schematic diagram of main modules of a data synchronization device according to an embodiment of the present invention;
[0033] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0034] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0036] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution of the present invention are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.
[0037] Figure 1 It is a schematic diagram of main steps of a data synchronization method according to an embodiment of the present invention.
[0038] like Figure 1 As shown, a data synchronization method according to an embodiment of the present invention mainly includes the following steps S101 to S104.
[0039] Step S101: In response to a data synchronization request, the data to be synchronized is obtained, where the data to be synchronized has an event time and a receiving time.
[0040] Specifically, the binlog (binary log file) recording MySQL data operation information is connected to the data source of flink (distributed streaming data flow engine). The binlog includes multiple data to be synchronized, each of which corresponds to one operation information of MySQL. Each data to be synchronized may include a primary key, a timestamp, and an operation type, etc. The operation type includes adding, deleting, modifying, etc. The event time of the data to be synchronized can be set to the timestamp of the data to be synchronized, and the receiving time is the system time when the system receives the data to be synchronized. Among them, the data to be synchronized can be partitioned according to the primary key in advance, so that the time windows and data between the partitions are independent of each other and do not affect each other.
[0041] It should be noted that event time and system time can be independent of each other. The event time of the data to be synchronized can be set to the timestamp of the data to be synchronized, or it can be other defined time.
[0042] Step S102: Generate a first synchronization time according to a preset synchronization time generation strategy, based on the receiving time and the event time.
[0043] In one embodiment, according to a preset synchronization time generation strategy, a first synchronization time is generated based on a receiving time and an event time, which may include: calculating a first difference between the receiving time and a preset delay duration, and a second difference between the event time and the delay duration; and taking the larger value of the first difference and the second difference as the first synchronization time.
[0044] A schematic diagram of processing data to be synchronized according to an embodiment of the present invention is shown in FIG. Figure 2 As shown, the preset delay time can be set to 5, the event time of the data A to be synchronized is 5, and the receiving time is 0, then the first difference is 0-5=-5, the second difference is 5-5=0, the second difference is greater than the first difference, and the first synchronization time of the data A to be synchronized is 0.
[0045] Step S103: Acquire the current time window, and if the first synchronization time is outside the current time window, acquire the target synchronization time of the current time window, wherein the target synchronization time may be the latest event time in the current time window.
[0046] In one embodiment, when the first synchronization time is within the current time window, the first synchronization time is compared with the second synchronization time, and it is determined that the first synchronization time is after the second synchronization time. Then, the target synchronization time of the current time window is updated according to the event time of the data to be synchronized, and the second synchronization time is updated according to the first synchronization time.
[0047] The second synchronization time may be a watermark of the time window. The watermark is a clock mark added to the data stream, that is, a mark used to record the current event time progress.
[0048] Specifically, see Figure 2 , set the initial value of the second synchronization time to the system time minus the delay time, the current time window is the time window [0, 10), and when receiving the data A to be synchronized, the initial value of the second synchronization time is 0-5=-5. If the first synchronization time of the data A to be synchronized is 0, then the first synchronization time of the data A to be synchronized is within the time window [0, 10), and the first synchronization time of the data A to be synchronized is after the second synchronization time, the target synchronization time of the time window [0, 10) can be updated to the event time of the data A to be synchronized, that is, the target synchronization time of the time window [0, 10) is updated to 5, and the second synchronization time of the time window [0, 10) is updated to the first synchronization time of the data A to be synchronized, that is, the second synchronization time of the time window [0, 10) is updated to 0.
[0049] Similarly, the event time of the data to be synchronized B is 8, and the receiving time is 12, then the first difference is 12-5=7, and the second difference is 8-5=3. The first difference is greater than the second difference. The first synchronization time of the data to be synchronized B is 7, and the first synchronization time of the data to be synchronized B is within the time window [0, 10), and the second synchronization time is 0 at this time, that is, the first synchronization time of the data to be synchronized B is after the second synchronization time. The target synchronization time of the time window [0, 10) can be updated to the event time of the data to be synchronized B, that is, the target synchronization time of the time window [0, 10) is updated to 8, and the second synchronization time of the time window [0, 10) is updated to the first synchronization time of the data to be synchronized B, that is, the second synchronization time of the time window [0, 10) is updated to 7.
[0050] In another embodiment, if the first synchronization time of the data to be synchronized is within the current time window but before the second synchronization time, it means that the data to be synchronized cannot represent the latest data to be synchronized and can be directly ignored.
[0051] In one embodiment, when the first synchronization time is outside the current time window, a target synchronization time of the current time window is acquired, wherein the target synchronization time may be the latest event time in the current time window.
[0052] Specifically, the event time of the data to be synchronized C is 14, and the receiving time is 16, so the first difference is 16-5=11, and the second difference is 14-5=9. The first difference is greater than the second difference. The first synchronization time of the data to be synchronized C is 11. The first synchronization time of the data to be synchronized C is outside the time window [0, 10), so the current time window is closed. At this time, the target synchronization time of the time window [0, 10) is 8.
[0053] In one embodiment, after obtaining the target synchronization time of the current time window, it can also include: closing the current time window; determining the next time window according to the first synchronization time, and opening the next time window; updating the target synchronization time of the next time window according to the event time of the data to be synchronized.
[0054] Specifically, see Figure 2 , according to the first synchronization time of the data to be synchronized C, the next time window is determined to be the time window [10, 20), and then the time window [10, 20) is opened. The target synchronization time of the time window [10, 20) is the event time 14 of the time C of the data to be synchronized, and the second synchronization time of the time window [10, 20) is the first synchronization time 11 of the time C of the data to be synchronized.
[0055] Step S104: taking the to-be-synchronized data corresponding to the target synchronization time as the target to-be-synchronized data, and performing data synchronization through the target to-be-synchronized data.
[0056] Specifically, the target synchronization time of the time window [0, 10) is 8, and the corresponding target data to be synchronized is data B to be synchronized, then data synchronization can be performed according to data B to be synchronized. When the target data to be synchronized is added or modified, the addition or modification operation is performed on the database to be synchronized according to the primary key information of the target data to be synchronized, and when the target data to be synchronized is deleted, the deletion operation is performed on the database to be synchronized according to the primary key information of the target data to be synchronized, or the deletion field is modified to a preset deletion indication value (such as 1).
[0057] In one embodiment, the current system time is obtained, and the opening duration of the current time window is calculated based on the current system time and the opening time; in response to the opening duration being greater than or equal to a preset opening duration threshold, the current time window is closed and the next time window is opened.
[0058] Specifically, see Figure 2 The preset opening time threshold can be set to 10. If no new data to be synchronized is received after the data to be synchronized C, when the opening time of the time window [10, 20) reaches 10, the time window [10, 20) is closed, and then the data to be synchronized corresponding to the target synchronization time of the time window [10, 20) is synchronized, and the time window [20, 30) is opened.
[0059] Figure 3 It is a flowchart of a data synchronization method according to an embodiment of the present invention.
[0060] like Figure 3 As shown, in one embodiment, a first synchronization time is generated according to the event time and the receiving time of the data to be synchronized. The current time window is obtained. When the first synchronization time is within the current time window, the first synchronization time is compared with the second synchronization time of the current time window. If the first synchronization time is after the second synchronization time, the target synchronization time of the current time window is updated according to the event time of the data to be synchronized, and the second synchronization time is updated according to the first synchronization time. Otherwise, the data to be synchronized is skipped. When the first synchronization time is outside the current time window, the current time window is closed, and the target synchronization time of the current time window is obtained at the same time, and the corresponding data to be synchronized is used as the target data to be synchronized, and data synchronization is performed through the target data to be synchronized. The opening duration of the current time window is calculated according to the current system time and the opening time. When the opening duration reaches the opening duration threshold, the current time window is closed and the next time window is opened.
[0061] An embodiment of the present invention determines a first synchronization time by the reception time and event time of the data to be synchronized. When the first synchronization time is outside the current time window, a target synchronization time is determined based on the current time window, and data synchronization is performed according to the corresponding target data to be synchronized. This can reduce the number of synchronization times for the database, reduce the pressure on the database, and improve data synchronization efficiency.
[0062] Figure 4 4 is a schematic diagram of main modules of a data synchronization device according to an embodiment of the present invention.
[0063] like Figure 4 As shown, a data synchronization device 400 according to an embodiment of the present invention mainly includes: a to-be-synchronized data acquisition module 401 , a first synchronization time generation module 402 , a target synchronization time acquisition module 403 , and a data synchronization module 404 .
[0064] The to-be-synchronized data acquisition module 401 is used to acquire the to-be-synchronized data in response to a data synchronization request. The to-be-synchronized data has an event time and a receiving time.
[0065] The first synchronization time generating module 402 is used to generate a first synchronization time according to a preset synchronization time generating strategy, based on the receiving time and the event time.
[0066] The target synchronization time acquisition module 403 is used to acquire the current time window. When the first synchronization time is outside the current time window, the target synchronization time of the current time window is acquired. The target synchronization time may be the latest event time in the current time window.
[0067] The data synchronization module 404 is used to take the to-be-synchronized data corresponding to the target synchronization time as the target to-be-synchronized data, and perform data synchronization through the target to-be-synchronized data.
[0068] In one embodiment, the device may further include a target synchronization time update module (not shown in the figure) for updating the target synchronization time of the current time window according to the event time of the data to be synchronized when the first synchronization time is within the current time window.
[0069] In one embodiment, the current time window has a second synchronization time; the target synchronization time update module is specifically used to: compare the first synchronization time and the second synchronization time, and determine that the first synchronization time is after the second synchronization time.
[0070] In one embodiment, the target synchronization time updating module is specifically used to update the second synchronization time according to the first synchronization time.
[0071] In one embodiment, the first synchronization time generation module 402 is specifically used to: calculate a first difference between the receiving time and the preset delay time, and a second difference between the event time and the delay time; and use the larger value of the first difference and the second difference as the first synchronization time.
[0072] In one embodiment, the device may also include a window opening module (not shown in the figure) used to: close the current time window; determine the next time window based on the first synchronization time, and open the next time window; update the target synchronization time of the next time window according to the event time of the data to be synchronized.
[0073] In one embodiment, the current time window has an opening time; the device may also include a window opening module (not shown in the figure), which is used to: obtain the current system time, and calculate the opening duration of the current time window based on the current system time and the opening time; in response to the opening duration being greater than or equal to a preset opening duration threshold, close the current time window and open the next time window.
[0074] In addition, the specific implementation content of the data synchronization device in the embodiment of the present invention has been described in detail in the above data synchronization method, so the repeated content will not be described again here.
[0075] Figure 5 An exemplary system architecture 500 is shown to which the data synchronization method or data synchronization device according to the embodiment of the present invention can be applied.
[0076] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0077] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as data synchronization applications, data processing applications, database applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0078] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0079] Server 505 may be a server that provides various services, such as a background management server (only an example) that supports data synchronization websites browsed by users using terminal devices 501, 502, and 503. The background management server may respond to the data synchronization request and other data received, obtain the data to be synchronized, and the data to be synchronized has an event time and a receiving time; generate a first synchronization time according to the receiving time and the event time according to a preset synchronization time generation strategy; obtain the current time window, and when the first synchronization time is outside the current time window, obtain the target synchronization time of the current time window, and the target synchronization time is the latest event time in the current time window; use the data to be synchronized corresponding to the target synchronization time as the target data to be synchronized, and perform data synchronization and other processing through the target data to be synchronized, and feed back the processing result (such as data synchronization - only an example) to the terminal device.
[0080] It should be noted that the data synchronization method provided in the embodiment of the present invention is generally executed by the server 505 , and accordingly, the data synchronization device is generally disposed in the server 505 .
[0081] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0082] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device or a server suitable for implementing an embodiment of the present invention. Figure 6 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0083] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0084] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0085] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0086] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0087] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0088] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a module for acquiring data to be synchronized, a first synchronization time generation module, a target synchronization time acquisition module, and a data synchronization module. The names of these modules do not, in some cases, constitute limitations on the modules themselves. For example, the module for acquiring data to be synchronized may also be described as "a module for acquiring data to be synchronized in response to a data synchronization request, wherein the data to be synchronized has an event time and a receiving time".
[0089] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: in response to a data synchronization request, obtaining data to be synchronized, the data to be synchronized has an event time and a receiving time; generating a first synchronization time according to the receiving time and the event time according to a preset synchronization time generation strategy; obtaining the current time window, and when the first synchronization time is outside the current time window, obtaining the target synchronization time of the current time window, the target synchronization time is the latest event time in the current time window; using the data to be synchronized corresponding to the target synchronization time as the target data to be synchronized, and performing data synchronization through the target data to be synchronized.
[0090] According to the technical solution of the embodiment of the present invention, in response to a data synchronization request, the data to be synchronized is obtained, and the data to be synchronized has an event time and a receiving time; according to a preset synchronization time generation strategy, a first synchronization time is generated according to the receiving time and the event time; the current time window is obtained, and when the first synchronization time is outside the current time window, the target synchronization time of the current time window is obtained, and the target synchronization time is the latest event time in the current time window; the data to be synchronized corresponding to the target synchronization time is used as the target data to be synchronized, and data synchronization is performed through the target data to be synchronized. The first synchronization time is determined by the receiving time and event time of the data to be synchronized, and when the first synchronization time is outside the current time window, the target synchronization time is determined based on the current time window, and data synchronization is performed according to the corresponding target data to be synchronized, which can reduce the number of synchronizations on the database, reduce the pressure on the database, and improve the efficiency of data synchronization.
[0091] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A data synchronization method, characterized in that: include: In response to a data synchronization request, acquiring data to be synchronized, where the data to be synchronized has an event time and a receiving time; Generate a first synchronization time according to the reception time and the event time in accordance with a preset synchronization time generation strategy; Acquire a current time window, and if the first synchronization time is outside the current time window, acquire a target synchronization time of the current time window, where the target synchronization time is the latest event time in the current time window; The data to be synchronized corresponding to the target synchronization time is used as the target data to be synchronized, and data synchronization is performed through the target data to be synchronized.
2. The method according to claim 1, characterized in that The method further comprises: When the first synchronization time is within the current time window, the target synchronization time of the current time window is updated according to the event time of the data to be synchronized.
3. The method according to claim 2, characterized in that The current time window has a second synchronization time; Before updating the target synchronization time of the current time window according to the event time of the data to be synchronized, the method further includes: The first synchronization time and the second synchronization time are compared, and it is determined that the first synchronization time is later than the second synchronization time.
4. The method according to claim 3, characterized in that After updating the target synchronization time of the current time window according to the event time of the data to be synchronized, the method further includes: The second synchronization time is updated according to the first synchronization time.
5. The method according to claim 3, characterized in that: The generating a first synchronization time according to the receiving time and the event time according to a preset synchronization time generation strategy includes: Calculate a first difference between the receiving time and a preset delay time, and a second difference between the event time and the delay time; The larger value of the first difference and the second difference is used as the first synchronization time.
6. The method according to claim 1, characterized in that After obtaining the target synchronization time of the current time window, the method further includes: Closing the current time window; Determine a next time window according to the first synchronization time, and open the next time window; The target synchronization time of the next time window is updated according to the event time of the data to be synchronized.
7. The method according to claim 1, characterized in that The current time window has an opening time; The method further comprises: Obtaining the current system time, and calculating the opening duration of the current time window according to the current system time and the opening time; In response to the opening time length being greater than or equal to a preset opening time length threshold, the current time window is closed and a next time window is opened.
8. A data synchronization device, characterized in that: include: A module for acquiring data to be synchronized, used for acquiring the data to be synchronized in response to a data synchronization request, wherein the data to be synchronized has an event time and a receiving time; A first synchronization time generation module, configured to generate a first synchronization time according to a preset synchronization time generation strategy and based on the reception time and the event time; A target synchronization time acquisition module, used to acquire a current time window, and when the first synchronization time is outside the current time window, acquire a target synchronization time of the current time window, wherein the target synchronization time is the latest event time in the current time window; The data synchronization module is used to take the data to be synchronized corresponding to the target synchronization time as the target data to be synchronized, and perform data synchronization through the target data to be synchronized.
9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.