A method for synchronizing data, a first server, and a system for synchronizing data
By monitoring the second server pointer in real time and determining the data to be synchronized, the data consistency update delay and resource occupation problems in distributed systems are solved, efficient data synchronization is achieved, and server performance is improved.
Patent Information
- Application Number
- CN202011173528.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-28
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2040-10-28
AI Technical Summary
When existing distributed systems maintain data consistency on each server, the timely update method causes data to be unable to be updated in time, and each time data is read again, it is necessary to traverse the database, occupy server resources, and affect performance.
By monitoring the second pointer on the second server in real time, it is determined whether the first pointer and the second pointer are the same. If it is not the same, the data to be synchronized is determined based on the second pointer, and only the data to be synchronized is updated synchronously, without traversing all the data.
The timely synchronization of the first server data is realized, computing resources are saved, and server performance is improved.
Smart Images

Figure CN113742376B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method for synchronizing data, a first server, and a system for synchronizing data. Background Art
[0002] With the advent of the big data era, the processing power of a single server can no longer meet the growing data processing needs. Therefore, distributed systems have come into being. Deploying application systems on multiple servers can reduce the pressure on each server to process data.
[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] Distributed systems need to ensure that the data stored on each server remains consistent. The current approach to maintaining data consistency is to update data regularly, that is, re-read data from the database every once in a while. However, this approach will result in data not being updated in a timely manner, and each time data is re-read, the database must be traversed. When there is a lot of data, it will occupy more server resources and affect server performance. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method for synchronizing data, a first server, and a system for synchronizing data. The first server monitors the second pointer on the second server in real time. When it is determined that the second pointer is different from its own first pointer, it can timely determine the data to be synchronized on the second server according to the second pointer, thereby achieving the effect of timely synchronization of its own first data. In addition, the first server can only synchronize the data to be synchronized on the determined second server without traversing all the data on the second server, thereby saving the computing resources of the first server and making the performance of the first server more effectively exerted.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for synchronizing data is provided.
[0007] A method for synchronizing data according to an embodiment of the present invention is applied to a first server, the first server includes first data and a first pointer, the first pointer is used to indicate the last updated data in the first data; the method includes:
[0008] Real-time monitoring of a second pointer on the second server, where the second pointer is used to indicate the last updated data in the second data on the second server;
[0009] Determine whether the first pointer and the second pointer are the same; if not, determine the data to be synchronized on the second server according to the second pointer;
[0010] The first data and the second data are synchronized according to the data to be synchronized.
[0011] Optionally,
[0012] Synchronizing the first data with the second data according to the data to be synchronized, including:
[0013] The first data is updated according to the data to be synchronized, so as to achieve synchronization between the first data and the second data.
[0014] Optionally,
[0015] The first data is updated according to the data to be synchronized, including:
[0016] Determine a cache queue for storing the data to be synchronized, the cache queue including: the data to be synchronized and a second pointer identifier corresponding to the data to be synchronized;
[0017] The following steps are repeated until the first and second pointers are the same:
[0018] The first pointer is incremented, a second pointer identifier that is the same as the incremented first pointer is determined from the cache queue, and the first data is updated according to the to-be-synchronized data corresponding to the determined second pointer identifier.
[0019] Optionally,
[0020] Determining whether the first pointer and the second pointer are the same includes:
[0021] Whether the first pointer and the second pointer are the same is determined by receiving a data update broadcast from a central server or monitoring the second pointer in real time.
[0022] Optionally,
[0023] The method further includes:
[0024] The timing starts after the first data is synchronized. When the recorded duration reaches a first preset duration threshold and the first data is not newly synchronized within the recorded duration, the second data is obtained from the second server and the first data is replaced according to the obtained second data.
[0025] Optionally,
[0026] The first data includes any one or more of the following: an item identification, an inventory quantity of the item, and a storage location of the item.
[0027] To achieve the above objective, according to another aspect of an embodiment of the present invention, a first server is provided.
[0028] A first server according to an embodiment of the present invention includes a monitoring module, a judgment module and a synchronization module; wherein:
[0029] A monitoring module, used for monitoring the second pointer on the second server in real time, the second pointer being used for indicating the last updated data in the second data on the second server;
[0030] A judging module, used to judge whether the first pointer is the same as the second pointer obtained by the monitoring module; if not, determining the data to be synchronized on the second server according to the second pointer;
[0031] The synchronization module is used to synchronize the first data with the second data according to the data to be synchronized determined by the judgment module.
[0032] To achieve the above objective, according to another aspect of an embodiment of the present invention, a system for synchronizing data is provided.
[0033] A system for synchronizing data according to an embodiment of the present invention comprises: a first server and a second server provided in the above-mentioned embodiment of the present invention; wherein:
[0034] The second server includes second data and a second pointer, where the second pointer is used to indicate the last updated data in the second data. When the second data is updated, the second pointer is updated.
[0035] Optionally,
[0036] The second server is further used to: loop through the following steps until all updated data is saved in the second database:
[0037] The second pointer is incremented, and the updated data is saved in the second data.
[0038] Optionally,
[0039] The second server is also used to: save the updated data and the corresponding second pointer identifier into the cache queue, and use the updated data as the data to be synchronized, so that the first server updates the first data according to the data to be synchronized corresponding to the second pointer identifier.
[0040] Optionally,
[0041] The second server is further configured to: when the to-be-synchronized data in the cache queue is not read within a second preset time threshold, delete the to-be-synchronized data in the cache queue and the second pointer identifier.
[0042] To achieve the above objective, according to another aspect of an embodiment of the present invention, a server for synchronizing data is provided.
[0043] A data synchronization server according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a data synchronization method according to an embodiment of the present invention.
[0044] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided.
[0045] A computer-readable storage medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, a method for synchronizing data according to an embodiment of the present invention is implemented.
[0046] An embodiment of the above invention has the following advantages or beneficial effects: when the data on the second server changes, the corresponding data on the first server can be synchronized and updated in time, and the first server only synchronizes and updates the data that has changed on the second server, without traversing all the data on the second server, thereby saving the computing resources of the first server and enabling the performance of the first server to be more effectively utilized.
[0047] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0049] Figure 1 is a schematic diagram of main steps of a method for synchronizing data according to an embodiment of the present invention;
[0050] Figure 2 is a schematic diagram of main steps of a method for updating first data according to data to be synchronized according to an embodiment of the present invention;
[0051] Figure 3 is a schematic diagram of main modules of a first server according to an embodiment of the present invention;
[0052] Figure 4 is a schematic diagram of main modules of a system for synchronizing data according to an embodiment of the present invention;
[0053] Figure 5 is a schematic diagram of main steps of another method for synchronizing data according to an embodiment of the present invention;
[0054] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0055] Figure 7It 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
[0056] 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.
[0057] It should be pointed out that the embodiments of the present invention and the technical features therein may be combined with each other without conflict.
[0058] Figure 1 It is a schematic diagram of main steps of a method for synchronizing data according to an embodiment of the present invention.
[0059] like Figure 1 As shown, a method for synchronizing data in an embodiment of the present invention mainly includes the following steps:
[0060] Step S101: monitor a second pointer on a second server in real time, where the second pointer is used to indicate the last updated data in the second data on the second server.
[0061] A method for synchronizing data provided by an embodiment of the present invention is applied to a first server. In the technology related to distributed systems, the first server is a server configured locally, and in the technology related to virtual machines, the first server is a virtual machine configured locally. The first server stores first data and a first pointer, the first data refers to cached data on the first server, and the first pointer is used to indicate the last updated data in the first data.
[0062] In the embodiment of the present invention, the first data may include any one or more of the following: an item identification, an inventory quantity of the item, and a storage location of the item.
[0063] In an embodiment of the present invention, the first server monitors the second pointer on the second server in real time to ensure timely knowledge of whether the second data on the second server is updated. The second server is a central server in the distributed system related technology or virtual machine related technology, which can be deployed online or in the cloud. The second server stores the second data and the second pointer, and the second pointer is used to indicate the last updated data in the second data.
[0064] In an embodiment of the present invention, when the second data on the second server is not updated, or after the second data is updated and the first server completes data synchronization, the first data and the second data are the same; and when the second data on the second server changes and the first server is synchronizing data, the first data and the second data are different. However, by real-time monitoring of the second pointer on the second server by the first server, when the second data on the second server is updated, the process of synchronizing data on the first server can be started in time, and under the current network transmission technology, the synchronization process takes a very short time, so the first data on the first server is consistent with the second data on the second server in most of the time, which largely solves the current problem of inconsistent data on different servers due to the inability to synchronize data in time between different servers.
[0065] Step S102: determine whether the first pointer and the second pointer are the same; if not, determine the data to be synchronized on the second server according to the second pointer.
[0066] In the embodiment of the present invention, the first pointer and the second pointer can respectively store the number of the first data and the second data. In this case, the first pointer and the second pointer are equivalent to counters. When there is data update, the second pointer is cyclically increased by 1. When data is synchronized, the first pointer is cyclically increased by 1, so that the first pointer and the second pointer respectively indicate the last updated data in the first data and the second data. For example, at a certain moment, the first pointer is "182", indicating that there are 182 data in the first data, and the 182nd data is the last updated data of the first server. At this time, the first server learns through monitoring that the second pointer is "184", indicating that there are 184 data in the second data, and the 184th data is the last updated data of the second server. Therefore, the first server can judge that the first pointer and the second pointer are not the same, and then determine the data to be synchronized on the second server according to the second pointer.
[0067] In an embodiment of the present invention, when the physical starting address of the first data on the first server is the same as the physical starting address of the second data on the second server, the first pointer and the second pointer may also respectively store the physical address of the last updated data in the first data and the second data, and when there is data update, the second pointer cyclically increases a step, and when synchronizing data, the first pointer cyclically increases a step. For example, at a certain moment, the first pointer points to "11230H", indicating that the last updated data in the first data is stored at "11230H", and at this time, the first server learns through monitoring that the second pointer points to "1123AH", indicating that the last updated data in the second data is stored at "1123AH", so the first server can determine that: the first pointer and the second pointer are not the same, and then determine the data to be synchronized on the second server based on the second pointer.
[0068] In the embodiment of the present invention, the first server can also monitor the second data pointed to by the second pointer in real time, and determine whether the second data is updated by judging whether the first data pointed to by the first pointer is the same as the second data pointed to by the second pointer. When the first data pointed to by the first pointer is different from the second data pointed to by the second pointer, it means that the second data has changed, and the first server determines the data to be synchronized on the second server according to the second pointer.
[0069] In an embodiment of the present invention, the data to be synchronized is data that has been updated on the second server but has not yet been synchronized with the first server. When it is determined that the first pointer and the second pointer are not the same, the first server can determine the data to be synchronized on the second server based on the second pointer. In this way, the first server can perform synchronization operations only on the data to be synchronized, without having to traverse the second data on the second server to determine the data to be synchronized, and without having to obtain all the second data on the second server to achieve the function of synchronizing data. It can be seen from the above description that the embodiment of the present invention can achieve the function of synchronizing data while occupying very few server resources, and will not affect the normal performance of the server.
[0070] In the embodiment of the present invention, the first server may determine whether the first pointer and the second pointer are the same by monitoring the second pointer in real time; or may determine whether the first pointer and the second pointer are the same by receiving a data update broadcast from the second server.
[0071] Step S103: Synchronize the first data and the second data according to the data to be synchronized.
[0072] In the embodiment of the present invention, after the first server determines the data to be synchronized on the second server according to the second pointer, it updates the first data according to the data to be synchronized to achieve synchronization between the first data and the second data. Figure 2 That is, it is a schematic diagram of main steps of a method for updating first data according to data to be synchronized according to an embodiment of the present invention.
[0073] like Figure 2 As shown, a method for updating first data according to data to be synchronized according to an embodiment of the present invention mainly includes the following steps:
[0074] Step S201: determining a cache queue storing data to be synchronized, wherein the cache queue includes: the data to be synchronized and a second pointer identifier corresponding to the data to be synchronized;
[0075] Step S202: incrementing the first pointer, and determining from the cache queue a second pointer identifier that is the same as the incremented first pointer;
[0076] Step S203: updating the first data according to the determined data to be synchronized corresponding to the second pointer identifier;
[0077] Step S204: Determine whether the first pointer and the second pointer are the same, if not, return to step S202, if yes, execute step S205;
[0078] Step S205: End the current process.
[0079] In the embodiment of the present invention, the update of the second data includes operations such as adding, deleting and modifying, and the amount of data in the second data will increase: when there is new data, the second server will directly write the new data into the second data; when the original data is deleted or modified, the second server will add a deletion or modification mark based on the original second data to generate new second data. The second pointer records the position where the second data is changed in an incremental manner.
[0080] The synchronization of the first data by the first server is similar to the update of the second data by the second server. Specifically, when there is new data in the second data, the first server will write the new data directly into the first data; when there is a deletion or modification operation on the second data, the first server will add a deletion or modification mark based on the original first data to generate new first data. At this time, the amount of data in the first data will increase, and the first pointer will record the location where the first data has changed in an incremental manner.
[0081] In an embodiment of the present invention, the cache queue is used to save the change track of the second data. The cache queue may include the data to be synchronized and the second pointer identifier corresponding to the data to be synchronized, and the second pointer identifier is used to save the value of the second pointer when the corresponding data to be synchronized is indicated by the second pointer. At this time, the first server directly determines the corresponding data to be synchronized based on the second pointer identifier that is the same as the incremented first pointer, and updates the first data based on the data to be synchronized.
[0082] In an embodiment of the present invention, the cache queue may also include a data id to be synchronized and a second pointer identifier corresponding to the data id to be synchronized, and the second pointer identifier is used to save the value of the second pointer when the corresponding data id to be synchronized is indicated by the second pointer. At this time, the first server first determines the corresponding data id to be synchronized according to the second pointer identifier that is the same as the incremented first pointer, and then determines the corresponding data to be synchronized from the second data according to the data id to be synchronized, and then updates the first data according to the data to be synchronized.
[0083] In the embodiment of the present invention, the increment of the first pointer and the second pointer may both start from 1, and each time the first data and the second data change, the first pointer and the second pointer increase by one step respectively.
[0084] In an embodiment of the present invention, when the first server has not synchronized with the second server for a long time, all the second data can be pulled from the second server once and replace the first data to avoid occasional errors in the data transmission process. Specifically: the first server starts timing after updating the first data. When the recorded duration reaches the first preset duration threshold and no new data update occurs within the recorded duration, the first server obtains all the second data from the second server and replaces the first data based on all the obtained second data. If the first server performs a synchronization operation during the timing process, the recorded duration is cleared and the timing is restarted. In a preferred embodiment of the present invention, the first preset duration threshold can be 30 minutes.
[0085] According to a method for synchronizing data according to an embodiment of the present invention, it can be seen that the first server monitors the second pointer on the second server in real time, and when it is determined that the second pointer is different from its own first pointer, it can timely determine the data to be synchronized on the second server according to the second pointer, thereby achieving the effect of timely synchronization of its own first data. In addition, the first server can only synchronize the data to be synchronized on the determined second server, without traversing all the data of the second server, thereby saving the computing resources of the first server and making the performance of the first server more effectively exerted.
[0086] Figure 3 is a schematic diagram of main modules of a first server according to an embodiment of the present invention.
[0087] like Figure 3 As shown, a first server 300 of an embodiment of the present invention includes: a monitoring module 301, a judgment module 302 and a synchronization module 303; wherein:
[0088] A monitoring module 301, used for real-time monitoring of a second pointer on the second server, where the second pointer is used to indicate the last updated data in the second data on the second server;
[0089] The judging module 302 is used to judge whether the first pointer is the same as the second pointer obtained by the monitoring module 301; if not, determine the data to be synchronized on the second server according to the second pointer;
[0090] The synchronization module 303 is used to synchronize the first data with the second data according to the data to be synchronized determined by the determination module 302 .
[0091] In the embodiment of the present invention, the synchronization module 303 may also be used to update the first data according to the data to be synchronized, so as to achieve synchronization between the first data and the second data.
[0092] In an embodiment of the present invention, the synchronization module 303 can also be used to: determine a cache queue for storing data to be synchronized, the cache queue including: data to be synchronized and a second pointer identifier corresponding to the data to be synchronized; loop the following steps until the first pointer and the second pointer are the same: increment the first pointer, determine a second pointer identifier that is the same as the incremented first pointer from the cache queue, and update the first data according to the data to be synchronized corresponding to the determined second pointer identifier.
[0093] In the embodiment of the present invention, the judgment module 302 may also be used to determine whether the first pointer and the second pointer are the same by receiving a data update broadcast from the central server or monitoring the second pointer in real time.
[0094] In an embodiment of the present invention, the synchronization module 303 can also be used to: start timing after the first data is updated, when the recorded duration reaches a preset duration threshold and no new data update occurs within the recorded duration, obtain second data from the second server, and replace the first data according to the obtained second data.
[0095] In the embodiment of the present invention, the first data includes any one or more of the following: an item identification, an inventory quantity of the item, and a storage location of the item.
[0096] According to a first server of an embodiment of the present invention, it can be seen that the first server monitors the second pointer on the second server in real time, and when it is determined that the second pointer is different from its own first pointer, it can timely determine the data to be synchronized on the second server according to the second pointer, thereby achieving the effect of timely synchronization of its own first data. In addition, the first server can only synchronize the data to be synchronized on the determined second server, without traversing all the data of the second server, thereby saving the computing resources of the first server and making the performance of the first server more effectively exerted.
[0097] Figure 4 4 is a schematic diagram of main modules of a system for synchronizing data according to an embodiment of the present invention.
[0098] like Figure 4 As shown, a system 400 for synchronizing data according to an embodiment of the present invention comprises: a first server 300 and a second server 401 provided in the above-mentioned embodiment of the present invention; wherein:
[0099] The second server 401 includes second data and a second pointer, where the second pointer is used to indicate the last updated data in the second data. When the second data is updated, the second pointer is updated.
[0100] In the embodiment of the present invention, the second server 401 may also be used to cyclically execute the following steps until all updated data are saved in the second data: increment the second pointer, and save the updated data in the second data.
[0101] In an embodiment of the present invention, the second server 401 can also be used to: save the updated data and the corresponding second pointer identifier in the cache queue, and use the updated data as the data to be synchronized, so that the first server updates the first data according to the data to be synchronized corresponding to the second pointer identifier.
[0102] In an embodiment of the present invention, the second server 401 can also be used to set an expiration policy, that is, when the data to be synchronized in the cache queue is not read within a second preset time threshold, the data to be synchronized in the cache queue and the second pointer identifier are deleted to avoid erroneous data.
[0103] In an embodiment of the present invention, the cache queue may also include a data ID to be synchronized and a second pointer identifier corresponding to the data ID to be synchronized. In this case, the second server 401 may also be used to: when the data ID to be synchronized in the cache queue is not read within the second preset time threshold, delete the data ID to be synchronized and the second pointer identifier in the cache queue. In a preferred embodiment of the present invention, the second preset time threshold may be 30 minutes.
[0104] According to a data synchronization system according to an embodiment of the present invention, it can be seen that the first server monitors the second pointer on the second server in real time, and when it is determined that the second pointer is different from its own first pointer, it can timely determine the data to be synchronized on the second server according to the second pointer, thereby achieving the effect of timely synchronization of its own first data. In addition, the first server can only synchronize the data to be synchronized on the determined second server, without traversing all the data of the second server, thereby saving the computing resources of the first server and making the performance of the first server more effectively exerted.
[0105] A method for synchronizing data provided by this solution is described below based on a relatively complete embodiment.
[0106] Figure 5 It is a schematic diagram of main steps of another method for synchronizing data according to an embodiment of the present invention.
[0107] like Figure 5 As shown, another method for synchronizing data in an embodiment of the present invention mainly includes the following steps:
[0108] Step S501: The first server monitors the second pointer on the second server in real time, where the second pointer is used to indicate the last updated data in the second data on the second server.
[0109] Step S502: The second server receives the updated data, cyclically increases the second pointer by 1, and saves the updated data into the second data.
[0110] Step S503: the second server takes the updated data as the data to be synchronized, saves the ID of the data to be synchronized and the corresponding second pointer identifier into the cache queue, and sets an expiration policy.
[0111] In the embodiment of the present invention, the purpose of setting the expiration policy is to save space in the cache queue. After the data in the cache queue has been read by all the first servers, the data is useless and erroneous data may appear. Therefore, after the expiration, the ID of the data to be synchronized and the second pointer identifier in the cache queue will be deleted.
[0112] Step S504: the first server determines whether the first pointer and the second pointer are the same. When the first pointer and the second pointer are not the same, the first server reads the data to be synchronized from the cache queue of the second server.
[0113] Step S505: the first server cyclically adds 1 to the first pointer, determines the corresponding data to be synchronized id according to the second pointer identifier that is the same as the first pointer, and then determines the corresponding data to be synchronized from the second data according to the data to be synchronized id.
[0114] Step S506: The first server synchronizes the first data according to the data to be synchronized.
[0115] Figure 6 An exemplary system architecture 600 of a method for synchronizing data or a first server to which an embodiment of the present invention may be applied is shown.
[0116] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0117] The user can use the terminal devices 601, 602, 603 to interact with the server 605 through the network 604 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 601, 602, 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0118] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0119] The server 605 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information and product information) to the terminal device.
[0120] It should be understood that Figure 6 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.
[0121] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device 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.
[0122] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0123] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0124] 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 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.
[0125] 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.
[0126] 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.
[0127] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be arranged in a processor, for example, they may be described as: a processor including a monitoring module, a judgment module and a synchronization module. The names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the monitoring module may also be described as a "module for real-time monitoring of the second pointer on the second server".
[0128] 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 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: real-time monitoring of the second pointer on the second server, the second pointer is used to indicate the last updated data in the second data on the second server; judging whether the first pointer and the second pointer are the same; if not, determining the data to be synchronized on the second server according to the second pointer; synchronizing the first data with the second data according to the data to be synchronized.
[0129] According to the technical solution of the embodiment of the present invention, the first server monitors the second pointer on the second server in real time, and when it determines that the second pointer is different from its own first pointer, it can timely determine the data to be synchronized on the second server according to the second pointer, thereby achieving the effect of timely synchronization of its own first data. In addition, the first server can only synchronize the determined data to be synchronized on the second server, without traversing all the data of the second server, thereby saving the computing resources of the first server and making the performance of the first server more effectively exerted.
[0130] 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 method for synchronizing data, characterized in that: Applied to a first server, the first server includes first data and a first pointer, the first pointer is used to indicate the last updated data in the first data; including: Real-time monitoring of a second pointer on the second server, where the second pointer is used to indicate the last updated data in the second data on the second server; Determine whether the first pointer and the second pointer are the same; if not, determine the data to be synchronized on the second server according to the second pointer; wherein the first pointer stores the amount of the first data; the second pointer stores the amount of the second data; when there is data update, the second pointer is cyclically increased by 1; when synchronizing data, the first pointer is cyclically increased by 1; The first data and the second data are synchronized according to the data to be synchronized.
2. The method according to claim 1, characterized in that The synchronizing the first data with the second data according to the data to be synchronized includes: The first data is updated according to the data to be synchronized, so as to achieve synchronization between the first data and the second data.
3. The method according to claim 2, characterized in that The updating of the first data according to the data to be synchronized includes: Determine a cache queue for storing the data to be synchronized, wherein the cache queue includes: the data to be synchronized and a second pointer identifier corresponding to the data to be synchronized; The following steps are executed repeatedly until the first pointer and the second pointer are the same: The first pointer is incremented, a second pointer identifier that is the same as the incremented first pointer is determined from the cache queue, and the first data is updated according to the to-be-synchronized data corresponding to the determined second pointer identifier.
4. The method according to claim 1, characterized in that: The determining whether the first pointer and the second pointer are the same includes: Whether the first pointer and the second pointer are the same is determined by receiving a data update broadcast from a central server or monitoring the second pointer in real time.
5. The method according to claim 1, characterized in that The method further includes: The timing starts after the first data is synchronized. When the recorded duration reaches a first preset duration threshold and the first data is not newly synchronized within the recorded duration, the second data is obtained from the second server and the first data is replaced according to the obtained second data.
6. The method according to claim 1, characterized in that The first data includes any one or more of the following: an item identification, an inventory quantity of the item, and a storage location of the item.
7. A first server, characterized in that: It includes a monitoring module, a judgment module and a synchronization module; wherein: The monitoring module is used to monitor the second pointer on the second server in real time, where the second pointer is used to indicate the last updated data in the second data on the second server; The judging module is used to judge whether the first pointer and the second pointer obtained by the monitoring module are the same; if not, determine the data to be synchronized on the second server according to the second pointer; wherein the first pointer stores the number of the first data; the second pointer stores the number of the second data; when there is data update, the second pointer is cyclically increased by 1; when synchronizing data, the first pointer is cyclically increased by 1; The synchronization module is used to synchronize the first data with the second data according to the data to be synchronized determined by the judgment module.
8. A system for synchronizing data, characterized in that: include: The first server and the second server as described in claim 7; wherein: The second server includes second data and a second pointer, where the second pointer is used to indicate the last updated data in the second data. When the second data is updated, the second pointer is updated.
9. The system according to claim 8, characterized in that The second server is further configured to: loop through the following steps until all updated data is saved in the second database: The second pointer is incremented, and the updated data is saved in the second data.
10. The system according to claim 8, characterized in that The second server is also used to: save the updated data and the corresponding second pointer identifier into a cache queue, and use the updated data as data to be synchronized, so that the first server updates the first data according to the data to be synchronized corresponding to the second pointer identifier.
11. The system according to claim 10, characterized in that The second server is further configured to: when the to-be-synchronized data in the cache queue is not read within a second preset time threshold, delete the to-be-synchronized data in the cache queue and the second pointer identifier.
12. A server for synchronizing data, 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 6.
13. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Hive data warehouse synchronization method, system and device and storage medium
CN111241203A