[go: up one dir, main page]

CN111835855A - A data synchronization method and system - Google Patents

A data synchronization method and system Download PDF

Info

Publication number
CN111835855A
CN111835855A CN202010689970.2A CN202010689970A CN111835855A CN 111835855 A CN111835855 A CN 111835855A CN 202010689970 A CN202010689970 A CN 202010689970A CN 111835855 A CN111835855 A CN 111835855A
Authority
CN
China
Prior art keywords
data
interface
server
client
update
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.)
Pending
Application number
CN202010689970.2A
Other languages
Chinese (zh)
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.)
Inspur Software Co Ltd
Original Assignee
Inspur Software 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 Inspur Software Co Ltd filed Critical Inspur Software Co Ltd
Priority to CN202010689970.2A priority Critical patent/CN111835855A/en
Publication of CN111835855A publication Critical patent/CN111835855A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/10Active monitoring, e.g. heartbeat, ping or trace-route
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/50Queue scheduling

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本发明公开了一种数据同步方法及系统,本发明包括S1、在服务端建立数据同步控制表,所述数据同步控制表中记录有每个接口最近一次进行数据更新的数据更新时间戳,且服务端在更新数据时,数据同步控制表更新相对应的数据更新时间戳;S2、服务端提供给客户端一个轮询接口,该接口的参数为客户端的接口以及每个接口最近一次同步数据的数据同步时间戳,函数为客户端的接口的数据同步时间戳与数据同步控制表中对应的数据更新时间戳对比,当存在不一致时,向客户端返回不一致的接口。本发明相对于原始每个接口都要进行轮询请求的情况,大大减少客户端的无效调用,节省了服务器的资源,减轻了数据库的压力,促使服务更加稳定。

Figure 202010689970

The present invention discloses a data synchronization method and system. The present invention includes S1, establishing a data synchronization control table at the server, wherein the data synchronization control table records the data update time stamp of the latest data update performed by each interface, and When the server updates data, the data synchronization control table updates the corresponding data update timestamp; S2, the server provides a polling interface to the client, and the parameters of this interface are the interface of the client and the latest synchronization data of each interface. Data synchronization timestamp. The function is to compare the data synchronization timestamp of the client's interface with the corresponding data update timestamp in the data synchronization control table. If there is inconsistency, return the inconsistent interface to the client. Compared with the original situation that each interface needs to perform polling request, the present invention greatly reduces the invalid calls of the client, saves the resources of the server, reduces the pressure of the database, and promotes the service to be more stable.

Figure 202010689970

Description

一种数据同步方法及系统A data synchronization method and system

技术领域technical field

本发明涉及计算机技术领域,具体地说是一种数据同步方法及系统。The invention relates to the technical field of computers, in particular to a data synchronization method and system.

背景技术Background technique

在构建网络应用中,客户端需要经常与服务端进行持续的通讯来保持双方 信息的同步,通常这种持久通讯在不刷新页面的情况下进行,通过“服务器推” 方案向客户端推送消息,用的较多的则是短轮询。短轮询的基本思路就是客户 端每隔一段时间向服务端发送http请求,服务器端在收到请求后,不论是否有 数据更新,都直接进行响应。这种方式实现的即时通信,本质上是客户端发送 请求,服务器接受请求的一个过程,通过让客户端不断的进行请求,使得客户 端能够模拟实时地收到服务器端的数据的变化。这种方式的优点是比较简单, 易于理解,实现起来也没有什么技术难点,但是缺点是显而易见的,这种方式由于需要不断的建立http连接,严重浪费了服务器端和客户端的资源。尤其是 在客户端,具体来说,如果有数量级相对比较大的人同时位于基于短轮询的应 用中,那么每一个用户的客户端都会疯狂的向服务器端发送http请求,而且不 会间断,人数越多,服务器端压力越大,这是很不合理的。In the construction of network applications, the client needs to constantly communicate with the server to maintain the synchronization of the information between the two parties. Usually, this persistent communication is carried out without refreshing the page, and the "server push" scheme is used to push messages to the client. The most commonly used is short polling. The basic idea of short polling is that the client sends http requests to the server at regular intervals, and the server responds directly after receiving the request, regardless of whether there is data update. The instant communication implemented in this way is essentially a process in which the client sends a request and the server accepts the request. By allowing the client to make continuous requests, the client can simulate real-time data changes received from the server. The advantage of this method is that it is relatively simple, easy to understand, and has no technical difficulties to implement, but the disadvantage is obvious. This method seriously wastes the resources of the server and the client due to the continuous establishment of http connections. Especially on the client side, specifically, if there are relatively large people in the short polling-based application at the same time, then each user's client side will frantically send http requests to the server side without interruption, The more people, the more pressure on the server side, which is very unreasonable.

