WO2021142965A1 - Data synchronization method and apparatus, and computer device and storage medium - Google Patents

Data synchronization method and apparatus, and computer device and storage medium Download PDF

Info

Publication number
WO2021142965A1
WO2021142965A1 PCT/CN2020/085566 CN2020085566W WO2021142965A1 WO 2021142965 A1 WO2021142965 A1 WO 2021142965A1 CN 2020085566 W CN2020085566 W CN 2020085566W WO 2021142965 A1 WO2021142965 A1 WO 2021142965A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
index
slave
queue
host
Prior art date
Application number
PCT/CN2020/085566
Other languages
French (fr)
Chinese (zh)
Inventor
丁晶晶
Original Assignee
深圳壹账通智能科技有限公司
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 深圳壹账通智能科技有限公司 filed Critical 深圳壹账通智能科技有限公司
Publication of WO2021142965A1 publication Critical patent/WO2021142965A1/en

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
    • H04L47/00Traffic control in data switching networks
    • H04L47/50Queue scheduling
    • H04L47/56Queue scheduling implementing delay-aware scheduling
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/50Queue scheduling
    • H04L47/62Queue scheduling characterised by scheduling criteria
    • H04L47/625Queue scheduling characterised by scheduling criteria for service slots or service orders
    • H04L47/6275Queue scheduling characterised by scheduling criteria for service slots or service orders based on priority
    • 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/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the field of data processing, and in particular to a data synchronization method, device, computer equipment, and storage medium.
  • All server data must be synchronized in real time, that is, for n test machines, the http data of 1 host will be synchronized to n- in real time.
  • One host at the same time, only one service request can be sensed on the server side, which can realize the operation and control of the measured object, and simultaneously record the intermediate data and power consumption characteristics in the operation process to develop Further analysis, and transfer to the PC side for storage, processing and analysis.
  • the data in the master-slave mode is usually synchronized through network mirroring, that is, the port of the master is mirrored to the slave.
  • the embodiments of the present application provide a data synchronization method, device, computer equipment, and storage medium to solve the problem of low data synchronization efficiency.
  • a data synchronization method includes:
  • the client cluster includes N clients, and N is a natural number greater than 1;
  • the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as the slaves;
  • the response data returned by the host is filled into the deadlock queue corresponding to the blocking queue, so that the data of the slave is consistent with all The data synchronization of the host.
  • a data synchronization device includes:
  • the cluster monitoring module is used for real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
  • the master-slave determination module is used to determine if any client in the cluster of N clients sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined As a slave
  • the queue establishment module is used to index the data corresponding to the data request sent by the master, and construct a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
  • An index check module configured to intercept the HTTP message in the data request sent by the host by means of a network proxy, and check whether the header message contained in the HTTP message exists in the index;
  • the data synchronization module is configured to, if the header message contained in the HTTP message does not exist in the index, fill the response data returned by the host into the deadlock queue corresponding to the blocking queue, so that the The data of the slave is synchronized with the data of the master.
  • a computer device includes a memory, a processor, and a computer program that is stored in the memory and can run on the processor, and the processor implements the above data synchronization method when the computer program is executed.
  • a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above data synchronization method is realized.
  • the client cluster is monitored in real time, and the client cluster includes N clients, so as to subsequently determine the master-slave role of each client in the client cluster; then, if it is detected To send a data request to any client in a cluster of N clients, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as slaves, which is convenient for the client cluster Maintenance also solves the problem of the inability to perceive the host caused by the inability to detect the host label in the client cluster; then, the data corresponding to the data request sent by the host is indexed, and the data construction length corresponding to the data request sent by the slave is N -1 blocking queue, so as to ensure that the queue with the longest waiting time can access the queue first, which is beneficial to improve the efficiency of obtaining data from the slave; next, use the network proxy to intercept the HTTP in the data request sent by the host Message, check whether the header message contained in the HTTP message exists in
  • FIG. 1 is a schematic diagram of an application environment of a data synchronization method provided by an embodiment of the present application
  • FIG. 2 is an example diagram of a data synchronization method provided by an embodiment of the present application
  • FIG. 3 is another example diagram of a data synchronization method provided by an embodiment of the present application.
  • FIG. 4 is another example diagram of a data synchronization method provided by an embodiment of the present application.
  • FIG. 5 is another example diagram of a data synchronization method provided by an embodiment of the present application.
  • Fig. 6 is a functional block diagram of a data synchronization device provided by an embodiment of the present application.
  • FIG. 7 is another functional block diagram of a data synchronization device provided by an embodiment of the present application.
  • FIG. 8 is another functional block diagram of a data synchronization device provided by an embodiment of the present application.
  • Fig. 9 is a schematic diagram of a computer device provided by an embodiment of the present application.
  • the data synchronization method provided by this application can be applied to the application environment as shown in Figure 1, where the client communicates with the server through the network, and the server monitors the client cluster in real time.
  • the client cluster includes N clients, when any client in the cluster of N clients is detected to send a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as slaves; then, the master is The data corresponding to the sent data request is indexed, and a blocking queue of length N-1 is constructed based on the data corresponding to the data request sent by the slave; then, the HTTP message in the data request sent by the host is intercepted by a network proxy.
  • the client can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices.
  • the server can be implemented with an independent server or a server cluster composed of multiple servers.
  • the method is applied to the server in FIG. 1 as an example for description, including the following steps:
  • the client cluster includes N clients, where N is a natural number greater than 1.
  • the server monitors the client cluster in real time.
  • the client cluster is composed of N clients. Taking software testing as an example, for a cluster composed of N test machines, that is, N clients, in order to prevent model differences (Differences between different clients) lead to differences in compatibility.
  • the server-side monitoring tool can monitor the status of the client cluster in real time, such as the number of connected clients, the number of message requests, etc., by monitoring the status of the client cluster, so as to subsequently determine each client cluster.
  • the master-slave role of each client can monitor the status of the client cluster in real time, such as the number of connected clients, the number of message requests, etc.
  • the server performs real-time detection on a client cluster composed of N clients, and determines 1 master and N-1 slaves according to the detection results, where N is a natural number greater than 1.
  • S30 Establish an index for the data corresponding to the data request sent by the host, and construct a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave.
  • the index is a sorted list, a data structure used for the database to efficiently obtain data.
  • the list of this data structure stores the value of the index and the physical address of the row where the data containing this value is located.
  • the index can greatly speed up the query. Therefore, you do not need to scan the entire table after using the index.
  • To locate a row of data first find the physical address corresponding to the row of data through the index table, and then access the corresponding data.
  • the master in step S20 is the client corresponding to the request for indexing that a request sent by a client does not exist, and the request from the slave machine is the client corresponding to the request for indexing for N-1 clients.
  • the blocking queue refers to a chain data structure with blocking function.
  • the read queue request is blocked, and it can be taken out when the queue is not empty; when the queue is full, the input queue is blocked and the queue needs to be waited. It can be input (inserted) when it is not full, which is used to increase the storage space of the returned data, and it can also ensure that there is only one thread operating the queue at the same time.
  • the data sending and receiving of the first host that sent the HTTP message is processed: the sent data is indexed first, and the received data is returned after the received data is returned to establish a fixed-length (equivalent to the number of slaves) blocking queue.
  • S40 Intercept the HTTP message in the data request sent by the host by means of a network proxy, and check whether the header message contained in the HTTP message is in the index.
  • the HTTP message refers to all data of the HTTP request protocol, including the data request sent by the client requesting the server and the response data returned by the server.
  • Network proxy that is, client C needs to access server S. Through proxy, client C does not directly access server S. Client C needs to access intermediate proxy server P first. After intermediate proxy server P receives client C’s request , The data request is sent to server S, and the response from server S is obtained at the same time, and then returned to client C.
  • the header message refers to the header of the HTTP message, that is, the message header, which is composed of key/value key-value pairs, one pair per line, and the key and value are separated by a colon ":".
  • the request header informs the server about
  • the request information on the client side is the information returned by the server according to the request. It can be obtained using the HttpServletRequest method.
  • the obtained header message is compared with the index established in step S30 to verify whether the header message contained in the HTTP message is It is stored in the index so that the data of the master and the data of the slave can be further processed according to the verification result.
  • intercepting the HTTP message in the request of the host to send data through a network proxy can hijack the data packet sent by the client to the server.
  • the host's sending and response are hijacked
  • the response of the remaining N-1 (slave) clients can be directly hijacked to synchronize the response of the master, so that the subsequent synchronization effect of the master and the slave can be achieved based on the requested content as an index. Therefore, the network proxy method allows the host and the slave to directly have a time delay, and can control the synchronization information of the slave.
  • the slave can selectively receive the synchronization data of the master according to the index.
  • a theoretical timeout value can also be set for the blocking queue, where the time can be 5 seconds (S).
  • the data of the client cluster is empty, so the corresponding data returned by the host is copied for N-1 copies and filled into the deadlock queue corresponding to the blocking queue .
  • the proxy method intercept the request sent from the slave machine and throw it away directly, look up the corresponding queue address from the index established by the master, and take out the data from the queue and send it to the slave machine. Send the data in the queue to the slave and find the corresponding information in the index.
  • the deadlock queue takes out an element and returns it to the slave to realize the synchronization of the data of the master and the data of the slave. Further, in this embodiment, the deadlock queue solves the problem of the time difference in request return. When the host's request arrives at the server, the queue will not be filled before the server returns, and then the deadlock from the opportunity is waiting for the host to send The return is responded, and interrupts are used in the deadlock queue mode, and the CPU hardware is used to process data, which reduces system overhead and improves system performance, thereby increasing the efficiency of data synchronization.
  • the HTTP message is added to the preset index, so that which client the host is can be determined, and the accuracy of the host can be further ensured and the data of the slave can be obtained 100%.
  • the client cluster is monitored in real time, and the client cluster includes N clients, so that the master-slave role of each client in the client cluster can be determined subsequently; then, if any of the N client clusters is detected
  • the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as slaves, which facilitates the maintenance of the client cluster and also solves the problem of the client cluster.
  • step S40 checking whether the header message contained in the HTTP message exists in the index, specifically includes the following steps:
  • URL Uniform Resource Locator
  • URL is a uniform resource locator, a concise representation of the location and access method of resources available on the Internet, and is the address of a standard resource on the Internet, such as http: //abcom/ queryData.do is the URL contained in the HTTP message.
  • the URL contained in the HTTP message can be extracted through request-URL, and the interface parameters can be extracted through the getParameters() method.
  • S42 Combine the URL and the interface parameters according to a preset combination manner to obtain a query index.
  • the preset combination mode refers to a preset information connection combination rule, and the combination mode in this embodiment is a sequential connection, that is, the "information A+information B" mode.
  • the uniqueness of the query index can be ensured by combining the URL and interface parameters according to a preset combination as the query index.
  • S43 Determine whether the header message included in the HTTP message exists in the index based on the query index.
  • the index method improves the query efficiency and speeds up the verification.
  • the index is a hashmap
  • the key is the index header
  • the URL and interface parameters contained in the HTTP message are extracted; then, the URL and interface parameters are combined according to a preset combination to obtain a query index to ensure the uniqueness of the query index; finally, based on the query index It is judged whether the header message contained in the HTTP message exists in the index, and the query efficiency is improved by the index method, and the speed of the verification is accelerated.
  • the data synchronization method further includes:
  • the network proxy server intercepts a request, for example, the address of an http request is: http://abcom/insertData.
  • the data can be retrieved. If the queue is blocked at this time, the execution will continue after waiting for the queue to be filled, and the data will be directly returned to the slave , That is, take out the value part in the index hashmap in step S43, that is, the data in this embodiment. Further, if the header message contained in the HTTP message is stored in the index, the server will discard the request from the slave to realize the interception of the data of the slave.
  • S70 Return the data to the slave, so that the data of the slave is synchronized with the data of the master.
  • the server after intercepting the data from the slave, the server directly returns the data retrieved from the index to the slave, which accurately and quickly realizes the synchronization of the data of the master and the data of the slave.
  • the data is taken out from the index to realize the interception of the data of the slave; the data is returned to the slave, so that the data of the slave and the master
  • the data synchronization can accurately and quickly realize the synchronization of the data of the master and the data of the slave.
  • the data synchronization method further includes:
  • the deadlock queue is released to cut off the data outgoing from the slave.
  • the fixed length is N-1 and the blocking queue is released immediately after being fetched, or the blocking queue is released immediately after the timeout, so as to prevent the same interface from the second time.
  • the request for data access to the first cache cuts off the outgoing of data from the slave, and further improves the efficiency of synchronization between the data of the slave and the data of the master.
  • data is released on the deadlock queue to cut off data outgoing from the slave, which further improves the efficiency of synchronization between the data of the slave and the data of the master.
  • releasing data from the deadlock queue to cut off data outgoing from the slave machine specifically includes the following steps:
  • the blocking queue takes the N-1 times of the blocking queue and release it actively.
  • the counter will increase by 1.
  • the blocking queue will be deleted from the index hashmap first, and then the blocking queue will be released. , Thereby cutting off the data from the slave machine, preventing the cache of the slave machine from being accessed, and improving the accuracy of data synchronization.
  • the preset timeout threshold can be set to 5S (set in step S40 The timeout theoretical value), the blocking queue is deleted and released, so that the data from the slave is no longer sent to the server, but directly fetched from the blocking queue cached by the slave, which ensures the accuracy and efficiency of data synchronization.
  • the blocking queue data is read N-1 times, the blocking queue is deleted, thereby intercepting the outgoing data of the slave machine, preventing the cache of the slave machine from being accessed, and improving the accuracy of data synchronization; If it is detected that the time that the blocking queue is filled is greater than the preset timeout threshold, the blocking queue is deleted so that the data from the slave is no longer sent to the server, but directly fetched from the blocking queue cached by the slave. Improve the accuracy and efficiency of data synchronization.
  • a data synchronization device is provided, and the data synchronization device corresponds to the data synchronization method in the above-mentioned embodiment one-to-one.
  • the data synchronization device includes a cluster monitoring module 10, a master-slave machine determination module 20, a queue establishment module 30, an index verification module 40 and a data synchronization module 50.
  • the detailed description of each functional module is as follows:
  • the cluster monitoring module 10 is used for real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
  • the master-slave determination module 20 is used to determine the client that sends the data request first as the master when any client in the cluster of N clients is detected to send a data request, and the remaining N-1 clients Determined as a slave;
  • the queue establishment module 30 is configured to index the data corresponding to the data request sent by the master, and construct a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
  • the index check module 40 is configured to intercept the HTTP message in the data request sent by the host by means of a network proxy, and check whether the header message contained in the HTTP message exists in the index;
  • the data synchronization module 50 is configured to fill the response data returned by the host into the deadlock queue corresponding to the blocking queue when the header message contained in the HTTP message does not exist in the index, so that all The data of the slave is synchronized with the data of the master.
  • the index verification module 40 includes a message extraction unit 41, an index acquisition unit 42 and a verification unit 43.
  • the message extraction unit 41 is configured to extract the URL and interface parameters contained in the HTTP message
  • the index obtaining unit 42 is configured to combine the URL and the interface parameters according to a preset combination manner to obtain a query index
  • the checking unit 43 is configured to judge whether the header message contained in the HTTP message exists in the set index based on the query index.
  • the data synchronization device further includes a data acquisition module 60 and a data return module 70.
  • the data acquisition module 60 is configured to retrieve data from the index if the header message included in the HTTP message is stored in the index;
  • the data return module 70 is configured to return the data to the slave, so that the data of the slave is synchronized with the data of the host.
  • the data synchronization device further includes a data release module, configured to release data from the deadlock queue to intercept data outgoing from the slave.
  • the data release module includes a queue deletion unit and a blocked queue deletion unit.
  • a queue deletion unit configured to delete the blocked queue if the blocked queue data is read N-1 times
  • the blocking queue deleting unit is configured to delete the blocking queue if it is detected that the time for which the blocking queue is filled is greater than the preset timeout threshold.
  • Each module in the above-mentioned data synchronization device can be implemented in whole or in part by software, hardware and a combination thereof.
  • the above-mentioned modules may be embedded in the form of hardware or independent of the processor in the computer equipment, or may be stored in the memory of the computer equipment in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned modules.
  • a computer device is provided.
  • the computer device may be a server, and its internal structure diagram may be as shown in FIG. 9.
  • the computer equipment includes a processor, a memory, a network interface, and a database connected through a system bus.
  • the processor of the computer device is used to provide calculation and control capabilities.
  • the memory of the computer device includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system, a computer program, and a database.
  • the internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium.
  • the database of the computer equipment is used to store the data used in the data method.
  • the network interface of the computer device is used to communicate with an external terminal through a network connection.
  • the computer program is executed by the processor to realize a data synchronization method.
  • a computer device which includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor.
  • the processor implements the data synchronization method in the foregoing embodiment when the processor executes the computer program.
  • a computer-readable storage medium is provided.
  • the storage medium is a volatile storage medium or a non-volatile storage medium, and a computer program is stored thereon.
  • the computer program is executed by a processor, the foregoing The data synchronization method in the embodiment.
  • Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory may include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Channel (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A data synchronization method and apparatus, and a computer device and a storage medium. The method comprises: monitoring a client cluster in real time, the client cluster comprising N clients, and N being a natural number greater than 1 (S10); if detecting that any client in the cluster of the N clients sends a data request, determining the client which sends a data request firstly to be a host, and determining the remaining N-1 clients to be slaves (S20); establishing an index for data corresponding to the data request sent by the host, and constructing a blocking queue having a length of N-1 on the basis of data corresponding to data requests sent by the slaves (S30); intercepting, in a network proxy manner, an HTTP packet in the data request sent by the host, and checking whether a header message contained in the HTTP packet exists in the index (S40); if the header message contained in the HTTP packet does not exist in the index, filling response data returned by the host into a deadlock queue corresponding to the blocking queue, such that the data of the slaves is synchronized with the data of the host (S50). Therefore, the data synchronization efficiency is improved.

Description

数据同步方法、装置、计算机设备及存储介质Data synchronization method, device, computer equipment and storage medium
本申请要求于2020年1月14日提交中国专利局、申请号为202010037664.0,发明名称为“数据同步方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on January 14, 2020, the application number is 202010037664.0, and the invention title is "data synchronization method, device, computer equipment and storage medium", the entire content of which is incorporated by reference In this application.
技术领域Technical field
本申请涉及数据处理领域,尤其涉及一种数据同步方法、装置、计算机设备及存储介质。This application relates to the field of data processing, and in particular to a data synchronization method, device, computer equipment, and storage medium.
背景技术Background technique
在软件测试中,需要对一个软件在不同操作系统版本、不同机型设备等进行兼容性测试,为了防止机型的差异出现兼容性差异,软件测试者需要将软件在不同机型和操作系统版本上进行遍历兼容性测试,为了减少测试时间,需要进行同步操作,需要将某台主机从服务器接收到的数据同步给从机并截断从机的外发,但是受制于不同设备在进行测试时网络会真正请求到服务器端,造成数据的紊乱以及数据依赖带来的操作不同步问题,必须对所有服务器数据进行实时同步,即对于n台测试机器,1台主机的http数据会实时同步到n-1台主机,同时在服务器端仅可感知一次服务请求,即可实现对被测对象进行运算操作控制的同时,也能同步对其运算过程中的中间数据、功耗特征等进行记录,以开展进一步的分析,并传送到PC端进行存储、处理和分析。In software testing, it is necessary to test the compatibility of a software in different operating system versions, different models of equipment, etc. In order to prevent compatibility differences due to differences in models, software testers need to install the software on different models and operating system versions. The traversal compatibility test is performed on the above. In order to reduce the test time, a synchronization operation is required. It is necessary to synchronize the data received by a host from the server to the slave and cut off the outgoing of the slave. However, it is subject to the network of different devices during the test. The real request will be sent to the server side, causing data disorder and unsynchronized operation caused by data dependence. All server data must be synchronized in real time, that is, for n test machines, the http data of 1 host will be synchronized to n- in real time. One host, at the same time, only one service request can be sensed on the server side, which can realize the operation and control of the measured object, and simultaneously record the intermediate data and power consumption characteristics in the operation process to develop Further analysis, and transfer to the PC side for storage, processing and analysis.
传统地,通常通过网络镜像的方式对主从模式的数据进行同步,即将主机的端口镜像到从机,发明人意识到这种方式由于从机无法选择性的跟主机保持同步,必须接受所有主机同步镜像灌入的数据。因此,需要一种新的数据同步技术,可以保持同一系统中各客户端之间的数据同步。Traditionally, the data in the master-slave mode is usually synchronized through network mirroring, that is, the port of the master is mirrored to the slave. The inventor realized that because the slave cannot selectively keep synchronized with the master, all masters must be accepted. Synchronize the data poured into the mirror. Therefore, there is a need for a new data synchronization technology that can maintain data synchronization between clients in the same system.
发明内容Summary of the invention
本申请实施例提供一种数据同步方法、装置、计算机设备及存储介质,以解决数据同步效率不高的问题。The embodiments of the present application provide a data synchronization method, device, computer equipment, and storage medium to solve the problem of low data synchronization efficiency.
一种数据同步方法,包括:A data synchronization method includes:
实时监控客户端集群,所述客户端集群包括N个客户端,N为大于1的自然数;Real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;If it is detected that any client in the cluster of N clients sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as the slaves;
对所述主机发出的数据请求对应的数据建立索引,并基于所述从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;Indexing the data corresponding to the data request sent by the master, and constructing a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
采用网络代理的方式截取所述主机发送的数据请求中的HTTP报文,校验所述HTTP报文中包含的头消息是否存在所述索引中;Intercepting the HTTP message in the data request sent by the host by means of a network proxy, and verifying whether the header message contained in the HTTP message exists in the index;
若所述HTTP报文中包含的头消息不存在所述索引中,则将所述主机返回的响应数据填充至所述阻塞队列对应的死锁队列中,以使所述从机的数据与所述主机的数据同步。If the header message contained in the HTTP message does not exist in the index, the response data returned by the host is filled into the deadlock queue corresponding to the blocking queue, so that the data of the slave is consistent with all The data synchronization of the host.
一种数据同步装置,包括:A data synchronization device includes:
集群监控模块,用于实时监控客户端集群,所述客户端集群包括N个客户端,N为大于1的自然数;The cluster monitoring module is used for real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
主从机确定模块,用于若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;The master-slave determination module is used to determine if any client in the cluster of N clients sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined As a slave
队列建立模块,用于对所述主机发出的数据请求对应的数据建立索引,并基于所述从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;The queue establishment module is used to index the data corresponding to the data request sent by the master, and construct a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
索引校验模块,用于采用网络代理的方式截取所述主机发送的数据请求中的HTTP报文,校验所述HTTP报文中包含的头消息是否存在所述索引中;An index check module, configured to intercept the HTTP message in the data request sent by the host by means of a network proxy, and check whether the header message contained in the HTTP message exists in the index;
数据同步模块,用于若所述HTTP报文中包含的头消息不存在所述索引中,则将所述主机返回的响应数据填充至所述阻塞队列对应的死锁队列中,以使所述从机的数据与所述主机的数据同步。The data synchronization module is configured to, if the header message contained in the HTTP message does not exist in the index, fill the response data returned by the host into the deadlock queue corresponding to the blocking queue, so that the The data of the slave is synchronized with the data of the master.
一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述数据同 步方法。A computer device includes a memory, a processor, and a computer program that is stored in the memory and can run on the processor, and the processor implements the above data synchronization method when the computer program is executed.
一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述数据同步方法。A computer-readable storage medium, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above data synchronization method is realized.
上述数据同步方法、装置、计算机设备及存储介质中,首先,实时监控客户端集群,客户端集群包括N个客户端,以便后续确定客户端集群中每个客户端的主从角色;然后,若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机,方便对客户端集群的维护,也解决了客户端集群中无法探知主机标签导致的无法感知主机的问题;接着,对主机发出的数据请求对应的数据建立索引,并基于从机发出的数据请求对应的数据构建长度为N-1的阻塞队列,以便后续能够保证等待时间最长的队列最优先能够访问队列,有利于提高从机的数据的获取效率;接下来,采用网络代理的方式截取主机发送的数据请求中的HTTP报文,校验HTTP报文中包含的头消息是否存在索引中,保证从机上送外发数据100%被截断,并且从机可根据索引选择性的接收主机的同步数据;最后,若HTTP报文中包含的头消息不存在索引中,则将主机返回的响应数据填充至阻塞队列对应的死锁队列中,以使从机的数据与主机的数据同步,减少系统开销,提高系统性能,进而提高了数据同步效率。In the above-mentioned data synchronization method, device, computer equipment and storage medium, firstly, the client cluster is monitored in real time, and the client cluster includes N clients, so as to subsequently determine the master-slave role of each client in the client cluster; then, if it is detected To send a data request to any client in a cluster of N clients, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as slaves, which is convenient for the client cluster Maintenance also solves the problem of the inability to perceive the host caused by the inability to detect the host label in the client cluster; then, the data corresponding to the data request sent by the host is indexed, and the data construction length corresponding to the data request sent by the slave is N -1 blocking queue, so as to ensure that the queue with the longest waiting time can access the queue first, which is beneficial to improve the efficiency of obtaining data from the slave; next, use the network proxy to intercept the HTTP in the data request sent by the host Message, check whether the header message contained in the HTTP message exists in the index, to ensure that 100% of the data sent from the slave machine is truncated, and the slave machine can selectively receive the synchronization data of the master according to the index; finally, if the HTTP message If the header message contained in the text does not exist in the index, the response data returned by the master is filled into the deadlock queue corresponding to the blocking queue, so that the data of the slave is synchronized with the data of the master, reducing system overhead, improving system performance, and then Improve the efficiency of data synchronization.
附图说明Description of the drawings
图1是本申请实施例提供的数据同步方法的应用环境示意图;FIG. 1 is a schematic diagram of an application environment of a data synchronization method provided by an embodiment of the present application;
图2是本申请实施例提供的数据同步方法一示例图;FIG. 2 is an example diagram of a data synchronization method provided by an embodiment of the present application;
图3是本申请实施例提供的数据同步方法的另一示例图;FIG. 3 is another example diagram of a data synchronization method provided by an embodiment of the present application;
图4是本申请实施例提供的数据同步方法的另一示例图;FIG. 4 is another example diagram of a data synchronization method provided by an embodiment of the present application;
图5是本申请实施例提供的数据同步方法的另一示例图;FIG. 5 is another example diagram of a data synchronization method provided by an embodiment of the present application;
图6是本申请实施例提供的数据同步装置的一原理框图;Fig. 6 is a functional block diagram of a data synchronization device provided by an embodiment of the present application;
图7是本申请实施例提供的数据同步装置的另一原理框图;FIG. 7 is another functional block diagram of a data synchronization device provided by an embodiment of the present application;
图8是本申请实施例提供的数据同步装置的另一原理框图;FIG. 8 is another functional block diagram of a data synchronization device provided by an embodiment of the present application;
图9是本申请实施例提供的计算机设备的一示意图。Fig. 9 is a schematic diagram of a computer device provided by an embodiment of the present application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of them. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of this application.
本申请提供的数据同步方法,可应用在如图1的应用环境中,其中,客户端通过网络与服务端进行通信,服务端实时监控客户端集群,该客户端集群包括N个客户端,当检测到N个客户端的集群中的任一客户端发送数据请求时,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;然后,对主机发出的数据请求对应的数据建立索引,并基于从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;接着,采用网络代理的方式截取主机发送的数据请求中的HTTP报文,校验HTTP报文中包含的头消息是否存在索引中;进而在HTTP报文中包含的头消息不存在索引中时,将主机返回的响应数据填充至阻塞队列对应的死锁队列中,以使从机的数据与主机的数据同步。其中,客户端可以但不限于是各种个人计算机、笔记本电脑、智能手机、平板电脑和便携式可穿戴设备。服务端可以用独立的服务器或者是多个服务器组成的服务器集群来实现。The data synchronization method provided by this application can be applied to the application environment as shown in Figure 1, where the client communicates with the server through the network, and the server monitors the client cluster in real time. The client cluster includes N clients, when When any client in the cluster of N clients is detected to send a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as slaves; then, the master is The data corresponding to the sent data request is indexed, and a blocking queue of length N-1 is constructed based on the data corresponding to the data request sent by the slave; then, the HTTP message in the data request sent by the host is intercepted by a network proxy. Check whether the header message contained in the HTTP message exists in the index; then when the header message included in the HTTP message does not exist in the index, the response data returned by the host is filled into the deadlock queue corresponding to the blocking queue, so that The data of the slave is synchronized with the data of the master. Among them, the client can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices. The server can be implemented with an independent server or a server cluster composed of multiple servers.
在一个实施例中,如图2所示,以该方法应用于图1中的服务端为例进行说明,包括如下步骤:In an embodiment, as shown in FIG. 2, the method is applied to the server in FIG. 1 as an example for description, including the following steps:
S10:实时监控客户端集群,客户端集群包括N个客户端,N为大于1的自然数。S10: Real-time monitoring of the client cluster. The client cluster includes N clients, where N is a natural number greater than 1.
具体地,服务端实时监控客户端集群,该客户端集群由N个客户端组成,以软件测试为例,对于N台测试机器组成的集群,也即N个客户端,为了防止机型的差异(不同客户端的差异)导致兼容性差异,通过服务端的监控工具实时监控客户端集群的状态,如连接客户数、消息请求次数等,通过监控客户端集群的状态,以便后续确定客户端集群中每个客户端的主从角色。Specifically, the server monitors the client cluster in real time. The client cluster is composed of N clients. Taking software testing as an example, for a cluster composed of N test machines, that is, N clients, in order to prevent model differences (Differences between different clients) lead to differences in compatibility. The server-side monitoring tool can monitor the status of the client cluster in real time, such as the number of connected clients, the number of message requests, etc., by monitoring the status of the client cluster, so as to subsequently determine each client cluster. The master-slave role of each client.
S20:若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机。S20: If it is detected that any client in the cluster of N clients sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as the slaves.
具体地,服务端对包含有N个客户端组成的客户端集群进行实时检测,根据检测结果确定出1个主机和N-1个从机,其中,N为大于1的自然数。Specifically, the server performs real-time detection on a client cluster composed of N clients, and determines 1 master and N-1 slaves according to the detection results, where N is a natural number greater than 1.
在对包含有N个客户端的客户端集群进行同步操作时,由于每个客户端本身的性能差异性,每个客户端发出到服务端的请求时存在时延,服务端将拦截到最早的一个请求,确定为第一个向服务器发出请求的客户端,也即主机,将客户端集群中的其余N-1个客户端确定为从机。可以理解地,将第一个发出请求的客户端作为主机,而不是强制划定主机,方便对客户端集群的维护,也解决了客户端集群中无法探知主机标签导致的无法感知主机的问题,进一步地,还能够防止在强制划定主机的情况下,解决从机的速度优于主机所带来的从机等待的问题,防止强制划定主机的情况下主机宕机,克服了整个集群无主机的的问题。When synchronizing a client cluster containing N clients, due to the performance differences of each client, there is a delay when each client sends a request to the server, and the server will intercept the earliest request , It is determined that it is the first client that sends a request to the server, that is, the master, and the remaining N-1 clients in the client cluster are determined as slaves. Understandably, using the first client to make the request as the host, instead of forcing the host to facilitate the maintenance of the client cluster, also solves the problem of the inability to perceive the host caused by the inability to detect the host label in the client cluster. Furthermore, it can also prevent the problem of slave waiting caused by the speed of the slave being better than the master when the master is forcibly designated, preventing the host from going down when the master is forcibly designated, and overcoming the failure of the entire cluster. The problem with the host.
S30:对主机发出的数据请求对应的数据建立索引,并基于从机发出的数据请求对应的数据构建长度为N-1的阻塞队列。S30: Establish an index for the data corresponding to the data request sent by the host, and construct a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave.
其中,索引(Index)是一个排序的列表,用于数据库高效获取数据的数据结构。在这个数据结构的列表中存储着索引的值和包含这个值的数据所在行的物理地址,在数据十分庞大的时候,索引可以大大加快查询的速度,因此,使用索引后可以不用扫描全表来定位某行的数据,而是先通过索引表找到该行数据对应的物理地址,然后访问相应的数据。可以理解地,步骤S20中的主机即为一客户端发出的请求不存在于索引的请求对应的客户端,从机为N-1个客户端发出的请求存在于索引的请求对应的客户端。Among them, the index (Index) is a sorted list, a data structure used for the database to efficiently obtain data. The list of this data structure stores the value of the index and the physical address of the row where the data containing this value is located. When the data is very large, the index can greatly speed up the query. Therefore, you do not need to scan the entire table after using the index. To locate a row of data, first find the physical address corresponding to the row of data through the index table, and then access the corresponding data. Understandably, the master in step S20 is the client corresponding to the request for indexing that a request sent by a client does not exist, and the request from the slave machine is the client corresponding to the request for indexing for N-1 clients.
其中,阻塞队列是指具有阻塞功能的链式数据结构,当队列空时读取队列请求被阻塞,需等待队列非空时才可以取出;当队列满时,输入队列时被阻塞,需要等待队列非满时才能被输入(插入),用于提高返回数据的存储空间,还能够保证同一时刻仅仅有一个线程操作队列。Among them, the blocking queue refers to a chain data structure with blocking function. When the queue is empty, the read queue request is blocked, and it can be taken out when the queue is not empty; when the queue is full, the input queue is blocked and the queue needs to be waited. It can be input (inserted) when it is not full, which is used to increase the storage space of the returned data, and it can also ensure that there is only one thread operating the queue at the same time.
具体地,将第一个发出HTTP报文的主机的数据发出和接收做处理:发出的数据先建立索引,接收数据返回后将接收的数据建立定长(等同于从机数目)阻 塞队列,可以采用SQL中的create index方法对主机发出的请求的数据建立索引,并基于从机发送数据请求中的数据,基于数组创建ArrayBlockingQueue对象,且该对象的容量为N-1,即构建了一个长度为N-1的阻塞队列,以便后续能够保证等待时间最长的队列最优先能够访问队列,有利于提高从机的数据的获取效率。Specifically, the data sending and receiving of the first host that sent the HTTP message is processed: the sent data is indexed first, and the received data is returned after the received data is returned to establish a fixed-length (equivalent to the number of slaves) blocking queue. Use the create index method in SQL to index the data requested by the host, and create an ArrayBlockingQueue object based on the array based on the data in the data request sent by the slave, and the capacity of the object is N-1, that is, a length of The blocking queue of N-1 can ensure that the queue with the longest waiting time can access the queue first, which is beneficial to improve the data acquisition efficiency of the slave.
S40:采用网络代理的方式截取主机发送的数据请求中的HTTP报文,校验HTTP报文中包含的头消息是否存在索引中。S40: Intercept the HTTP message in the data request sent by the host by means of a network proxy, and check whether the header message contained in the HTTP message is in the index.
其中,HTTP报文是指HTTP请求协议的所有数据,包含客户端请求服务器发出的数据请求以及服务器返回的应答数据。网络代理,即客户端C需要访问服务器S,通过代理的方式,则客户端C不直接访问服务器S,客户端C需要先访问中间代理服务器P,中间代理服务器P接收到客户端C的请求后,将数据请求发往服务器S,同时获得服务器S的返回响应,再返回给客户端C。其中,头消息是指HTTP报文的报文头,即消息头部,由key/value键值对组成,每行一对,key和value用冒号″:″分隔,请求头部通知服务器有关于client端的请求信息,是服务端根据请求返回的信息,可以使用HttpServletRequest的方法获取,将获取到的头消息与步骤S30中建立的索引进行比对,以校验HTTP报文中包含的头消息是否存在索引中,以便后续根据校验结果对主机的数据以及从机的数据进行进一步地处理。Among them, the HTTP message refers to all data of the HTTP request protocol, including the data request sent by the client requesting the server and the response data returned by the server. Network proxy, that is, client C needs to access server S. Through proxy, client C does not directly access server S. Client C needs to access intermediate proxy server P first. After intermediate proxy server P receives client C’s request , The data request is sent to server S, and the response from server S is obtained at the same time, and then returned to client C. Among them, the header message refers to the header of the HTTP message, that is, the message header, which is composed of key/value key-value pairs, one pair per line, and the key and value are separated by a colon ":". The request header informs the server about The request information on the client side is the information returned by the server according to the request. It can be obtained using the HttpServletRequest method. The obtained header message is compared with the index established in step S30 to verify whether the header message contained in the HTTP message is It is stored in the index so that the data of the master and the data of the slave can be further processed according to the verification result.
可以理解地,通过网络代理的方式截取主机发送数据的请求中的HTTP报文,能够劫持客户端发往服务端的数据包,同时在N个客户端的客户端集群中,主机的发送和响应被劫持后,可直接劫持其余N-1个(从机)客户端的响应同步主机的响应,以便后续依据请求内容作为索引实现主机与从机同步的效果。因此,网络代理的方式可允许主机和从机直接存在时间延时,可控制从机同步信息。进一步地,从机的请求到达代理服务之后,因为可以通过索引头查询到此索引头已存在,请求信息直接抛掉,不上送服务端,直接从阻塞队列里取返回内容返回给各个从机,保证从机上送外发数据100%被截断,并且从机可根据索引选择性的接收主机的同步数据。Understandably, intercepting the HTTP message in the request of the host to send data through a network proxy can hijack the data packet sent by the client to the server. At the same time, in a client cluster of N clients, the host's sending and response are hijacked After that, the response of the remaining N-1 (slave) clients can be directly hijacked to synchronize the response of the master, so that the subsequent synchronization effect of the master and the slave can be achieved based on the requested content as an index. Therefore, the network proxy method allows the host and the slave to directly have a time delay, and can control the synchronization information of the slave. Further, after the request from the slave reaches the proxy service, because the index header can be queried through the index header, the request information is directly thrown away, not sent to the server, and the returned content is directly taken from the blocking queue and returned to each slave. , To ensure that 100% of the data sent from the slave is truncated, and the slave can selectively receive the synchronization data of the master according to the index.
优选地,还可以对阻塞队列设置超时理论值,其中,该时间可以是5秒(S) 。Preferably, a theoretical timeout value can also be set for the blocking queue, where the time can be 5 seconds (S).
S50:若HTTP报文中包含的头消息不存在索引中,则将主机返回的响应数据填充至阻塞队列对应的死锁队列中,以使从机的数据与主机的数据同步。S50: If the header message contained in the HTTP message does not exist in the index, fill the response data returned by the host into the deadlock queue corresponding to the blocking queue, so that the data of the slave and the data of the host are synchronized.
具体地,若HTTP报文中包含的头消息不存在索引中,则客户端集群的数据为空,因此将主机的返回的相应数据复制N-1份,并填充到阻塞队列对应的死锁队列,采用代理的方式,截取从机上送外发的请求直接抛掉,从主机建立的索引里查找对应的队列地址,从队列中取出数据发给从机。将队列中的数据发送给从机,在索引中找到对应信息的情况,如果请求经过代理服务器时在索引中得到信息,即返回一个死锁队列,且死锁队列不为空,则从死锁队列取出一个元素,返回给从机从而实现了主机的数据和从机的数据的同步。进一步地,本实施例中通过死锁队列解决了请求返回的时间差问题,当主机的请求到了服务端,服务端未返回之前,队列不会被填充,则此时从机会死锁等待主机发出的返回被响应,并且采用死锁队列的模式使用了中断,用cpu硬件处理数据,减少系统开销,提高系统性能,进而提高了数据同步效率。Specifically, if the header message contained in the HTTP message does not exist in the index, the data of the client cluster is empty, so the corresponding data returned by the host is copied for N-1 copies and filled into the deadlock queue corresponding to the blocking queue , Using the proxy method, intercept the request sent from the slave machine and throw it away directly, look up the corresponding queue address from the index established by the master, and take out the data from the queue and send it to the slave machine. Send the data in the queue to the slave and find the corresponding information in the index. If the information is obtained in the index when the request passes through the proxy server, a deadlock queue is returned, and the deadlock queue is not empty, then the deadlock The queue takes out an element and returns it to the slave to realize the synchronization of the data of the master and the data of the slave. Further, in this embodiment, the deadlock queue solves the problem of the time difference in request return. When the host's request arrives at the server, the queue will not be filled before the server returns, and then the deadlock from the opportunity is waiting for the host to send The return is responded, and interrupts are used in the deadlock queue mode, and the CPU hardware is used to process data, which reduces system overhead and improves system performance, thereby increasing the efficiency of data synchronization.
需要说明的是,本实施例中,将HTTP报文加入预设的索引中,从而可以确定主机是哪一个客户端,进一步保证主机的准确性和从机数据可以100%取到。It should be noted that in this embodiment, the HTTP message is added to the preset index, so that which client the host is can be determined, and the accuracy of the host can be further ensured and the data of the slave can be obtained 100%.
本实施例中,首先,实时监控客户端集群,客户端集群包括N个客户端,以便后续确定客户端集群中每个客户端的主从角色;然后,若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机,方便对客户端集群的维护,也解决了客户端集群中无法探知主机标签导致的无法感知主机的问题;接着,对主机发出的数据请求对应的数据建立索引,并基于从机发出的数据请求对应的数据构建长度为N-1的阻塞队列,以便后续能够保证等待时间最长的队列最优先能够访问队列,有利于提高从机的数据的获取效率;接下来,采用网络代理的方式截取主机发送的数据请求中的HTTP报文,校验HTTP报文中包含的头消息是否存在索引中,保证从机上送外发数据100%被截断,并且从机可根据索引选择性的接收主机的同步数据;最后,若HTTP报文中包含的头消息不存在索引中,则将主机返回的响应数据填充至阻塞队列对应的死锁队列中,以使从机的数据与主机的 数据同步,减少系统开销,提高系统性能,进而提高了数据同步效率。In this embodiment, first, the client cluster is monitored in real time, and the client cluster includes N clients, so that the master-slave role of each client in the client cluster can be determined subsequently; then, if any of the N client clusters is detected When a client sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as slaves, which facilitates the maintenance of the client cluster and also solves the problem of the client cluster. Unable to detect the problem of the inability to perceive the host caused by the host tag; then, index the data corresponding to the data request sent by the host, and build a blocking queue of length N-1 based on the data corresponding to the data request sent by the slave, so that it can be subsequently It is ensured that the queue with the longest waiting time can access the queue first, which is beneficial to improve the efficiency of obtaining data from the slave; then, the HTTP message in the data request sent by the host is intercepted by the network proxy method, and the HTTP message is checked Whether the included header message exists in the index, to ensure that 100% of the data sent from the slave machine is truncated, and the slave machine can selectively receive the synchronization data of the host according to the index; finally, if the header message included in the HTTP message does not have an index In the middle, the response data returned by the master is filled into the deadlock queue corresponding to the blocking queue, so that the data of the slave is synchronized with the data of the master, reducing system overhead, improving system performance, and improving data synchronization efficiency.
在一实施例中,如图3所示,步骤S40中,校验HTTP报文中包含的头消息是否存在索引中,具体包括如下步骤:In one embodiment, as shown in FIG. 3, in step S40, checking whether the header message contained in the HTTP message exists in the index, specifically includes the following steps:
S41:提取HTTP报文中包含的URL和接口参数。S41: Extract the URL and interface parameters contained in the HTTP message.
其中,URL(Uniform Resource Locator)是统一资源定位符,对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址,如http://a.b.com/queryData.do即为HTTP报文中包含的URL。接口参数是指HTTP报文请求行的参数,如a_key=a_data。具体地,可以通过request-URL提取HTTP报文中包含的URL,通过getParameters()方法提取接口参数。Among them, URL (Uniform Resource Locator) is a uniform resource locator, a concise representation of the location and access method of resources available on the Internet, and is the address of a standard resource on the Internet, such as http: //abcom/ queryData.do is the URL contained in the HTTP message. The interface parameters refer to the parameters of the HTTP message request line, such as a_key=a_data. Specifically, the URL contained in the HTTP message can be extracted through request-URL, and the interface parameters can be extracted through the getParameters() method.
S42:将URL和接口参数按照预设的组合方式进行组合得到查询索引。S42: Combine the URL and the interface parameters according to a preset combination manner to obtain a query index.
其中,预设的组合方式是指预先设定的信息连接组合规则,本实施例中的组合方式为顺序连接,即“信息A+信息B”的方式。查询索引是指用于查询或者搜索的关键信息。示例性地,当网络代理服务器拦截到一个请求,例如一个http请求的地址是:http://a.b.com/queryData.do参数是a_key=a_data;b_key=b_data,则查询索引为:Among them, the preset combination mode refers to a preset information connection combination rule, and the combination mode in this embodiment is a sequential connection, that is, the "information A+information B" mode. Query index refers to key information used for query or search. Exemplarily, when the network proxy server intercepts a request, for example, the address of an http request is: http://a.b.com/queryData.do The parameter is a_key=a_data; b_key=b_data, then the query index is:
http://a.b.com/queryData.do?a_key=a_data&b_key=b_data。http: //a.b.com/queryData.do? a_key=a_data&b_key=b_data.
可以理解地,采用将URL和接口参数按照预设的组合方式进行组合作为查询索引,可以保证查询索引的唯一性。Understandably, the uniqueness of the query index can be ensured by combining the URL and interface parameters according to a preset combination as the query index.
S43:基于查询索引判断HTTP报文中包含的头消息是否存在索引中。S43: Determine whether the header message included in the HTTP message exists in the index based on the query index.
具体地,以步骤S42中的查询索引为例,即以http://a.b.com/queryData.do?a_key=a_data&b_key=b_data作为查询索引,判断此HTTP报文中包含的头消息是否存在索引中,通过索引的方式提高了查询效率,加快了校验的速度。Specifically, take the query index in step S42 as an example, that is, http://a.b.com/queryData.do? a_key=a_data&b_key=b_data is used as the query index to determine whether the header message contained in the HTTP message exists in the index. The index method improves the query efficiency and speeds up the verification.
需要说明的是,由于索引是一个hashmap,key为索引头,数据value为死锁队列。若索引中不存在该查询索引,则将该查询索引http://a.b.com/queryData.do?a_key=a_data&b_key=b_data加入hashmap,则索引头对应的value为一个新建的空的死锁队列,以保证索引的准确完整性。It should be noted that since the index is a hashmap, the key is the index header, and the data value is the deadlock queue. If the query index does not exist in the index, then the query index http://a.b.com/queryData.do? a_key=a_data&b_key=b_data is added to the hashmap, and the value corresponding to the index header is a newly created empty deadlock queue to ensure the accuracy and integrity of the index.
本实施例中,首先,提取HTTP报文中包含的URL和接口参数;然后,将URL和接口参数按照预设的组合方式进行组合得到查询索引,保证查询索引的唯一 性;最后,基于查询索引判断HTTP报文中包含的头消息是否存在索引中,通过索引的方式提高了查询效率,加快了校验的速度。In this embodiment, first, the URL and interface parameters contained in the HTTP message are extracted; then, the URL and interface parameters are combined according to a preset combination to obtain a query index to ensure the uniqueness of the query index; finally, based on the query index It is judged whether the header message contained in the HTTP message exists in the index, and the query efficiency is improved by the index method, and the speed of the verification is accelerated.
在一实施例中,如图4所示,在步骤S40之后,即在校验HTTP报文中包含的头消息是否存在索引中之后,该数据同步方法还包括:In an embodiment, as shown in FIG. 4, after step S40, that is, after checking whether the header message contained in the HTTP message exists in the index, the data synchronization method further includes:
S60:若HTTP报文中包含的头消息存在索引中,则从索引中取出数据。S60: If the header message included in the HTTP message is stored in the index, then the data is retrieved from the index.
具体地,网络代理服务器拦截到一个请求,例如一个http请求的地址是:http://a.b.com/insertData.do参数是c_key=c_data;d_key=d_data,则HTTP报文中包含的头消息为http://a.b.com/insertData.do?c_key=c_data&d_key=d_data,查询此请求是否在索引中,当头消息存在索引中时,则索引头存在,即确定发送该该请求对应客户端是从机,由于索引已命中,则利用索引头从索引中取出返回数据,则利用索引头从索引中取出返回数据,如果此时队列不阻塞,则可以取出数据,如果此时队列阻塞,则等待队列被填充后继续执行,将数据直接返回给从机,即取出步骤S43中的索引hashmap中的value部分,即本实施例中的数据。进一步地,若HTTP报文中包含的头消息存在索引中,则服务端会将该从机的请求抛掉,实现对从机的数据的拦截。Specifically, the network proxy server intercepts a request, for example, the address of an http request is: http://abcom/insertData. The parameter of do is c_key=c_data; d_key=d_data, then the header message contained in the HTTP message is http : //Abcom/insertData.do? c_key=c_data&d_key=d_data, query whether the request is in the index, when the header message exists in the index, the index header exists, that is, it is determined that the client corresponding to the request is a slave. Since the index has been hit, the index header is used from the index If the returned data is retrieved from the index, the index header is used to retrieve the returned data from the index. If the queue is not blocked at this time, the data can be retrieved. If the queue is blocked at this time, the execution will continue after waiting for the queue to be filled, and the data will be directly returned to the slave , That is, take out the value part in the index hashmap in step S43, that is, the data in this embodiment. Further, if the header message contained in the HTTP message is stored in the index, the server will discard the request from the slave to realize the interception of the data of the slave.
S70:将数据返回给从机,以使从机的数据与主机的数据同步。S70: Return the data to the slave, so that the data of the slave is synchronized with the data of the master.
具体地,服务端将从机的数据拦截后,将索引中取出的数据直接返回给从机,准确且快速地实现了对主机的数据和从机的数据的同步。Specifically, after intercepting the data from the slave, the server directly returns the data retrieved from the index to the slave, which accurately and quickly realizes the synchronization of the data of the master and the data of the slave.
本实施例中,若HTTP报文中包含的头消息存在索引中,则从索引中取出数据,实现了对从机的数据的拦截;将数据返回给从机,以使从机的数据与主机的数据同步,准确且快速地实现了对主机的数据和从机的数据的同步。In this embodiment, if the header message contained in the HTTP message exists in the index, the data is taken out from the index to realize the interception of the data of the slave; the data is returned to the slave, so that the data of the slave and the master The data synchronization can accurately and quickly realize the synchronization of the data of the master and the data of the slave.
在一实施例中,在步骤S50之后,即在以使从机的数据与主机的数据同步之后,数据同步方法还包括:In an embodiment, after step S50, that is, after synchronizing the data of the slave with the data of the master, the data synchronization method further includes:
对死锁队列进行数据释放以截断从机的数据外发。Release data from the deadlock queue to cut off the data outgoing from the slave.
具体地,对死锁队列进行数据释放以截断从机的数据外发,定长为N-1阻塞队列被取完后立即释放,或者阻塞队列超时后立即释放,从而能够防止相同接口第二次请求数据访问第一次缓存,截断了从机的数据的外发,进一步提高了从机的数据与主机的数据的实现同步的效率。Specifically, the deadlock queue is released to cut off the data outgoing from the slave. The fixed length is N-1 and the blocking queue is released immediately after being fetched, or the blocking queue is released immediately after the timeout, so as to prevent the same interface from the second time The request for data access to the first cache cuts off the outgoing of data from the slave, and further improves the efficiency of synchronization between the data of the slave and the data of the master.
本实施例中,对死锁队列进行数据释放以截断从机的数据外发,进一步提高了从机的数据与主机的数据的实现同步的效率。In this embodiment, data is released on the deadlock queue to cut off data outgoing from the slave, which further improves the efficiency of synchronization between the data of the slave and the data of the master.
在一实施例中,如图5所示,对死锁队列进行数据释放以截断从机的数据外发,具体包括如下步骤:In one embodiment, as shown in FIG. 5, releasing data from the deadlock queue to cut off data outgoing from the slave machine specifically includes the following steps:
S81:若阻塞队列数据被读取N-1次,则对阻塞队列进行删除。S81: If the blocking queue data is read N-1 times, delete the blocking queue.
具体地,取阻塞队列的N-1次后主动释放,在队列取的时候计数器会加1,当取到第N-1次之后,阻塞队列会先从索引hashmap中删除,之后阻塞队列将释放,从而截断了从机的数据的外发,防止从机的缓存被访问,提高数据同步的准确性。Specifically, take the N-1 times of the blocking queue and release it actively. When the queue is fetched, the counter will increase by 1. When the N-1th time is fetched, the blocking queue will be deleted from the index hashmap first, and then the blocking queue will be released. , Thereby cutting off the data from the slave machine, preventing the cache of the slave machine from being accessed, and improving the accuracy of data synchronization.
S82:若监测到阻塞队列被填充的时间大于预设的超时阈值,则对阻塞队列进行删除。S82: If it is detected that the time that the blocking queue is filled is greater than the preset timeout threshold, delete the blocking queue.
具体地,在全局存在一个线程,从线程循环监控阻塞队列的存在时长,如果监控到某阻塞队列被填充后超过预设的超时阈值,该预设的超时阈值可设置为5S(步骤S40中设置的超时理论值),则删除阻塞队列并释放,使得从机的数据不再发往服务端,而是直接从从机缓存的阻塞队列里取到,保证了数据同步的准确性的效率。Specifically, there is a thread globally, and the existence time of the blocking queue is monitored from the thread loop. If it is monitored that a certain blocking queue is filled and exceeds a preset timeout threshold, the preset timeout threshold can be set to 5S (set in step S40 The timeout theoretical value), the blocking queue is deleted and released, so that the data from the slave is no longer sent to the server, but directly fetched from the blocking queue cached by the slave, which ensures the accuracy and efficiency of data synchronization.
本实施例中,若阻塞队列数据被读取N-1次,则对阻塞队列进行删除,从而截断了从机的数据的外发,防止从机的缓存被访问,提高数据同步的准确性;若监测到阻塞队列被填充的时间大于预设的超时阈值,则对阻塞队列进行删除,使得从机的数据不再发往服务端,而是直接从从机缓存的阻塞队列里取到,保证了数据同步的准确性的效率。In this embodiment, if the blocking queue data is read N-1 times, the blocking queue is deleted, thereby intercepting the outgoing data of the slave machine, preventing the cache of the slave machine from being accessed, and improving the accuracy of data synchronization; If it is detected that the time that the blocking queue is filled is greater than the preset timeout threshold, the blocking queue is deleted so that the data from the slave is no longer sent to the server, but directly fetched from the blocking queue cached by the slave. Improve the accuracy and efficiency of data synchronization.
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that the size of the sequence number of each step in the foregoing embodiment does not mean the order of execution. The execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
在一实施例中,提供一种数据同步装置,该数据同步装置与上述实施例中数据同步方法一一对应。如图6所示,该数据同步装置包括集群监控模块10、主从机确定模块20、队列建立模块30、索引校验模块40和数据同步模块50。各功能模块详细说明如下:In one embodiment, a data synchronization device is provided, and the data synchronization device corresponds to the data synchronization method in the above-mentioned embodiment one-to-one. As shown in FIG. 6, the data synchronization device includes a cluster monitoring module 10, a master-slave machine determination module 20, a queue establishment module 30, an index verification module 40 and a data synchronization module 50. The detailed description of each functional module is as follows:
集群监控模块10,用于实时监控客户端集群,所述客户端集群包括N个客户端,N为大于1的自然数;The cluster monitoring module 10 is used for real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
主从机确定模块20,用于在检测到N个客户端的集群中的任一客户端发送数据请求时,将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;The master-slave determination module 20 is used to determine the client that sends the data request first as the master when any client in the cluster of N clients is detected to send a data request, and the remaining N-1 clients Determined as a slave;
队列建立模块30,用于对所述主机发出的数据请求对应的数据建立索引,并基于所述从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;The queue establishment module 30 is configured to index the data corresponding to the data request sent by the master, and construct a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
索引校验模块40,用于采用网络代理的方式截取所述主机发送的数据请求中的HTTP报文,校验所述HTTP报文中包含的头消息是否存在所述索引中;The index check module 40 is configured to intercept the HTTP message in the data request sent by the host by means of a network proxy, and check whether the header message contained in the HTTP message exists in the index;
数据同步模块50,用于在所述HTTP报文中包含的头消息不存在所述索引中时,将所述主机返回的响应数据填充至所述阻塞队列对应的死锁队列中,以使所述从机的数据与所述主机的数据同步。The data synchronization module 50 is configured to fill the response data returned by the host into the deadlock queue corresponding to the blocking queue when the header message contained in the HTTP message does not exist in the index, so that all The data of the slave is synchronized with the data of the master.
优选地,如图7所示,索引校验模块40包括报文提取单元41、索引获取单元42和检验单元43。Preferably, as shown in FIG. 7, the index verification module 40 includes a message extraction unit 41, an index acquisition unit 42 and a verification unit 43.
报文提取单元41,用于提取所述HTTP报文中包含的URL和接口参数;The message extraction unit 41 is configured to extract the URL and interface parameters contained in the HTTP message;
索引获取单元42,用于将所述URL和所述接口参数按照预设的组合方式进行组合得到查询索引;The index obtaining unit 42 is configured to combine the URL and the interface parameters according to a preset combination manner to obtain a query index;
检验单元43,用于基于所述查询索引判断所述HTTP报文中包含的头消息是否存在所述设索引中。The checking unit 43 is configured to judge whether the header message contained in the HTTP message exists in the set index based on the query index.
优选地,如图8所示,数据同步装置还包括数据获取模块60和数据返回模块70。Preferably, as shown in FIG. 8, the data synchronization device further includes a data acquisition module 60 and a data return module 70.
数据获取模块60,用于若所述HTTP报文中包含的头消息存在所述索引中,则从所述索引中取出数据;The data acquisition module 60 is configured to retrieve data from the index if the header message included in the HTTP message is stored in the index;
数据返回模块70,用于将所述数据返回给所述从机,以使所述从机的数据与所述主机的数据同步。The data return module 70 is configured to return the data to the slave, so that the data of the slave is synchronized with the data of the host.
优选地,数据同步装置还包括数据释放模块,用于对所述死锁队列进行数据释放以截断所述从机的数据外发。Preferably, the data synchronization device further includes a data release module, configured to release data from the deadlock queue to intercept data outgoing from the slave.
优选地,数据释放模块包括队列删除单元和阻塞队列删除单元。Preferably, the data release module includes a queue deletion unit and a blocked queue deletion unit.
队列删除单元,用于若所述阻塞队列数据被读取N-1次,则对所述阻塞队列进行删除;A queue deletion unit, configured to delete the blocked queue if the blocked queue data is read N-1 times;
阻塞队列删除单元,用于若监测到所述阻塞队列被填充的时间大于预设的超时阈值,则对所述阻塞队列进行删除。The blocking queue deleting unit is configured to delete the blocking queue if it is detected that the time for which the blocking queue is filled is greater than the preset timeout threshold.
关于数据同步装置的具体限定可以参见上文中对于数据同步方法的限定,在此不再赘述。上述数据同步装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。For the specific limitation of the data synchronization device, please refer to the above limitation of the data synchronization method, which will not be repeated here. Each module in the above-mentioned data synchronization device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules may be embedded in the form of hardware or independent of the processor in the computer equipment, or may be stored in the memory of the computer equipment in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned modules.
在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图9所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于存储数据方法中所使用的数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种数据同步方法。In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. 9. The computer equipment includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer device is used to provide calculation and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer equipment is used to store the data used in the data method. The network interface of the computer device is used to communicate with an external terminal through a network connection. The computer program is executed by the processor to realize a data synchronization method.
在一个实施例中,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,处理器执行计算机程序时实现上述实施例中的数据同步方法。In one embodiment, a computer device is provided, which includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor. The processor implements the data synchronization method in the foregoing embodiment when the processor executes the computer program.
在一个实施例中,提供了一种计算机可读存储介质,所述存储介质为易失性存储介质或非易失性存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现上述实施例中的数据同步方法。In one embodiment, a computer-readable storage medium is provided. The storage medium is a volatile storage medium or a non-volatile storage medium, and a computer program is stored thereon. When the computer program is executed by a processor, the foregoing The data synchronization method in the embodiment.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非 易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage. In the medium, when the computer program is executed, it may include the processes of the above-mentioned method embodiments. Wherein, any reference to memory, storage, database, or other media used in the embodiments provided in this application may include non-volatile and/or volatile memory. Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not a limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Channel (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。Those skilled in the art can clearly understand that, for the convenience and conciseness of description, only the division of the above functional units and modules is used as an example. In practical applications, the above functions can be allocated to different functional units and modules as needed. Module completion, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, a person of ordinary skill in the art should understand that it can still implement the foregoing The technical solutions recorded in the examples are modified, or some of the technical features are equivalently replaced; these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the application, and should be included in Within the scope of protection of this application.
发明概述Summary of the invention
技术问题technical problem
问题的解决方案The solution to the problem
发明的有益效果The beneficial effects of the invention

Claims (20)

  1. 一种数据同步方法,所述数据同步方法包括:A data synchronization method, the data synchronization method includes:
    实时监控客户端集群,所述客户端集群包括N个客户端,N为大于1的自然数;Real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
    若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;If it is detected that any client in the cluster of N clients sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as the slaves;
    对所述主机发出的数据请求对应的数据建立索引,并基于所述从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;Indexing the data corresponding to the data request sent by the master, and constructing a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
    采用网络代理的方式截取所述主机发送的数据请求中的HTTP报文,校验所述HTTP报文中包含的头消息是否存在所述索引中;Intercepting the HTTP message in the data request sent by the host by means of a network proxy, and verifying whether the header message contained in the HTTP message exists in the index;
    若所述HTTP报文中包含的头消息不存在所述索引中,则将所述主机返回的响应数据填充至所述阻塞队列对应的死锁队列中,以使所述从机的数据与所述主机的数据同步。If the header message contained in the HTTP message does not exist in the index, the response data returned by the host is filled into the deadlock queue corresponding to the blocking queue, so that the data of the slave is consistent with all The data synchronization of the host.
  2. 如权利要求1所述的数据同步方法,所述校验所述HTTP报文中包含的头消息是否存在所述索引中,包括:The data synchronization method according to claim 1, wherein the checking whether the header message contained in the HTTP message exists in the index comprises:
    提取所述HTTP报文中包含的URL和接口参数;Extracting the URL and interface parameters contained in the HTTP message;
    将所述URL和所述接口参数按照预设的组合方式进行组合得到查询索引;Combine the URL and the interface parameters according to a preset combination manner to obtain a query index;
    基于所述查询索引判断所述HTTP报文中包含的头消息是否存在所述索引中。Determine whether the header message included in the HTTP message exists in the index based on the query index.
  3. 如权利要求1所述的数据同步方法,在所述校验所述HTTP报文中包含的头消息是否存在所述索引中之后,所述数据同步方法还包括:5. The data synchronization method according to claim 1, after the checking whether the header message contained in the HTTP message exists in the index, the data synchronization method further comprises:
    若所述HTTP报文中包含的头消息存在所述索引中,则从所述索引中取出数据;If the header message included in the HTTP message is stored in the index, then data is retrieved from the index;
    将所述数据返回给所述从机,以使所述从机的数据与所述主机的数据同步。The data is returned to the slave, so that the data of the slave is synchronized with the data of the host.
  4. 如权利要求1所述的数据同步方法,在所述以使所述从机的数据与所述主机的数据同步之后,所述数据同步方法还包括:8. The data synchronization method according to claim 1, after said synchronizing the data of the slave machine with the data of the master, the data synchronization method further comprises:
    对所述死锁队列进行数据释放以截断所述从机的数据外发。Release data from the deadlock queue to cut off data outgoing from the slave.
  5. 如权利要求4所述的数据同步方法,所述对所述死锁队列进行数据释放以截断所述从机的数据外发,包括:8. The data synchronization method according to claim 4, said releasing data from the deadlock queue to cut off data outgoing from the slave machine, comprising:
    若所述阻塞队列数据被读取N-1次,则对所述阻塞队列进行删除;If the blocking queue data is read N-1 times, delete the blocking queue;
    若监测到所述阻塞队列被填充的时间大于预设的超时阈值,则对所述阻塞队列进行删除。If it is detected that the time that the blocking queue is filled is greater than the preset timeout threshold, the blocking queue is deleted.
  6. 一种数据同步装置,所述数据同步装置包括:A data synchronization device, the data synchronization device includes:
    集群监控模块,用于实时监控客户端集群,所述客户端集群包括N个客户端,N为大于1的自然数;The cluster monitoring module is used for real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
    主从机确定模块,用于在检测到N个客户端的集群中的任一客户端发送数据请求时,将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;The master-slave determination module is used to determine the client that sends the data request first as the master when any client in the cluster of N clients is detected to send a data request, and the remaining N-1 clients are determined As a slave
    队列建立模块,用于对所述主机发出的数据请求对应的数据建立索引,并基于所述从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;The queue establishment module is used to index the data corresponding to the data request sent by the master, and construct a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
    索引校验模块,用于采用网络代理的方式截取所述主机发送的数据请求中的HTTP报文,校验所述HTTP报文中包含的头消息是否存在所述索引中;An index check module, configured to intercept the HTTP message in the data request sent by the host by means of a network proxy, and check whether the header message contained in the HTTP message exists in the index;
    数据同步模块,用于在所述HTTP报文中包含的头消息不存在所述索引中时,将所述主机返回的响应数据填充至所述阻塞队列对应的死锁队列中,以使所述从机的数据与所述主机的数据同步。The data synchronization module is used to fill the response data returned by the host into the deadlock queue corresponding to the blocking queue when the header message contained in the HTTP message does not exist in the index, so that the The data of the slave is synchronized with the data of the master.
  7. 如权利要求6所述的数据同步装置,所述索引校验模块包括:7. The data synchronization device according to claim 6, wherein the index check module comprises:
    报文提取单元,用于提取所述HTTP报文中包含的URL和接口参数;The message extraction unit is used to extract the URL and interface parameters contained in the HTTP message;
    索引获取单元,用于将所述URL和所述接口参数按照预设的组合方式进行组合得到查询索引;An index obtaining unit, configured to combine the URL and the interface parameters according to a preset combination manner to obtain a query index;
    检验单元,用于基于所述查询索引判断所述HTTP报文中包含的头消息是否存在所述设索引中。The checking unit is configured to judge whether the header message contained in the HTTP message exists in the set index based on the query index.
  8. 如权利要求6所述的数据同步装置,所述数据同步装置还包括:7. The data synchronization device according to claim 6, the data synchronization device further comprising:
    数据获取模块,用于在所述HTTP报文中包含的头消息存在所述索引中时,从所述索引中取出数据;A data acquisition module, configured to retrieve data from the index when the header message contained in the HTTP message is stored in the index;
    数据返回模块,用于将所述数据返回给所述从机,以使所述从机的数据与所述主机的数据同步。The data return module is used to return the data to the slave, so that the data of the slave is synchronized with the data of the host.
  9. 如权利要求6所述的数据同步装置,所述数据同步装置还包括:7. The data synchronization device according to claim 6, the data synchronization device further comprising:
    数据释放模块,用于对所述死锁队列进行数据释放以截断所述从机的数据外发。The data release module is used to release data from the deadlock queue to cut off the data outgoing from the slave.
  10. 如权利要求9所述的数据同步装置,所述数据释放模块包括:9. The data synchronization device according to claim 9, wherein the data release module comprises:
    队列删除单元,用于当所述阻塞队列数据被读取N-1次时,对所述阻塞队列进行删除;A queue deleting unit, configured to delete the blocking queue when the blocking queue data is read N-1 times;
    阻塞队列删除单元,用于在监测到所述阻塞队列被填充的时间大于预设的超时阈值时,对所述阻塞队列进行删除。The blocking queue deleting unit is configured to delete the blocking queue when it is monitored that the time for which the blocking queue is filled is greater than a preset timeout threshold.
  11. 一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现一种数据同步方法:A computer device includes a memory, a processor, and a computer program that is stored in the memory and can run on the processor, and when the processor executes the computer program, a data synchronization method is implemented:
    其中,所述数据同步方法包括:Wherein, the data synchronization method includes:
    实时监控客户端集群,所述客户端集群包括N个客户端,N为大于1的自然数;Real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
    若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;If it is detected that any client in the cluster of N clients sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as the slaves;
    对所述主机发出的数据请求对应的数据建立索引,并基于所述从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;Indexing the data corresponding to the data request sent by the master, and constructing a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
    采用网络代理的方式截取所述主机发送的数据请求中的HTTP报文,校验所述HTTP报文中包含的头消息是否存在所述索引中;Intercepting the HTTP message in the data request sent by the host by means of a network proxy, and verifying whether the header message contained in the HTTP message exists in the index;
    若所述HTTP报文中包含的头消息不存在所述索引中,则将所述主机返回的响应数据填充至所述阻塞队列对应的死锁队列中,以使所述从机的数据与所述主机的数据同步。If the header message contained in the HTTP message does not exist in the index, the response data returned by the host is filled into the deadlock queue corresponding to the blocking queue, so that the data of the slave is consistent with all The data synchronization of the host.
  12. 如权利要求11所述的一种计算机设备,所述校验所述HTTP报文中包含的头消息是否存在所述索引中的步骤包括:11. The computer device according to claim 11, wherein the step of verifying whether the header message contained in the HTTP message exists in the index comprises:
    提取所述HTTP报文中包含的URL和接口参数;Extracting the URL and interface parameters contained in the HTTP message;
    将所述URL和所述接口参数按照预设的组合方式进行组合得到查询索引;Combine the URL and the interface parameters according to a preset combination manner to obtain a query index;
    基于所述查询索引判断所述HTTP报文中包含的头消息是否存在所述索引中。Determine whether the header message included in the HTTP message exists in the index based on the query index.
  13. 如权利要求11所述的一种计算机设备,在所述校验所述HTTP报文中包含的头消息是否存在所述索引中的步骤之后,还包括:11. The computer device according to claim 11, after the step of verifying whether the header message contained in the HTTP message exists in the index, further comprising:
    若所述HTTP报文中包含的头消息存在所述索引中,则从所述索引中取出数据;If the header message included in the HTTP message is stored in the index, then data is retrieved from the index;
    将所述数据返回给所述从机,以使所述从机的数据与所述主机的数据同步。The data is returned to the slave, so that the data of the slave is synchronized with the data of the host.
  14. 如权利要求11所述的一种计算机设备,在所述以使所述从机的数据与所述主机的数据同步的步骤之后,还包括:11. The computer device according to claim 11, after the step of synchronizing the data of the slave with the data of the master, further comprising:
    对所述死锁队列进行数据释放以截断所述从机的数据外发。Release data from the deadlock queue to cut off data outgoing from the slave.
  15. 如权利要求14所述的一种计算机设备,所述对所述死锁队列进行数据释放以截断所述从机的数据外发的步骤包括:The computer device according to claim 14, wherein the step of releasing data from the deadlock queue to intercept data outgoing from the slave machine comprises:
    若所述阻塞队列数据被读取N-1次,则对所述阻塞队列进行删除;If the blocking queue data is read N-1 times, delete the blocking queue;
    若监测到所述阻塞队列被填充的时间大于预设的超时阈值,则对所述阻塞队列进行删除。If it is detected that the time that the blocking queue is filled is greater than the preset timeout threshold, the blocking queue is deleted.
  16. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现数据同步方法:A computer-readable storage medium, the computer-readable storage medium stores a computer program, and a method for data synchronization when the computer program is executed by a processor:
    其中,所述数据同步方法包括以下步骤:Wherein, the data synchronization method includes the following steps:
    实时监控客户端集群,所述客户端集群包括N个客户端,N为大于 1的自然数;Real-time monitoring of a client cluster, the client cluster includes N clients, and N is a natural number greater than 1;
    若检测到N个客户端的集群中的任一客户端发送数据请求,则将最先发送数据请求的客户端确定为主机,将其余的N-1个客户端确定为从机;If it is detected that any client in the cluster of N clients sends a data request, the client that sends the data request first is determined as the master, and the remaining N-1 clients are determined as the slaves;
    对所述主机发出的数据请求对应的数据建立索引,并基于所述从机发出的数据请求对应的数据构建长度为N-1的阻塞队列;Indexing the data corresponding to the data request sent by the master, and constructing a blocking queue with a length of N-1 based on the data corresponding to the data request sent by the slave;
    采用网络代理的方式截取所述主机发送的数据请求中的HTTP报文,校验所述HTTP报文中包含的头消息是否存在所述索引中;Intercepting the HTTP message in the data request sent by the host by means of a network proxy, and verifying whether the header message contained in the HTTP message exists in the index;
    若所述HTTP报文中包含的头消息不存在所述索引中,则将所述主机返回的响应数据填充至所述阻塞队列对应的死锁队列中,以使所述从机的数据与所述主机的数据同步。If the header message contained in the HTTP message does not exist in the index, the response data returned by the host is filled into the deadlock queue corresponding to the blocking queue, so that the data of the slave is consistent with all The data synchronization of the host.
  17. 如权利要求16所述的计算机可读存储介质,所述校验所述HTTP报文中包含的头消息是否存在所述索引中的步骤包括:16. The computer-readable storage medium according to claim 16, wherein the step of verifying whether the header message contained in the HTTP message exists in the index comprises:
    提取所述HTTP报文中包含的URL和接口参数;Extracting the URL and interface parameters contained in the HTTP message;
    将所述URL和所述接口参数按照预设的组合方式进行组合得到查询索引;Combine the URL and the interface parameters according to a preset combination manner to obtain a query index;
    基于所述查询索引判断所述HTTP报文中包含的头消息是否存在所述索引中。Determine whether the header message included in the HTTP message exists in the index based on the query index.
  18. 如权利要求16所述的计算机可读存储介质,在所述校验所述HTTP报文中包含的头消息是否存在所述索引中的步骤之后,还包括:16. The computer-readable storage medium according to claim 16, after the step of verifying whether the header message contained in the HTTP message exists in the index, further comprising:
    若所述HTTP报文中包含的头消息存在所述索引中,则从所述索引中取出数据;If the header message included in the HTTP message is stored in the index, then data is retrieved from the index;
    将所述数据返回给所述从机,以使所述从机的数据与所述主机的数据同步。The data is returned to the slave, so that the data of the slave is synchronized with the data of the host.
  19. 如权利要求16所述的计算机可读存储介质,在所述以使所述从机的数据与所述主机的数据同步的步骤之后,还包括:15. The computer-readable storage medium according to claim 16, after the step of synchronizing the data of the slave with the data of the master, further comprising:
    对所述死锁队列进行数据释放以截断所述从机的数据外发。Release data from the deadlock queue to cut off data outgoing from the slave.
  20. 如权利要求19所述的计算机可读存储介质,所述对所述死锁队列 进行数据释放以截断所述从机的数据外发的步骤包括:The computer-readable storage medium according to claim 19, wherein the step of releasing data from the deadlock queue to intercept data outgoing from the slave machine comprises:
    若所述阻塞队列数据被读取N-1次,则对所述阻塞队列进行删除;若监测到所述阻塞队列被填充的时间大于预设的超时阈值,则对所述阻塞队列进行删除。If the blocking queue data is read N-1 times, the blocking queue is deleted; if it is detected that the time for the blocking queue to be filled is greater than the preset timeout threshold, the blocking queue is deleted.
PCT/CN2020/085566 2020-01-14 2020-04-20 Data synchronization method and apparatus, and computer device and storage medium WO2021142965A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010037664.0 2020-01-14
CN202010037664.0A CN111262923B (en) 2020-01-14 2020-01-14 Data synchronization method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2021142965A1 true WO2021142965A1 (en) 2021-07-22

Family

ID=70950490

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/085566 WO2021142965A1 (en) 2020-01-14 2020-04-20 Data synchronization method and apparatus, and computer device and storage medium

Country Status (2)

Country Link
CN (1) CN111262923B (en)
WO (1) WO2021142965A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113946534A (en) * 2021-10-18 2022-01-18 广东工业大学 USB data interception processing system and method based on wireless transmission
CN117009309A (en) * 2023-05-31 2023-11-07 合芯科技(苏州)有限公司 File real-time synchronization method and device based on rsync
CN117076371A (en) * 2023-08-28 2023-11-17 广州市粤港澳大湾区前沿创新技术研究院 Multi-machine data transmission method and device, storage medium and electronic equipment

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434600B (en) * 2021-06-30 2023-06-09 青岛海尔科技有限公司 Data synchronization method and device
CN114979174B (en) * 2022-04-15 2023-07-21 四川虹美智能科技有限公司 Method for processing HTTP blocking waiting step-by-step service data
CN117640748B (en) * 2024-01-24 2024-04-05 金数信息科技(苏州)有限公司 Cross-platform equipment information acquisition system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150293712A1 (en) * 2012-12-28 2015-10-15 Tencent Technology (Shenzhen) Co., Ltd. Data synchronization method, apparatus and system
CN105528294A (en) * 2015-12-29 2016-04-27 广东金赋信息科技有限公司 Method and system for automatically generating interface testing case
CN106131138A (en) * 2016-06-27 2016-11-16 浪潮软件股份有限公司 A kind of display data real time propelling movement system and method based on non-obstruction queue
CN109309631A (en) * 2018-08-15 2019-02-05 新华三技术有限公司成都分公司 A kind of method and device based on universal network file system write-in data
CN109857565A (en) * 2019-01-18 2019-06-07 深圳壹账通智能科技有限公司 Data processing method, device, computer equipment and storage medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN202551056U (en) * 2012-01-16 2012-11-21 西安奇维科技股份有限公司 Data automatic synchronizing apparatus in LVDS interface communication
CN106201853A (en) * 2015-04-30 2016-12-07 阿里巴巴集团控股有限公司 Method of testing and device
CN106469158B (en) * 2015-08-17 2019-10-08 杭州海康威视系统技术有限公司 Method of data synchronization and device
CN106712887B (en) * 2016-12-23 2018-10-26 北京航天测控技术有限公司 A kind of principal and subordinate's two-shipper state synchronization method based on Network Time Protocol
CN106878473B (en) * 2017-04-20 2021-03-30 腾讯科技(深圳)有限公司 Message processing method, server cluster and system
CN108306864B (en) * 2018-01-12 2021-02-26 深圳壹账通智能科技有限公司 Network data detection method and device, computer equipment and storage medium
CN109361770A (en) * 2018-12-11 2019-02-19 苏州创旅天下信息技术有限公司 The system and method for bidirectional real-time is realized based on WebSocket and message queue

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150293712A1 (en) * 2012-12-28 2015-10-15 Tencent Technology (Shenzhen) Co., Ltd. Data synchronization method, apparatus and system
CN105528294A (en) * 2015-12-29 2016-04-27 广东金赋信息科技有限公司 Method and system for automatically generating interface testing case
CN106131138A (en) * 2016-06-27 2016-11-16 浪潮软件股份有限公司 A kind of display data real time propelling movement system and method based on non-obstruction queue
CN109309631A (en) * 2018-08-15 2019-02-05 新华三技术有限公司成都分公司 A kind of method and device based on universal network file system write-in data
CN109857565A (en) * 2019-01-18 2019-06-07 深圳壹账通智能科技有限公司 Data processing method, device, computer equipment and storage medium

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113946534A (en) * 2021-10-18 2022-01-18 广东工业大学 USB data interception processing system and method based on wireless transmission
CN113946534B (en) * 2021-10-18 2023-09-12 广东工业大学 USB data interception processing system and method based on wireless transmission
CN117009309A (en) * 2023-05-31 2023-11-07 合芯科技(苏州)有限公司 File real-time synchronization method and device based on rsync
CN117009309B (en) * 2023-05-31 2024-05-07 合芯科技(苏州)有限公司 File real-time synchronization method and device based on rsync
CN117076371A (en) * 2023-08-28 2023-11-17 广州市粤港澳大湾区前沿创新技术研究院 Multi-machine data transmission method and device, storage medium and electronic equipment
CN117076371B (en) * 2023-08-28 2024-04-12 广州市粤港澳大湾区前沿创新技术研究院 Multi-machine data transmission method and device, storage medium and electronic equipment

Also Published As

Publication number Publication date
CN111262923B (en) 2022-08-19
CN111262923A (en) 2020-06-09

Similar Documents

Publication Publication Date Title
WO2021142965A1 (en) Data synchronization method and apparatus, and computer device and storage medium
US11886731B2 (en) Hot data migration method, apparatus, and system
US11392497B1 (en) Low latency access to data sets using shared data set portions
US20150363319A1 (en) Fast warm-up of host flash cache after node failover
WO2020233352A1 (en) Block chain data chaining method, device, computer apparatus and storage medium
CN108683668B (en) Resource checking method, device, storage medium and equipment in content distribution network
US9367261B2 (en) Computer system, data management method and data management program
US10318475B2 (en) System and method for persistence of application data using replication over remote direct memory access
CN105447046A (en) Distributed system data consistency processing method, device and system
WO2021169275A1 (en) Sdn network device access method and apparatus, computer device, and storage medium
WO2020151181A1 (en) Cross-platform data updating method and apparatus based on block chain, and computer device
WO2022057231A1 (en) Method and apparatus for accessing server, device, and storage medium
US9984139B1 (en) Publish session framework for datastore operation records
US20200125473A1 (en) Hybrid log viewer with thin memory usage
CN109729108A (en) A kind of method, associated server and system for preventing caching from puncturing
US11593270B1 (en) Fast distributed caching using erasure coded object parts
WO2019057193A1 (en) Data deletion method and distributed storage system
CN113419824A (en) Data processing method, device, system and computer storage medium
US11409711B2 (en) Barriers for dependent operations among sharded data stores
US11082494B2 (en) Cross storage protocol access response for object data stores
US11507277B2 (en) Key value store using progress verification
CN108540510B (en) Cloud host creation method and device and cloud service system
US20220358106A1 (en) Proxy-based database scaling
CN110837423A (en) Method and device for automatically acquiring data of guided transport vehicle
CN115203159B (en) Data storage method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20914083

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 09/11/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20914083

Country of ref document: EP

Kind code of ref document: A1