CN111241189A - Method and device for synchronizing data - Google Patents

Method and device for synchronizing data Download PDF

Info

Publication number
CN111241189A
CN111241189A CN201811442486.9A CN201811442486A CN111241189A CN 111241189 A CN111241189 A CN 111241189A CN 201811442486 A CN201811442486 A CN 201811442486A CN 111241189 A CN111241189 A CN 111241189A
Authority
CN
China
Prior art keywords
sliding window
cache
data
service data
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201811442486.9A
Other languages
Chinese (zh)
Other versions
CN111241189B (en
Inventor
佀庆乾
谭杨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201811442486.9A priority Critical patent/CN111241189B/en
Publication of CN111241189A publication Critical patent/CN111241189A/en
Application granted granted Critical
Publication of CN111241189B publication Critical patent/CN111241189B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method and a device for synchronizing data, and relates to the technical field of computers. One embodiment of the method comprises: storing the service data to be updated into a cache; storing the changed service data in the cache into a current sliding window; and creating a new sliding window, taking the new sliding window as the current sliding window, and synchronizing the service data in the original sliding window into the database. The implementation mode can solve the problems of high use cost and data loss.

Description

Method and device for synchronizing data
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for synchronizing data.
Background
Currently, monitoring statistics on a large amount of real-time data is often required to generate a real-time report, for example, real-time statistics on the delivery of a certain sorting center in a certain time period. If the relevant records in the database are updated every time an order is sent, because the operation of the sorting center is very frequent, the relevant tables of the database are frequently updated for counting a large number of indexes, so that very large pressure is caused on the database, and the problems of overhigh CPU (Central processing Unit) of the database, large master-slave delay and the like are caused.
To address the above problems, there are currently two solutions: firstly, the database is divided into a database and a table, namely a plurality of databases are used for storing data, so that the pressure of a single database is reduced; secondly, storing a database snapshot in the redis, directly updating the data snapshot in the redis each time data is updated, and then synchronizing the data snapshot stored in the redis to the database through a timing task.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
1) the data storage is carried out in a database-dividing and table-dividing mode, so that a large amount of database resources are wasted, and the cost is overhigh; moreover, the data size of some real-time reports is small, and only the number of data updating times is very large, so that the database and table division is not suitable;
2) the use of the redis cache data snapshot can reduce the use of database resources and reduce the cost, but the mode is inflexible, and if the redis or the timing task is abnormal, the data cannot be quickly switched to the database, which can result in data loss.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for synchronizing data, which can solve the problems of high use cost and data loss.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method of synchronizing data, including:
storing the service data to be updated into a cache;
storing the changed service data in the cache into a current sliding window;
and creating a new sliding window, taking the new sliding window as the current sliding window, and synchronizing the service data in the original sliding window into the database.
Optionally, storing the service data to be updated in a cache includes:
and acquiring the identifier of the current sliding window pointed by the pointer, splicing the service main key of the service data and the identifier of the sliding window into a character string, taking the character string as a key, taking the attribute and the attribute value of the service data as a value, and storing the value into a cache.
Optionally, storing the changed service data in the cache into the current sliding window includes:
and storing the key corresponding to the service data with the changed attribute value stored in the cache into the current sliding window pointed by the pointer.
Optionally, creating a new sliding window, taking the new sliding window as a current sliding window, and synchronizing the service data in the original sliding window into the database, including:
querying the identification of the unsynchronized sliding window from the task list;
creating a new sliding window, generating an identifier of the new sliding window, pointing a pointer to the sliding window, and storing the identifier of the sliding window into a task list;
locking the searched unsynchronized sliding window, and synchronizing the service data in the sliding window into a database;
and deleting the sliding window from the cache, and setting the state of the sliding window in the task list to be invalid.
Optionally, synchronizing the service data in the sliding window into a database includes:
taking out the key from the sliding window, converting the business data corresponding to the key into java objects, and synchronizing the java objects into a database;
delete the key in the sliding window.
Optionally, the method further comprises:
receiving real-time data streams and splicing the real-time data streams into service data to be updated;
and calling a persistence interface, and determining to persist the business data to be updated into a database or store the business data to be updated into a cache according to a cache annotation on the persistence interface.
Optionally, the determining, according to a cache annotation on the persistent interface, to persist the service data to be updated into a database or store the service data to be updated into a cache includes:
calling a persistence method, and executing annotation analysis;
if the annotation analysis is successfully executed, storing the service data to be updated into a cache;
and if the annotation analysis fails, the business data to be updated is persisted into the database.
In addition, according to another aspect of an embodiment of the present invention, there is provided an apparatus for synchronizing data, including:
the storage module is used for storing the service data to be updated into a cache;
the sliding window module is used for storing the changed service data in the cache into a current sliding window;
and the synchronization module is used for creating a new sliding window, using the new sliding window as the current sliding window and synchronizing the service data in the original sliding window into the database.
Optionally, the storage module is configured to:
and acquiring the identifier of the current sliding window pointed by the pointer, splicing the service main key of the service data and the identifier of the sliding window into a character string, taking the character string as a key, taking the attribute and the attribute value of the service data as a value, and storing the value into a cache.
Optionally, the sliding window module is configured to:
and storing the key corresponding to the service data with the changed attribute value stored in the cache into the current sliding window pointed by the pointer.
Optionally, the synchronization module is configured to:
querying the identification of the unsynchronized sliding window from the task list;
creating a new sliding window, generating an identifier of the new sliding window, pointing a pointer to the sliding window, and storing the identifier of the sliding window into a task list;
locking the searched unsynchronized sliding window, and synchronizing the service data in the sliding window into a database;
and deleting the sliding window from the cache, and setting the state of the sliding window in the task list to be invalid.
Optionally, synchronizing the service data in the sliding window into a database includes:
taking out the key from the sliding window, converting the business data corresponding to the key into java objects, and synchronizing the java objects into a database;
delete the key in the sliding window.
Optionally, the apparatus further comprises:
the receiving module is used for receiving the real-time data stream and splicing the real-time data stream into service data to be updated;
and the judging module is used for calling a persistent interface and judging whether the service data to be updated is persisted in a database or stored in a cache according to the cache annotation on the persistent interface.
Optionally, the determining, according to a cache annotation on the persistent interface, to persist the service data to be updated into a database or store the service data to be updated into a cache includes:
calling a persistence method, and executing annotation analysis;
if the annotation analysis is successfully executed, storing the service data to be updated into a cache;
and if the annotation analysis fails, the business data to be updated is persisted into the database.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any of the embodiments described above.
According to another aspect of the embodiments of the present invention, there is also provided a computer readable medium, on which a computer program is stored, which when executed by a processor implements the method of any of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: because the technical means of storing the changed business data in the cache into the current sliding window, creating a new sliding window and synchronizing the business data in the original sliding window into the database is adopted, the technical problems of high use cost and data loss are solved; the embodiment of the invention stores the objects updated within a certain time interval in the sliding window, and the timing task only needs to synchronize the changed objects in the sliding window, thereby reducing the data volume required to be synchronized every time and improving the application performance. Moreover, the embodiment of the invention can also realize the random switching of the application write cache and the database, if the cache or the timing task is abnormal, the application can be switched to the direct write database, and the data stored in the cache is synchronized to the corresponding record of the database, thereby being capable of conveniently realizing the degradation.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of a main flow of a method of synchronizing data according to an embodiment of the invention;
FIG. 2 is a schematic diagram of a sliding window and pointer according to an embodiment of the present invention;
FIG. 3 is a diagram showing a main flow of a method of synchronizing data according to a referential embodiment of the present invention;
FIG. 4 is a schematic view of a main flow of a method of synchronizing data according to another referenceable embodiment of the present invention;
FIG. 5 is a schematic diagram of the main modules of an apparatus for synchronizing data according to an embodiment of the present invention;
FIG. 6 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 7 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a method of synchronizing data according to an embodiment of the present invention. As shown in fig. 1, as an embodiment of the present invention, the method for synchronizing data includes:
step 101, storing service data to be updated in a cache.
In this step, the service data to be updated in a certain time interval may be stored in the buffer. Optionally, the cache may be a redis, and the service data to be updated is hashed (hash) in the redis. In addition, the time interval may be set according to actual needs, and the embodiment of the present invention is not limited to this.
As still another embodiment of the present invention, the step 101 may include: and acquiring the identifier of the current sliding window pointed by the pointer, splicing the service main key of the service data and the identifier of the sliding window into a character string, taking the character string as a key, taking the attribute and the attribute value of the service data as a value, and storing the value into a cache.
Specifically, the service data may be stored in redis using hash map (HashMap), key is a string assembled by the service primary key of each service data and the identifier of the sliding window where the service primary key is located, the value format is { "field 1": value1, "field 2": value2, … }, and each attribute value is increased by 1 or decreased by 1 using hnirby (key, field, delta) in redis. The identifier of the sliding window may be the current time, or may be a constant, as long as the sliding window can be distinguished, which is not limited in this embodiment of the present invention.
For example, the traffic data may be as follows:
service data 1:
businessId1_car_002:{“field1”:value1,“field2”:value2,…}
service data 2:
businessId2_car_002:{“field1”:value1,“field2”:value2,…}
……
service data N:
businessIdN_car_002:{“field1”:value1,“field2”:value2,…}
wherein businessIdN is a service primary key, car _002 is an identifier of a sliding window, businessIdN _ car _002 is key, { "field 1": value1, "field 2": value2, … } is value.
Optionally, before step 101, the method further comprises: receiving real-time data streams, and splicing the real-time data streams into service data to be updated; and calling a persistence interface, and determining to persist the business data to be updated into a database or store the business data to be updated into a cache according to a cache annotation on the persistence interface. Therefore, when the cache or the timing task is abnormal, the application can be switched to the direct writing database, and the data stored in the cache can be updated to the corresponding record of the database.
Optionally, the determining, according to a cache annotation on the persistent interface, to persist the service data to be updated into a database or store the service data to be updated into a cache includes: calling a persistence method, and executing annotation analysis; if the annotation analysis is successfully executed, storing the service data to be updated into a cache; and if the annotation analysis fails, the business data to be updated is persisted into the database. When the persistent method is called and the persistent object is called, annotation analysis is executed, and whether the data is stored in a cache or is persisted in a database is selected. The embodiment of the invention adopts an annotation mode to access the cache layer, can realize the isolation of the cache and the service, and enables developers to concentrate on the service development. And the pluggable cache layer can be realized, and the service code does not need to be modified when the cache is not needed.
The embodiment of the invention realizes the update of the service data by an AOP (Aspect organized Programming) mode, and only needs to add a self-defined annotation on a persistence method when in use, thereby realizing the separation of service logic processing and data persistence.
For example, this may be implemented by the following custom annotation @ Redis MappingCache:
@RedisMappingCache(pointor=”p_test”,cacheBean=”redisBean”,disable=true,timeOut=10*60)
public int updateDetail(Sample sample){
}
the custom annotation RedisMappingCache is described as follows:
a pointer: and the pointer points to the current window, and after the business data is modified, the key of the pointer is placed into the window pointed by the pointer.
cacheBean: a cache cluster is used.
disable: whether the cache is started or not, and if the cache is true, using cache storage; false, use database storage.
timeOut: and if the time is overtime, the object survival time is destroyed automatically when the time is over, so that the object is prevented from being recycled and is stored in the cache all the time.
And 102, storing the changed service data in the cache into the current sliding window.
And on the basis of the step 101, storing the key corresponding to the service data with the changed attribute value stored in the cache into the current sliding window pointed by the pointer. It should be noted that each attribute value of the service data stored in the cache is not necessarily changed, and the cache stores both the service data with the changed attribute value and the service data without the changed attribute value. Therefore, the key corresponding to the service data with the changed attribute value is stored in the current sliding window pointed by the pointer, as shown in fig. 2, through step 102. The sliding window can be implemented using a set in redis, where a pointer points to the current sliding window.
It should be noted that if the same key appears in the sliding window, the deduplication process is performed to ensure that there is no same key in one sliding window.
Therefore, the embodiment of the invention records the key of the service data with the changed attribute value in each time period by adding the sliding window, so that the service data can be updated to the database in real time in the subsequent steps.
And 103, creating a new sliding window, taking the new sliding window as the current sliding window, and synchronizing the service data in the original sliding window into the database.
After storing the service data in a certain time interval into the buffer, the timing task may be executed at a certain time interval: firstly, a new sliding window is created, a pointer points to the new window, and then the service data in the original sliding window is synchronized into a database. In each time interval, the service data cannot be updated, so that the timing task does not need to update all the service data stored in the cache into the database every time, and only needs to update the updated data in the current time period into the database.
As still another embodiment of the present invention, step 103 may include: firstly, inquiring the identification of the unsynchronized sliding window from a task list; then, creating a new sliding window, generating an identifier of the new sliding window, pointing the pointer to the sliding window, and storing the identifier of the sliding window into a task list; then, locking the searched unsynchronized sliding window, and synchronizing the service data in the sliding window into a database; and finally, deleting the sliding window from the cache, and setting the state of the sliding window in the task list to be invalid. The embodiment of the invention inquires out the unsynchronized sliding windows through the task list and then sequentially synchronizes the unsynchronized sliding windows so as to ensure that data cannot be lost. Moreover, the sliding window can be prevented from being processed repeatedly by locking the sliding window.
Optionally, synchronizing the service data in the sliding window into a database includes: taking out the key from the sliding window, converting the business data corresponding to the key into java objects, and synchronizing the java objects into a database; delete the key in the sliding window. Optionally, the java object may be associated with the business data stored in the cache through annotation, so that the business data in the cache is converted into the java object. For example, a po object in Java is associated with business data in redis by the custom annotation @ RedisMapping.
Redemapping notes are added to classes or attributes as follows:
@RedisMapping(key=“id”)
Public class Sample{
@RedisMapping(field=“id”,type=”set”)
private String id;
@RedisMapping(field=“waybill_count”,type=”incr”)
private Integer waybillCount;
}
the custom annotation Redismapping is described as follows:
key: the service data corresponds to the key of the hash in the redis.
field: the service data attribute corresponds to the field in the redis hash.
type, which is whether the variation mode of the corresponding field data is incr or set; incr represents an increase over the original value; set denotes setting a field value to a new value.
According to the various embodiments, it can be seen that the technical scheme of storing the changed service data in the cache into the current sliding window, creating a new sliding window, and synchronizing the service data in the original sliding window into the database is adopted by the invention, so that the problems of high use cost and data loss are solved. The embodiment of the invention stores the objects updated within a certain time interval in the sliding window, and the timing task only needs to synchronize the changed objects in the sliding window, thereby reducing the data volume required to be synchronized every time and improving the application performance. Moreover, the embodiment of the invention can also realize the random switching of the application write cache and the database, if the cache or the timing task is abnormal, the application can be switched to the direct write database, and the data stored in the cache is synchronized to the corresponding record of the database, thereby being capable of conveniently realizing the degradation. In addition, the embodiment of the invention encapsulates the persistence of the data into the component, realizes the mapping association between the po object in java and the hash structure in redis and the decoupling with the service through the self-defined annotation, and can directly reuse the component when developing the real-time report, thereby reducing the development cost and improving the development efficiency.
Fig. 3 is a schematic diagram of a main flow of a method of synchronizing data according to one referential embodiment of the present invention, which may include:
step 301, receiving a real-time data stream, assembling the real-time data stream into service data to be updated, and calling a persistent interface;
step 302, judging whether to store the business data into the redis according to the cache annotation on the persistent interface; if yes, go to step 303; if not, go to step 308;
step 303, judging whether a sliding window in the redis is empty; if not, go to step 304; if yes, go to step 308;
step 304, acquiring the identifier of the current sliding window pointed by the pointer;
305, splicing a service main key of the service data and the identification of the sliding window into a key;
step 306, updating each attribute value of the service data in the redis;
307, storing the key corresponding to the service data with the changed attribute value into the current sliding window;
step 308, persisting the service data to be updated into the database.
In addition, in one embodiment of the present invention, the detailed implementation of the method for synchronizing data is described in detail above, so that the repeated description is not repeated here.
Fig. 4 is a schematic diagram of a main flow of a method of synchronizing data according to another referenceable embodiment of the present invention, which may include:
step 401, querying out an identifier of an unsynchronized sliding window from a task list;
step 402, creating a new sliding window, generating an identifier of the new sliding window, pointing a pointer to the sliding window, and storing the identifier of the sliding window into a task list;
step 403, locking the searched unsynchronized sliding window;
step 404, taking out the key from the sliding window;
step 405, converting the service data corresponding to the key stored in the redis into a java object;
step 406, persisting the java object to the data;
step 407, deleting the key of the service data from the sliding window;
step 408, whether the sliding window is empty or not; if not, go to step 404; if yes, go to step 409;
step 409, deleting the sliding window from the redis;
step 410, the state of the sliding window in the task list is set to be invalid.
In addition, in another embodiment of the present invention, the detailed implementation of the method for synchronizing data is described in detail above, so that the repeated description is not repeated here.
Fig. 5 is a schematic diagram of main blocks of an apparatus for synchronizing data according to an embodiment of the present invention. As shown in fig. 5, the apparatus 500 for synchronizing data includes a storage module 501, a sliding window module 502, and a synchronization module 503. The storage module 501 stores the service data to be updated into a cache; the sliding window module 502 stores the changed service data in the cache into the current sliding window; the synchronization module 503 creates a new sliding window, uses the new sliding window as the current sliding window, and synchronizes the service data in the original sliding window to the database.
Optionally, the storage module 501 obtains an identifier of a current sliding window pointed by the pointer, assembles a service key of the service data and the identifier of the sliding window into a character string, uses the character string as a key, uses an attribute and an attribute value of the service data as a value, and stores the value in the cache.
Optionally, the sliding window module 502 stores the key corresponding to the service data whose attribute value is changed and stored in the cache into the current sliding window pointed by the pointer.
Optionally, the synchronization module 503 queries the task list for an identifier of an unsynchronized sliding window; creating a new sliding window, generating an identifier of the new sliding window, pointing a pointer to the sliding window, and storing the identifier of the sliding window into a task list; locking the searched unsynchronized sliding window, and synchronizing the service data in the sliding window into a database; and deleting the sliding window from the cache, and setting the state of the sliding window in the task list to be invalid.
Optionally, synchronizing the service data in the sliding window into a database includes:
taking out the key from the sliding window, converting the business data corresponding to the key into java objects, and synchronizing the java objects into a database;
delete the key in the sliding window.
Optionally, the device further includes a receiving module and a determining module, where the receiving module receives the real-time data stream and assembles the real-time data stream into service data to be updated; and the judging module calls a persistent interface and judges whether the service data to be updated is persisted in a database or stored in a cache according to the cache annotation on the persistent interface.
Optionally, the determining, according to a cache annotation on the persistent interface, to persist the service data to be updated into a database or store the service data to be updated into a cache includes:
calling a persistence method, and executing annotation analysis;
if the annotation analysis is successfully executed, storing the service data to be updated into a cache;
and if the annotation analysis fails, the business data to be updated is persisted into the database.
According to the various embodiments, it can be seen that the technical scheme of storing the changed service data in the cache into the current sliding window, creating a new sliding window, and synchronizing the service data in the original sliding window into the database is adopted by the invention, so that the problems of high use cost and data loss are solved. The embodiment of the invention stores the objects updated within a certain time interval in the sliding window, and the timing task only needs to synchronize the changed objects in the sliding window, thereby reducing the data volume required to be synchronized every time and improving the application performance. Moreover, the embodiment of the invention can also realize the random switching of the application write cache and the database, if the cache or the timing task is abnormal, the application can be switched to the direct write database, and the data stored in the cache is synchronized to the corresponding record of the database, thereby being capable of conveniently realizing the degradation. In addition, the embodiment of the invention encapsulates the persistence of the data into the component, realizes the mapping association between the po object in java and the hash structure in redis and the decoupling with the service through the self-defined annotation, and can directly reuse the component when developing the real-time report, thereby reducing the development cost and improving the development efficiency.
It should be noted that, in the implementation of the apparatus for synchronizing data according to the present invention, the above method for synchronizing data has been described in detail, and therefore, the repeated content herein is not described again.
Fig. 6 illustrates an exemplary system architecture 600 to which the method of synchronizing data or the method of synchronizing data of embodiments of the present invention may be applied.
As shown in fig. 6, the system architecture 600 may include terminal devices 601, 602, 603, a network 604, and a server 605. The network 604 serves to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. Network 604 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 601, 602, 603 to interact with the server 605 via the network 604 to receive or send messages or the like. The terminal devices 601, 602, 603 may have installed thereon various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 605 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 601, 602, 603. The background management server may analyze and process the received data such as the product information query request, and feed back a processing result (for example, target push information and product information — only an example) to the terminal device.
It should be noted that the method for synchronizing data provided by the embodiment of the present invention is generally executed in the server 605, and accordingly, the apparatus for synchronizing data is generally disposed in the server 605.
It should be understood that the number of terminal devices, networks, and servers in fig. 6 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary 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 bus 704.
The following components are connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. 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, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a memory module, a sliding window module, and a synchronization module, where the names of the modules do not in some cases constitute a limitation on the modules themselves.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: storing the service data to be updated into a cache; storing the changed service data in the cache into a current sliding window; and creating a new sliding window, taking the new sliding window as the current sliding window, and synchronizing the service data in the original sliding window into the database.
According to the technical scheme of the embodiment of the invention, because the technical means of storing the changed business data in the cache into the current sliding window, creating a new sliding window and synchronizing the business data in the original sliding window into the database is adopted, the technical problems of high use cost and data loss are solved; the embodiment of the invention stores the objects updated within a certain time interval in the sliding window, and the timing task only needs to synchronize the changed objects in the sliding window, thereby reducing the data volume required to be synchronized every time and improving the application performance. Moreover, the embodiment of the invention can also realize the random switching of the application write cache and the database, if the cache or the timing task is abnormal, the application can be switched to the direct write database, and the data stored in the cache is synchronized to the corresponding record of the database, thereby being capable of conveniently realizing the degradation.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of synchronizing data, comprising:
storing the service data to be updated into a cache;
storing the changed service data in the cache into a current sliding window;
and creating a new sliding window, taking the new sliding window as the current sliding window, and synchronizing the service data in the original sliding window into the database.
2. The method of claim 1, wherein storing the service data to be updated in a cache comprises:
and acquiring the identifier of the current sliding window pointed by the pointer, splicing the service main key of the service data and the identifier of the sliding window into a character string, taking the character string as a key, taking the attribute and the attribute value of the service data as a value, and storing the value into a cache.
3. The method of claim 2, wherein storing the changed service data in the buffer into a current sliding window comprises:
and storing the key corresponding to the service data with the changed attribute value stored in the cache into the current sliding window pointed by the pointer.
4. The method of claim 1, wherein creating a new sliding window as a current sliding window and synchronizing the service data in the original sliding window into the database comprises:
querying the identification of the unsynchronized sliding window from the task list;
creating a new sliding window, generating an identifier of the new sliding window, pointing a pointer to the sliding window, and storing the identifier of the sliding window into a task list;
locking the searched unsynchronized sliding window, and synchronizing the service data in the sliding window into a database;
and deleting the sliding window from the cache, and setting the state of the sliding window in the task list to be invalid.
5. The method of claim 4, wherein synchronizing the traffic data in the sliding window to a database comprises:
taking out the key from the sliding window, converting the business data corresponding to the key into java objects, and synchronizing the java objects into a database;
delete the key in the sliding window.
6. The method of claim 1, further comprising:
receiving real-time data streams and splicing the real-time data streams into service data to be updated;
and calling a persistence interface, and determining to persist the business data to be updated into a database or store the business data to be updated into a cache according to a cache annotation on the persistence interface.
7. The method of claim 6, wherein determining to persist the business data to be updated to a database or to store the business data to be updated to a cache according to a cache annotation on the persistent interface comprises:
calling a persistence method, and executing annotation analysis;
if the annotation analysis is successfully executed, storing the service data to be updated into a cache;
and if the annotation analysis fails, the business data to be updated is persisted into the database.
8. An apparatus for synchronizing data, comprising:
the storage module is used for storing the service data to be updated into a cache;
the sliding window module is used for storing the changed service data in the cache into a current sliding window;
and the synchronization module is used for creating a new sliding window, using the new sliding window as the current sliding window and synchronizing the service data in the original sliding window into the database.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN201811442486.9A 2018-11-29 2018-11-29 Method and device for synchronizing data Active CN111241189B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811442486.9A CN111241189B (en) 2018-11-29 2018-11-29 Method and device for synchronizing data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811442486.9A CN111241189B (en) 2018-11-29 2018-11-29 Method and device for synchronizing data

