[go: up one dir, main page]

CN111259029A - Data read and write batch processing method, server and computer readable storage medium - Google Patents

Data read and write batch processing method, server and computer readable storage medium Download PDF

Info

Publication number
CN111259029A
CN111259029A CN202010044481.1A CN202010044481A CN111259029A CN 111259029 A CN111259029 A CN 111259029A CN 202010044481 A CN202010044481 A CN 202010044481A CN 111259029 A CN111259029 A CN 111259029A
Authority
CN
China
Prior art keywords
read
write
request
task
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010044481.1A
Other languages
Chinese (zh)
Other versions
CN111259029B (en
Inventor
袁彪
张要伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Securities Co Ltd
Original Assignee
Ping An Securities Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Securities Co Ltd filed Critical Ping An Securities Co Ltd
Priority to CN202010044481.1A priority Critical patent/CN111259029B/en
Publication of CN111259029A publication Critical patent/CN111259029A/en
Application granted granted Critical
Publication of CN111259029B publication Critical patent/CN111259029B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/23Updating
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution

Landscapes

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

Abstract

The invention relates to a data processing technology, and discloses a data read-write batch processing method, which comprises the following steps: when batch data read-write requests aiming at a single database or multiple databases are received from a calling party, respectively allocating a unique request ID for each read-write request; creating a storage structure for each read-write request in a hash memory, wherein the storage structure comprises a keyword and a value structure, writing a request ID into the keyword, and writing a connection mark of a calling party, a read-write sql statement and a read-write sql number into the value structure; sending each read-write task of the read-write request to a corresponding database for parallel processing according to the database identifier in each read-write request; and receiving a processing result returned by the database and updating the processing result into the value structure corresponding to the read-write request. The invention also provides a server and a computer readable storage medium. The invention can perform parallel processing on the batch read-write tasks and reduce the time consumption of access.

Description

数据读写批量处理方法、服务器及计算机可读存储介质Data read and write batch processing method, server and computer readable storage medium

技术领域technical field

本发明涉及数据处理技术领域,尤其涉及一种数据读写批量处理方法、服务器及计算机可读存储介质。The present invention relates to the technical field of data processing, and in particular, to a method for batch processing of data reading and writing, a server and a computer-readable storage medium.

背景技术Background technique

目前,在涉及单数据库或多个数据库批量数据读写时,无法做完美处理。针对单数据库批量读写,目前大多数做法是处理模块先执行一个sql任务,等数据库处理返回后,再执行下一个sql任务。若其中读或写处理失败则返回给调用方。针对多数据库批量读写,目前的大多数做法是处理模块先确定第一个sql任务对应的数据表是在哪个数据库,再从该数据库中执行该sql任务,等数据返回后再确定第二个sql任务对应的数据表是在哪个数据库,以此类推,若其中一个sql任务执行失败则返回给调用方。At present, when it involves a single database or batch data reading and writing of multiple databases, it cannot be perfectly processed. For batch reading and writing of a single database, most of the current practice is that the processing module first executes a SQL task, and then executes the next SQL task after the database processing returns. If the read or write processing fails, it is returned to the caller. For multi-database batch read and write, most of the current practice is that the processing module first determines which database the data table corresponding to the first SQL task is located, and then executes the SQL task from the database, and then determines the second one after the data is returned. In which database the data table corresponding to the sql task is located, and so on. If one of the sql tasks fails, it will be returned to the caller.

以上方式的缺陷在于,多个sql任务之间并无先后执行关系,但目前做法为方便简单处理进行顺序执行,耗时过长。并且,每多一类读写均需增加逻辑代码维护,增加人工成本。The disadvantage of the above method is that there is no sequential execution relationship between multiple SQL tasks, but the current practice is to perform sequential execution for convenient and simple processing, which takes too long. Moreover, each additional type of reading and writing requires additional logic code maintenance and labor costs.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明提出一种数据读写批量处理方法、服务器及计算机可读存储介质,以解决至少一个上述技术问题。In view of this, the present invention provides a method for batch processing data read and write, a server and a computer-readable storage medium to solve at least one of the above technical problems.

首先,为实现上述目的,本发明提出一种数据读写批量处理方法,该方法包括步骤:First, in order to achieve the above purpose, the present invention proposes a method for batch processing of data read and write, the method comprising the steps of:

当从调用方接收到针对单数据库或多数据库的批量数据读写请求时,为每个读写请求分别分配唯一的请求ID,所述读写请求中的请求参数包含数据库标识和读写任务,其中每个读写任务包括一个读写sql编号及需要执行的读写sql语句;When a batch data read/write request for a single database or multiple databases is received from the caller, a unique request ID is assigned to each read/write request, and the request parameters in the read/write request include the database identifier and the read/write task, Each read-write task includes a read-write sql number and a read-write sql statement to be executed;

在hash内存中创建针对每个所述读写请求的存储结构,包括关键字和value结构,将所述请求ID写入所述关键字中,并将每个所述读写请求对应的调用方的连接标示、以及所述读写请求中每个读写任务对应的读写sql语句及读写sql编号作为数组,写入所述value结构中;Create a storage structure for each read and write request in the hash memory, including a keyword and a value structure, write the request ID into the keyword, and write the caller corresponding to each read and write request The connection sign, and the read-write sql statement and the read-write sql number corresponding to each read-write task in the read-write request are written into the value structure as an array;

根据每个所述读写请求中的数据库标识将所述读写请求的各个读写任务发送至对应的数据库并行处理;及According to the database identifier in each read and write request, each read and write task of the read and write request is sent to the corresponding database for parallel processing; and

接收数据库返回的针对每个所述读写请求的各个读写任务的处理结果并更新至所述读写请求对应的所述value结构中。The processing result of each read/write task for each read/write request returned by the database is received and updated into the value structure corresponding to the read/write request.

可选地,该方法还包括步骤:Optionally, the method further includes the steps:

根据所述value结构,判断所述读写请求的读写任务是否已全部返回处理结果;According to the value structure, determine whether the read and write tasks of the read and write request have all returned processing results;

当所述读写请求的读写任务已全部返回处理结果时,组合所述读写请求的所有读写任务的处理结果并返回给调用方。When the read-write tasks of the read-write request have all returned processing results, the processing results of all the read-write tasks of the read-write request are combined and returned to the caller.

可选地,在所述根据每个所述读写请求中的数据库标识将所述读写请求的各个读写任务发送至对应的数据库并行处理的步骤中,发送给每个数据库的读写任务数据包含请求ID、读写sql编号、读写sql语句。Optionally, in the step of sending each read-write task of the read-write request to the corresponding database for parallel processing according to the database identifier in each of the read-write requests, the read-write task sent to each database The data includes request ID, read and write SQL numbers, and read and write SQL statements.

可选地,所述处理结果包括请求ID、读写sql编号、任务返回标识和任务返回数据。Optionally, the processing result includes a request ID, a read/write SQL number, a task return identifier, and task return data.

可选地,所述value结构中还包括每个读写任务对应的任务返回标识和任务返回数据,所述接收数据库返回的针对所述读写请求的各个读写任务的处理结果并更新至所述读写请求对应的所述value结构中的步骤包括:Optionally, the value structure also includes a task return identifier and task return data corresponding to each read-write task, and the processing result of each read-write task returned by the receiving database for the read-write request is updated to the corresponding task return identifier. The steps in the value structure corresponding to the read-write request include:

异步接收各个数据库返回的处理结果,根据每个处理结果中的请求ID到hash内存中获取对应的value结构,再根据读写sql编号找出所述value结构中对应的读写任务,更新所述读写任务的任务返回标识和任务返回数据。Asynchronously receive the processing results returned by each database, obtain the corresponding value structure from the hash memory according to the request ID in each processing result, and then find out the corresponding read and write tasks in the value structure according to the read and write SQL numbers, and update the The task return identifier and the task return data of the read and write tasks.

可选地,所述任务返回标识用于标示读写sql语句执行成功与否,返回数值0表示执行成功,非0表示执行失败。Optionally, the task return identifier is used to indicate whether the read-write sql statement is executed successfully or not, and the return value 0 indicates that the execution is successful, and a non-zero value indicates that the execution fails.

可选地,所述任务返回数据用于标示读写sql语句对应的返回数据,当所述读写sql语句为查询任务且执行成功时,返回具体的查询结果数据;当所述读写sql语句为非查询任务或查询任务执行失败时,返回空值null。Optionally, the task return data is used to indicate the return data corresponding to the read-write sql statement, when the read-write sql statement is a query task and the execution is successful, the specific query result data is returned; when the read-write sql statement is When it is a non-query task or a query task fails to execute, it returns null.

可选地,该方法还包括步骤:Optionally, the method further includes the steps:

当所述读写请求的读写任务未全部返回处理结果而需要继续等待时,同时继续处理其他读写请求。When the read and write tasks of the read and write requests do not all return processing results and need to continue to wait, other read and write requests continue to be processed at the same time.

此外,为实现上述目的,本发明还提供一种服务器,包括存储器、处理器,所述存储器上存储有可在所述处理器上运行的数据读写批量处理系统,所述数据读写批量处理系统被所述处理器执行时实现如上述的数据读写批量处理方法的步骤。In addition, in order to achieve the above object, the present invention also provides a server, including a memory and a processor, the memory stores a data read and write batch processing system that can run on the processor, and the data read and write batch processing system When the system is executed by the processor, the steps of the above-mentioned data read and write batch processing method are implemented.

进一步地,为实现上述目的,本发明还提供一种计算机可读存储介质,所述计算机可读存储介质存储有数据读写批量处理系统,所述数据读写批量处理系统可被至少一个处理器执行,以使所述至少一个处理器执行如上述的数据读写批量处理方法的步骤。Further, in order to achieve the above object, the present invention also provides a computer-readable storage medium, the computer-readable storage medium stores a data read-write batch processing system, and the data read-write batch processing system can be processed by at least one processor. Execute, so that the at least one processor executes the steps of the above-mentioned data read and write batch processing method.

相较于现有技术,本发明所提出的数据读写批量处理方法、服务器及计算机可读存储介质,可以提供统一的多数据库读写任务接口,当接收到批量数据读写请求后在hash内存中以每个读写请求唯一的请求ID作为关键字,保存每个读写请求的各个读写任务对应信息,并将批量的读写任务同时发送至相应数据库进行并行处理,在接收到针对每个读写任务返回的处理结果时也写入hash内存中,使得多数据库的批量读写任务既可以并发处理,又不会产生数据混乱,访问耗时大大减少。Compared with the prior art, the data read and write batch processing method, server and computer-readable storage medium proposed by the present invention can provide a unified multi-database read and write task interface. The unique request ID of each read and write request is used as the key to save the corresponding information of each read and write task of each read and write request, and the batch of read and write tasks are sent to the corresponding database for parallel processing. The processing results returned by each read and write task are also written into the hash memory, so that batch read and write tasks of multiple databases can be processed concurrently without data confusion, and the access time is greatly reduced.

附图说明Description of drawings

图1是本发明各个实施例一可选的应用环境架构示意图;1 is a schematic diagram of an optional application environment architecture of each embodiment of the present invention;

图2是图1中的服务器一可选的硬件架构的示意图;Fig. 2 is a schematic diagram of an optional hardware architecture of the server in Fig. 1;

图3是本发明数据读写批量处理系统第一实施例的程序模块示意图;3 is a schematic diagram of a program module of the first embodiment of the data read-write batch processing system of the present invention;

图4是本发明在hash内存中创建的存储结构的示意图;Fig. 4 is the schematic diagram of the storage structure that the present invention creates in hash memory;

图5是本发明数据读写批量处理系统第二实施例的程序模块示意图;5 is a schematic diagram of a program module of the second embodiment of the data read-write batch processing system of the present invention;

图6是本发明数据读写批量处理方法第一实施例的流程示意图;6 is a schematic flowchart of the first embodiment of the data read/write batch processing method of the present invention;

图7是本发明数据读写批量处理方法第二实施例的流程示意图;7 is a schematic flowchart of the second embodiment of the data read/write batch processing method of the present invention;

本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization, functional characteristics and advantages of the present invention will be further described with reference to the accompanying drawings in conjunction with the embodiments.

具体实施方式Detailed ways

为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention, but not to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

需要说明的是,在本发明中涉及“第一”、“第二”等的描述仅用于描述目的,而不能理解为指示或暗示其相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括至少一个该特征。另外,各个实施例之间的技术方案可以相互结合,但是必须是以本领域普通技术人员能够实现为基础,当技术方案的结合出现相互矛盾或无法实现时应当认为这种技术方案的结合不存在,也不在本发明要求的保护范围之内。It should be noted that the descriptions involving "first", "second", etc. in the present invention are only for the purpose of description, and should not be construed as indicating or implying their relative importance or implying the number of indicated technical features . Thus, a feature delimited with "first", "second" may expressly or implicitly include at least one of that feature. In addition, the technical solutions between the various embodiments can be combined with each other, but must be based on the realization by those of ordinary skill in the art. When the combination of technical solutions is contradictory or cannot be realized, it should be considered that the combination of such technical solutions does not exist. , is not within the scope of protection required by the present invention.

参阅图1所示,是本发明各个实施例一可选的应用环境架构示意图。Referring to FIG. 1 , it is a schematic diagram of an optional application environment architecture of each embodiment of the present invention.

在本实施例中,本发明可应用于包括,但不仅限于,调用方1、服务器2、数据库3的应用环境中。其中,所述调用方1可以是移动电话、智能电话、笔记本电脑、数字广播接收器、PDA(个人数字助理)、PAD(平板电脑)、PMP(便携式多媒体播放器)、导航装置、车载装置等可移动设备,以及诸如数字TV、台式计算机、笔记本、服务器等固定终端。所述服务器2可以是机架式服务器、刀片式服务器、塔式服务器或机柜式服务器等计算设备,该服务器2可以是独立的服务器,也可以是多个服务器所组成的服务器集群。In this embodiment, the present invention can be applied to an application environment including, but not limited to, the caller 1 , the server 2 , and the database 3 . Wherein, the caller 1 can be a mobile phone, a smart phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a navigation device, a vehicle-mounted device, etc. Mobile devices, and stationary terminals such as digital TVs, desktop computers, notebooks, servers, etc. The server 2 may be a computing device such as a rack server, a blade server, a tower server or a cabinet server, and the server 2 may be an independent server or a server cluster composed of multiple servers.

所述服务器2通过网络(图中未示出)分别与一个或多个所述调用方1及所述数据库3通信连接,以进行数据传输和交互。所述网络可以是企业内部网(Intranet)、互联网(Internet)、全球移动通讯系统(Global System of Mobile communication,GSM)、宽带码分多址(Wideband Code Division Multiple Access,WCDMA)、4G网络、5G网络、蓝牙(Bluetooth)、Wi-Fi、通话网络等无线或有线网络。The server 2 is connected in communication with one or more of the callers 1 and the database 3 through a network (not shown in the figure), respectively, for data transmission and interaction. The network can be an intranet (Intranet), the Internet (Internet), a Global System of Mobile communication (GSM), a Wideband Code Division Multiple Access (WCDMA), a 4G network, a 5G network Network, Bluetooth (Bluetooth), Wi-Fi, call network and other wireless or wired networks.

其中,每个所述数据库3对应一个数据库访问模块30,通过所述数据库访问模块30,可以接收并处理针对所述数据库3的读写请求,然后返回处理结果。Wherein, each of the databases 3 corresponds to a database access module 30, through which the database access module 30 can receive and process read and write requests for the database 3, and then return the processing results.

参阅图2所示,是本发明服务器2一可选的硬件架构的示意图。Referring to FIG. 2 , it is a schematic diagram of an optional hardware architecture of the server 2 of the present invention.

本实施例中,所述服务器2可包括,但不仅限于,可通过系统总线相互通信连接存储器11、处理器12、网络接口13。需要指出的是,图2仅示出了具有组件11-13的服务器2,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。In this embodiment, the server 2 may include, but is not limited to, the memory 11 , the processor 12 , and the network interface 13 that can communicate with each other through a system bus. It should be pointed out that FIG. 2 only shows the server 2 having the components 11-13, but it should be understood that it is not required to implement all the shown components, and more or less components may be implemented instead.

其中,所述服务器2可以是机架式服务器、刀片式服务器、塔式服务器或机柜式服务器等计算设备,该服务器2可以是独立的服务器,也可以是多个服务器所组成的服务器集群。The server 2 may be a computing device such as a rack server, a blade server, a tower server or a cabinet server, and the server 2 may be an independent server or a server cluster composed of multiple servers.

所述存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘等。在一些实施例中,所述存储器11可以是所述服务器2的内部存储单元,例如该服务器2的硬盘或内存。在另一些实施例中,所述存储器11也可以是所述服务器2的外部存储设备,例如该服务器2上配备的插接式硬盘,智能存储卡(SmartMedia Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。当然,所述存储器11还可以既包括所述服务器2的内部存储单元也包括其外部存储设备。本实施例中,所述存储器11通常用于存储安装于所述服务器2的操作系统和各类应用软件,例如数据读写批量处理系统200的程序代码等。此外,所述存储器11还可以用于暂时地存储已经输出或者将要输出的各类数据。The memory 11 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (eg, SD or DX memory, etc.), random access memory (RAM), static Random Access Memory (SRAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), Programmable Read Only Memory (PROM), Magnetic Memory, Magnetic Disk, Optical Disk, etc. In some embodiments, the memory 11 may be an internal storage unit of the server 2 , such as a hard disk or a memory of the server 2 . In other embodiments, the memory 11 may also be an external storage device of the server 2, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital) equipped on the server 2 , SD) card, flash memory card (Flash Card) and so on. Of course, the memory 11 may also include both the internal storage unit of the server 2 and its external storage device. In this embodiment, the memory 11 is generally used to store the operating system and various application software installed on the server 2 , such as program codes of the data read and write batch processing system 200 . In addition, the memory 11 can also be used to temporarily store various types of data that have been output or will be output.