比如不管是大型连锁超市和线下店铺里一般都会用云pos收银系统进行进 销存管理,这类系统为了断网情况下依然能够正常使用,会把商品数据、库存 数据、用户数据(如新增收银员等)、机构参数、类目信息、活动等下载到本地 客户端。后台更新以上信息后不能主动通知客户端,客户端想拿到最新数据, 需要采用轮询方式,如每10分钟定时往服务端发送请求,采用增量下载方式获 取变更的数据。住主要逻辑是后台修改数据时会同时更新对应的时间戳,客户 端发起请求时带着本地的时间戳,服务端接收到请求对比两个时间戳,只从数 据库中取大于本地时间戳的数据。实际上大部分的数据很少改变,如用户数据 只有新增收银员或修改用户信息的时候才会变更,商品数据只有新增、修改、 删除的时候变更,用户后台操作的时间也比较集中,这就导致一直在发送无效 请求,这无疑对数据库和服务端应用产生压力,浪费资源,极端情况导致数据 库和应用宕机,服务不可用。比如在某一云POS服务商中,全国大约有50万零 售户,客户端有20个定时下载接口每十分钟分别往服务端发送一次请求,每个 零售户每天在线时长按10个小时计算,总共一天就有6亿次请求。客户端的主 要功能就是销售,销售主要涉及变更的业务只有库存,销售之后减库存数据才 会改变,改变的频率跟商品的销量成正比。所以说这6亿次请求只有少部分是 有效调用,即少部分接口对应的后台数据会改变,才会返回有变更的数据。For example, whether it is a large supermarket chain or offline stores, the cloud POS cash register system is generally used for invoicing management. In order to be able to use normally even when the network is disconnected, such systems will store product data, inventory data, user data (such as new Add cashiers, etc.), institutional parameters, category information, activities, etc. are downloaded to the local client. After the above information is updated in the background, the client cannot be actively notified. If the client wants to get the latest data, it needs to use the polling method. For example, it sends a request to the server every 10 minutes and uses the incremental download method to obtain the changed data. The main logic is that when the data is modified in the background, the corresponding timestamp will be updated at the same time. The client initiates the request with the local timestamp. The server receives the request and compares the two timestamps, and only retrieves data from the database that is greater than the local timestamp. . In fact, most of the data is rarely changed. For example, user data will only be changed when a cashier is added or user information is modified. Product data will only be changed when added, modified, or deleted. The time of user background operations is also relatively concentrated. As a result, invalid requests are being sent all the time, which undoubtedly puts pressure on the database and server-side applications, wastes resources, and in extreme cases, causes the database and application to go down and services become unavailable. For example, in a cloud POS service provider, there are about 500,000 retailers nationwide, and the client has 20 regular download interfaces to send requests to the server every ten minutes, and the online time of each retailer is calculated as 10 hours per day. , 600 million requests a day in total. The main function of the client is sales. Sales mainly involve changes in the business only inventory. After sales, the inventory data will be changed. The frequency of changes is proportional to the sales of products. Therefore, only a small part of these 600 million requests are valid calls, that is, the background data corresponding to a small part of the interface will change, and the changed data will be returned.

发明内容SUMMARY OF THE INVENTION

本发明的目的是针对以上不足,提供一种基于上述短轮询的方式数据同步 方法及系统,减少数据接口请求次数,降低服务器压力。The purpose of the present invention is to address the above deficiencies, to provide a method and system for data synchronization based on the above short polling method, which reduces the number of data interface requests and reduces server pressure.

本发明所采用技术方案是:The technical scheme adopted in the present invention is:

一种数据同步方法,所述方法包括如下步骤:A data synchronization method, the method comprises the following steps:

S1、在服务端建立数据同步控制表,所述数据同步控制表中记录有每个接 口最近一次进行数据更新的数据更新时间戳,且服务端在更新数据时,数据同 步控制表更新相对应的数据更新时间戳;S1, establish a data synchronization control table on the server, the data synchronization control table records the data update timestamp of the latest data update performed by each interface, and when the server updates data, the data synchronization control table updates the corresponding data update timestamp;

S2、服务端提供给客户端一个轮询接口,该接口的参数为客户端的接口以 及每个接口最近一次同步数据的数据同步时间戳,函数为客户端的接口的数据 同步时间戳与数据同步控制表中对应的数据更新时间戳对比,当存在不一致时, 向客户端返回不一致的接口,客户端调取返回的接口向服务端请求数据同步。S2. The server provides a polling interface to the client. The parameters of this interface are the interface of the client and the data synchronization timestamp of the latest synchronization data of each interface. The function is the data synchronization timestamp of the client interface and the data synchronization control table. When there is inconsistency, the inconsistent interface is returned to the client, and the client calls the returned interface to request data synchronization from the server.

具体的,本发明所述数据同步控制表中包含数据列为用户编码、接口ID 和最近一次数据更新的数据更新时间戳,用户编码用于对应客户端,接口ID 对接客户端的各个数据请求同步的接口ID,服务端接受人为数据更新时,数据 同步控制表中对接接口ID的数据更新时间戳更改为进行数据更新时的时间点。Specifically, the data synchronization control table of the present invention contains data columns as user code, interface ID and data update timestamp of the latest data update. Interface ID. When the server accepts manual data updates, the data update timestamp of the docking interface ID in the data synchronization control table is changed to the time when the data is updated.

作为对本发明方法的进一步优化,本发明当服务端进行数据更新时,通过 建立消息队列对不同接口的数据更新时间戳以及其他与数据相关数据表进行更 新。As a further optimization of the method of the present invention, the present invention updates the data update timestamps of different interfaces and other data-related data tables by establishing a message queue when the server updates data.

作为对本发明方法的进一步优化,本发明步骤S2中,服务端客户端本地的 接口的数据同步时间戳与数据同步控制表中的数据更新时间戳进行对比,并将 数据同步时间戳与数据更新时间戳不一致的接口ID返回至客户端。As a further optimization of the method of the present invention, in step S2 of the present invention, the data synchronization time stamp of the local interface of the server client is compared with the data update time stamp in the data synchronization control table, and the data synchronization time stamp and the data update time are compared. Stamp inconsistent interface IDs back to the client.

