WO2016091069A1 - Data operation method and device - Google Patents

Data operation method and device Download PDF

Info

Publication number
WO2016091069A1
WO2016091069A1 PCT/CN2015/095544 CN2015095544W WO2016091069A1 WO 2016091069 A1 WO2016091069 A1 WO 2016091069A1 CN 2015095544 W CN2015095544 W CN 2015095544W WO 2016091069 A1 WO2016091069 A1 WO 2016091069A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
library
time
read
read request
Prior art date
Application number
PCT/CN2015/095544
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 WO2016091069A1 publication Critical patent/WO2016091069A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • the present invention relates to the field of computer technologies, and in particular, to a data operation method and apparatus.
  • the database is divided into a main library and a slave library, and the data is processed by means of read-write separation: the read request issued by the client is processed by the library, and the write request sent by the client is processed by the main library.
  • a middleware (a data transfer device) is usually disposed between the database and the client to manage the connection interaction between the database and a large number of clients, and provide data services for each client, that is, the client.
  • the data connection is made between the end and the database through the middleware.
  • the middleware establishes a connection with the database, the request sent by the user is sent to the main library or the slave library according to the type of the request.
  • the middleware sends the write request to the main library after receiving the write request; when the client issues a read request, the middleware sends the read request to the slave library.
  • the main library executes the write request sent by the client, after the operation of writing the data is completed, the main library sends a log to the slave library, so that the newly written data is synchronized to the slave library, thereby completing the process of synchronously updating the data in the database.
  • the main library synchronizes data with the slave library. If the main library synchronizes a certain data to the slave library, the client issues a read request to read the data, then the synchronization process cannot be completed because the synchronization process is not completed. The data is read from the library, which in turn causes the read data to fail. It can be seen that there is a great chance in the prior art that the data cannot be read normally.
  • the present invention has been made in order to provide a data operation method and apparatus that overcomes the above problems or at least partially solves the above problems, and can effectively avoid a large probability that data cannot be read normally due to data synchronization.
  • a data operation method comprising: receiving a read request for data;
  • the read request is sent to the main library or the slave library to read the data according to the write time.
  • a data operation apparatus including: a receiving module, a lookup module, a time difference module, and a judgment processing module, wherein
  • the receiving module is configured to receive a read request for data
  • the searching module is configured to search for a write moment of writing the data to the main library
  • the time module is configured to determine a length of time from the writing time to the current time
  • the determining processing module is configured to determine whether the length of time is greater than a preset threshold, and if yes, send the read request to the slave library to read the data; otherwise, send the read request to the main library to read The data.
  • a computer program comprising computer readable code causing the computing device to perform the data manipulation method described above when the computer readable code is run on a computing device .
  • a computer readable medium wherein the computer program described above is stored.
  • the middleware after receiving the read request for a certain data, the middleware does not directly send the read request to the slave library to read the data, but searches for the write of the recorded data. At the moment, it is determined whether the length of time from the writing time of the data to the current time is greater than a preset threshold. If the length of time is greater than the threshold, the data may be considered to have been synchronized from the main library to the slave library, then the middleware will read the request. Send to the slave library to read the data; if the length of time is less than the threshold, it means that the data has not been synchronized to the slave library, so the middleware sends the read request to the master library to read directly from the master library. take. In this way, when data is read, even if the data is not synchronized from the library, the data can be read directly from the main library, and the data does not fail because the data is not synchronized. The situation effectively improves the success rate of reading data.
  • FIG. 1 is a schematic diagram of a data operation process according to an embodiment of the present invention.
  • FIG. 2 is a schematic diagram showing a connection architecture of a client, a middleware, and a database in an example according to an embodiment of the present invention
  • FIG. 3 is a schematic diagram of a data operation process in practical application according to an embodiment of the present invention.
  • FIG. 4 is a schematic structural diagram of a data operation device according to an embodiment of the present invention.
  • Figure 5 shows schematically a block diagram of a computing device for performing the method according to the invention
  • Fig. 6 schematically shows a storage unit for holding or carrying program code implementing the method according to the invention.
  • FIG. 1 is a data operation method according to an embodiment of the present invention, which may include the following steps:
  • S101 Receive a read request for data.
  • S103 Send the read request to the main library or the slave library according to the write time to read the data.
  • the middleware after receiving the read request for a certain data, the middleware does not directly send the read request to the data read from the library, but searches for the recorded data.
  • the purpose of finding the write time of the data is to determine whether the data has completed the synchronization process from the main library to the slave library according to the write time. In this way, the read request can be sent to the main library or the slave library to read the data according to the write timing of the data. Effectively improve the success rate of reading data.
  • the middleware can determine the data corresponding to the read request according to the read request sent by the client, and then send the read request to the corresponding database to read the data.
  • the middleware directly transmits the received read request to the slave library to read the data, there is a case where the read failure occurs because the data is not synchronized. Therefore, in the embodiment of the present invention, when the middleware receives a read request for a certain data, it will find the write time of the data.
  • the method further includes: determining the write time to the current The length of time is determined by whether the length of time is greater than a preset threshold, and the read request is sent to the main library or the slave library to read the data according to the foregoing judgment result.
  • the data may be considered to have been synchronized from the main library to the slave library, then the middleware sends the read request to the slave library to read the data; If the length of time is less than the threshold, it means that the data has not been synchronized to the slave library, so that the middleware sends the read request to the master library to read directly from the master library. In this way, when data is read, even if the data is not synchronized from the library, the data can be read directly from the main library, and the data does not fail because the data is not synchronized. The situation effectively improves the success rate of reading data.
  • the data write operation is performed by the main library, that is, after receiving the write request of the data sent by the client, the middleware sends the write request to the main library for data writing. Then, the time at which the data is written is the time at which the main library receives the write request and writes the data.
  • the method before receiving a read request for data, the method further includes: receiving a write request for the data, and transmitting the write request to a main library for writing, recording the The time at which the data was written.
  • the middleware can be notified immediately after the main library completes the writing of the data, and the middleware records the time when the notification is received as the writing time of the data.
  • the main library responsible for writing data can also be used.
  • the middleware reads the write time of the data recorded by the main library in real time.
  • the length of time from the writing time to the current time can be determined.
  • the current time is the time when the middleware receives the read request for the data.
  • the data is synchronized to the slave library, specifically, the master library synchronizes the data with the slave library, and the binlog log can be used to synchronize the data, that is, the main library will already be
  • the written data is recorded in the binlog log, and the binlog log is sent to the slave library.
  • the operation records in the log are replayed, and the data synchronization is completed.
  • a synchronous manner does not constitute a limitation of the present invention. Obviously, it takes a certain amount of time to synchronize the data from the library.
  • the middleware determines whether the data is synchronized according to the length of time from the current time to the writing time of the data and the preset threshold, and further determines whether to send the read request to the main library or the slave library according to the determination result.
  • the middleware determines whether the length of time from the writing time of the data to the current time is greater than a preset threshold. If the length of time is greater than (or equal to) the preset threshold, it indicates that the slave has completed the synchronization of the data, and the middleware sends a read request for the data to the slave library for reading. If the length of time is less than the preset threshold, it indicates that the slave library has not completed the synchronization of the data. At this time, the middleware sends the read request to the slave library, which causes the read failure. Therefore, in order to successfully read the data, the middle is The piece sends the read request to the main library.
  • the method for setting the preset threshold may be: determining an average duration of the primary library to synchronize data to the slave library, and setting the average duration to the preset threshold. This is because the time required for the main library to synchronize different data to the slave library is different. In order to reflect the time consuming of all data synchronization processes, the average length of time required to synchronize each data is averaged, and the average duration is obtained. The average duration is set to a preset threshold. Through the preset threshold, it is possible to basically determine whether the data has been synchronized.
  • a small amount of data may take a long time in the synchronization process, and may be greater than a preset threshold. Therefore, as another mode of the embodiment of the present invention, the maximum duration of the synchronization data may be set to the pre-predetermined value. Set the threshold.
  • the above preset threshold can be adjusted according to the needs of the actual application. It is not intended to limit the invention.
  • the foregoing preset threshold is dynamically changed, and the preset threshold will be changed according to the data that has been synchronized. Specifically, the more the number of data that has been synchronized, the more the main library synchronizes the data to the average duration of the slave library. Accurate (that is, the more accurately it reflects the overall time-consuming size).
  • Figure 2 shows the connection architecture of the client, middleware, main library, and slave library in practical applications. Assuming that the preset threshold is 2 s, data A and data B have been written in the main library, wherein the write time of data A is 10:20:17, and the write time of data B is 10:20:20.
  • the middleware receives the read request I and the read request II sent by the client, wherein the data to be read by the read request I is data A, and the data to be read by the read request II is data B.
  • the writing time of the data A of the middleware search record is 10:20:17, and the time length of the writing time of the data A to the current time (10:20:21) is 4s. Obviously, the length of time 4s is greater than the preset.
  • the threshold is 2 s, which means that the data A has been synchronized to the slave library, so the middleware sends the read request I to the slave library to read the data A.
  • the writing time of the data B of the middleware search record is 10:20:20, and the writing time of the data B to the current time (10:20:21) is 1 s. Obviously, the length of time 1s is less than the preset.
  • the threshold is 2s, which means that the data B has not been synchronized yet, so the middleware sends the read request II directly to the main library to read the data B.
  • S301 The middleware receives a read request for data.
  • S302 The middleware searches for the write time of the recorded data.
  • S303 The middleware determines a length of time from the writing time to the current time.
  • step S304 The middleware determines whether the length of time is greater than a preset threshold. If yes, step S305 is performed; otherwise, step S306 is performed.
  • S305 The middleware sends the read request to the slave library to read the data.
  • S306 The middleware sends the read request to the main library to read the data.
  • the embodiment of the present invention further provides a data operation device, as shown in FIG. 4 .
  • the data operating device in FIG. 4 is disposed in the middleware and connected to the client and the server.
  • the device includes: a receiving module 401, a searching module 402, a time module 403, and a determining processing module 404, where
  • the receiving module 401 is configured to receive a read request for data.
  • the searching module 402 is configured to search for a write moment of writing the data to the main library.
  • the time module 403 is configured to determine a length of time from the writing time to the current time.
  • the determining processing module 404 is configured to determine whether the length of time is greater than a preset threshold, and if yes, send the read request to the slave library to read the data; otherwise, send the read request to the main library to read Take this data.
  • the receiving module 401 is further configured to receive a write request for the data.
  • the determining processing module 404 is further configured to send the received write request for the data to the main library for writing.
  • the data operation device further includes: a recording module 405, configured to record a write time when the data is written into the main library.
  • the preset threshold is set by determining that the main library synchronizes data to an average duration of the slave library, and setting the average duration to the preset threshold; or determining that the primary library synchronizes data to The maximum duration is set to the preset threshold from the maximum duration of the library.
  • Embodiments of the present invention provide a data operation method and apparatus. After receiving a read request for a certain data, the middleware does not directly send the read request to the slave library to read data, but searches for the recorded The writing time of the data is determined whether the length of time from the writing time of the data to the current time is greater than a preset threshold. If the time length is greater than the threshold, the data may be considered to have been synchronized from the main library to the slave library, then The middleware sends a read request to the slave library to read the data; and if the length of time is less than the threshold, it indicates that the data has not been synchronized to the slave library, so that the middleware sends the read request to the master library to directly Read from the main library. In this way, when data is read, even if the data is not synchronized from the library, the data can be read directly from the main library, and the data does not fail because the data is not synchronized. The situation effectively improves the success rate of reading data.
  • modules in the devices of the embodiments can be adaptively changed and placed in one or more devices different from the embodiment.
  • the modules or units or components of the embodiments may be combined into one module or unit or component, and further they may be divided into a plurality of sub-modules or sub-units or sub-components.
  • any combination of the features disclosed in the specification, including the accompanying claims, the abstract and the drawings, and any methods so disclosed, or All processes or units of the device are combined.
  • Each feature disclosed in this specification (including the accompanying claims, the abstract and the drawings) may be replaced by alternative features that provide the same, equivalent or similar purpose.
  • the various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof.
  • Those skilled in the art should It is understood that some or all of the functionality of some or all of the components of the data manipulation device in accordance with embodiments of the present invention may be implemented in practice using a microprocessor or digital signal processor (DSP).
  • DSP digital signal processor
  • the invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein.
  • Such a program implementing the invention may be stored on a computer readable medium or may be in the form of one or more signals. Such signals may be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.
  • Figure 5 schematically illustrates a block diagram of a computing device for performing the method in accordance with the present invention.
  • the computing device conventionally includes a processor 510 and a computer program product or computer readable medium in the form of a memory 520.
  • the memory 520 may be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read Only Memory), an EPROM, a hard disk, or a ROM.
  • Memory 520 has a storage space 530 that stores program code 531 for performing any of the method steps described above.
  • storage space 530 storing program code may include various program code 531 for implementing various steps in the above methods, respectively.
  • the program code can be read from or written to one or more computer program products.
  • Such computer program products include program code carriers such as hard disks, compact disks (CDs), memory cards or floppy disks.
  • Such a computer program product is typically a portable or fixed storage unit such as that shown in FIG.
  • the storage unit may have storage segments, storage spaces, and the like that are similarly arranged to memory 520 in the computing device of FIG.
  • the program code can be compressed, for example, in an appropriate form.
  • the storage unit comprises computer readable code 531 ' for performing the steps of the method according to the invention, ie code that can be read by a processor such as 510, which when executed by the computing device causes the calculation The device performs the various steps in the methods described above.
  • the present invention is applicable to computer systems/servers that can operate with numerous other general purpose or special purpose computing system environments or configurations.
  • Examples of well-known computing systems, environments, and/or configurations suitable for use with computer systems/servers include, but are not limited to, personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, based on Microprocessor systems, set-top boxes, programmable consumer electronics, networked personal computers, small computer systems, mainframe computer systems, and distributed cloud computing technology environments including any of the above, and the like.
  • the computer system/server can be described in the general context of computer system executable instructions (such as program modules) being executed by a computer system.
  • program modules may include routines, programs, target programs, components, logic, data structures, and the like that perform particular tasks or implement particular abstract data types.
  • the computer system/server can be implemented in a distributed cloud computing environment where tasks are performed by remote processing devices that are linked through a communication network.
  • program modules may be located on a local or remote computing system storage medium including storage devices.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Computing Systems (AREA)