所述处理器12在一些实施例中可以是中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器、或其他数据处理芯片。该处理器12通常用于控制所述服务器2的总体操作。本实施例中,所述处理器12用于运行所述存储器11中存储的程序代码或者处理数据,例如运行所述的数据读写批量处理系统200等。In some embodiments, the processor 12 may be a central processing unit (Central Processing Unit, CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. This processor 12 is typically used to control the overall operation of the server 2 . In this embodiment, the processor 12 is configured to run program codes or process data stored in the memory 11 , for example, run the data read and write batch processing system 200 and the like.

所述网络接口13可包括无线网络接口或有线网络接口,该网络接口13通常用于在所述服务器2与其他电子设备之间建立通信连接。The network interface 13 may include a wireless network interface or a wired network interface, and the network interface 13 is generally used to establish a communication connection between the server 2 and other electronic devices.

至此,己经详细介绍了本发明的应用环境架构及相关设备的硬件结构和功能。下面,将基于上述介绍提出本发明的各个实施例。So far, the application environment architecture of the present invention and the hardware structure and functions of the related devices have been described in detail. In the following, various embodiments of the present invention will be proposed based on the above description.

首先,本发明提出一种数据读写批量处理系统200。First, the present invention proposes a data read/write batch processing system 200 .

参阅图3所示,是本发明数据读写批量处理系统200第一实施例的程序模块图。Referring to FIG. 3 , it is a program module diagram of the first embodiment of the data read/write batch processing system 200 of the present invention.

本实施例中,所述数据读写批量处理系统200包括一系列的存储于存储器11上的计算机程序指令,当该计算机程序指令被处理器12执行时,可以实现本发明各实施例的数据读写批量处理操作。在一些实施例中,基于该计算机程序指令各部分所实现的特定的操作,数据读写批量处理系统200可以被划分为一个或多个模块。例如,在图3中,所述数据读写批量处理系统200可以被分割成分配模块201、保存模块202、发送模块203、更新模块204。其中:In this embodiment, the data read and write batch processing system 200 includes a series of computer program instructions stored in the memory 11 , and when the computer program instructions are executed by the processor 12 , the data read and write according to the embodiments of the present invention can be implemented. Write batch operations. In some embodiments, the data read and write batch processing system 200 may be divided into one or more modules based on the specific operations implemented by the various parts of the computer program instructions. For example, in FIG. 3 , the data read/write batch processing system 200 may be divided into an allocation module 201 , a storage module 202 , a transmission module 203 , and an update module 204 . in:

所述分配模块201,用于为接收到的每个读写请求分配唯一的请求ID。The assigning module 201 is configured to assign a unique request ID to each read and write request received.

具体地,调用方1采用json格式向服务器2发起针对单个数据库3或多个数据库3的批量数据读写请求。所述读写请求中包含数据库标识(db_id)、读写sql编号(sql_id,同一笔请求中sql_id不能相同)及需要执行的sql语句等请求参数。其中数据库标识用来标示数据库访问模块30,如A表示是通过数据库访问模块A访问数据库A。每个读写sql编号及对应的sql语句表示一个读写任务。每个读写请求可能包括一个或多个数据库标识和读写任务。所述分配模块201接收所述读写请求,并为每个所述读写请求分配唯一的请求ID,即request_id。Specifically, the caller 1 initiates a batch data read/write request for a single database 3 or multiple databases 3 to the server 2 in json format. The read-write request includes request parameters such as a database identifier (db_id), a read-write SQL number (sql_id, the sql_id cannot be the same in the same request), and a SQL statement to be executed. The database identifier is used to identify the database access module 30 , for example, A indicates that the database A is accessed through the database access module A. Each read and write SQL number and the corresponding SQL statement represent a read and write task. Each read and write request may include one or more database identification and read and write tasks. The allocation module 201 receives the read and write requests, and allocates a unique request ID, ie request_id, to each of the read and write requests.

针对单个数据库3的批量数据读写请求,例如一个数据库中有学生表(stu)、老师表(teac)、学生成绩表(stu_score),现在接收到一个针对该数据库的批量数据读写请求,需同时查询学生表中“小王”的数据(sql1:select*from stu where stu_name=’小王’)、查询老师表中“张老师”的数据(sql2:select*from teac where teac_name=’张老师’)、更新学生成绩表中“小李”的数据(sql3:update stu_score set score=90where stu_name=’小李’)。所述分配模块201可以为该读写请求分配一个唯一的请求ID,例如178652986。A batch data read and write request for a single database 3, for example, a database has a student table (stu), a teacher table (teac), and a student score table (stu_score), and now a batch data read and write request for this database is received. At the same time, query the data of "Xiao Wang" in the student table (sql1:select*from stu where stu_name='Xiaowang'), and query the data of "Mr. Zhang" in the teacher table (sql2:select*from teac where teac_name='Mr.Zhang' '), update the data of "Xiao Li" in the student score table (sql3:update stu_score set score=90where stu_name='Xiao Li'). The allocation module 201 can allocate a unique request ID, such as 178652986, to the read and write request.

针对多个数据库3的批量数据读写请求,例如有数据库A包含学生表(stu)、老师表(teac),数据库B包含学生成绩表(stu_score),现在接收到一个针对数据库A和B的批量数据读写请求,需同时查询数据库A的学生表中的“小张”的数据和老师表中的“张三”的数据(sql1:select*from stu where stu_name=’小张’;sql2:select*from teac whereteac_name=’张三’)、查询数据库B的学生成绩表中“小李”的数据及修改“小明”的数据(sql3:select*from stu_score where stu_name=’小李’;sql4:update stu_score setscore=90where stu_name=’小明’)。同样地,所述分配模块201也可以为该读写请求分配一个唯一的请求ID,例如178652987。Batch data read and write requests for multiple databases 3, for example, database A contains student table (stu), teacher table (teac), database B contains student score table (stu_score), and now a batch for database A and B is received For data read and write requests, it is necessary to query the data of "Xiao Zhang" in the student table of database A and the data of "Zhang San" in the teacher table (sql1:select*from stu where stu_name='Xiao Zhang'; sql2:select *from teac whereteac_name='Zhang San'), query the data of "Xiao Li" in the student transcript of database B and modify the data of "Xiao Ming" (sql3:select*from stu_score where stu_name='Xiao Li'; sql4:update stu_score setscore=90where stu_name='Xiao Ming'). Similarly, the allocation module 201 can also allocate a unique request ID, such as 178652987, to the read and write request.

所述保存模块202,用于将所述读写请求写入hash内存。The saving module 202 is configured to write the read and write requests into the hash memory.

具体地,在hash内存中创建针对每个所述读写请求的存储结构,每个所述存储结构包括关键字(key)和value结构。将所述读写请求写入hash内存,其中,请求ID即request_id作为hash内存中所述读写请求对应的key,并且将所述读写请求对应的调用方连接标示tcp socket、以及所述读写请求中每个读写任务对应的读写sql语句及读写sql_id作为数组,写入所述请求ID对应的value结构中。另外,该value结构的数组中还包含任务返回标识(sql_ret)和任务返回数据(sql_data)两项,用于后续写入针对所述读写请求返回的处理结果。参阅图4所示,为在hash内存中创建的所述存储结构的示意图。Specifically, a storage structure for each of the read and write requests is created in the hash memory, and each of the storage structures includes a key (key) and a value structure. Write the read-write request into the hash memory, wherein the request ID, that is, request_id, is used as the key corresponding to the read-write request in the hash memory, and the caller connection corresponding to the read-write request is marked tcp socket and the read/write request. The read-write sql statement and the read-write sql_id corresponding to each read-write task in the write request are taken as an array and written into the value structure corresponding to the request ID. In addition, the array of the value structure also includes two items, a task return identifier (sql_ret) and a task return data (sql_data), which are used for subsequent writing of the processing result returned for the read and write request. Referring to FIG. 4, it is a schematic diagram of the storage structure created in the hash memory.

例如,以上述两个读写请求的请求ID作为key,将这两个读写请求的信息在hash内存中进行保存,并分别以这两个读写请求的调用方连接标示、读写sql语句及读写sql_id作为数组,写入各自的请求ID对应的hash内存的value结构中。以上述针对数据库A和B的读写请求为例,在hash内存中以该读写请求的请求ID“178652987”作为key,以调用方连接标示、读写sql语句(select*from stu where stu_name=’小张’;select*from teac whereteac_name=’张三’;select*from stu_score where stu_name=’小李’;update stu_score set score=90where stu_name=’小明’)及读写sql_id(sql1、sql2、sql3、sql4)作为数组,写入对应的value结构。For example, using the request IDs of the above two read and write requests as the key, the information of the two read and write requests is stored in the hash memory, and the caller connection of the two read and write requests is used to identify, read and write SQL statements respectively. And read and write sql_id as an array, and write it into the value structure of the hash memory corresponding to the respective request ID. Taking the above read and write requests for databases A and B as an example, the request ID "178652987" of the read and write requests is used as the key in the hash memory, and the caller connection is marked to read and write SQL statements (select*from stu where stu_name= 'Xiao Zhang'; select*from teac whereteac_name='Zhang San'; select*from stu_score where stu_name='Xiao Li'; update stu_score set score=90where stu_name='Xiao Ming') and read and write sql_id (sql1, sql2, sql3 , sql4) as an array, write the corresponding value structure.

所述发送模块203,用于根据所述读写请求中的数据库标识将所述读写请求的各个读写任务发送至对应的数据库3并行处理。The sending module 203 is configured to send each read-write task of the read-write request to the corresponding database 3 for parallel processing according to the database identifier in the read-write request.

具体地,获取所述读写请求中的请求参数,根据请求参数中的数据库标识即db_id,将属于不同数据库3(或者同一个数据库3)的多个数据读写任务同时发送到对应的数据库3。发送给每个数据库3的读写任务数据包含请求ID(request_id)、任务ID(task_id,与sql_id一致)、读写sql语句等。每个数据库3包含对应的数据库访问模块30,用于接收并处理该数据库3的读写请求,然后返回处理结果。返回的处理结果包含请求ID(request_id)、任务ID(task_id,与sql_id一致)、任务返回标识(sql_ret)、任务返回数据(sql_data)等。其中,任务返回标识用来标示sql语句执行成功与否,返回数值0表示执行成功,非0表示执行失败。任务返回数据用来标示sql语句对应的返回数据,当该sql语句为查询任务且执行成功时,返回具体的查询结果数据,当该sql语句为非查询任务时或查询执行失败时,返回空值null。Specifically, obtain the request parameters in the read-write request, and send multiple data read-write tasks belonging to different databases 3 (or the same database 3 ) to the corresponding database 3 at the same time according to the database identifier in the request parameters, that is, db_id . The read and write task data sent to each database 3 includes a request ID (request_id), a task ID (task_id, which is consistent with sql_id), read and write SQL statements, and the like. Each database 3 includes a corresponding database access module 30 for receiving and processing read and write requests of the database 3, and then returning the processing result. The returned processing result includes a request ID (request_id), a task ID (task_id, which is consistent with sql_id), a task return identifier (sql_ret), and task return data (sql_data). Among them, the task return identifier is used to indicate whether the SQL statement is executed successfully or not. The return value of 0 means the execution is successful, and non-0 means the execution fails. The task return data is used to indicate the return data corresponding to the sql statement. When the sql statement is a query task and the execution is successful, the specific query result data is returned. When the sql statement is a non-query task or the query execution fails, a null value is returned. null.

例如,上述数据库B针对查询学生成绩表中“小李”的数据(sql3:select*fromstu_score where stu_name=’小李’)这个查询任务,返回的处理结果中请求ID为178652987,任务ID为3,任务返回标识为0,任务返回数据为{“stu_name”:“小李”,“stu_score”:“95”};针对修改学生成绩表中“小明”的数据(sql4:update stu_score set score=90where stu_name=’小明’)这个非查询任务,返回的处理结果中请求ID为178652987,任务ID为4,任务返回标识为0,任务返回数据为null。For example, for the query task of querying the data of "Xiao Li" in the student's score table (sql3:select*fromstu_score where stu_name='Xiao Li'), the returned processing result in database B is 178652987 for the request ID and 3 for the task ID. The task return identifier is 0, and the task return data is {"stu_name": "Xiao Li", "stu_score": "95"}; for modifying the data of "Xiao Ming" in the student score table (sql4:update stu_score set score=90where stu_name ='Xiao Ming') This non-query task, in the returned processing result, the request ID is 178652987, the task ID is 4, the task return ID is 0, and the task return data is null.

在本实施例中,多个读写请求中的所有读写任务可以同时发送至对应数据库3中,所有子任务并行处理,耗时是其中一个最大子任务的耗时。In this embodiment, all read and write tasks in multiple read and write requests can be sent to the corresponding database 3 at the same time, all subtasks are processed in parallel, and the time consumption is the time consumption of one of the largest subtasks.

所述更新模块204,用于接收数据库3返回的处理结果并更新至所述读写请求对应的value结构中。The updating module 204 is configured to receive the processing result returned by the database 3 and update it into the value structure corresponding to the read-write request.

具体地,所述更新模块204异步接收各个数据库3返回的针对每个所述读写请求的各个读写任务的处理结果,根据每个处理结果中的请求ID到hash内存中获取对应的value结构,再根据sql_id(与任务ID一致)找出value结构中对应的读写任务,更新该读写任务的任务返回标识和任务返回数据。Specifically, the update module 204 asynchronously receives the processing results of each read/write task returned by each database 3 for each of the read/write requests, and obtains the corresponding value structure from the hash memory according to the request ID in each processing result , and then find the corresponding read/write task in the value structure according to the sql_id (consistent with the task ID), and update the task return identifier and task return data of the read/write task.

例如,将上述数据库B返回的处理结果更新至hash内存中请求ID“178652987”对应的value结构中。For example, update the processing result returned by the above database B to the value structure corresponding to the request ID "178652987" in the hash memory.

本实施例提供的数据读写批量处理系统,可以提供统一的多数据库读写任务接口,当接收到批量数据读写请求后在hash内存中以每个读写请求唯一的请求ID作为关键字,保存每个读写请求的各个读写任务对应信息,并将批量的读写任务同时发送至相应数据库进行并行处理,在接收到针对每个读写任务返回的处理结果时也写入hash内存中,使得多数据库的批量读写任务既可以并发处理,又不会产生数据混乱,访问耗时大大减少。The data read/write batch processing system provided by this embodiment can provide a unified multi-database read/write task interface. After receiving a batch data read/write request, the unique request ID of each read/write request is used as a key in the hash memory. Save the corresponding information of each read and write task of each read and write request, and send the batch of read and write tasks to the corresponding database for parallel processing, and also write the processing result returned for each read and write task into the hash memory , so that the batch read and write tasks of multiple databases can be processed concurrently without data confusion, and the access time is greatly reduced.

参阅图5所示,是本发明数据读写批量处理系统200第二实施例的程序模块图。本实施例中,所述的数据读写批量处理系统200除了包括第一实施例中的所述分配模块201、保存模块202、发送模块203、更新模块204之外,还包括判断模块205、返回模块206。Referring to FIG. 5, it is a program module diagram of the second embodiment of the data read/write batch processing system 200 of the present invention. In this embodiment, the data read and write batch processing system 200 includes, in addition to the allocation module 201 , the storage module 202 , the transmission module 203 , and the update module 204 in the first embodiment, a judgment module 205 , a return module 206.

所述判断模块205,用于判断所述读写请求的读写任务是否已全部返回处理结果。The judging module 205 is configured to judge whether the read and write tasks of the read and write request have all returned processing results.

具体地,针对每个读写请求,判断对应value结构中的读写任务是否已全部返回处理结果。若未全部返回,则继续等待相应数据库3返回处理结果,直至该读写请求的读写任务全部返回处理结果。Specifically, for each read/write request, it is determined whether all read/write tasks in the corresponding value structure have returned processing results. If not all are returned, continue to wait for the corresponding database 3 to return the processing result, until all the read-write tasks of the read-write request return the processing result.

值得注意的是,在本实施例中,当所述读写请求的读写任务未全部返回处理结果而需要继续等待时,可以同时继续处理其他读写请求,即其他读写请求不用排队等待,不会影响其他读写请求的处理时间。It is worth noting that, in this embodiment, when the read and write tasks of the read and write requests have not all returned processing results and need to continue to wait, other read and write requests can be processed at the same time, that is, other read and write requests do not need to wait in line, Does not affect the processing time of other read and write requests.

所述返回模块206,用于当所述读写请求的读写任务已全部返回处理结果时,组合处理结果并返回给调用方1。The returning module 206 is configured to combine the processing results and return them to the caller 1 when all the reading and writing tasks of the reading and writing request have returned processing results.

具体地,若所述读写请求的读写任务已经全部返回处理结果,则获取对应value结构中的调用方连接标示,并组合所述读写请求的所有读写任务的处理结果,将组合后的结果返回给调用方1。返回给调用方1的组合处理结果中包含数据库ID(db_id)、读写sql_id、任务返回标识(sql_ret)、任务返回数据(sql_data)等数据。Specifically, if all the read/write tasks of the read/write request have returned processing results, the caller connection flag in the corresponding value structure is obtained, and the processing results of all read/write tasks of the read/write request are combined. The result is returned to caller 1. The combined processing result returned to the caller 1 includes database ID (db_id), read/write sql_id, task return identifier (sql_ret), task return data (sql_data) and other data.

例如,针对上述请求ID为178652987的读写请求,判断对应value结构中的四个读写任务(sql1:select*from stu where stu_name=’小张’;sql2:select*from teacwhere teac_name=’张三’;sql3:select*from stu_score where stu_name=’小李’;sql4:update stu_score set score=90where stu_name=’小明’)是否已全部返回,即这四个任务ID对应的任务返回标识和任务返回数据是否已更新。若未全部返回,例如仅数据库B返回但数据库A还未返回,则继续等待数据库A返回的处理结果(此时可以同时处理其他读写请求)。若已全部返回,则将所有四个任务的处理结果组合起来,返回给调用方1。For example, for the read/write request whose request ID is 178652987, determine the four read/write tasks in the corresponding value structure (sql1:select*from stu where stu_name='Xiao Zhang'; sql2:select*from teac where teac_name='Zhang San' '; sql3:select*from stu_score where stu_name='Xiao Li';sql4:update stu_score set score=90where stu_name='Xiao Ming') have all been returned, that is, the task return identifier and task return data corresponding to these four task IDs Is it updated. If not all are returned, for example, only database B returns but database A has not returned, continue to wait for the processing result returned by database A (other read and write requests can be processed at the same time). If all have been returned, the processing results of all four tasks are combined and returned to the caller 1.

值得注意的是,所述数据读写批量处理系统200的各个模块及各个数据库3的数据库访问模块30均可配置多个进程同步处理。本实施例是批量处理针对单个数据库3或多个数据库3的读写请求,可以同时处理多个不同的读写请求,即单个或多个数据库3的多个读请求与多个写请求可以混在一起批量并发处理。It is worth noting that, each module of the data read/write batch processing system 200 and the database access module 30 of each database 3 can be configured with multiple processes for synchronous processing. This embodiment processes read and write requests for a single database 3 or multiple databases 3 in batches, and can process multiple different read and write requests at the same time, that is, multiple read requests and multiple write requests of a single or multiple databases 3 can be mixed Batch and concurrent processing together.

本实施例提供的数据读写批量处理系统,可以提供统一的多数据库读写任务接口,对于批量的读写任务同时发送至相应数据库进行并行处理,并发能力高,访问耗时大大减少。调用方只需根据统一接口组装需要访问的数据库的读写任务列表,再根据统一接口返回的处理结果数据做逻辑处理即可,达到业务层与数据访问层抽象隔离的效果,提高生产效率。并且,本实施例的读写不依赖具体表,字段均是抽象获取,支持动态扩展表而不用修改代码,提高生产能力。另外,本实施例支持分布式部署和配置多进程处理,大大利用CPU多核硬件资源,提高处理能力。The data read and write batch processing system provided by this embodiment can provide a unified multi-database read and write task interface, and the batch read and write tasks are simultaneously sent to the corresponding database for parallel processing, with high concurrency capability and greatly reduced access time. The caller only needs to assemble the read and write task list of the database to be accessed according to the unified interface, and then perform logical processing according to the processing result data returned by the unified interface, so as to achieve the effect of abstract isolation between the business layer and the data access layer, and improve production efficiency. In addition, the reading and writing of this embodiment does not depend on the specific table, and the fields are abstractly obtained, which supports dynamic expansion of the table without modifying the code, and improves the production capacity. In addition, this embodiment supports distributed deployment and configuration of multi-process processing, greatly utilizes CPU multi-core hardware resources, and improves processing capability.

此外,本发明还提出一种数据读写批量处理方法。In addition, the present invention also provides a batch processing method for data read and write.

参阅图6所示,是本发明数据读写批量处理方法第一实施例的流程示意图。在本实施例中,根据不同的需求,图6所示的流程图中的步骤的执行顺序可以改变,某些步骤可以省略。Referring to FIG. 6 , it is a schematic flowchart of the first embodiment of the data read/write batch processing method of the present invention. In this embodiment, according to different requirements, the execution order of the steps in the flowchart shown in FIG. 6 can be changed, and some steps can be omitted.

该方法包括以下步骤:The method includes the following steps:

步骤S400,为接收到的每个读写请求分配唯一的请求ID。Step S400, assign a unique request ID to each read and write request received.

具体地,调用方1采用json格式向服务器2发起针对单个数据库3或多个数据库3的批量数据读写请求。所述读写请求中包含数据库标识(db_id)、读写sql编号(sql_id,同一笔请求中sql_id不能相同)及需要执行的sql语句等请求参数。其中数据库标识用来标示数据库访问模块30,如A表示是通过数据库访问模块A访问数据库A。每个读写sql编号及对应的sql语句表示一个读写任务。每个读写请求可能包括一个或多个数据库标识和读写任务。所述服务器2接收所述读写请求,并为每个所述读写请求分配唯一的请求ID,即request_id。Specifically, the caller 1 initiates a batch data read/write request for a single database 3 or multiple databases 3 to the server 2 in json format. The read-write request includes request parameters such as a database identifier (db_id), a read-write SQL number (sql_id, the sql_id cannot be the same in the same request), and a SQL statement to be executed. The database identifier is used to identify the database access module 30 , for example, A indicates that the database A is accessed through the database access module A. Each read and write SQL number and the corresponding SQL statement represent a read and write task. Each read and write request may include one or more database identification and read and write tasks. The server 2 receives the read and write requests, and assigns a unique request ID, ie, request_id, to each of the read and write requests.

针对单个数据库3的批量数据读写请求,例如一个数据库中有学生表(stu)、老师表(teac)、学生成绩表(stu_score),现在接收到一个针对该数据库的批量数据读写请求,需同时查询学生表中“小王”的数据(sql1:select*from stu where stu_name=’小王’)、查询老师表中“张老师”的数据(sql2:select*from teac where teac_name=’张老师’)、更新学生成绩表中“小李”的数据(sql3:update stu_score set score=90where stu_name=’小李’)。所述服务器2可以为该读写请求分配一个唯一的请求ID,例如178652986。A batch data read and write request for a single database 3, for example, a database has a student table (stu), a teacher table (teac), and a student score table (stu_score), and now a batch data read and write request for this database is received. At the same time, query the data of "Xiao Wang" in the student table (sql1:select*from stu where stu_name='Xiaowang'), and query the data of "Mr. Zhang" in the teacher table (sql2:select*from teac where teac_name='Mr.Zhang' '), update the data of "Xiao Li" in the student score table (sql3:update stu_score set score=90where stu_name='Xiao Li'). The server 2 can assign a unique request ID, such as 178652986, to the read and write request.

针对多个数据库3的批量数据读写请求,例如有数据库A包含学生表(stu)、老师表(teac),数据库B包含学生成绩表(stu_score),现在接收到一个针对数据库A和B的批量数据读写请求,需同时查询数据库A的学生表中的“小张”的数据和老师表中的“张三”的数据(sql1:select*from stu where stu_name=’小张’;sql2:select*from teac whereteac_name=’张三’)、查询数据库B的学生成绩表中“小李”的数据及修改“小明”的数据(sql3:select*from stu_score where stu_name=’小李’;sql4:update stu_score setscore=90where stu_name=’小明’)。同样地,所述服务器2也可以为该读写请求分配一个唯一的请求ID,例如178652987。Batch data read and write requests for multiple databases 3, for example, database A contains student table (stu), teacher table (teac), database B contains student score table (stu_score), and now a batch for database A and B is received For data read and write requests, it is necessary to query the data of "Xiao Zhang" in the student table of database A and the data of "Zhang San" in the teacher table (sql1:select*from stu where stu_name='Xiao Zhang'; sql2:select *from teac whereteac_name='Zhang San'), query the data of "Xiao Li" in the student transcript of database B and modify the data of "Xiao Ming" (sql3:select*from stu_score where stu_name='Xiao Li'; sql4:update stu_score setscore=90where stu_name='Xiao Ming'). Similarly, the server 2 can also assign a unique request ID, such as 178652987, to the read and write request.

步骤S402,将所述读写请求写入hash内存。Step S402, write the read/write request into the hash memory.

具体地,在hash内存中创建针对每个所述读写请求的存储结构,每个所述存储结构包括关键字(key)和value结构。将所述读写请求写入hash内存,其中,请求ID即request_id作为hash内存中所述读写请求对应的key,并且将所述读写请求对应的调用方连接标示tcp socket、以及所述读写请求中每个读写任务对应的读写sql语句及读写sql_id作为数组,写入所述请求ID对应的value结构中。另外,该value结构的数组中还包含任务返回标识(sql_ret)和任务返回数据(sql_data)两项,用于后续写入针对所述读写请求返回的处理结果。Specifically, a storage structure for each of the read and write requests is created in the hash memory, and each of the storage structures includes a key (key) and a value structure. Write the read-write request into the hash memory, wherein the request ID, that is, request_id, is used as the key corresponding to the read-write request in the hash memory, and the caller connection corresponding to the read-write request is marked tcp socket and the read/write request. The read-write sql statement and the read-write sql_id corresponding to each read-write task in the write request are taken as an array and written into the value structure corresponding to the request ID. In addition, the array of the value structure also includes two items, a task return identifier (sql_ret) and a task return data (sql_data), which are used for subsequent writing of the processing result returned for the read and write request.

例如,以上述两个读写请求的请求ID作为key,将这两个读写请求的信息在hash内存中进行保存,并分别以这两个读写请求的调用方连接标示、读写sql语句及读写sql_id作为数组,写入各自的请求ID对应的hash内存的value结构中。以上述针对数据库A和B的读写请求为例,在hash内存中以该读写请求的请求ID“178652987”作为key,以调用方连接标示、读写sql语句(select*from stu where stu_name=’小张’;select*from teac whereteac_name=’张三’;select*from stu_score where stu_name=’小李’;update stu_score set score=90where stu_name=’小明’)及读写sql_id(sql1、sql2、sql3、sql4)作为数组,写入对应的value结构。For example, using the request IDs of the above two read and write requests as the key, the information of the two read and write requests is stored in the hash memory, and the caller connection of the two read and write requests is used to identify, read and write SQL statements respectively. And read and write sql_id as an array, and write it into the value structure of the hash memory corresponding to the respective request ID. Taking the above read and write requests for databases A and B as an example, the request ID "178652987" of the read and write requests is used as the key in the hash memory, and the caller connection is marked to read and write SQL statements (select*from stu where stu_name= 'Xiao Zhang'; select*from teac whereteac_name='Zhang San'; select*from stu_score where stu_name='Xiao Li'; update stu_score set score=90where stu_name='Xiao Ming') and read and write sql_id (sql1, sql2, sql3 , sql4) as an array, write the corresponding value structure.

步骤S404,根据所述读写请求中的数据库标识将所述读写请求的各个读写任务发送至对应的数据库3并行处理。Step S404, according to the database identifier in the read/write request, send each read/write task of the read/write request to the corresponding database 3 for parallel processing.

具体地,获取所述读写请求中的请求参数,根据请求参数中的数据库标识即db_id,将属于不同数据库3(或者同一个数据库3)的多个数据读写任务同时发送到对应的数据库3。发送给每个数据库3的读写任务数据包含请求ID(request_id)、任务ID(task_id,与sql_id一致)、读写sql语句等。每个数据库3包含对应的数据库访问模块30,用于接收并处理该数据库3的读写请求,然后返回处理结果。返回的处理结果包含请求ID(request_id)、任务ID(task_id,与sql_id一致)、任务返回标识(sql_ret)、任务返回数据(sql_data)等。其中,任务返回标识用来标示sql语句执行成功与否,返回数值0表示执行成功,非0表示执行失败。任务返回数据用来标示sql语句对应的返回数据,当该sql语句为查询任务且执行成功时,返回具体的查询结果数据,当该sql语句为非查询任务时或查询执行失败时,返回空值null。Specifically, obtain the request parameters in the read-write request, and send multiple data read-write tasks belonging to different databases 3 (or the same database 3 ) to the corresponding database 3 at the same time according to the database identifier in the request parameters, that is, db_id . The read and write task data sent to each database 3 includes a request ID (request_id), a task ID (task_id, which is consistent with sql_id), read and write SQL statements, and the like. Each database 3 includes a corresponding database access module 30 for receiving and processing read and write requests of the database 3, and then returning the processing result. The returned processing result includes a request ID (request_id), a task ID (task_id, which is consistent with sql_id), a task return identifier (sql_ret), and task return data (sql_data). Among them, the task return identifier is used to indicate whether the SQL statement is executed successfully or not. The return value of 0 means the execution is successful, and non-0 means the execution fails. The task return data is used to indicate the return data corresponding to the sql statement. When the sql statement is a query task and the execution is successful, the specific query result data is returned. When the sql statement is a non-query task or the query execution fails, a null value is returned. null.

例如,上述数据库B针对查询学生成绩表中“小李”的数据(sql3:select*fromstu_score where stu_name=’小李’)这个查询任务,返回的处理结果中请求ID为178652987,任务ID为3,任务返回标识为0,任务返回数据为{“stu_name”:“小李”,“stu_score”:“95”};针对修改学生成绩表中“小明”的数据(sql4:update stu_score set score=90where stu_name=’小明’)这个非查询任务,返回的处理结果中请求ID为178652987,任务ID为4,任务返回标识为0,任务返回数据为null。For example, for the query task of querying the data of "Xiao Li" in the student's score table (sql3:select*fromstu_score where stu_name='Xiao Li'), the returned processing result in database B is 178652987 for the request ID and 3 for the task ID. The task return identifier is 0, and the task return data is {"stu_name": "Xiao Li", "stu_score": "95"}; for modifying the data of "Xiao Ming" in the student score table (sql4:update stu_score set score=90where stu_name ='Xiao Ming') This non-query task, in the returned processing result, the request ID is 178652987, the task ID is 4, the task return ID is 0, and the task return data is null.

在本实施例中,多个读写请求中的所有读写任务可以同时发送至对应数据库3中,所有子任务并行处理,耗时是其中一个最大子任务的耗时。In this embodiment, all read and write tasks in multiple read and write requests can be sent to the corresponding database 3 at the same time, all subtasks are processed in parallel, and the time consumption is the time consumption of one of the largest subtasks.

步骤S406,接收数据库3返回的处理结果并更新至所述读写请求对应的value结构中。Step S406, the processing result returned by the database 3 is received and updated into the value structure corresponding to the read and write request.

具体地,所述服务器2异步接收各个数据库3返回的针对每个所述读写请求的各个读写任务的处理结果,根据每个处理结果中的请求ID到hash内存中获取对应的value结构,再根据sql_id(与任务ID一致)找出value结构中对应的读写任务,更新该读写任务的任务返回标识和任务返回数据。Specifically, the server 2 asynchronously receives the processing results of each read and write task returned by each database 3 for each of the read and write requests, and obtains the corresponding value structure from the hash memory according to the request ID in each processing result, Then find out the corresponding read/write task in the value structure according to sql_id (consistent with the task ID), and update the task return identifier and task return data of the read/write task.

例如,将上述数据库B返回的处理结果更新至hash内存中请求ID“178652987”对应的value结构中。For example, update the processing result returned by the above database B to the value structure corresponding to the request ID "178652987" in the hash memory.

本实施例提供的数据读写批量处理方法,可以提供统一的多数据库读写任务接口,当接收到批量数据读写请求后在hash内存中以每个读写请求唯一的请求ID作为关键字,保存每个读写请求的各个读写任务对应信息,并将批量的读写任务同时发送至相应数据库进行并行处理,在接收到针对每个读写任务返回的处理结果时也写入hash内存中,使得多数据库的批量读写任务既可以并发处理,又不会产生数据混乱,访问耗时大大减少。The data read and write batch processing method provided by this embodiment can provide a unified multi-database read and write task interface. After receiving a batch data read and write request, the unique request ID of each read and write request is used as a key in the hash memory, Save the corresponding information of each read and write task of each read and write request, and send the batch of read and write tasks to the corresponding database for parallel processing, and also write the processing result returned for each read and write task into the hash memory , so that the batch read and write tasks of multiple databases can be processed concurrently without data confusion, and the access time is greatly reduced.

如图7所示,是本发明数据读写批量处理方法的第二实施例的流程示意图。本实施例中,所述数据读写批量处理方法的步骤S500-S506与第一实施例的步骤S400-S406相类似,区别在于该方法还包括步骤S508-S510。As shown in FIG. 7 , it is a schematic flowchart of the second embodiment of the data read and write batch processing method of the present invention. In this embodiment, steps S500-S506 of the data read/write batch processing method are similar to steps S400-S406 of the first embodiment, the difference is that the method further includes steps S508-S510.

该方法包括以下步骤:The method includes the following steps:

步骤S500,为接收到的每个读写请求分配唯一的请求ID。Step S500, assigning a unique request ID to each read and write request received.

具体地,调用方1采用json格式向服务器2发起针对单个数据库3或多个数据库3的批量数据读写请求。所述读写请求中包含数据库标识(db_id)、读写sql编号(sql_id,同一笔请求中sql_id不能相同)及需要执行的sql语句等请求参数。其中数据库标识用来标示数据库访问模块30,如A表示是通过数据库访问模块A访问数据库A。每个读写sql编号及对应的sql语句表示一个读写任务。每个读写请求可能包括一个或多个数据库标识和读写任务。所述服务器2接收所述读写请求,并为每个所述读写请求分配唯一的请求ID,即request_id。Specifically, the caller 1 initiates a batch data read/write request for a single database 3 or multiple databases 3 to the server 2 in json format. The read-write request includes request parameters such as a database identifier (db_id), a read-write SQL number (sql_id, the sql_id cannot be the same in the same request), and a SQL statement to be executed. The database identifier is used to identify the database access module 30 , for example, A indicates that the database A is accessed through the database access module A. Each read and write SQL number and the corresponding SQL statement represent a read and write task. Each read and write request may include one or more database identification and read and write tasks. The server 2 receives the read and write requests, and assigns a unique request ID, ie, request_id, to each of the read and write requests.

针对单个数据库3的批量数据读写请求,例如一个数据库中有学生表(stu)、老师表(teac)、学生成绩表(stu_score),现在接收到一个针对该数据库的批量数据读写请求,需同时查询学生表中“小王”的数据(sql1:select*from stu where stu_name=’小王’)、查询老师表中“张老师”的数据(sql2:select*from teac where teac_name=’张老师’)、更新学生成绩表中“小李”的数据(sql3:update stu_score set score=90where stu_name=’小李’)。所述服务器2可以为该读写请求分配一个唯一的请求ID,例如178652986。A batch data read and write request for a single database 3, for example, a database has a student table (stu), a teacher table (teac), and a student score table (stu_score), and now a batch data read and write request for this database is received. At the same time, query the data of "Xiao Wang" in the student table (sql1:select*from stu where stu_name='Xiaowang'), and query the data of "Mr. Zhang" in the teacher table (sql2:select*from teac where teac_name='Mr.Zhang' '), update the data of "Xiao Li" in the student score table (sql3:update stu_score set score=90where stu_name='Xiao Li'). The server 2 can assign a unique request ID, such as 178652986, to the read and write request.

针对多个数据库3的批量数据读写请求,例如有数据库A包含学生表(stu)、老师表(teac),数据库B包含学生成绩表(stu_score),现在接收到一个针对数据库A和B的批量数据读写请求,需同时查询数据库A的学生表中的“小张”的数据和老师表中的“张三”的数据(sql1:select*from stu where stu_name=’小张’;sql2:select*from teac whereteac_name=’张三’)、查询数据库B的学生成绩表中“小李”的数据及修改“小明”的数据(sql3:select*from stu_score where stu_name=’小李’;sql4:update stu_score setscore=90where stu_name=’小明’)。同样地,所述服务器2也可以为该读写请求分配一个唯一的请求ID,例如178652987。Batch data read and write requests for multiple databases 3, for example, database A contains student table (stu), teacher table (teac), database B contains student score table (stu_score), and now a batch for database A and B is received For data read and write requests, it is necessary to query the data of "Xiao Zhang" in the student table of database A and the data of "Zhang San" in the teacher table (sql1:select*from stu where stu_name='Xiao Zhang'; sql2:select *from teac whereteac_name='Zhang San'), query the data of "Xiao Li" in the student transcript of database B and modify the data of "Xiao Ming" (sql3:select*from stu_score where stu_name='Xiao Li'; sql4:update stu_score setscore=90where stu_name='Xiao Ming'). Similarly, the server 2 can also assign a unique request ID, such as 178652987, to the read and write request.

步骤S502,将所述读写请求写入hash内存。Step S502, write the read/write request into the hash memory.

具体地,在hash内存中创建针对每个所述读写请求的存储结构,每个所述存储结构包括关键字(key)和value结构。将所述读写请求写入hash内存,其中,请求ID即request_id作为hash内存中所述读写请求对应的key,并且将所述读写请求对应的调用方连接标示tcp socket、以及所述读写请求中每个读写任务对应的读写sql语句及读写sql_id作为数组,写入所述请求ID对应的hash内存的value结构中。另外,该value结构的数组中还包含任务返回标识(sql_ret)和任务返回数据(sql_data)两项,用于后续写入针对所述读写请求返回的处理结果。Specifically, a storage structure for each of the read and write requests is created in the hash memory, and each of the storage structures includes a key (key) and a value structure. Write the read-write request into the hash memory, wherein the request ID, that is, request_id, is used as the key corresponding to the read-write request in the hash memory, and the caller connection corresponding to the read-write request is marked tcp socket and the read/write request. The read-write sql statement and the read-write sql_id corresponding to each read-write task in the write request are taken as an array, and written into the value structure of the hash memory corresponding to the request ID. In addition, the array of the value structure also includes two items, a task return identifier (sql_ret) and a task return data (sql_data), which are used for subsequent writing of the processing result returned for the read and write request.

例如,以上述两个读写请求的请求ID作为key,将这两个读写请求的信息在hash内存中进行保存,并分别以这两个读写请求的调用方连接标示、读写sql语句及读写sql_id作为数组,写入各自的请求ID对应的hash内存的value结构中。以上述针对数据库A和B的读写请求为例,在hash内存中以该读写请求的请求ID“178652987”作为key,以调用方连接标示、读写sql语句(select*from stu where stu_name=’小张’;select*from teac whereteac_name=’张三’;select*from stu_score where stu_name=’小李’;update stu_score set score=90where stu_name=’小明’)及读写sql_id(sql1、sql2、sql3、sql4)作为数组,写入对应的value结构。For example, using the request IDs of the above two read and write requests as the key, the information of the two read and write requests is stored in the hash memory, and the caller connection of the two read and write requests is used to identify, read and write SQL statements respectively. And read and write sql_id as an array, and write it into the value structure of the hash memory corresponding to the respective request ID. Taking the above read and write requests for databases A and B as an example, the request ID "178652987" of the read and write requests is used as the key in the hash memory, and the caller connection is marked to read and write SQL statements (select*from stu where stu_name= 'Xiao Zhang'; select*from teac whereteac_name='Zhang San'; select*from stu_score where stu_name='Xiao Li'; update stu_score set score=90where stu_name='Xiao Ming') and read and write sql_id (sql1, sql2, sql3 , sql4) as an array, write the corresponding value structure.

步骤S504,根据所述读写请求中的数据库标识将所述读写请求的各个读写任务发送至对应的数据库3并行处理。Step S504, according to the database identifier in the read/write request, each read/write task of the read/write request is sent to the corresponding database 3 for parallel processing.

具体地,获取所述读写请求中的请求参数,根据请求参数中的数据库标识即db_id,将属于不同数据库3(或者同一个数据库3)的多个数据读写任务同时发送到对应的数据库3。发送给每个数据库3的读写任务数据包含请求ID(request_id)、任务ID(task_id,与sql_id一致)、读写sql语句等。每个数据库3包含对应的数据库访问模块30,用于接收并处理该数据库3的读写请求,然后返回处理结果。返回的处理结果包含请求ID(request_id)、任务ID(task_id,与sql_id一致)、任务返回标识(sql_ret)、任务返回数据(sql_data)等。其中,任务返回标识用来标示sql语句执行成功与否,返回数值0表示执行成功,非0表示执行失败。任务返回数据用来标示sql语句对应的返回数据,当该sql语句为查询任务且执行成功时,返回具体的查询结果数据,当该sql语句为非查询任务时或查询执行失败时,返回空值null。Specifically, obtain the request parameters in the read-write request, and send multiple data read-write tasks belonging to different databases 3 (or the same database 3 ) to the corresponding database 3 at the same time according to the database identifier in the request parameters, that is, db_id . The read and write task data sent to each database 3 includes a request ID (request_id), a task ID (task_id, which is consistent with sql_id), read and write SQL statements, and the like. Each database 3 includes a corresponding database access module 30 for receiving and processing read and write requests of the database 3, and then returning the processing result. The returned processing result includes a request ID (request_id), a task ID (task_id, which is consistent with sql_id), a task return identifier (sql_ret), and task return data (sql_data). Among them, the task return identifier is used to indicate whether the SQL statement is executed successfully or not. The return value of 0 means the execution is successful, and non-0 means the execution fails. The task return data is used to indicate the return data corresponding to the sql statement. When the sql statement is a query task and the execution is successful, the specific query result data is returned. When the sql statement is a non-query task or the query execution fails, a null value is returned. null.

例如,上述数据库B针对查询学生成绩表中“小李”的数据(sql3:select*fromstu_score where stu_name=’小李’)这个查询任务,返回的处理结果中请求ID为178652987,任务ID为3,任务返回标识为0,任务返回数据为{“stu_name”:“小李”,“stu_score”:“95”};针对修改学生成绩表中“小明”的数据(sql4:update stu_score set score=90where stu_name=’小明’)这个非查询任务,返回的处理结果中请求ID为178652987,任务ID为4,任务返回标识为0,任务返回数据为null。For example, for the query task of querying the data of "Xiao Li" in the student's score table (sql3:select*fromstu_score where stu_name='Xiao Li'), the returned processing result in database B is 178652987 for the request ID and 3 for the task ID. The task return identifier is 0, and the task return data is {"stu_name": "Xiao Li", "stu_score": "95"}; for modifying the data of "Xiao Ming" in the student score table (sql4:update stu_score set score=90where stu_name ='Xiao Ming') This non-query task, in the returned processing result, the request ID is 178652987, the task ID is 4, the task return ID is 0, and the task return data is null.

在本实施例中,多个读写请求中的所有读写任务可以同时发送至对应数据库3中,所有子任务并行处理,耗时是其中一个最大子任务的耗时。In this embodiment, all read and write tasks in multiple read and write requests can be sent to the corresponding database 3 at the same time, all subtasks are processed in parallel, and the time consumption is the time consumption of one of the largest subtasks.

步骤S506,接收数据库3返回的处理结果并更新至所述读写请求对应的value结构中。Step S506, the processing result returned by the database 3 is received and updated into the value structure corresponding to the read and write request.

具体地,所述服务器2异步接收各个数据库3返回的针对每个所述读写请求的各个读写任务的处理结果,根据每个处理结果中的请求ID到hash内存中获取对应的value结构,再根据sql_id(与任务ID一致)找出value结构中对应的读写任务,更新该读写任务的任务返回标识和任务返回数据。Specifically, the server 2 asynchronously receives the processing results of each read and write task returned by each database 3 for each of the read and write requests, and obtains the corresponding value structure from the hash memory according to the request ID in each processing result, Then find out the corresponding read/write task in the value structure according to sql_id (consistent with the task ID), and update the task return identifier and task return data of the read/write task.

例如,将上述数据库B返回的处理结果更新至hash内存中请求ID“178652987”对应的value结构中。For example, update the processing result returned by the above database B to the value structure corresponding to the request ID "178652987" in the hash memory.

步骤S508,判断所述读写请求的读写任务是否已全部返回处理结果。Step S508, judging whether the read and write tasks of the read and write request have all returned processing results.

具体地,针对每个读写请求,判断对应value结构中的读写任务是否已全部返回处理结果。若未全部返回,则继续等待相应数据库3返回处理结果,直至该读写请求的读写任务全部返回处理结果。Specifically, for each read/write request, it is determined whether all read/write tasks in the corresponding value structure have returned processing results. If not all are returned, continue to wait for the corresponding database 3 to return the processing result, until all the read-write tasks of the read-write request return the processing result.

值得注意的是,在本实施例中,当所述读写请求的读写任务未全部返回处理结果而需要继续等待时,可以同时继续处理其他读写请求,即其他读写请求不用排队等待,不会影响其他读写请求的处理时间。It is worth noting that, in this embodiment, when the read and write tasks of the read and write requests have not all returned processing results and need to continue to wait, other read and write requests can be processed at the same time, that is, other read and write requests do not need to wait in line, Does not affect the processing time of other read and write requests.

步骤S510,当所述读写请求的读写任务已全部返回处理结果时,组合处理结果并返回给调用方1。Step S510 , when all the read/write tasks of the read/write request have returned processing results, combine the processing results and return them to the caller 1 .

具体地,若所述读写请求的读写任务已经全部返回处理结果,则获取对应value结构中的调用方连接标示,并组合所述读写请求的所有读写任务的处理结果,将组合后的结果返回给调用方1。返回给调用方1的组合处理结果中包含数据库ID(db_id)、读写sql_id、任务返回标识(sql_ret)、任务返回数据(sql_data)等数据。Specifically, if all the read/write tasks of the read/write request have returned processing results, the caller connection flag in the corresponding value structure is obtained, and the processing results of all read/write tasks of the read/write request are combined. The result is returned to caller 1. The combined processing result returned to the caller 1 includes database ID (db_id), read/write sql_id, task return identifier (sql_ret), task return data (sql_data) and other data.

例如,针对上述请求ID为178652987的读写请求,判断对应value结构中的四个读写任务(sql1:select*from stu where stu_name=’小张’;sql2:select*from teacwhere teac_name=’张三’;sql3:select*from stu_score where stu_name=’小李’;sql4:update stu_score set score=90where stu_name=’小明’)是否已全部返回,即这四个任务ID对应的任务返回标识和任务返回数据是否已更新。若未全部返回,例如仅数据库B返回但数据库A还未返回,则继续等待数据库A返回的处理结果(此时可以同时处理其他读写请求)。若已全部返回,则将所有四个任务的处理结果组合起来,返回给调用方1。For example, for the read/write request whose request ID is 178652987, determine the four read/write tasks in the corresponding value structure (sql1:select*from stu where stu_name='Xiao Zhang'; sql2:select*from teac where teac_name='Zhang San' '; sql3:select*from stu_score where stu_name='Xiao Li';sql4:update stu_score set score=90where stu_name='Xiao Ming') have all been returned, that is, the task return identifier and task return data corresponding to these four task IDs Is it updated. If not all are returned, for example, only database B returns but database A has not returned, continue to wait for the processing result returned by database A (other read and write requests can be processed at the same time). If all have been returned, the processing results of all four tasks are combined and returned to the caller 1.

值得注意的是,所述数据读写批量处理方法的各个步骤及各个数据库3的数据库访问模块30均可配置多个进程同步处理。本实施例是批量处理针对单个数据库3或多个数据库3的读写请求,可以同时处理多个不同的读写请求,即单个或多个数据库3的多个读请求与多个写请求可以混在一起批量并发处理。It is worth noting that, each step of the data read/write batch processing method and the database access module 30 of each database 3 can be configured with multiple processes for synchronous processing. This embodiment processes read and write requests for a single database 3 or multiple databases 3 in batches, and can process multiple different read and write requests at the same time, that is, multiple read requests and multiple write requests of a single or multiple databases 3 can be mixed Batch and concurrent processing together.

本实施例提供的数据读写批量处理方法,可以提供统一的多数据库读写任务接口,对于批量的读写任务同时发送至相应数据库进行并行处理,并发能力高,访问耗时大大减少。调用方只需根据统一接口组装需要访问的数据库的读写任务列表,再根据统一接口返回的处理结果数据做逻辑处理即可,达到业务层与数据访问层抽象隔离的效果,提高生产效率。并且,本实施例的读写不依赖具体表,字段均是抽象获取,支持动态扩展表而不用修改代码,提高生产能力。另外,本实施例支持分布式部署和配置多进程处理,大大利用CPU多核硬件资源,提高处理能力。The data read and write batch processing method provided by this embodiment can provide a unified multi-database read and write task interface, and the batch read and write tasks are simultaneously sent to the corresponding database for parallel processing, with high concurrency capability and greatly reduced access time. The caller only needs to assemble the read and write task list of the database to be accessed according to the unified interface, and then perform logical processing according to the processing result data returned by the unified interface, so as to achieve the effect of abstract isolation between the business layer and the data access layer, and improve production efficiency. In addition, the reading and writing of this embodiment does not depend on the specific table, and the fields are abstractly obtained, which supports dynamic expansion of the table without modifying the code, and improves the production capacity. In addition, this embodiment supports distributed deployment and configuration of multi-process processing, greatly utilizes CPU multi-core hardware resources, and improves processing capability.

本发明还提供了另一种实施方式,即提供一种计算机可读存储介质,所述计算机可读存储介质存储有数据读写批量处理程序,所述数据读写批量处理程序可被至少一个处理器执行,以使所述至少一个处理器执行如上述的数据读写批量处理方法的步骤。Another embodiment of the present invention is to provide a computer-readable storage medium, where the computer-readable storage medium stores a data read and write batch processing program, and the data read and write batch processing program can be processed by at least one The processor executes, so that the at least one processor executes the steps of the above-mentioned data read and write batch processing method.

上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。The above-mentioned serial numbers of the embodiments of the present invention are only for description, and do not represent the advantages or disadvantages of the embodiments.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本发明各个实施例所述的方法。From the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is better implementation. Based on this understanding, the technical solutions of the present invention can be embodied in the form of software products in essence or the parts that make contributions to the prior art, and the computer software products are stored in a storage medium (such as ROM/RAM, magnetic disk, CD-ROM), including several instructions to make a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute the methods described in the various embodiments of the present invention.

以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only preferred embodiments of the present invention, and are not intended to limit the scope of the present invention. Any equivalent structure or equivalent process transformation made by using the contents of the description and drawings of the present invention, or directly or indirectly applied in other related technical fields , are similarly included in the scope of patent protection of the present invention.

Claims (10)

1.一种数据读写批量处理方法,其特征在于,所述方法包括步骤:1. a data read-write batch processing method, is characterized in that, described method comprises the steps: 当从调用方接收到针对单数据库或多数据库的一个或多个批量数据读写请求时,为每个读写请求分别分配唯一的请求ID,所述读写请求中的请求参数包含数据库标识和读写任务,其中每个读写任务包括一个读写sql编号及需要执行的读写sql语句;When one or more batch data read/write requests for a single database or multiple databases are received from the caller, each read/write request is assigned a unique request ID, and the request parameters in the read/write request include the database identifier and Read and write tasks, where each read and write task includes a read and write SQL number and the read and write SQL statements to be executed; 在hash内存中创建针对每个所述读写请求的存储结构,包括关键字和value结构,将所述请求ID写入所述关键字中,并将每个所述读写请求对应的调用方的连接标示、以及所述读写请求中每个读写任务对应的读写sql语句及读写sql编号作为数组,写入所述value结构中;Create a storage structure for each read and write request in the hash memory, including a keyword and a value structure, write the request ID into the keyword, and write the caller corresponding to each read and write request The connection sign, and the read-write sql statement and the read-write sql number corresponding to each read-write task in the read-write request are written into the value structure as an array; 根据每个所述读写请求中的数据库标识将所述读写请求的各个读写任务发送至对应的数据库并行处理;及According to the database identifier in each read and write request, each read and write task of the read and write request is sent to the corresponding database for parallel processing; and 接收数据库返回的针对每个所述读写请求的各个读写任务的处理结果并更新至每个所述读写请求对应的所述value结构中。The processing result of each read and write task for each of the read and write requests returned by the database is received and updated into the value structure corresponding to each of the read and write requests. 2.如权利要求1所述的数据读写批量处理方法,其特征在于,该方法还包括步骤:2. data read-write batch processing method as claimed in claim 1, is characterized in that, this method also comprises the step: 根据所述value结构,判断所述读写请求的读写任务是否已全部返回处理结果;According to the value structure, determine whether the read and write tasks of the read and write request have all returned processing results; 当所述读写请求的读写任务已全部返回处理结果时,组合所述读写请求的所有读写任务的处理结果并返回给调用方。When the read-write tasks of the read-write request have all returned processing results, the processing results of all the read-write tasks of the read-write request are combined and returned to the caller. 3.如权利要求1或2所述的数据读写批量处理方法,其特征在于,在所述根据每个所述读写请求中的数据库标识将所述读写请求的各个读写任务发送至对应的数据库并行处理的步骤中,发送给每个数据库的读写任务数据包含请求ID、读写sql编号、读写sql语句。3. data read-write batch processing method as claimed in claim 1 or 2 is characterized in that, in described according to the database identification in each described read-write request, each read-write task of described read-write request is sent to In the corresponding database parallel processing step, the read/write task data sent to each database includes a request ID, a read/write SQL number, and a read/write SQL statement. 4.如权利要求1或2所述的数据读写批量处理方法,其特征在于,所述处理结果包括请求ID、读写sql编号、任务返回标识和任务返回数据。4. The method for batch processing of data reading and writing according to claim 1 or 2, wherein the processing result comprises a request ID, a reading and writing sql number, a task return identifier and task return data. 5.如权利要求4所述的数据读写批量处理方法,其特征在于,所述value结构中还包括每个读写任务对应的任务返回标识和任务返回数据,所述接收数据库返回的针对所述读写请求的各个读写任务的处理结果并更新至所述读写请求对应的所述value结构中的步骤包括:5. data read-write batch processing method as claimed in claim 4, is characterized in that, in described value structure, also comprises the task return identification and the task return data corresponding to each read-write task, the described receiving database returns for all. The steps of updating the processing results of each read-write task of the read-write request to the value structure corresponding to the read-write request include: 异步接收各个数据库返回的处理结果,根据每个处理结果中的请求ID到hash内存中获取对应的value结构,再根据读写sql编号找出所述value结构中对应的读写任务,更新所述读写任务的任务返回标识和任务返回数据。Asynchronously receive the processing results returned by each database, obtain the corresponding value structure from the hash memory according to the request ID in each processing result, and then find out the corresponding read and write tasks in the value structure according to the read and write SQL numbers, and update the The task return identifier and the task return data of the read and write tasks. 6.如权利要求5所述的数据读写批量处理方法,其特征在于,所述任务返回标识用于标示读写sql语句执行成功与否,返回数值0表示执行成功,非0表示执行失败。6. The data read-write batch processing method according to claim 5, wherein the task return identifier is used to indicate whether the read-write sql statement is executed successfully or not, and a return value of 0 indicates that the execution is successful, and non-0 indicates that the execution fails. 7.如权利要求5所述的数据读写批量处理方法,其特征在于,所述任务返回数据用于标示读写sql语句对应的返回数据,当所述读写sql语句为查询任务且执行成功时,返回具体的查询结果数据;当所述读写sql语句为非查询任务或查询任务执行失败时,返回空值null。7. data read-write batch processing method as claimed in claim 5 is characterized in that, described task return data is used to mark the return data corresponding to read-write sql statement, when described read-write sql statement is query task and executes successfully When the query result data is returned; when the read-write sql statement is a non-query task or the query task fails to execute, the null value null is returned. 8.如权利要求2所述的数据读写批量处理方法,其特征在于,该方法还包括步骤:8. data read-write batch processing method as claimed in claim 2, is characterized in that, this method also comprises the step: 当所述读写请求的读写任务未全部返回处理结果而需要继续等待时,同时继续处理其他读写请求。When the read and write tasks of the read and write requests do not all return processing results and need to continue to wait, other read and write requests continue to be processed at the same time. 9.一种服务器,其特征在于,所述服务器包括存储器、处理器,所述存储器上存储有可在所述处理器上运行的数据读写批量处理系统,所述数据读写批量处理系统被所述处理器执行时实现如权利要求1-8中任一项所述的数据读写批量处理方法的步骤。9. A server, characterized in that the server comprises a memory and a processor, and the memory stores a data read/write batch processing system that can run on the processor, and the data read/write batch processing system is The processor implements the steps of the data read and write batch processing method according to any one of claims 1-8 when executed. 10.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有数据读写批量处理系统,所述数据读写批量处理系统可被至少一个处理器执行,以使所述至少一个处理器执行如权利要求1-8中任一项所述的数据读写批量处理方法的步骤。10. A computer-readable storage medium, wherein the computer-readable storage medium stores a data read-write batch processing system, and the data read-write batch processing system can be executed by at least one processor, so that the At least one processor executes the steps of the data read and write batch processing method according to any one of claims 1-8.
CN202010044481.1A 2020-01-15 2020-01-15 Data reading and writing batch processing method, server and computer readable storage medium Active CN111259029B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010044481.1A CN111259029B (en) 2020-01-15 2020-01-15 Data reading and writing batch processing method, server and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010044481.1A CN111259029B (en) 2020-01-15 2020-01-15 Data reading and writing batch processing method, server and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN111259029A true CN111259029A (en) 2020-06-09
CN111259029B CN111259029B (en) 2025-05-27

Family

ID=70952108

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010044481.1A Active CN111259029B (en) 2020-01-15 2020-01-15 Data reading and writing batch processing method, server and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN111259029B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111897828A (en) * 2020-07-31 2020-11-06 广州视源电子科技股份有限公司 Data batch processing method, device, device and storage medium
CN114385665A (en) * 2021-12-24 2022-04-22 苏州银丰睿哲信息科技有限公司 Presto-based heterogeneous data risk analysis method and system across financial institutions

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010009195A (en) * 2008-06-25 2010-01-14 Hitachi Ltd Batch processing method, batch processing program, request execution device and database system
CN106815218A (en) * 2015-11-27 2017-06-09 华为技术有限公司 Data bank access method, device and Database Systems
US20180046693A1 (en) * 2016-08-09 2018-02-15 International Business Machines Corporation Consistent query execution in hybrid dbms
WO2018161881A1 (en) * 2017-03-09 2018-09-13 腾讯科技(深圳)有限公司 Structuralized data processing method, data storage medium, and computer apparatus
CN109522311A (en) * 2018-11-20 2019-03-26 北京锐安科技有限公司 Date storage method, device, server and storage medium
US20190102107A1 (en) * 2017-09-29 2019-04-04 Intel Corporation Techniques for batch operations to storage devices
CN109697370A (en) * 2018-09-30 2019-04-30 深圳财富农场互联网金融服务有限公司 Database data encipher-decipher method, device, computer equipment and storage medium
CN110191168A (en) * 2019-05-23 2019-08-30 北京百度网讯科技有限公司 Processing method, device, computer equipment and the storage medium of online business datum
CN110515969A (en) * 2019-07-08 2019-11-29 中国平安人寿保险股份有限公司 Data query processing method, electronic device, computer equipment and storage medium
CN110580258A (en) * 2019-09-20 2019-12-17 中国银行股份有限公司 big data free query method and device

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010009195A (en) * 2008-06-25 2010-01-14 Hitachi Ltd Batch processing method, batch processing program, request execution device and database system
CN106815218A (en) * 2015-11-27 2017-06-09 华为技术有限公司 Data bank access method, device and Database Systems
US20180046693A1 (en) * 2016-08-09 2018-02-15 International Business Machines Corporation Consistent query execution in hybrid dbms
WO2018161881A1 (en) * 2017-03-09 2018-09-13 腾讯科技(深圳)有限公司 Structuralized data processing method, data storage medium, and computer apparatus
US20190102107A1 (en) * 2017-09-29 2019-04-04 Intel Corporation Techniques for batch operations to storage devices
CN109697370A (en) * 2018-09-30 2019-04-30 深圳财富农场互联网金融服务有限公司 Database data encipher-decipher method, device, computer equipment and storage medium
CN109522311A (en) * 2018-11-20 2019-03-26 北京锐安科技有限公司 Date storage method, device, server and storage medium
CN110191168A (en) * 2019-05-23 2019-08-30 北京百度网讯科技有限公司 Processing method, device, computer equipment and the storage medium of online business datum
CN110515969A (en) * 2019-07-08 2019-11-29 中国平安人寿保险股份有限公司 Data query processing method, electronic device, computer equipment and storage medium
CN110580258A (en) * 2019-09-20 2019-12-17 中国银行股份有限公司 big data free query method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
陈玉标;李建中;李英姝;李发明;高宏;: "基于闪存固态硬盘内部并行机制的R-树优化方法", 计算机研究与发展, no. 09, 15 September 2018 (2018-09-15) *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111897828A (en) * 2020-07-31 2020-11-06 广州视源电子科技股份有限公司 Data batch processing method, device, device and storage medium
CN114385665A (en) * 2021-12-24 2022-04-22 苏州银丰睿哲信息科技有限公司 Presto-based heterogeneous data risk analysis method and system across financial institutions

Also Published As

Publication number Publication date
CN111259029B (en) 2025-05-27

Similar Documents

Publication Publication Date Title
CN109376004B (en) Cluster calculation-based data batch processing method and device, electronic equipment and medium
CN111797134B (en) Data query method, device and storage medium of distributed database
CN110221901A (en) Container asset creation method, apparatus, equipment and computer readable storage medium
WO2019148722A1 (en) Electronic device, data migrating and calling method and storage medium
CN111901238B (en) Dynamic routing service method, device, electronic device and storage medium
EP3376403A1 (en) Method of accessing distributed database and device providing distributed data service
CN110377369B (en) Method, device and computer storage medium for running small program
CN115729951B (en) Data query method, system, device and computer readable storage medium
CN111259029A (en) Data read and write batch processing method, server and computer readable storage medium
CN114201297A (en) Data processing method and device, electronic equipment and storage medium
CN112988874A (en) Data processing method, system, computing device and readable storage medium
CN114138895B (en) Data synchronization method and device for multiple data sources, computer equipment and storage medium
CN113392091B (en) Distributed cluster data migration method and device
WO2022206170A1 (en) Data processing method, server and system
WO2020019314A1 (en) Graph data storage method and system and electronic device
CN118503311A (en) Data query method, electronic device and storage medium
CN110059080B (en) Data processing method and device
CN115062044B (en) A data query method, device, equipment and storage medium
CN114079659B (en) Distributed storage system server, distributed storage system, data storage and data access method and system
CN114003661A (en) Offline data entry method, device, electronic device and storage medium
CN116257550A (en) A data processing method, device, equipment and medium
CN114640652B (en) Information processing method and device
CN119200968B (en) Shared memory data calling method, device, equipment and readable storage medium
CN114063914A (en) DRAM-HBM hybrid memory oriented data management method
CN111858652A (en) Cross-data-source query method and system based on message queue and server node

Legal Events

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