作为对本发明方法的进一步优化,本发明步骤S2中,客户端调取返回的接 口向服务端请求数据同步的过程包括:As a further optimization to the method of the present invention, in step S2 of the present invention, the process of requesting data synchronization from the server by the interface that the client calls and returns includes:

S201、客户端调用服务端返回的接口ID并向服务端请求同步数据;S201, the client invokes the interface ID returned by the server and requests synchronization data from the server;

S202、服务端返回请求的数据至相对应接口,相应接口数据完成更新,并 更新该接口的数据同步时间戳。S202, the server returns the requested data to the corresponding interface, the corresponding interface data is updated, and the data synchronization timestamp of the interface is updated.

本发明还提供一种数据同步系统,包括服务端和客户端,所述服务端包括 数据同步控制表、对比模块和数据发送模块;The present invention also provides a data synchronization system, including a server and a client, and the server includes a data synchronization control table, a comparison module and a data transmission module;

其中,所述数据同步控制表用于记录服务端所服务接口以及每个接口最近 数据更新的数据更新时间戳;Wherein, the data synchronization control table is used to record the service interface of the server and the data update timestamp of the latest data update of each interface;

所述对比模块用于接受客户端的相应请求后,将客户端的接口最近同步数 据的数据同步时间戳与数据同步控制表中对应的数据更新时间戳进行对比,并 向客户端输出两个时间戳不一致的接口;The comparison module is used to compare the data synchronization timestamp of the latest synchronization data of the client interface with the corresponding data update timestamp in the data synchronization control table after accepting the corresponding request of the client, and output the two timestamps to the client that are inconsistent. Interface;

所述数据发送模块用于接口客户端的接口数据同步请求,并向该接口发送 相应更新数据。The data sending module is used for the interface data synchronization request of the interface client, and sends corresponding update data to the interface.

作为对本发明系统的进一步的优化,本发明所述服务端还包括数据更新模 块,当服务端进行数据更新,且同一数据的更新涉及到多个接口的数据更新时 间戳更新时,数据更新模块通过建立消息队列对不同接口的时间戳进行更新。As a further optimization of the system of the present invention, the server of the present invention further includes a data update module. When the server performs data update, and the update of the same data involves the update of the data update timestamps of multiple interfaces, the data update module passes Establish a message queue to update the timestamps of different interfaces.

本发明还提供另一种一种数据同步系统,包括客户端和服务端,所述客户 端包括接口更新筛选模块和接口数据请求模块,所述服务端中设置有数据同步 控制表,所述数据同步控制表用于记录所服务接口最近更新数据的时间戳;The present invention also provides another data synchronization system, including a client and a server, the client includes an interface update screening module and an interface data request module, the server is provided with a data synchronization control table, the data The synchronization control table is used to record the timestamp of the latest updated data of the service interface;

其中:所述接口更新筛选模块用于向服务端发送轮询请求,并接收服务端 返回的客户端接口的数据同步时间戳与服务端中数据同步控制表中对应的数据 更新时间戳不一致的接口;Wherein: the interface update screening module is used to send a polling request to the server, and receive an interface in which the data synchronization timestamp of the client interface returned by the server is inconsistent with the corresponding data update timestamp in the data synchronization control table in the server ;

所述接口数据请求模块调用上述接口更新筛选模块接收的接口并向服务端 请求同步数据,并接收服务端返回的数据更新原数据。The interface data request module calls the interface received by the above-mentioned interface update screening module and requests synchronization data from the server, and receives the data returned by the server to update the original data.

本发明具有以下优点:The present invention has the following advantages:

1、本发明的方法通过在服务端增加一个记录有每个接口进行数据更新时间 点的数据表,并提供给客户端一个轮询的接口,客户端通过该接口先对比本地 接口的数据同步时间戳与数据表中数据更新时间戳对比,当不一致时返回客户 端不一致的接口,客户端在调用这些接口向服务端请求数据同步,相对于原始 每个接口都要进行轮询请求的情况,大大减少客户端的无效调用,节省了服务 器的资源,减轻了数据库的压力,促使服务更加稳定;1. The method of the present invention adds a data table that records the data update time point of each interface on the server side, and provides the client with a polling interface, and the client first compares the data synchronization time of the local interface through this interface. The stamp is compared with the data update timestamp in the data table. When it is inconsistent, the interface that is inconsistent with the client is returned. The client calls these interfaces to request data synchronization from the server. Compared with the original polling request for each interface, it is greatly Reduce the invalid calls of the client, save the resources of the server, reduce the pressure on the database, and make the service more stable;

2、本发明的服务端在数据更新时,通过消息列队的方式对数据表的时间戳 进行更新,能够降低系统复杂性,减少出错的可能,避免锁表情况的发生,且 消息队列的异步数据更新方式对本发明的方法没有影响。2. When the data is updated, the server of the present invention updates the timestamp of the data table by means of message queue, which can reduce the complexity of the system, reduce the possibility of errors, avoid the occurrence of table lock, and the asynchronous data of the message queue. The way of updating has no effect on the method of the present invention.

附图说明Description of drawings

为了更清楚地说明本发明实施例中的技术方案,下面将对实施例中描述中 所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本发明 的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动的前提 下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present invention more clearly, the following briefly introduces the accompanying drawings used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.