Publications (2)

Publication Number Publication Date
CN111241189A true CN111241189A (en) 2020-06-05
CN111241189B CN111241189B (en) 2024-09-20

Family

ID=70875877

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811442486.9A Active CN111241189B (en) 2018-11-29 2018-11-29 Method and device for synchronizing data

Country Status (1)

Country Link
CN (1) CN111241189B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113034715A (en) * 2021-03-02 2021-06-25 创优数字科技(广东)有限公司 Attendance data processing method and device, server and storage medium
CN113127554A (en) * 2021-05-10 2021-07-16 广州欢网科技有限责任公司 Method and system for synchronizing data between interface and background system
CN113312351A (en) * 2021-06-01 2021-08-27 北京沃东天骏信息技术有限公司 Data processing method and device
CN115203214A (en) * 2022-09-16 2022-10-18 杭州谐云科技有限公司 Report data updating method and system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101984717A (en) * 2010-11-19 2011-03-09 中兴通讯股份有限公司 Data synchronization method, mobile terminal and data synchronization system
CN103581262A (en) * 2012-08-06 2014-02-12 腾讯科技(深圳)有限公司 Master-and-backup data synchronizing method, device and system
CN104573064A (en) * 2015-01-23 2015-04-29 四川中科腾信科技有限公司 Data processing method under big-data environment
CN105007302A (en) * 2015-06-04 2015-10-28 成都果豆数字娱乐有限公司 Mobile terminal data storage method
US20180260125A1 (en) * 2017-03-10 2018-09-13 Pure Storage, Inc. Synchronously replicating datasets and other managed objects to cloud-based storage systems

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101984717A (en) * 2010-11-19 2011-03-09 中兴通讯股份有限公司 Data synchronization method, mobile terminal and data synchronization system
CN103581262A (en) * 2012-08-06 2014-02-12 腾讯科技(深圳)有限公司 Master-and-backup data synchronizing method, device and system
CN104573064A (en) * 2015-01-23 2015-04-29 四川中科腾信科技有限公司 Data processing method under big-data environment
CN105007302A (en) * 2015-06-04 2015-10-28 成都果豆数字娱乐有限公司 Mobile terminal data storage method
US20180260125A1 (en) * 2017-03-10 2018-09-13 Pure Storage, Inc. Synchronously replicating datasets and other managed objects to cloud-based storage systems

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113034715A (en) * 2021-03-02 2021-06-25 创优数字科技(广东)有限公司 Attendance data processing method and device, server and storage medium
CN113127554A (en) * 2021-05-10 2021-07-16 广州欢网科技有限责任公司 Method and system for synchronizing data between interface and background system
CN113312351A (en) * 2021-06-01 2021-08-27 北京沃东天骏信息技术有限公司 Data processing method and device
CN115203214A (en) * 2022-09-16 2022-10-18 杭州谐云科技有限公司 Report data updating method and system