Abstract

Disclosed are a data operation method and device. The method comprises: receiving a read request for data (S101); searching for a recorded write moment at which the data is written into a primary library (S102); and determining a time length from the write moment to a current moment, and sending the read request to the primary library or a secondary library according to the write moment so as to read the data (S103). In the method, after receiving the read request for the data, middleware performs judgement based on the length of time from the write moment to the current moment of the data and a pre-set threshold value as to decide whether to send the read request to the primary library or the secondary library instead of directly sending the read request to the secondary library to read the data. Thus, during reading of the data, even if data synchronisation is not completed in the secondary library, the data can still be read from the primary library directly, the scenario of reading failure caused by non-completion of data synchronisation is avoided, and the success rate of data reading is effectively improved.

Description

一种数据操作方法及装置Data operation method and device 技术领域Technical field
本发明涉及计算机技术领域,尤其涉及一种数据操作方法及装置。The present invention relates to the field of computer technologies, and in particular, to a data operation method and apparatus.
背景技术Background technique
随着信息技术的发展,用户可以使用客户端通过网络途径访问相应的数据库(如MySQL数据库、Oracle数据库等)来获取所需的数据。数据库中分为主库和从库,并采用读写分离的方式处理数据:由从库处理客户端发出的读请求,由主库处理客户端发出的写请求。With the development of information technology, users can use the client to access the corresponding database (such as MySQL database, Oracle database, etc.) through the network to obtain the required data. The database is divided into a main library and a slave library, and the data is processed by means of read-write separation: the read request issued by the client is processed by the library, and the write request sent by the client is processed by the main library.
现有技术中,通常在数据库和客户端之间设置有中间件(一种数据中转设备),以管理数据库与大量客户端之间的连接交互,并为各客户端提供数据服务,即,客户端与数据库之间通过中间件进行数据连接。中间件建立了与数据库之间的连接之后,会将用户发出的请求按照所属的请求类型分别发送至主库或从库中。In the prior art, a middleware (a data transfer device) is usually disposed between the database and the client to manage the connection interaction between the database and a large number of clients, and provide data services for each client, that is, the client. The data connection is made between the end and the database through the middleware. After the middleware establishes a connection with the database, the request sent by the user is sent to the main library or the slave library according to the type of the request.
例如:客户端发出写请求,则中间件在接收到该写请求后,将该写请求发送至主库中;客户端发出读请求,则中间件将该读请求发送至从库中。For example, if the client issues a write request, the middleware sends the write request to the main library after receiving the write request; when the client issues a read request, the middleware sends the read request to the slave library.
主库执行客户端发送的写请求,完成写入数据的操作后,主库会向从库发送日志,使新写入的数据同步到从库中,从而完成了数据库中数据同步更新的过程。After the main library executes the write request sent by the client, after the operation of writing the data is completed, the main library sends a log to the slave library, so that the newly written data is synchronized to the slave library, thereby completing the process of synchronously updating the data in the database.
但是,主库向从库同步数据需要一定的时间,若主库将某一数据同步至从库的过程中,客户端发出读请求以读取该数据,那么,由于同步过程未结束,不能在从库中读取到该数据,进而导致读数据失败。可见,现有技术中有很大几率不能正常读取数据。However, it takes a certain time for the main library to synchronize data with the slave library. If the main library synchronizes a certain data to the slave library, the client issues a read request to read the data, then the synchronization process cannot be completed because the synchronization process is not completed. The data is read from the library, which in turn causes the read data to fail. It can be seen that there is a great chance in the prior art that the data cannot be read normally.
发明内容Summary of the invention
鉴于上述问题,提出了本发明以便提供一种克服上述问题或者至少部分地解决上述问题的数据操作方法及装置,能够有效避免因数据同步而导致有很大几率不能正常读取数据。 In view of the above problems, the present invention has been made in order to provide a data operation method and apparatus that overcomes the above problems or at least partially solves the above problems, and can effectively avoid a large probability that data cannot be read normally due to data synchronization.
根据本发明的第一个方面,提出一种数据操作方法,包括:接收针对数据的读请求;According to a first aspect of the present invention, a data operation method is provided, comprising: receiving a read request for data;
查找记录的将所述数据写入主库的写入时刻;Finding the write time of the record to write the data to the main library;
根据所述写入时刻将该读请求发送至主库或者从库以读取该数据。The read request is sent to the main library or the slave library to read the data according to the write time.
根据本发明的第二个方面,提出一种数据操作装置,包括:接收模块、查找模块、时差模块以及判断处理模块,其中;According to a second aspect of the present invention, a data operation apparatus is provided, including: a receiving module, a lookup module, a time difference module, and a judgment processing module, wherein
所述接收模块,用于接收针对数据的读请求;The receiving module is configured to receive a read request for data;
所述查找模块,用于查找记录的将所述数据写入主库的写入时刻;The searching module is configured to search for a write moment of writing the data to the main library;
所述时间模块,用于确定所述写入时刻到当前时刻的时间长度;The time module is configured to determine a length of time from the writing time to the current time;
所述判断处理模块,用于判断所述时间长度是否大于预设阈值,若是,则将该读请求发送至从库以读取该数据,否则,则将该读请求发送至主库以读取该数据。The determining processing module is configured to determine whether the length of time is greater than a preset threshold, and if yes, send the read request to the slave library to read the data; otherwise, send the read request to the main library to read The data.
根据本发明的第三个方面,提出了一种计算机程序,包括计算机可读代码,当所述计算机可读代码在计算设备上运行时,导致所述计算设备执行上文所述的数据操作方法。According to a third aspect of the present invention, a computer program is presented, comprising computer readable code causing the computing device to perform the data manipulation method described above when the computer readable code is run on a computing device .
根据本发明的第四个方面,提出了一种计算机可读介质,其中存储了上述的计算机程序。According to a fourth aspect of the invention, a computer readable medium is proposed, wherein the computer program described above is stored.
根据本发明提供的数据操作方法,中间件在接收到针对某一数据的读请求后,并不是直接将该读请求发送至从库以读取数据,而是查找已记录的该数据的写入时刻,判断该数据的写入时刻到当前时刻的时间长度是否大于预设的阈值,如果时间长度大于阈值,可以认为该数据已经从主库中同步到了从库中,那么,中间件将读请求发送至从库以读取该数据;而如果时间长度小于阈值,就说明该数据还未同步到从库中,从而,中间件将该读请求发送至主库,以直接从主库中进行读取。通过这样的方式,在读取数据时,即使从库中未完成数据的同步,仍可以直接从主库中读取该数据,不会因为数据未完成同步,而导致读取数据时发生失败的情况,有效提升了读取数据的成功率。According to the data operation method provided by the present invention, after receiving the read request for a certain data, the middleware does not directly send the read request to the slave library to read the data, but searches for the write of the recorded data. At the moment, it is determined whether the length of time from the writing time of the data to the current time is greater than a preset threshold. If the length of time is greater than the threshold, the data may be considered to have been synchronized from the main library to the slave library, then the middleware will read the request. Send to the slave library to read the data; if the length of time is less than the threshold, it means that the data has not been synchronized to the slave library, so the middleware sends the read request to the master library to read directly from the master library. take. In this way, when data is read, even if the data is not synchronized from the library, the data can be read directly from the main library, and the data does not fail because the data is not synchronized. The situation effectively improves the success rate of reading data.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的 具体实施方式。The above description is only an overview of the technical solutions of the present invention, and the above-described and other objects, features and advantages of the present invention can be more clearly understood. , the following specializes in the invention detailed description.
附图说明DRAWINGS
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those skilled in the art from a The drawings are only for the purpose of illustrating the preferred embodiments and are not to be construed as limiting. Throughout the drawings, the same reference numerals are used to refer to the same parts. In the drawing:
图1为依据本发明一个实施例的数据操作过程的示意图;1 is a schematic diagram of a data operation process according to an embodiment of the present invention;
图2为依据本发明一个实施例的实例中客户端、中间件以及数据库的连接架构示意图;2 is a schematic diagram showing a connection architecture of a client, a middleware, and a database in an example according to an embodiment of the present invention;
图3为依据本发明一个实施例的数据操作过程在实际应用中的示意图;3 is a schematic diagram of a data operation process in practical application according to an embodiment of the present invention;
图4为依据本发明一个实施例的数据操作装置结构示意图;4 is a schematic structural diagram of a data operation device according to an embodiment of the present invention;
图5示意性地示出了用于执行根据本发明的方法的计算设备的框图;以及Figure 5 shows schematically a block diagram of a computing device for performing the method according to the invention;
图6示意性地示出了用于保持或者携带实现根据本发明的方法的程序代码的存储单元。Fig. 6 schematically shows a storage unit for holding or carrying program code implementing the method according to the invention.
具体实施例Specific embodiment
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While the embodiments of the present invention have been shown in the drawings, the embodiments Rather, these embodiments are provided so that this disclosure will be more fully understood and the scope of the disclosure will be fully disclosed.
下面结合说明书附图,对本发明实施例进行详细描述。The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
图1为依据本发明一个实施例的数据操作方法,可以包括步骤:FIG. 1 is a data operation method according to an embodiment of the present invention, which may include the following steps:
S101:接收针对数据的读请求。S101: Receive a read request for data.
S102:查找已记录的所述数据的写入时刻。S102: Find a write time of the recorded data.
S103:根据所述写入时刻将所述读请求发送至主库或者从库以读取该数据。S103: Send the read request to the main library or the slave library according to the write time to read the data.
从上述可知,在该实施例中,中间件在接收到针对某一数据的读请求后,并不是直接将该读请求发送至从库中读取数据,而是查找已记录的该数据的 写入时刻,查找该数据的写入时刻的目的在于:根据所述写入时刻,可以判断出该数据是否已经完成了主库到从库的同步过程。这样一来,便可以根据该数据的写入时刻将所述读请求发送至主库或者从库以读取该数据。有效提升了读取数据的成功率。As can be seen from the above, in this embodiment, after receiving the read request for a certain data, the middleware does not directly send the read request to the data read from the library, but searches for the recorded data. At the time of writing, the purpose of finding the write time of the data is to determine whether the data has completed the synchronization process from the main library to the slave library according to the write time. In this way, the read request can be sent to the main library or the slave library to read the data according to the write timing of the data. Effectively improve the success rate of reading data.
依据本发明的一个实施例,中间件可以根据客户端发出的读请求,确定出该读请求所对应的数据,进而将读请求发送至相应的数据库以读取数据。考虑到现有技术中,中间件将接收到的读请求直接发送至从库以读取数据时,存在因数据未同步完成而导致读取失败的情况。因此在本发明实施例中,当中间件接收到针对某一数据的读请求之后,将查找该数据的写入时刻。According to an embodiment of the present invention, the middleware can determine the data corresponding to the read request according to the read request sent by the client, and then send the read request to the corresponding database to read the data. In view of the prior art, when the middleware directly transmits the received read request to the slave library to read the data, there is a case where the read failure occurs because the data is not synchronized. Therefore, in the embodiment of the present invention, when the middleware receives a read request for a certain data, it will find the write time of the data.
也就是说,在本发明中,根据所述数据的写入时刻,就可以确定在发出读请求时,该数据是否完成了同步,具体地,上述方法还包括:确定所述写入时刻到当前时刻的时间长度,判断所述时间长度是否大于预设阈值,并依据上述判断结果将该读请求发送至主库或者从库以读取该数据。That is, in the present invention, based on the write time of the data, it can be determined whether the data is synchronized when the read request is issued. Specifically, the method further includes: determining the write time to the current The length of time is determined by whether the length of time is greater than a preset threshold, and the read request is sent to the main library or the slave library to read the data according to the foregoing judgment result.
如果该数据的写入时刻到当前时刻的时间长度大于预设阈值,可以认为该数据已经从主库中同步到了从库中,那么,中间件将读请求发送至从库以读取该数据;而如果时间长度小于阈值,就说明该数据还未同步到从库中,从而,中间件将该读请求发送至主库,以直接从主库中进行读取。通过这样的方式,在读取数据时,即使从库中未完成数据的同步,仍可以直接从主库中读取该数据,不会因为数据未完成同步,而导致读取数据时发生失败的情况,有效提升了读取数据的成功率。If the length of time from the writing time of the data to the current time is greater than a preset threshold, the data may be considered to have been synchronized from the main library to the slave library, then the middleware sends the read request to the slave library to read the data; If the length of time is less than the threshold, it means that the data has not been synchronized to the slave library, so that the middleware sends the read request to the master library to read directly from the master library. In this way, when data is read, even if the data is not synchronized from the library, the data can be read directly from the main library, and the data does not fail because the data is not synchronized. The situation effectively improves the success rate of reading data.
这里需要说明的是,数据的写入操作由主库执行,也即,中间件在接收到客户端发送的数据的写请求之后,将该写请求发送给主库以进行数据写入。那么,数据的写入时刻,就是主库接收到写请求并对该数据进行写入操作的时刻。具体地,依据本发明的一个实施例,在接收针对数据的读请求之前,还包括:接收针对所述数据的写请求,并将所述写请求发送至主库以进行写入,记录所述数据的写入时刻。It should be noted here that the data write operation is performed by the main library, that is, after receiving the write request of the data sent by the client, the middleware sends the write request to the main library for data writing. Then, the time at which the data is written is the time at which the main library receives the write request and writes the data. Specifically, in accordance with an embodiment of the present invention, before receiving a read request for data, the method further includes: receiving a write request for the data, and transmitting the write request to a main library for writing, recording the The time at which the data was written.
这样一来,主库中所写入的所有的数据,均有各自所对应的写入时刻。当然,在本发明中,对于数据的写入时刻的记录,可以在主库完成数据的写入后,立即通知中间件,中间件将记录接收到该通知的时刻,作为该数据的写入时刻。当然,在本发明的另一种方式下,也可由负责写入数据的主库记 录各数据对应的写入时刻,中间件会实时读取主库所记录的数据的写入时刻。In this way, all the data written in the main library have their respective write times. Of course, in the present invention, for the recording of the data writing time, the middleware can be notified immediately after the main library completes the writing of the data, and the middleware records the time when the notification is received as the writing time of the data. . Of course, in another mode of the present invention, the main library responsible for writing data can also be used. When the write time corresponding to each data is recorded, the middleware reads the write time of the data recorded by the main library in real time.
依据本发明的一个实施例,中间件查找到数据的写入时刻后,就可以确定出该写入时刻到当前时刻的时间长度。本发明实施例中,当前时刻就是中间件接收到针对数据的读请求的时刻。According to an embodiment of the present invention, after the middleware finds the writing time of the data, the length of time from the writing time to the current time can be determined. In the embodiment of the present invention, the current time is the time when the middleware receives the read request for the data.
还需要说明的是,主库在写入数据之后,会向从库同步数据,具体地,主库向从库同步数据的方式,可以采用binlog日志的方式同步数据,也即,主库将已经写入的数据记载在binlog日志中,将该binlog日志发送至从库,从库接收到该binlog日志后重放该日志中的各操作记录,完成数据的同步。当然,这样的同步方式并不构成对本发明的限定。显然,从库完成数据的同步需要一定的时间。It should also be noted that after the main library writes the data, the data is synchronized to the slave library, specifically, the master library synchronizes the data with the slave library, and the binlog log can be used to synchronize the data, that is, the main library will already be The written data is recorded in the binlog log, and the binlog log is sent to the slave library. After receiving the binlog log from the library, the operation records in the log are replayed, and the data synchronization is completed. Of course, such a synchronous manner does not constitute a limitation of the present invention. Obviously, it takes a certain amount of time to synchronize the data from the library.
那么,对于中间件所接收到的读请求,其所要读取的数据可能已经完成了同步,也可能未完成同步。因此,中间件将根据当前时刻到该数据的写入时刻的时间长度,和预先设置的阈值,来判断该数据是否完成同步,进而根据判断结果确定将该读请求发送给主库还是从库。Then, for the read request received by the middleware, the data to be read may have been synchronized or may not be synchronized. Therefore, the middleware determines whether the data is synchronized according to the length of time from the current time to the writing time of the data and the preset threshold, and further determines whether to send the read request to the main library or the slave library according to the determination result.
具体地,中间件判断数据的写入时刻到当前时刻的时间长度,是否大于预置阈值。如果时间长度大于(或等于)预设阈值,就说明从库已经完成了数据的同步,中间件便将针对该数据的读请求,发送至从库以进行读取。而如果时间长度小于预设阈值,就说明从库还未完成数据的同步,此时中间件将该读请求发送至从库,就会造成读取失败,因此,为了能够成功读取数据,中间件将该读请求发送至主库。Specifically, the middleware determines whether the length of time from the writing time of the data to the current time is greater than a preset threshold. If the length of time is greater than (or equal to) the preset threshold, it indicates that the slave has completed the synchronization of the data, and the middleware sends a read request for the data to the slave library for reading. If the length of time is less than the preset threshold, it indicates that the slave library has not completed the synchronization of the data. At this time, the middleware sends the read request to the slave library, which causes the read failure. Therefore, in order to successfully read the data, the middle is The piece sends the read request to the main library.
其中,上述预设阈值的设定方法,具体可以为:确定所述主库将数据同步到从库的平均时长,将该平均时长设定为所述预设阈值。这是因为,主库将不同的数据同步到从库所需的时间各不相同,为了反映所有数据同步过程的耗时,将各数据进行同步所需的时长进行平均后,得到平均时长,将该平均时长设定为预设阈值。通过该预设阈值,便可以基本确定数据是否已经同步完成。Specifically, the method for setting the preset threshold may be: determining an average duration of the primary library to synchronize data to the slave library, and setting the average duration to the preset threshold. This is because the time required for the main library to synchronize different data to the slave library is different. In order to reflect the time consuming of all data synchronization processes, the average length of time required to synchronize each data is averaged, and the average duration is obtained. The average duration is set to a preset threshold. Through the preset threshold, it is possible to basically determine whether the data has been synchronized.
在实际应用中,少数数据在同步过程中耗时较长,可能会大于预设阈值,因此,作为本发明实施例的另一种方式,也可以将同步数据的最大时长设定为所述预设阈值。上述预设阈值的方式可以根据实际应用的需要进行调整设 置,并不构成对本发明的限定。In a practical application, a small amount of data may take a long time in the synchronization process, and may be greater than a preset threshold. Therefore, as another mode of the embodiment of the present invention, the maximum duration of the synchronization data may be set to the pre-predetermined value. Set the threshold. The above preset threshold can be adjusted according to the needs of the actual application. It is not intended to limit the invention.
当然,上述预设阈值是动态变化的,预设阈值将根据已完成同步的数据进行变化,具体地,已完成同步的数据的数量越多,主库将数据同步到从库的平均时长就越精确(即越能准确反映整体耗时的大小)。Certainly, the foregoing preset threshold is dynamically changed, and the preset threshold will be changed according to the data that has been synchronized. Specifically, the more the number of data that has been synchronized, the more the main library synchronizes the data to the average duration of the slave library. Accurate (that is, the more accurately it reflects the overall time-consuming size).
本发明所述的数据操作方法的具体应用实例如下:Specific application examples of the data operation method described in the present invention are as follows:
图2示出了在实际应用中,客户端、中间件、主库以及从库的连接架构。假设预设阈值为2s,主库中已写入数据A和数据B,其中,数据A的写入时刻为10:20:17,数据B的写入时刻为10:20:20。Figure 2 shows the connection architecture of the client, middleware, main library, and slave library in practical applications. Assuming that the preset threshold is 2 s, data A and data B have been written in the main library, wherein the write time of data A is 10:20:17, and the write time of data B is 10:20:20.
在10:20:21时,中间件接收到客户端发送的读请求I和读请求II,其中,读请求I所要读取的数据为数据A,读请求II所要读取的数据为数据B。At 10:20:21, the middleware receives the read request I and the read request II sent by the client, wherein the data to be read by the read request I is data A, and the data to be read by the read request II is data B.
中间件查找记录的该数据A的写入时刻为10:20:17,该数据A的写入时刻到当前时刻(10:20:21)的时间长度为4s,显然,时间长度4s大于预设阈值2s,这就说明,该数据A已经同步到了从库中,因此,中间件将该读请求I发送至从库,以读取数据A。The writing time of the data A of the middleware search record is 10:20:17, and the time length of the writing time of the data A to the current time (10:20:21) is 4s. Obviously, the length of time 4s is greater than the preset. The threshold is 2 s, which means that the data A has been synchronized to the slave library, so the middleware sends the read request I to the slave library to read the data A.
中间件查找记录的该数据B的写入时刻为10:20:20,该数据B的写入时刻到当前时刻(10:20:21)的时间长度为1s,显然,时间长度1s小于预设阈值2s,这就说明,该数据B还未完成同步,因此,中间件将该读请求II直接发送至主库,以读取数据B。The writing time of the data B of the middleware search record is 10:20:20, and the writing time of the data B to the current time (10:20:21) is 1 s. Obviously, the length of time 1s is less than the preset. The threshold is 2s, which means that the data B has not been synchronized yet, so the middleware sends the read request II directly to the main library to read the data B.
如图3所示,结合上述方法及应用实例,在本发明中,图1中的数据操作方法S101~S103的实际应用如下:As shown in FIG. 3, in combination with the above method and application example, in the present invention, the practical applications of the data operation methods S101 to S103 in FIG. 1 are as follows:
S301:中间件接收针对数据的读请求。S301: The middleware receives a read request for data.
S302:中间件查找已记录的所述数据的写入时刻。S302: The middleware searches for the write time of the recorded data.
S303:中间件确定所述写入时刻到当前时刻的时间长度。S303: The middleware determines a length of time from the writing time to the current time.
S304:中间件判断所述时间长度是否大于预设阈值,若是,则执行步骤S305,否则,则执行步骤S306。S304: The middleware determines whether the length of time is greater than a preset threshold. If yes, step S305 is performed; otherwise, step S306 is performed.
S305:中间件将所述读请求发送至从库以读取所述数据。S305: The middleware sends the read request to the slave library to read the data.
S306:中间件将所述读请求发送至主库以读取所述数据。S306: The middleware sends the read request to the main library to read the data.
以上为本发明实施例提供的数据操作方法,基于同样的思路,本发明实施例还提供一种数据操作装置,如图4所示。The above is the data operation method provided by the embodiment of the present invention. Based on the same idea, the embodiment of the present invention further provides a data operation device, as shown in FIG. 4 .
图4中的数据操作装置,设置在中间件中,与客户端和服务器相连接, 所述装置包括:接收模块401、查找模块402、时间模块403以及判断处理模块404,其中,The data operating device in FIG. 4 is disposed in the middleware and connected to the client and the server. The device includes: a receiving module 401, a searching module 402, a time module 403, and a determining processing module 404, where
所述接收模块401,用于接收针对数据的读请求。The receiving module 401 is configured to receive a read request for data.
所述查找模块402,用于查找记录的将所述数据写入主库的写入时刻。The searching module 402 is configured to search for a write moment of writing the data to the main library.
所述时间模块403,用于确定所述写入时刻到当前时刻的时间长度。The time module 403 is configured to determine a length of time from the writing time to the current time.
所述判断处理模块404,用于判断所述时间长度是否大于预设阈值,若是,则将该读请求发送至从库以读取该数据,否则,则将该读请求发送至主库以读取该数据。The determining processing module 404 is configured to determine whether the length of time is greater than a preset threshold, and if yes, send the read request to the slave library to read the data; otherwise, send the read request to the main library to read Take this data.
在本发明的一个实施例中,所述接收模块401,还用于接收针对所述数据的写请求。In an embodiment of the present invention, the receiving module 401 is further configured to receive a write request for the data.
在本发明的一个实施例中,所述判断处理模块404,还用于将接收的针对所述数据的写请求发送至主库以进行写入。In an embodiment of the present invention, the determining processing module 404 is further configured to send the received write request for the data to the main library for writing.
在本发明的一个实施例中,所述数据操作装置,还包括:记录模块405,用于记录所述数据写入主库时的写入时刻。In an embodiment of the present invention, the data operation device further includes: a recording module 405, configured to record a write time when the data is written into the main library.
所述预设阈值通过以下方式设定:确定所述主库将数据同步到从库的平均时长,将该平均时长设定为所述预设阈值;或者,确定所述主库将数据同步到从库的最大时长,将该最大时长设定为所述预设阈值。The preset threshold is set by determining that the main library synchronizes data to an average duration of the slave library, and setting the average duration to the preset threshold; or determining that the primary library synchronizes data to The maximum duration is set to the preset threshold from the maximum duration of the library.
本发明实施例提供一种数据操作方法及装置,该方法中间件在接收到针对某一数据的读请求后,并不是直接将该读请求发送至从库以读取数据,而是查找已记录的该数据的写入时刻,判断该数据的写入时刻到当前时刻的时间长度是否大于预设的阈值,如果时间长度大于阈值,可以认为该数据已经从主库中同步到了从库中,那么,中间件将读请求发送至从库以读取该数据;而如果时间长度小于阈值,就说明该数据还未同步到从库中,从而,中间件将该读请求发送至主库,以直接从主库中进行读取。通过这样的方式,在读取数据时,即使从库中未完成数据的同步,仍可以直接从主库中读取该数据,不会因为数据未完成同步,而导致读取数据时发生失败的情况,有效提升了读取数据的成功率。Embodiments of the present invention provide a data operation method and apparatus. After receiving a read request for a certain data, the middleware does not directly send the read request to the slave library to read data, but searches for the recorded The writing time of the data is determined whether the length of time from the writing time of the data to the current time is greater than a preset threshold. If the time length is greater than the threshold, the data may be considered to have been synchronized from the main library to the slave library, then The middleware sends a read request to the slave library to read the data; and if the length of time is less than the threshold, it indicates that the data has not been synchronized to the slave library, so that the middleware sends the read request to the master library to directly Read from the main library. In this way, when data is read, even if the data is not synchronized from the library, the data can be read directly from the main library, and the data does not fail because the data is not synchronized. The situation effectively improves the success rate of reading data.
在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述, 构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The algorithms and displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general purpose systems can also be used with the teaching based on the teachings herein. According to the above description, The structure required to construct such a system is obvious. Moreover, the invention is not directed to any particular programming language. It is to be understood that the invention may be embodied in a variety of programming language, and the description of the specific language has been described above in order to disclose the preferred embodiments of the invention.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood that the embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of the description.
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, the various features of the invention are sometimes grouped together into a single embodiment, in the above description of the exemplary embodiments of the invention, Figure, or a description of it. However, the method disclosed is not to be interpreted as reflecting the intention that the claimed invention requires more features than those recited in the claims. Rather, as the following claims reflect, inventive aspects reside in less than all features of the single embodiments disclosed herein. Therefore, the claims following the specific embodiments are hereby explicitly incorporated into the embodiments, and each of the claims as a separate embodiment of the invention.
本领域那些技术人员可以理解,可以对实施例中的设备中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个设备中。可以把实施例中的模块或单元或组件组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者单元中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的的替代特征来代替。Those skilled in the art will appreciate that the modules in the devices of the embodiments can be adaptively changed and placed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and further they may be divided into a plurality of sub-modules or sub-units or sub-components. In addition to such features and/or at least some of the processes or units being mutually exclusive, any combination of the features disclosed in the specification, including the accompanying claims, the abstract and the drawings, and any methods so disclosed, or All processes or units of the device are combined. Each feature disclosed in this specification (including the accompanying claims, the abstract and the drawings) may be replaced by alternative features that provide the same, equivalent or similar purpose.
此外,本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在下面的权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features that are included in other embodiments and not in other features, combinations of features of different embodiments are intended to be within the scope of the present invention. Different embodiments are formed and formed. For example, in the following claims, any one of the claimed embodiments can be used in any combination.
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当 理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的数据操作装置中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof. Those skilled in the art should It is understood that some or all of the functionality of some or all of the components of the data manipulation device in accordance with embodiments of the present invention may be implemented in practice using a microprocessor or digital signal processor (DSP). The invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein. Such a program implementing the invention may be stored on a computer readable medium or may be in the form of one or more signals. Such signals may be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.
例如,图5示意性地示出了用于执行根据本发明的方法的计算设备的框图。该计算设备传统上包括处理器510和以存储器520形式的计算机程序产品或者计算机可读介质。存储器520可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。存储器520具有存储用于执行上述方法中的任何方法步骤的程序代码531的存储空间530。例如,存储程序代码的存储空间530可以包括分别用于实现上面的方法中的各种步骤的各个程序代码531。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。这些计算机程序产品包括诸如硬盘,紧致盘(CD)、存储卡或者软盘之类的程序代码载体。这样的计算机程序产品通常为例如图6所示的便携式或者固定存储单元。该存储单元可以具有与图5的计算设备中的存储器520类似布置的存储段、存储空间等。程序代码可以例如以适当形式进行压缩。通常,存储单元包括用于执行根据本发明的方法步骤的计算机可读代码531’,即可以由例如诸如510之类的处理器读取的代码,当这些代码由计算设备运行时,导致该计算设备执行上面所描述的方法中的各个步骤。For example, Figure 5 schematically illustrates a block diagram of a computing device for performing the method in accordance with the present invention. The computing device conventionally includes a processor 510 and a computer program product or computer readable medium in the form of a memory 520. The memory 520 may be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read Only Memory), an EPROM, a hard disk, or a ROM. Memory 520 has a storage space 530 that stores program code 531 for performing any of the method steps described above. For example, storage space 530 storing program code may include various program code 531 for implementing various steps in the above methods, respectively. The program code can be read from or written to one or more computer program products. These computer program products include program code carriers such as hard disks, compact disks (CDs), memory cards or floppy disks. Such a computer program product is typically a portable or fixed storage unit such as that shown in FIG. The storage unit may have storage segments, storage spaces, and the like that are similarly arranged to memory 520 in the computing device of FIG. The program code can be compressed, for example, in an appropriate form. Typically, the storage unit comprises computer readable code 531 ' for performing the steps of the method according to the invention, ie code that can be read by a processor such as 510, which when executed by the computing device causes the calculation The device performs the various steps in the methods described above.
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包括”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。 在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It is to be noted that the above-described embodiments are illustrative of the invention and are not intended to be limiting, and that the invention may be devised without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as a limitation. The word 'comprising' does not exclude the presence of the elements or steps that are not recited in the claims. The word "a" or "an" The invention can be implemented by means of hardware comprising several distinct elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means can be embodied by the same hardware item. The use of the words first, second, and third does not indicate any order. These words can be interpreted as names.
此外,还应当注意,本说明书中使用的语言主要是为了可读性和教导的目的而选择的,而不是为了解释或者限定本发明的主题而选择的。因此,在不偏离所附权利要求书的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。对于本发明的范围,对本发明所做的公开是说明性的,而非限制性的,本发明的范围由所附权利要求书限定。In addition, it should be noted that the language used in the specification has been selected for the purpose of readability and teaching, and is not intended to be construed or limited. Therefore, many modifications and changes will be apparent to those skilled in the art without departing from the scope of the invention. The disclosure of the present invention is intended to be illustrative, and not restrictive, and the scope of the invention is defined by the appended claims.
本发明可以应用于计算机系统/服务器,其可与众多其它通用或专用计算系统环境或配置一起操作。适于与计算机系统/服务器一起使用的众所周知的计算系统、环境和/或配置的例子包括但不限于:个人计算机系统、服务器计算机系统、瘦客户机、厚客户机、手持或膝上设备、基于微处理器的系统、机顶盒、可编程消费电子产品、网络个人电脑、小型计算机系统、大型计算机系统和包括上述任何系统的分布式云计算技术环境,等等。The present invention is applicable to computer systems/servers that can operate with numerous other general purpose or special purpose computing system environments or configurations. Examples of well-known computing systems, environments, and/or configurations suitable for use with computer systems/servers include, but are not limited to, personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, based on Microprocessor systems, set-top boxes, programmable consumer electronics, networked personal computers, small computer systems, mainframe computer systems, and distributed cloud computing technology environments including any of the above, and the like.
计算机系统/服务器可以在由计算机系统执行的计算机系统可执行指令(诸如程序模块)的一般语境下描述。通常,程序模块可以包括例程、程序、目标程序、组件、逻辑、数据结构等等,它们执行特定的任务或者实现特定的抽象数据类型。计算机系统/服务器可以在分布式云计算环境中实施,分布式云计算环境中,任务是由通过通信网络链接的远程处理设备执行的。在分布式云计算环境中,程序模块可以位于包括存储设备的本地或远程计算系统存储介质上。The computer system/server can be described in the general context of computer system executable instructions (such as program modules) being executed by a computer system. Generally, program modules may include routines, programs, target programs, components, logic, data structures, and the like that perform particular tasks or implement particular abstract data types. The computer system/server can be implemented in a distributed cloud computing environment where tasks are performed by remote processing devices that are linked through a communication network. In a distributed cloud computing environment, program modules may be located on a local or remote computing system storage medium including storage devices.
本文中所称的“一个实施例”、“实施例”或者“一个或者多个实施例”意味着,结合实施例描述的特定特征、结构或者特性包括在本发明的至少一个实施例中。此外,请注意,这里“在一个实施例中”的词语例子不一定全指同一个实施例。 "an embodiment," or "an embodiment," or "an embodiment," In addition, it is noted that the phrase "in one embodiment" is not necessarily referring to the same embodiment.