下面结合附图对本发明进一步说明:Below in conjunction with accompanying drawing, the present invention is further described:

图1为为本发明的数据同步控制表的格式示意图;Fig. 1 is the format schematic diagram of the data synchronization control table of the present invention;

具体实施方式Detailed ways

下面结合附图和具体实施例对本发明作进一步说明,以使本领域的技术人 员可以更好地理解本发明并能予以实施,但所举实施例不作为对本发明的限定, 在不冲突的情况下,本发明实施例以及实施例中的技术特征可以相互结合。The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments, so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention. Hereinafter, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.

需要理解的是,在本发明实施例的描述中,“第一”、“第二”等词汇,仅用 于区分描述的目的,而不能理解为指示或暗示相对重要性,也不能理解为指示 或暗示顺序。在本发明实施例中的“多个”,是指两个或两个以上。It should be understood that, in the description of the embodiments of the present invention, words such as "first" and "second" are only used for the purpose of distinguishing the description, and should not be understood as indicating or implying relative importance, nor should it be understood as indicating or implied order. In the embodiments of the present invention, "a plurality" refers to two or more.

本发明实施例中的属于“和/或”,仅仅是一种描述关联对象的关联关系, 表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,单独存在B, 同时存在A和B这三种情况。另外,本文中字符“/”一般表示前后关联对象是 一种“或”关系。In this embodiment of the present invention, "and/or" is only an association relationship describing associated objects, indicating that three relationships may exist, for example, A and/or B may indicate that A exists alone, B exists alone, There are three cases A and B at the same time. In addition, the character "/" in this text generally indicates that the contextual object is an "or" relationship.

本实施例提供一种数据同步方法,所述方法包括如下步骤:This embodiment provides a data synchronization method, and the method includes the following steps:

S1、在服务端建立数据同步控制表,所述数据同步控制表中包含数据列为 用户编码、接口ID和最近一次数据更新的数据更新时间戳,如图1所示,USER_ID 为用户编码,API_ID为接口ID,TIME_STAMP为时间戳,用户编码用于对应客 户端,接口ID对接客户端的各个数据请求同步的接口ID,服务端接受人为数 据更新时,数据同步控制表中对接接口ID的数据更新时间戳更改为进行数据更 新时的时间点,服务端在更新数据时,数据同步控制表更新相对应的数据更新 时间戳;S1, establish a data synchronization control table at the server, the data synchronization control table contains data columns as user code, interface ID and the data update timestamp of the latest data update, as shown in Figure 1, USER_ID is the user code, API_ID is the interface ID, TIME_STAMP is the timestamp, the user code is used to correspond to the client, and the interface ID is the interface ID that is connected to each data request synchronization of the client. When the server accepts manual data updates, the data update time of the interface ID in the data synchronization control table The stamp is changed to the time point when the data is updated. When the server updates the data, the data synchronization control table updates the corresponding data update timestamp;

S2、服务端提供给客户端一个轮询接口,该接口的参数为客户端的接口ID 以及每个接口ID最近一次同步数据的数据同步时间戳,函数为客户端的接口 ID的数据同步时间戳与数据同步控制表中对应的数据更新时间戳对比,当存在 不一致时,代表该接口存在数据需要进行同步,向客户端返回不一致的接口ID, 客户端调取返回的接口向服务端请求数据同步,当所有接口的对比均相同时, 代表不存在数据同步,服务端向客户端返回值为NULL;S2. The server provides a polling interface to the client. The parameters of this interface are the interface ID of the client and the data synchronization timestamp of the latest synchronization data of each interface ID. The function is the data synchronization timestamp and data of the interface ID of the client. Compare the corresponding data update timestamps in the synchronization control table. If there is inconsistency, it means that there is data in the interface that needs to be synchronized, and the inconsistent interface ID is returned to the client. The client calls the returned interface and requests data synchronization from the server. When the comparison of all interfaces is the same, it means that there is no data synchronization, and the server returns NULL to the client;

客户端调取返回的接口向服务端请求数据同步的过程包括:The process that the client calls the returned interface to request data synchronization from the server includes:

S201、客户端调用服务端返回的接口ID并向服务端请求同步数据;S201, the client invokes the interface ID returned by the server and requests synchronization data from the server;

S202、服务端返回请求的数据至相对应接口,相应接口数据完成更新,并 更新该接口的数据同步时间戳。S202, the server returns the requested data to the corresponding interface, the corresponding interface data is updated, and the data synchronization timestamp of the interface is updated.

作为一种优选的实施例,在步骤S1中,当服务端进行数据更新,且同一数 据的更新涉及到多个接口的数据更新时间戳需要更新时,通过建立消息队列对 不同接口的数据更新时间戳进行更新。在数据更新时,同一数据的更改会牵连 到多个相关数据行的更改,如在后台修改商品信息后,该商品的数据更新时间 戳以及总商品表的数据更新时间戳都需要更新,采用业务直接更新数据库时, 多个业务同时更新数据库中一条记录时会产生锁等待,批量更新还可能产生死 锁,使用消息列队异步修改多个数据同步控制表中的时间戳,能够降低系统的 复杂性、减少出错,避免产生锁表的情况发生,虽然采用消息队列会产生数据 更新不及时的情况,但是本方法客户端与服务端采用短轮询的方式进行更新客 户端数据,因此服务端异步修改数据更新时间戳对本发明数据同步没有影响。As a preferred embodiment, in step S1, when the server performs data update, and the update of the same data involves the data update timestamps of multiple interfaces and needs to be updated, the data update time of different interfaces is updated by establishing a message queue. Click to update. When data is updated, the change of the same data will involve the change of multiple related data rows. For example, after the product information is modified in the background, the data update timestamp of the product and the data update timestamp of the total product table need to be updated. When updating the database directly, lock waiting will occur when multiple services update a record in the database at the same time, and batch updates may also cause deadlocks. Using message queues to asynchronously modify timestamps in multiple data synchronization control tables can reduce the complexity of the system. , Reduce errors and avoid the occurrence of lock table. Although the use of message queues will cause data to be updated untimely, this method uses short polling between the client and the server to update client data, so the server modifies asynchronously. The data update time stamp has no effect on the data synchronization of the present invention.