Also Published As

Publication number Publication date
CN111241189B (en) 2024-09-20

Similar Documents

Publication Publication Date Title
CN111241189B (en) Method and device for synchronizing data
CN110019211A (en) The methods, devices and systems of association index
CN110837409A (en) Method and system for executing task regularly
CN111666293A (en) Database access method and device
CN113342686B (en) Test data generation method and device
CN110572422A (en) Data downloading method and device
CN112579695A (en) Data synchronization method and device
CN108959294B (en) Method and device for accessing search engine
CN112748866B (en) Incremental index data processing method and device
CN111427899A (en) Method, device, equipment and computer readable medium for storing file
CN118312076A (en) Map icon processing method and device, electronic equipment and computer readable medium
CN112100168A (en) Method and device for determining data association relationship
CN112214500A (en) Data comparison method and device, electronic equipment and storage medium
CN111159207A (en) Information processing method and device
CN113347052B (en) Method and device for counting user access data through access log
CN110019671B (en) Method and system for processing real-time message
CN112988857A (en) Service data processing method and device
CN113704242A (en) Data processing method and device
CN113779018A (en) Data processing method and device
CN113704222A (en) Method and device for processing service request
CN117478535B (en) Log storage method and device
CN110705935A (en) Logistics document processing method and device
CN115994145B (en) Method and device for processing data
US11842077B2 (en) Method, device, and computer program product for transmitting data for object storage
CN113778909B (en) Method and device for caching data

Legal Events

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