Claims (14)

  1. 一种数据操作方法,包括:A method of data manipulation, comprising:
    接收针对数据的读请求;Receiving a read request for data;
    查找记录的将所述数据写入主库的写入时刻;以及Finding the write time of the record that writes the data to the main library;
    根据所述写入时刻将该读请求发送至主库或者从库以读取该数据。The read request is sent to the main library or the slave library to read the data according to the write time.
  2. 如权利要求1所述的方法,还包括:The method of claim 1 further comprising:
    确定所述写入时刻到当前时刻的时间长度;以及Determining a length of time from the writing time to the current time;
    判断所述时间长度是否大于预设阈值;Determining whether the length of time is greater than a preset threshold;
    其中,根据所述写入时刻将该读请求发送至主库或者从库以读取该数据具体包括:The sending the read request to the main library or the slave library to read the data according to the writing moment specifically includes:
    依据上述判断结果将该读请求发送至主库或者从库以读取该数据。The read request is sent to the main library or the slave library to read the data according to the above judgment result.
  3. 如权利要求2所述的方法,其中,The method of claim 2, wherein
    若所述时间长度大于预设阈值,则将该读请求发送至从库以读取该数据;If the length of time is greater than a preset threshold, sending the read request to the slave library to read the data;
    否则,则将该读请求发送至主库以读取该数据。Otherwise, the read request is sent to the main library to read the data.
  4. 如权利要求1-3中任一项所述的方法,其中,接收针对数据的读请求之前,所述方法还包括:The method of any of claims 1-3, wherein before receiving the read request for the data, the method further comprises:
    接收针对所述数据的写请求;Receiving a write request for the data;
    将所述写请求发送至主库以进行写入;以及Sending the write request to the main library for writing;
    记录所述数据的写入时刻。The write time of the data is recorded.
  5. 如权利要求1-4中任一项所述的方法,其中,所述预设阈值通过以下方式设定:The method of any of claims 1-4, wherein the preset threshold is set by:
    确定所述主库将数据同步到从库的平均时长,将该平均时长设定为所述预设阈值。Determining, by the main library, the data to be synchronized to the average duration of the slave library, and setting the average duration to the preset threshold.
  6. 如权利要求1-4中任一项所述的方法,其中,所述预设阈值通过以下方式设定:The method of any of claims 1-4, wherein the preset threshold is set by:
    确定所述主库将数据同步到从库的最大时长,将该最大时长设定为所述预设阈值。Determining that the main library synchronizes data to a maximum duration of the slave library, and setting the maximum duration to the preset threshold.
  7. 一种数据操作装置,其特征在于,所述装置包括:接收模块、查找 模块、时差模块以及判断处理模块,其中;A data operation device, comprising: receiving module, searching a module, a time difference module, and a judgment processing module, wherein
    所述接收模块,用于接收针对数据的读请求;The receiving module is configured to receive a read request for data;
    所述查找模块,用于查找记录的将所述数据写入主库的写入时刻;The searching module is configured to search for a write moment of writing the data to the main library;
    所述时间模块,用于确定所述写入时刻到当前时刻的时间长度;以及The time module is configured to determine a length of time from the writing time to the current time;
    所述判断处理模块,用于判断所述时间长度是否大于预设阈值,若是,则将该读请求发送至从库以读取该数据,否则,则将该读请求发送至主库以读取该数据。The determining processing module is configured to determine whether the length of time is greater than a preset threshold, and if yes, send the read request to the slave library to read the data; otherwise, send the read request to the main library to read The data.
  8. 如权利要求7所述的装置,其中,所述接收模块还用于接收针对所述数据的写请求。The apparatus of claim 7, wherein the receiving module is further for receiving a write request for the data.
  9. 如权利要求8所述的装置,其中,所述判断处理模块还用于将接收的针对所述数据的写请求发送至主库以进行写入。The apparatus of claim 8, wherein the determination processing module is further configured to send the received write request for the data to a main library for writing.
  10. 如权利要求9所述的装置,其中,所述装置还包括:记录模块,用于记录所述数据写入主库时的写入时刻。The apparatus of claim 9, wherein the apparatus further comprises: a recording module for recording a write time when the data is written to the main library.
  11. 如权利要求7-10中任一项所述的装置,其中,所述预设阈值通过以下方式设定:The apparatus of any of claims 7-10, wherein the preset threshold is set by:
    确定所述主库将数据同步到从库的平均时长,将该平均时长设定为所述预设阈值。Determining, by the main library, the data to be synchronized to the average duration of the slave library, and setting the average duration to the preset threshold.
  12. 如权利要求7-10中任一项所述的装置,其中,所述预设阈值通过以下方式设定:The apparatus of any of claims 7-10, wherein the preset threshold is set by:
    确定所述主库将数据同步到从库的最大时长,将该最大时长设定为所述预设阈值。Determining that the main library synchronizes data to a maximum duration of the slave library, and setting the maximum duration to the preset threshold.
  13. 一种计算机程序,包括计算机可读代码,当所述计算机可读代码在计算设备上运行时,导致所述计算设备执行根据权利要求1-6中的任一项所述的数据操作方法。A computer program comprising computer readable code, when the computer readable code is run on a computing device, causing the computing device to perform the data manipulation method of any of claims 1-6.
  14. 一种计算机可读介质,其中存储了如权利要求13所述的计算机程序。 A computer readable medium storing the computer program of claim 13.