基于上述数据同步方法,本发明该提供一种数据同步系统的实施例,从服 务端的角度说明,包括服务端和客户端,所述服务端包括数据更新模块、数据 同步控制表、对比模块数据发送模块和数据更新模块;Based on the above data synchronization method, the present invention provides an embodiment of a data synchronization system, which is described from the perspective of a server, including a server and a client, and the server includes a data update module, a data synchronization control table, and a comparison module for data transmission modules and data update modules;

其中,所述数据同步控制表用于记录服务端所服务接口以及每个接口最近 数据更新的数据更新时间戳;Wherein, the data synchronization control table is used to record the service interface of the server and the data update timestamp of the latest data update of each interface;

所述对比模块用于接受客户端的相应请求后,将客户端的接口最近同步数 据的数据同步时间戳与数据同步控制表中对应的数据更新时间戳进行对比,并 向客户端输出两个时间戳不一致的接口;The comparison module is used to compare the data synchronization timestamp of the latest synchronization data of the client interface with the corresponding data update timestamp in the data synchronization control table after accepting the corresponding request of the client, and output the two timestamps to the client that are inconsistent. Interface;

所述数据发送模块用于接口客户端的接口请求,并向该接口发送相应更新 数据;The data sending module is used for the interface request of the interface client, and sends corresponding update data to the interface;

所述数据更新模块将数据同步控制表中时间戳更新与数据更新元素之间通 过消息队列的方式进行连接,数据更新元素进行数据更新后,采用消息队列异 步修改数据同步控制表中相应的时间戳。The data update module connects the time stamp update and the data update element in the data synchronization control table by means of a message queue, and after the data update element performs data update, the message queue is used to asynchronously modify the corresponding time stamp in the data synchronization control table. .

本发明实施例还提供另一种数据同步系统,从客户端的角度说明,包括客 户端和服务端,所述客户端包括接口更新筛选模块和接口数据请求模块,所述 服务端中设置有数据同步控制表,所述数据同步控制表用于记录所服务接口最 近更新数据的时间戳;The embodiment of the present invention also provides another data synchronization system, which is described from the perspective of the client, including a client and a server, the client includes an interface update screening module and an interface data request module, and the server is provided with data synchronization a control table, the data synchronization control table is used to record the timestamp of the latest updated data of the service interface;

其中:所述接口更新筛选模块用于向服务端发送轮询请求,并接收服务端 返回的客户端接口的数据同步时间戳与服务端中数据同步控制表中对应的数据 更新时间戳不一致的接口;Wherein: the interface update screening module is used to send a polling request to the server, and receive an interface in which the data synchronization timestamp of the client interface returned by the server is inconsistent with the corresponding data update timestamp in the data synchronization control table in the server ;

所述接口数据请求模块调用上述接口更新筛选模块接收的接口并向服务端 请求同步数据,并接收服务端返回的数据更新原数据。The interface data request module calls the interface received by the above-mentioned interface update screening module and requests synchronization data from the server, and receives the data returned by the server to update the original data.

本发明的数据同步需要服务端和客户端共同完成,在服务端建立一张数据 同步控制表,然后服务端提供一个轮询接口供客户端发送请求连接,客户端轮 询时先将本地的接口的数据同步时间戳与服务端的数据同步控制表中的相应数 据更新时间戳,数据同步实际那戳与数据更新时间戳不一致时,代表该接口存 在数据更新,服务端向客户端返回不一致的接口ID,然后客户端在调用不一致 的接口向服务端请求数据更新。The data synchronization of the present invention needs to be completed by the server and the client. A data synchronization control table is established on the server, and then the server provides a polling interface for the client to send a request for connection. When the client polls, the local interface is first The data synchronization timestamp is the same as the corresponding data update timestamp in the data synchronization control table of the server. If the actual data synchronization timestamp is inconsistent with the data update timestamp, it means that there is a data update on the interface, and the server returns an inconsistent interface ID to the client. , and then the client requests data updates from the server by calling the inconsistent interface.

下面通过一个开发实例对本发明的技术方案进行说明:The technical scheme of the present invention is described below by a development example:

以其中一个零售品牌的云POS项目为例,全国大约有50万个零售户,以每 个零售户仅存在一个云POS机,每个云POS机存在20个数据下载接口,每个数 据下载接口对应类型的数据,如商品数据、库存数据、用户数据、机构参数、 类目信息、活动信息等等,且每个云POS以每天10小时的在线时间,如果按照 传统短轮询方式,每个接口都要定时向服务端请求同步数据,服务端每天要接 受6亿次的请求,由于每个接口的修改较少,这些请求中均为无效请求,参照 本发明的方法对上述方案进行优化:Taking the cloud POS project of one of the retail brands as an example, there are about 500,000 retailers in the country, and each retailer has only one cloud POS machine, each cloud POS machine has 20 data download interfaces, and each data download interface Corresponding types of data, such as commodity data, inventory data, user data, institutional parameters, category information, activity information, etc., and each cloud POS has an online time of 10 hours per day. If the traditional short polling method is used, each The interface must periodically request synchronization data from the server, and the server has to accept 600 million requests every day. Since the modification of each interface is small, these requests are all invalid requests. The above scheme is optimized with reference to the method of the present invention:

首先,在服务端增加一个数据表,该数据表中的数据列分别为用户编码、 接口ID和时间戳,该时间戳为该接口最近一次数据更新的时间点;当商户在后 台修改数据时,修改的数据所对应索引表上的接口的时间戳会进行更新;First, add a data table on the server side, the data columns in the data table are user code, interface ID and timestamp respectively, and the timestamp is the time point of the latest data update of the interface; when the merchant modifies the data in the background, The timestamp of the interface on the index table corresponding to the modified data will be updated;

当业务数据变更,要同时更新数据同步控制表中记录,如商品管理功能中 修改了商品信息,程序中要同时修改该用户对应商品下载接口的时间戳跟商品 表中时间戳一致,为降低复杂性、减少出错和防止锁表,采用消息队列(MQ) 异步修改数据同步控制表中时间戳。When the business data changes, the records in the data synchronization control table should be updated at the same time. For example, if the commodity information is modified in the commodity management function, the timestamp of the user's corresponding commodity download interface should be modified in the program to be consistent with the timestamp in the commodity table. In order to reduce complexity To improve performance, reduce errors and prevent lock tables, use message queue (MQ) to asynchronously modify timestamps in data synchronization control tables.

然后在服务端增加一个轮询接口供每个云POS进行定时进行链接请求,但 是该轮询接口并不是用于接口同步数据的,该接口的参数为该云POS机上每个 接口ID以及该接口ID的最近一次数据同步的时间戳,函数为云POS机的接口 ID最近一次同步数据的时间戳与数据表中对应接口数据的时间戳对比,返回值 为对比结果不一致的客户端的接口ID,当出现不一样时,云POS机上接口最近 一次同步数据的时间戳会早于数据表中相对应数据行中记录的时间戳,代表该 接口ID下存在数据更新,然后云POS机再调用返回的接口ID向服务端请求数 据更新,如云POS机中存在20个数据下载接口,云POS机通过轮询接口向服务 端请求连接,通过对比发现,本次轮询与上次轮询相比,只存在2个接口的时 间戳不同,代表只有这2个接口的数据发生改变,服务端向云POS机返回这两 个接口的接口ID,云POS机只需要调用这2个接口向服务端获取最近数据即可, 免去了18次的无效调用。扩展到50万零售户,每天能够节省掉大量的无效数 据请求。Then add a polling interface on the server side for each cloud POS to make link requests at regular intervals, but the polling interface is not used for interface synchronization data, the parameters of this interface are each interface ID on the cloud POS machine and the interface The timestamp of the latest data synchronization of the ID. The function is the interface ID of the cloud POS machine. The timestamp of the latest synchronized data is compared with the timestamp of the corresponding interface data in the data table. The return value is the interface ID of the client whose comparison result is inconsistent. When there is a difference, the timestamp of the latest data synchronization of the interface on the cloud POS machine will be earlier than the timestamp recorded in the corresponding data row in the data table, indicating that there is data update under the interface ID, and then the cloud POS machine will call the returned interface. ID requests data update from the server. For example, there are 20 data download interfaces in the cloud POS machine. The cloud POS machine requests connection from the server through the polling interface. There are two interfaces with different timestamps, which means that only the data of these two interfaces has changed. The server returns the interface IDs of these two interfaces to the cloud POS machine. The cloud POS machine only needs to call these two interfaces to obtain the latest data from the server. The data is enough, eliminating the need for 18 invalid calls. Scaling to 500,000 retail customers can save a lot of invalid data requests every day.

以上所述实施例仅是为充分说明本发明而所举的较佳的实施例,本发明的 保护范围不限于此。本技术领域的技术人员在本发明基础上所作的等同替代或 变换,均在本发明的保护范围之内。本发明的保护范围以权利要求书为准。The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or transformations made by those skilled in the art on the basis of the present invention are all within the protection scope of the present invention. The protection scope of the present invention is subject to the claims.

Claims (8)

1.一种数据同步方法,其特征在于:所述方法包括如下步骤:1. a data synchronization method, is characterized in that: described method comprises the steps: S1、在服务端建立数据同步控制表,所述数据同步控制表中记录有每个接口最近一次进行数据更新的数据更新时间戳,且服务端在更新数据时,数据同步控制表更新相对应的数据更新时间戳;S1, establish a data synchronization control table on the server, the data synchronization control table records the data update timestamp of the latest data update performed by each interface, and when the server updates data, the data synchronization control table updates the corresponding data update timestamp; S2、服务端提供给客户端一个轮询接口,该接口的参数为客户端的接口以及每个接口最近一次同步数据的数据同步时间戳,函数为客户端的接口的数据同步时间戳与数据同步控制表中对应的数据更新时间戳对比,当存在不一致时,向客户端返回不一致的接口,客户端调取返回的接口向服务端请求数据同步。S2. The server provides a polling interface to the client. The parameters of this interface are the interface of the client and the data synchronization timestamp of the latest synchronization data of each interface. The function is the data synchronization timestamp of the client interface and the data synchronization control table. If there is inconsistency, the inconsistent interface is returned to the client, and the client calls the returned interface to request data synchronization from the server. 2.根据权利要求1所述的数据同步方法,其特征在于:所述数据同步控制表中包含数据列为用户编码、接口ID和最近一次数据更新的数据更新时间戳,用户编码用于对应客户端,接口ID对接客户端的各个数据请求同步的接口ID,服务端接受人为数据更新时,数据同步控制表中对接接口ID的数据更新时间戳更改为进行数据更新时的时间点。2. data synchronization method according to claim 1, is characterized in that: in described data synchronization control table, comprising data as the data update time stamp of user code, interface ID and latest data update, user code is used for corresponding customer When the server accepts manual data updates, the data update timestamp of the docking interface ID in the data synchronization control table is changed to the point in time when the data is updated. 3.根据权利要求1所述的数据同步方法,其特征在于:在步骤S1中,当服务端进行数据更新时,通过建立消息队列对不同接口的数据更新时间戳以及其他与数据相关数据表进行更新。3. data synchronization method according to claim 1 is characterized in that: in step S1, when server carries out data update, by establishing message queue, the data update time stamp of different interfaces and other data-related data tables are carried out. renew. 4.根据权利要求2所述的数据同步方法,其特征在于:步骤S2中,服务端客户端本地的接口的数据同步时间戳与数据同步控制表中的数据更新时间戳进行对比,并将数据同步时间戳与数据更新时间戳不一致的接口ID返回至客户端。4. data synchronization method according to claim 2 is characterized in that: in step S2, the data synchronization time stamp of the local interface of the server client is compared with the data update time stamp in the data synchronization control table, and the data The interface ID whose synchronization timestamp is inconsistent with the data update timestamp is returned to the client. 5.根据权利要求4所述的数据同步方法,其特征在于:步骤S2中,客户端调取返回的接口向服务端请求数据同步的过程包括:5. The data synchronization method according to claim 4, characterized in that: in step S2, the process that the client fetches the returned interface and requests data synchronization from the server comprises: S201、客户端调用服务端返回的接口ID并向服务端请求同步数据;S201, the client invokes the interface ID returned by the server and requests synchronization data from the server; S202、服务端返回请求的数据至相对应接口,相应接口数据完成更新,并更新该接口的数据同步时间戳。S202, the server returns the requested data to the corresponding interface, the corresponding interface data is updated, and the data synchronization timestamp of the interface is updated. 6.一种数据同步系统,其特征在于:包括服务端和客户端,所述服务端包括数据同步控制表、对比模块和数据发送模块;6. A data synchronization system, characterized in that: comprising a server and a client, the server comprising a data synchronization control table, a comparison module and a data transmission module; 其中,所述数据同步控制表用于记录服务端所服务接口以及每个接口最近数据更新的数据更新时间戳;Wherein, the data synchronization control table is used to record the interface served by the server and the data update timestamp of the latest data update of each interface; 所述对比模块用于接受客户端的相应请求后,将客户端的接口最近同步数据的数据同步时间戳与数据同步控制表中对应的数据更新时间戳进行对比,并向客户端输出两个时间戳不一致的接口;The comparison module is used to compare the data synchronization timestamp of the latest synchronization data of the client interface with the corresponding data update timestamp in the data synchronization control table after accepting the corresponding request of the client, and output the two timestamps to the client that are inconsistent. Interface; 所述数据发送模块用于接口客户端的接口数据同步请求,并向该接口发送相应更新数据。The data sending module is used for the interface data synchronization request of the interface client, and sends corresponding update data to the interface. 7.根据权利要求6所述的数据同步系统,其特征在于:所述服务端还包括数据更新模块,当服务端进行数据更新,且同一数据的更新涉及到多个接口的数据更新时间戳更新时,数据更新模块通过建立消息队列对不同接口的时间戳进行更新。7. The data synchronization system according to claim 6, characterized in that: the server further comprises a data update module, when the server performs data update, and the update of the same data involves the data update timestamp update of multiple interfaces When , the data update module updates the time stamps of different interfaces by establishing a message queue. 8.一种数据同步系统,其特征在于:包括客户端和服务端,所述客户端包括接口更新筛选模块和接口数据请求模块,所述服务端中设置有数据同步控制表,所述数据同步控制表用于记录所服务接口最近更新数据的时间戳;8. A data synchronization system, characterized in that it comprises a client and a server, the client includes an interface update screening module and an interface data request module, the server is provided with a data synchronization control table, and the data synchronization The control table is used to record the timestamp of the latest updated data of the service interface; 其中:所述接口更新筛选模块用于向服务端发送轮询请求,并接收服务端返回的客户端接口的数据同步时间戳与服务端中数据同步控制表中对应的数据更新时间戳不一致的接口;Wherein: the interface update screening module is used to send a polling request to the server, and receive an interface in which the data synchronization timestamp of the client interface returned by the server is inconsistent with the corresponding data update timestamp in the data synchronization control table in the server ; 所述接口数据请求模块调用上述接口更新筛选模块接收的接口并向服务端请求同步数据,并接收服务端返回的数据更新原数据。The interface data request module invokes the interface received by the above-mentioned interface update screening module and requests synchronization data from the server, and receives the data returned by the server to update the original data.
CN202010689970.2A 2020-07-17 2020-07-17 A data synchronization method and system Pending CN111835855A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010689970.2A CN111835855A (en) 2020-07-17 2020-07-17 A data synchronization method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010689970.2A CN111835855A (en) 2020-07-17 2020-07-17 A data synchronization method and system