PCT/CN2015/095544 2014-12-12 2015-11-25 Data operation method and device WO2016091069A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410773822.3 2014-12-12
CN201410773822.3A CN104376127B (en) 2014-12-12 2014-12-12 A kind of data manipulation method and device

Publications (1)

Publication Number Publication Date
WO2016091069A1 true WO2016091069A1 (en) 2016-06-16

Family

ID=52555034

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/095544 WO2016091069A1 (en) 2014-12-12 2015-11-25 Data operation method and device

Country Status (2)

Country Link
CN (1) CN104376127B (en)
WO (1) WO2016091069A1 (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107656937A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for realizing read-write data consistency
CN110704000A (en) * 2019-10-10 2020-01-17 北京字节跳动网络技术有限公司 Data processing method and device, electronic equipment and storage medium
CN111581238A (en) * 2020-04-01 2020-08-25 北京奇艺世纪科技有限公司 Information query method and device, electronic equipment and computer readable storage medium
CN112527809A (en) * 2020-12-10 2021-03-19 盛立金融软件开发(杭州)有限公司 Database data writing method, device, equipment and storage medium
CN112965956A (en) * 2021-03-18 2021-06-15 上海东普信息科技有限公司 Database horizontal capacity expansion method, device, equipment and storage medium
CN117251500A (en) * 2023-11-20 2023-12-19 深圳市雁联计算系统有限公司 System and method for dynamic read-write separation of database

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104376127B (en) * 2014-12-12 2018-08-03 北京奇虎科技有限公司 A kind of data manipulation method and device
CN105095423B (en) * 2015-07-15 2018-10-09 北京奇虎科技有限公司 Enumeration data wiring method and device
CN107784021A (en) * 2016-08-31 2018-03-09 北京国双科技有限公司 The method, apparatus and system that control data is deleted
KR20180108939A (en) * 2017-03-23 2018-10-05 에스케이하이닉스 주식회사 Data storage device and operating method thereof
CN108121782B (en) * 2017-12-18 2020-11-10 新华三云计算技术有限公司 Distribution method of query request, database middleware system and electronic equipment
CN114328711A (en) * 2020-09-30 2022-04-12 北京金山云网络技术有限公司 Data processing method and device, computer equipment and storage medium
CN113076343B (en) * 2021-04-30 2024-04-05 北京京东振世信息技术有限公司 Data query method, device, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100287346A1 (en) * 2009-05-07 2010-11-11 Sap Ag Method and system for managing large write-once tables in shadow page databases
CN102591964A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Implementation method and device for data reading-writing splitting system
CN104021200A (en) * 2014-06-16 2014-09-03 北京京东尚科信息技术有限公司 Data synchronizing method and device of database
CN104376127A (en) * 2014-12-12 2015-02-25 北京奇虎科技有限公司 Data manipulation method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100287346A1 (en) * 2009-05-07 2010-11-11 Sap Ag Method and system for managing large write-once tables in shadow page databases
CN102591964A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Implementation method and device for data reading-writing splitting system
CN104021200A (en) * 2014-06-16 2014-09-03 北京京东尚科信息技术有限公司 Data synchronizing method and device of database
CN104376127A (en) * 2014-12-12 2015-02-25 北京奇虎科技有限公司 Data manipulation method and device

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107656937A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for realizing read-write data consistency
CN110704000A (en) * 2019-10-10 2020-01-17 北京字节跳动网络技术有限公司 Data processing method and device, electronic equipment and storage medium
CN111581238A (en) * 2020-04-01 2020-08-25 北京奇艺世纪科技有限公司 Information query method and device, electronic equipment and computer readable storage medium
CN111581238B (en) * 2020-04-01 2023-10-24 北京奇艺世纪科技有限公司 Information query method and device, electronic equipment and computer readable storage medium
CN112527809A (en) * 2020-12-10 2021-03-19 盛立金融软件开发(杭州)有限公司 Database data writing method, device, equipment and storage medium
CN112527809B (en) * 2020-12-10 2023-10-27 盛立安元科技(杭州)股份有限公司 Database data writing method, device, equipment and storage medium
CN112965956A (en) * 2021-03-18 2021-06-15 上海东普信息科技有限公司 Database horizontal capacity expansion method, device, equipment and storage medium
CN117251500A (en) * 2023-11-20 2023-12-19 深圳市雁联计算系统有限公司 System and method for dynamic read-write separation of database
CN117251500B (en) * 2023-11-20 2024-02-09 深圳市雁联计算系统有限公司 Dynamic read-write separation method for database

Also Published As

Publication number Publication date
CN104376127A (en) 2015-02-25
CN104376127B (en) 2018-08-03

Similar Documents

Publication Publication Date Title
WO2016091069A1 (en) Data operation method and device
CN110741342B (en) Blockchain transaction commit ordering
US10311230B2 (en) Anomaly detection in distributed ledger systems
US10255108B2 (en) Parallel execution of blockchain transactions
WO2016101752A1 (en) Method and device for data synchronization
WO2016101718A1 (en) Method and device for complementing data
EP2168042B1 (en) Execution of point-in-time copy operations in continuous mirroring environments
KR20130121937A (en) Data synchronization
US11188560B2 (en) Synchronizing object in local object storage node
US20140108753A1 (en) Merging an out of synchronization indicator and a change recording indicator in response to a failure in consistency group formation
US20160224609A1 (en) Data replication from a cloud-based storage resource
WO2017101642A1 (en) Method and apparatus for upgrading data node of distributed system
US11176110B2 (en) Data updating method and device for a distributed database system
WO2018233630A1 (en) Fault discovery
WO2017113694A1 (en) File synchronizing method, device and system
WO2017084348A1 (en) Management method and apparatus for ip hard disk
WO2016138859A1 (en) Data synchronization method and cluster node
WO2016091085A1 (en) Data transmission method, device, and server
CN111813868B (en) Data synchronization method and device
JP2012510094A5 (en)
WO2016101759A1 (en) Data routing method, data management device and distributed storage system
CN112866302B (en) Method, apparatus, medium and program product for integrity checking of cluster data
WO2016091068A1 (en) Method and device for executing special instruction
WO2016155384A1 (en) Search optimization method, apparatus, and system
US9779105B1 (en) Transaction logging using file-system-specific log files

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: 15867119

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15867119

Country of ref document: EP

Kind code of ref document: A1