Publications (1)

Publication Number Publication Date
CN111835855A true CN111835855A (en) 2020-10-27

Family

ID=72924405

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010689970.2A Pending CN111835855A (en) 2020-07-17 2020-07-17 A data synchronization method and system

Country Status (1)

Country Link
CN (1) CN111835855A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113205413A (en) * 2021-06-07 2021-08-03 中国银行股份有限公司 Mobile banking data processing method and device
CN116132066A (en) * 2023-02-08 2023-05-16 北京思特奇信息技术股份有限公司 A data processing method, system, device and storage medium
CN116567005A (en) * 2023-06-05 2023-08-08 山东浪潮数字商业科技有限公司 Method and tool for downloading foreground and background data interaction on demand based on query mechanism

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100205243A1 (en) * 2008-09-12 2010-08-12 salesforce.com,inc. Methods and systems for polling an on demand service
CN102904887A (en) * 2012-09-26 2013-01-30 东软集团股份有限公司 Method and system for data synchronization of Web client and server
CN105915636A (en) * 2016-06-03 2016-08-31 青岛海信移动通信技术股份有限公司 Method and device for synchronizing contact information
CN106648917A (en) * 2016-09-19 2017-05-10 福建天泉教育科技有限公司 Cache data differential updating method and system
WO2017114111A1 (en) * 2015-12-31 2017-07-06 语联网(武汉)信息技术有限公司 Asynchronous data synchronization method for distributed system
CN107741994A (en) * 2017-11-09 2018-02-27 校脸科技(北京)有限公司 A kind of data-updating method and device
CN108200220A (en) * 2018-04-08 2018-06-22 武汉斗鱼网络科技有限公司 A kind of method of data synchronization, server and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100205243A1 (en) * 2008-09-12 2010-08-12 salesforce.com,inc. Methods and systems for polling an on demand service
CN102904887A (en) * 2012-09-26 2013-01-30 东软集团股份有限公司 Method and system for data synchronization of Web client and server
WO2017114111A1 (en) * 2015-12-31 2017-07-06 语联网(武汉)信息技术有限公司 Asynchronous data synchronization method for distributed system
CN105915636A (en) * 2016-06-03 2016-08-31 青岛海信移动通信技术股份有限公司 Method and device for synchronizing contact information
CN106648917A (en) * 2016-09-19 2017-05-10 福建天泉教育科技有限公司 Cache data differential updating method and system
CN107741994A (en) * 2017-11-09 2018-02-27 校脸科技(北京)有限公司 A kind of data-updating method and device
CN108200220A (en) * 2018-04-08 2018-06-22 武汉斗鱼网络科技有限公司 A kind of method of data synchronization, server and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113205413A (en) * 2021-06-07 2021-08-03 中国银行股份有限公司 Mobile banking data processing method and device
CN113205413B (en) * 2021-06-07 2024-02-27 中国银行股份有限公司 Mobile phone bank data processing method and device
CN116132066A (en) * 2023-02-08 2023-05-16 北京思特奇信息技术股份有限公司 A data processing method, system, device and storage medium
CN116567005A (en) * 2023-06-05 2023-08-08 山东浪潮数字商业科技有限公司 Method and tool for downloading foreground and background data interaction on demand based on query mechanism

Similar Documents

Publication Publication Date Title
US7856420B2 (en) Zero latency enterprise enriched publish/subscribe
US11036713B2 (en) Sending notifications in a multi-client database environment
CN111835855A (en) A data synchronization method and system
US20030220901A1 (en) Interaction manager
US20090247134A1 (en) Synchronizing communications and data between mobile devices and servers
US11061926B2 (en) Data warehouse management and synchronization systems and methods
US20090282125A1 (en) Synchronizing Events Between Mobile Devices and Servers
JP2004538542A (en) Frameworks, architectures, methods and systems for reducing delays in business operations of an enterprise
EP1332430B1 (en) Systems and methods for providing centralized management of heterogeneous distributed enterprise application integration objects
US20030004822A1 (en) Method and apparatus for integrated multi-channel retailing
CN110795443A (en) Method, device, equipment and computer readable medium for data synchronization
US7899783B1 (en) Monitoring data integrity
US20250307900A1 (en) Method and system for processing interactive message on social platform
KR20120056847A (en) Systems and methods for customer contact
US20060161550A1 (en) System and method for distributing customer relationship management information
CN101192229B (en) A method and system for synchronizing data
CN107958398A (en) A kind of method and system to issue invoice
CN102739562A (en) Method and device for sending collection information
WO2025213518A1 (en) Product process tracking method and system for physical commodity order management
CN114584576B (en) Data storage method, apparatus, device, storage medium and computer program product
CN115391364A (en) Commodity inventory data processing method and device
CN114418693A (en) Takeaway order taking control method and device
CN110458632A (en) An automatic invoicing system and method based on enterprise invoicing quota
CN120499143B (en) Main data management method, device, medium and electronic equipment
KR20250111499A (en) Development of delivery order integrated POS solution system with various delivery order platforms

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20201027