CN102982145A - System for allocating database operating requests - Google Patents
System for allocating database operating requests Download PDFInfo
- Publication number
- CN102982145A CN102982145A CN2012104833443A CN201210483344A CN102982145A CN 102982145 A CN102982145 A CN 102982145A CN 2012104833443 A CN2012104833443 A CN 2012104833443A CN 201210483344 A CN201210483344 A CN 201210483344A CN 102982145 A CN102982145 A CN 102982145A
- Authority
- CN
- China
- Prior art keywords
- database server
- operation requests
- database
- operation request
- described operation
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000007689 inspection Methods 0.000 claims description 4
- 230000005540 biological transmission Effects 0.000 claims 1
- 238000000034 method Methods 0.000 description 21
- 230000002159 abnormal effect Effects 0.000 description 5
- 238000011161 development Methods 0.000 description 4
- 230000008901 benefit Effects 0.000 description 3
- 238000013500 data storage Methods 0.000 description 3
- 238000012423 maintenance Methods 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 238000004590 computer program Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 238000000429 assembly Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000008676 import Effects 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种分配数据库操作请求的系统(1000),其包括:分配数据库操作请求的设备(200);一个或者多个应用程序服务器(300-1,…,300-n),适于向设备(200)发送对于数据库的操作请求;主数据库服务器(400a)以及一个或者多个从数据库服务器(400b1,…,400bn),适于响应于设备(200)的检查,向设备(200)返回其状态,并且接收设备(200)分配的操作请求;以及分配数据库操作请求的设备(200)包括:网络接口(201),适于接收对于数据库的操作请求;操作请求解析器(203),适于解析操作请求,以检测操作请求中的类型注释,并确定与类型注释相对应的数据库服务器;以及操作请求分配器(207),适于将所述操作请求分配给所确定的数据库服务器。
The invention discloses a system (1000) for allocating database operation requests, which includes: a device (200) for allocating database operation requests; one or more application program servers (300-1,...,300-n), suitable for Sending an operation request for the database to the device (200); the master database server (400a) and one or more slave database servers (400b1, ..., 400bn), adapted to respond to the check of the device (200), send the device (200) return its status, and receive the operation request assigned by the device (200); and the device (200) for assigning the database operation request includes: a network interface (201), adapted to receive an operation request for the database; an operation request resolver (203), adapted to parse the operation request to detect a type annotation in the operation request and determine a database server corresponding to the type annotation; and an operation request dispatcher (207) adapted to assign the operation request to the determined database server.
Description
技术领域technical field
本发明涉及数据库技术,尤其涉及一种分配数据库操作请求的系统。The invention relates to database technology, in particular to a system for allocating database operation requests.
背景技术Background technique
随着计算机网络的快速发展,出现了具有大量用户的网络应用,这些网络应用需要存储大量的用户数据以及相关数据。先前的单台数据存储服务器的数据存储方式已经不能满足当前网络应用的数据存储要求。目前数据库在使用中普遍采用主-从架构(一般来说,主数据库有一个,从数据库有多个),从数据库只承担读操作,所有的写操作都由主数据库来执行。为了保证数据的一致性,从数据库会不断地从主数据库同步最新写入的数据到从数据库上。应用程序员需要根据数据库操作的读写类型,分别将数据库操作语句发往主数据库或从数据库,增加了应用程序员的负担,提高了开发成本。With the rapid development of computer networks, network applications with a large number of users appear, and these network applications need to store a large amount of user data and related data. The previous data storage method of a single data storage server can no longer meet the data storage requirements of current network applications. At present, databases generally adopt a master-slave architecture (generally speaking, there is one master database and multiple slave databases). The slave database only undertakes read operations, and all write operations are performed by the master database. In order to ensure data consistency, the slave database will continuously synchronize the latest written data from the master database to the slave database. Application programmers need to send database operation statements to the master database or slave database respectively according to the type of read and write of database operations, which increases the burden on application programmers and increases development costs.
另外,从主数据库到从数据库的数据同步不是完全实时的,而是存在着一定的延迟时间,这就带来了问题。设想以下情况:应用程序向数据库写一条数据,如上所述,该数据会被写入到主数据库中,然后马上又要读出该数据,读操作由从数据库执行,但此时从数据库尚未来得及把该数据由主数据库同步到本地,读操作的执行结果必然是未找到该数据或是读到了该数据的旧版本,这就造成了错误发生。除此之外,如果某台数据库服务器发生故障,而程序仍然向不可用的机器导入请求,就会发生错误,此时只能通过修改程序来解决,维护成本很高。In addition, the data synchronization from the master database to the slave database is not completely real-time, but there is a certain delay time, which brings problems. Imagine the following situation: the application program writes a piece of data to the database. As mentioned above, the data will be written into the master database, and then the data will be read out again immediately. The read operation is performed by the slave database, but the slave database has not yet had time When the data is synchronized from the main database to the local, the execution result of the read operation must be that the data is not found or the old version of the data is read, which causes errors. In addition, if a database server fails and the program still imports requests to the unavailable machine, an error will occur. At this time, it can only be solved by modifying the program, and the maintenance cost is very high.
发明内容Contents of the invention
鉴于上述问题,提出了本发明,以便提供一种克服上述问题或者至少部分地解决上述问题的分配数据库操作请求的系统。In view of the above problems, the present invention is proposed to provide a system for allocating database operation requests that overcomes the above problems or at least partially solves the above problems.
依据本发明的一个方面,提供了一种分配数据库操作请求的系统,包括:分配数据库操作请求的设备;一个或者多个应用程序服务器,适于向该设备发送对于数据库的操作请求;以及主数据库服务器以及一个或者多个从数据库服务器,适于响应于该设备的检查,向该设备返回其状态,并且接收该设备分配的操作请求;其中,所述分配数据库操作请求的设备包括:网络接口,适于接收对于数据库的操作请求;操作请求解析器,适于解析该操作请求,以检测该操作请求中的类型注释,确定与该类型注释相对应的数据库服务器;以及操作请求分配器,适于将该操作请求分配给所确定的数据库服务器。According to one aspect of the present invention, a system for distributing database operation requests is provided, including: a device for distributing database operation requests; one or more application program servers, adapted to send the device an operation request for the database; and a master database The server and one or more slave database servers are adapted to respond to the check of the device, return its status to the device, and receive the operation request assigned by the device; wherein, the device for assigning the database operation request includes: a network interface, adapted to receive an operation request for the database; an operation request parser, adapted to parse the operation request, to detect a type annotation in the operation request, and determine a database server corresponding to the type annotation; and an operation request distributor, adapted to The operation request is assigned to the determined database server.
可选地,在根据本发明的实施例的分配数据库操作请求的设备中,当该操作请求解析器未检测到该操作请求中的类型注释时,解析该操作请求,以判断该操作请求的类型,确定与该操作请求的类型相对应的数据库服务器;并且该操作请求分配器将该操作请求分配给所确定的与该操作请求的类型相对应的数据库服务器。Optionally, in the device for allocating database operation requests according to an embodiment of the present invention, when the operation request parser does not detect the type annotation in the operation request, parse the operation request to determine the type of the operation request , determining a database server corresponding to the type of the operation request; and the operation request distributor assigns the operation request to the determined database server corresponding to the type of the operation request.
可选地,在根据本发明的实施例的分配数据库操作请求的设备中,该操作请求的类型包括写操作和读操作。Optionally, in the device for allocating database operation requests according to the embodiment of the present invention, types of the operation requests include write operations and read operations.
可选地,在根据本发明的实施例的分配数据库操作请求的设备中,该数据库服务器包括主数据库服务器和从数据库服务器,对应于写操作的数据库服务器是主数据库服务器,对应于读操作的数据库服务器是从数据库服务器。Optionally, in the device for distributing database operation requests according to an embodiment of the present invention, the database server includes a master database server and a slave database server, the database server corresponding to the write operation is the master database server, and the database server corresponding to the read operation The server is the slave database server.
可选地,所述分配数据库操作请求的设备还包括数据库检查器,适于检查该数据库服务器;并且该操作请求分配器根据检查结果将该操作请求分配给相应的数据库服务器或者返回错误提示。Optionally, the device for allocating database operation requests further includes a database checker adapted to check the database server; and the operation request allocator allocates the operation request to the corresponding database server or returns an error prompt according to the check result.
本发明提供了上述分配数据库操作请求的系统。根据本发明的实施例,可以解析接收到的对于数据库的操作请求,以检测操作请求中的类型注释,并根据类型注释,确定相对应的数据库服务器,并向其分配该操作请求。这样,应用开发人员通过利用例如在诸如SQL语句之类的操作请求中本来没有意义的注释语句,就可以确定要将操作请求分配给具体数据库服务器,从而极大地提高了应用开发的灵活性。对于实时性要求较高的读操作,只需要简单地在操作请求中添加表示主数据库类型的类型注释,就能自动地将该操作请求分配给主数据库服务器,避免发生找不到所请求的数据或者读取到该数据的旧版本的问题。The present invention provides the above-mentioned system for allocating database operation requests. According to the embodiment of the present invention, the received operation request for the database can be parsed to detect the type annotation in the operation request, and according to the type annotation, the corresponding database server can be determined and the operation request can be assigned to it. In this way, the application developer can determine to allocate the operation request to a specific database server by using, for example, the meaningless comment statement in the operation request such as SQL statement, thereby greatly improving the flexibility of application development. For read operations with high real-time requirements, you only need to simply add a type annotation indicating the type of the main database to the operation request, and the operation request can be automatically assigned to the main database server to avoid the occurrence of not being able to find the requested data Or a problem reading an older version of the data.
另外,根据本发明的实施例,在确定了要将操作请求分配到的数据库服务器之后,还可以检查该数据库服务器,并根据检查结果将该操作请求分配给相应的数据库服务器或者返回错误提示。这样,在数据库服务器集群中的某一台或者多台数据库服务器发生故障时,可以自动检测到该故障,不再把操作请求分配给存在故障的数据库服务器。其中,在主数据库服务器出现故障的情况下,写操作无法执行,但读操作不受影响;而在从数据库服务器出现故障的情况下,可以转而将读操作分配给主数据库服务器,从而读写操作均不受影响。这一过程对于应用程序完全透明,应用程序员不在不需要对应用程序作出任何修改,降低了应用程序的维护成本。In addition, according to the embodiment of the present invention, after the database server to which the operation request is assigned is determined, the database server can be checked, and the operation request is assigned to the corresponding database server or an error prompt is returned according to the inspection result. In this way, when one or more database servers in the database server cluster fail, the failure can be automatically detected, and the operation request is no longer allocated to the failed database server. Among them, in the case of failure of the primary database server, the write operation cannot be performed, but the read operation is not affected; and in the case of a failure of the secondary database server, the read operation can be assigned to the primary database server instead, so as to read and write Operations are not affected. This process is completely transparent to the application program, and the application programmer does not need to make any modification to the application program, which reduces the maintenance cost of the application program.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。The above description is only an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention, it can be implemented according to the contents of the description, and in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable , the specific embodiments of the present invention are enumerated below.
附图说明Description of drawings
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiment. The drawings are only for the purpose of illustrating a preferred embodiment and are not to be considered as limiting the invention. Also throughout the drawings, the same reference numerals are used to designate the same components. In the attached picture:
图1是根据本发明的实施例的分配数据库操作请求的方法的流程图;1 is a flowchart of a method for allocating database operation requests according to an embodiment of the present invention;
图2是根据本发明的一个实施例的分配数据库操作请求的方法各步骤的流程图;以及FIG. 2 is a flow chart of steps of a method for allocating database operation requests according to an embodiment of the present invention; and
图3是根据本发明的实施例的分配数据库操作请求的设备以及系统的框图。Fig. 3 is a block diagram of a device and a system for allocating database operation requests according to an embodiment of the present invention.
具体实施方式Detailed ways
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided for more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
图1示意性地图示了根据本发明的实施例的分配数据库操作请求的方法100的流程图。Fig. 1 schematically illustrates a flowchart of a
根据本发明的实施例,数据库例如可以是MySQL数据库。在下文中,以MySQL数据库为例,对本发明的原理进行描述,然而,这只是为了示例的目的,本发明的范围并不限于此,本发明的原理同样适用于其它类型的数据库。According to an embodiment of the present invention, the database may be, for example, a MySQL database. In the following, the MySQL database is taken as an example to describe the principle of the present invention. However, this is only for the purpose of illustration, and the scope of the present invention is not limited thereto. The principle of the present invention is also applicable to other types of databases.
如图1所示,根据本发明的实施例的分配数据库操作请求的方法100始于步骤S101,其中,接收对于数据库的操作请求。该对于数据库的操作请求例如来自于一个或者多个应用服务器。As shown in FIG. 1 , the
图2示意性地图示了根据本发明的一个实施例的分配数据库操作请求的方法各步骤的流程图,下面将结合图2对本发明的原理进行详细的描述。Fig. 2 schematically illustrates a flow chart of steps of a method for allocating database operation requests according to an embodiment of the present invention, and the principle of the present invention will be described in detail below in conjunction with Fig. 2 .
参见图2,首先,从应用服务器接收对于数据库的操作请求,如果没有接收到,则继续等待;如果已经接收到,则进入下一步骤,即图1所示的步骤S103。Referring to FIG. 2 , firstly, an operation request for the database is received from the application server, if not received, then continue to wait; if received, then enter the next step, that is, step S103 shown in FIG. 1 .
在步骤S103中,解析该操作请求,从而检测操作请求中的类型注释。根据本发明的实施例,该操作请求可以包括数据库程序语言语句,该数据库程序语言可以是SQL(Structured Query Language,结构化查询语言),即,该操作请求包括SQL语句。然而,SQL语言和SQL语句仅为示例,用于帮助读者理解本发明的原理,本发明的范围并不限于此,而是同样适用于其它适当的数据库程序语言和相对应的语句。In step S103, the operation request is parsed, so as to detect the type annotation in the operation request. According to an embodiment of the present invention, the operation request may include a database program language statement, and the database program language may be SQL (Structured Query Language, Structured Query Language), that is, the operation request includes an SQL statement. However, the SQL language and SQL statements are only examples to help readers understand the principles of the present invention, and the scope of the present invention is not limited thereto, but is equally applicable to other appropriate database programming languages and corresponding statements.
在解析操作请求时,例如可以检测SQL语句的开头是否包含类型注释,即是否包含例如“/*master*/”的主数据库类型注释。如果包含,即检测到操作请求中的类型注释,则可以进入如图1所示的步骤S105。在步骤S105中,确定与该检测到的类型注释相对应的数据库服务器。可选地,在此之前,如图2所示,可以将该类型注释从操作请求中删除。When parsing the operation request, for example, it may be detected whether the beginning of the SQL statement contains a type annotation, that is, whether it contains a master database type annotation such as "/*master*/". If it is included, that is, the type annotation in the operation request is detected, it may enter step S105 as shown in FIG. 1 . In step S105, the database server corresponding to the detected type annotation is determined. Optionally, before this, as shown in FIG. 2 , the type annotation can be deleted from the operation request.
根据本发明的实施例,数据库服务器可以包括主数据库服务器和从数据库服务器。在步骤S105中,检测该类型注释是否表示主数据库服务器类型,如果是,即,例如类型注释为“/*master*/”,则可以确定与该类型注释相对应的数据库服务器为主数据库服务器。这样,在随后的步骤S107中,就可以将操作请求分配给主数据库服务器。According to an embodiment of the present invention, the database server may include a master database server and a slave database server. In step S105, it is detected whether the type annotation indicates the type of the master database server, and if so, that is, for example, the type annotation is "/*master*/", then the database server corresponding to the type annotation can be determined to be the master database server. In this way, in the subsequent step S107, the operation request can be allocated to the main database server.
然而,如果在步骤S103中,通过解析操作请求,未检测到类型注释时,就可以执行步骤S103’,即,进一步解析操作请求,来判断操作请求的类型。However, if in step S103, the type annotation is not detected by parsing the operation request, step S103' can be executed, that is, further parsing the operation request to determine the type of the operation request.
根据本发明的实施例,操作请求的类型包括写操作和读操作。在步骤S103’中,可以根据SQL语句中的关键字,来判断操作请求的类型。例如,可以检测SQL语句中的第一个单词,如果该单词为例如INSERT、UPDATE、REPLACE等表示写操作的单词,则判断操作请求的类型为写操作;而如果该单词为不表示写操作的其它单词,则判断操作请求的类型为读操作。然后,执行步骤S105’,确定与操作请求类型相对应的数据库服务器。根据本发明的实施例,对应于写操作的数据库服务器是主数据库服务器,对应于读操作的数据库服务器是从数据库服务器。According to an embodiment of the present invention, types of operation requests include write operations and read operations. In step S103', the type of the operation request can be determined according to the keywords in the SQL statement. For example, the first word in the SQL statement can be detected, and if the word is a word indicating a write operation such as INSERT, UPDATE, REPLACE, etc., then the type of the operation request is judged to be a write operation; and if the word does not indicate a write operation If other words are used, it is judged that the type of the operation request is a read operation. Then, step S105' is executed to determine the database server corresponding to the type of operation request. According to an embodiment of the present invention, the database server corresponding to the write operation is the master database server, and the database server corresponding to the read operation is the slave database server.
可选地,而在上述步骤S105中,如果检测到注释类型不表示主数据库服务器类型,则如图2所示,也可以考虑执行步骤S103’和步骤S105’,即解析操作请求,判断操作请求的类型,并且确定与该类型相对应的数据库服务器。Optionally, in the above step S105, if it is detected that the comment type does not represent the main database server type, as shown in Figure 2, it is also possible to consider performing steps S103' and S105', that is, to parse the operation request and determine the operation request type and determine the database server corresponding to that type.
在步骤S105’之后,执行步骤S107,其中,将该操作请求分配给与操作请求的类型相对应的数据库服务器,即,如果操作请求的类型是写操作,则将操作请求分配给主数据库服务器;而如果操作请求的类型是读操作,则将操作请求分配给从数据库服务器。After step S105', step S107 is executed, wherein the operation request is allocated to the database server corresponding to the type of the operation request, that is, if the type of the operation request is a write operation, the operation request is allocated to the main database server; And if the type of the operation request is a read operation, the operation request is assigned to the slave database server.
根据本发明的实施例,在上述步骤S107之前,还可以执行步骤S106,其中,检查所确定的数据库服务器,并且在步骤S107中,根据检查结果来讲操作请求分配给相应的数据库服务器或者返回错误提示。其中,如图2所示,在所确定的数据库服务器是从数据库服务器的情况下,在检查结果表示从数据库服务器状态正常时,将操作请求分配给从数据库服务器。而在检查结果表示从数据库服务器状态不正常时,检查主数据库服务器,在主数据库服务器状态正常时,将该操作请求分配给主数据库服务器;而在主数据库服务器状态不正常时,返回表示数据库服务器不可用的错误提示,例如,向应用程序服务器返回“数据库不可用”的错误提示。According to an embodiment of the present invention, before the above step S107, step S106 may also be performed, wherein the determined database server is checked, and in step S107, the operation request is allocated to the corresponding database server or an error is returned according to the check result hint. Wherein, as shown in FIG. 2 , in the case that the determined database server is a slave database server, when the check result indicates that the status of the slave database server is normal, the operation request is allocated to the slave database server. When the check result shows that the status of the slave database server is abnormal, check the master database server. When the status of the master database server is normal, assign the operation request to the master database server; An unavailable error message, for example, returns a "database unavailable" error message to the application server.
而在所确定的数据库服务器是主数据库服务器的情况下,在检查结果表示主数据库服务器状态正常时,将操作请求分配给主数据库服务器;在检查结果表示主数据库服务器状态不正常时,返回表示数据库服务器不可用的错误提示,例如,向应用程序服务器返回“数据库不可用”的错误提示。In the case that the determined database server is the master database server, when the check result shows that the master database server is in normal state, the operation request is assigned to the master database server; An error message that the server is unavailable, for example, return a "database unavailable" error message to the application server.
下面,为了帮助读者理解本发明,结合三个示例SQL语句来说明本发明的原理。In the following, in order to help readers understand the present invention, the principle of the present invention will be described in conjunction with three example SQL statements.
(1)假设操作请求中所包含的SQL语句为:INSERT INTOmytable VALUES(1,‘abc’),首先检测SQL语句开头是否包含类型注释,此SQL语句不包含注释,则判断操作请求的类型,检查SQL语句中的第一个单词,发现是INSERT,从而判断出操作请求的类型是写操作,应当分配给主数据库服务器,检查主数据库服务器,如果主数据库服务器状态正常,则向其分配操作请求,如果主数据库服务器状态不正常,则可以向应用程序服务器返回“数据库不可用”的错误提示。(1) Assuming that the SQL statement contained in the operation request is: INSERT INTOmytable VALUES(1,'abc'), first check whether the beginning of the SQL statement contains a type comment, if the SQL statement does not contain a comment, then determine the type of the operation request, check The first word in the SQL statement is found to be INSERT, so it can be judged that the type of operation request is a write operation, which should be assigned to the main database server, check the main database server, and if the status of the main database server is normal, assign the operation request to it, If the status of the main database server is abnormal, an error message of "database is unavailable" may be returned to the application server.
(2)假设操作请求中所包含的SQL语句为:SELECT*FROMmytable,首先检测SQL语句开头是否包含类型注释,此SQL语句不包含注释,则判断操作请求的类型,检查SQL语句中的第一个单词,发现是SELECT,从而判断出操作请求的类型是读操作,应当分配给从数据库服务器,检查从数据库服务器,如果其状态正常则向其分配操作请求,如果其状态不正常,则检查主数据库服务器,如果主数据库服务器状态正常,则向其分配操作请求,如果主数据库服务器状态不正常,则可以向应用程序服务器返回“数据库不可用”的错误提示。(2) Assuming that the SQL statement contained in the operation request is: SELECT*FROMmytable, first check whether the beginning of the SQL statement contains a type comment, if the SQL statement does not contain a comment, then determine the type of the operation request, and check the first The word is found to be SELECT, so it can be judged that the type of operation request is a read operation, which should be assigned to the slave database server, check the slave database server, if its status is normal, assign the operation request to it, if its status is not normal, then check the master database server, if the state of the main database server is normal, then assign an operation request to it; if the state of the main database server is not normal, then an error prompt of "database is unavailable" may be returned to the application server.
(3)假设操作请求中所包含的SQL语句为:/*master*/SELECT*FROM mytable,首先检测SQL语句开头是否包含类型注释,此句SQL包含注释,且注释内容为/*master*/,表示主数据库服务器,检查主数据库服务器,如果主数据库服务器状态正常,则向其分配操作请求,如果主数据库服务器状态不正常,则可以向应用程序服务器返回“数据库不可用”的错误提示。(3) Assuming that the SQL statement contained in the operation request is: /*master*/SELECT*FROM mytable, first check whether the beginning of the SQL statement contains a type comment. This SQL sentence contains a comment, and the content of the comment is /*master*/, Indicates the main database server, check the main database server, if the main database server status is normal, assign operation request to it, if the main database server status is not normal, you can return the error message of "database is unavailable" to the application server.
本发明提供了一种分配数据库操作请求的方法。根据本发明的实施例,可以解析接收到的对于数据库的操作请求,以检测操作请求中的类型注释,并根据类型注释,确定相对应的数据库服务器,并向其分配该操作请求。这样,应用开发人员通过利用例如在诸如SQL语句之类的操作请求中本来没有意义的注释语句,就可以确定要将操作请求分配给具体数据库服务器,从而极大地提高了应用开发的灵活性。对于实时性要求较高的读操作,只需要简单地在操作请求中添加表示主数据库类型的类型注释,就能自动地将该操作请求分配给主数据库服务器,避免发生找不到所请求的数据或者读取到该数据的旧版本的问题。The invention provides a method for allocating database operation requests. According to the embodiment of the present invention, the received operation request for the database can be parsed to detect the type annotation in the operation request, and according to the type annotation, the corresponding database server can be determined and the operation request can be assigned to it. In this way, the application developer can determine to allocate the operation request to a specific database server by using, for example, the meaningless comment statement in the operation request such as SQL statement, thereby greatly improving the flexibility of application development. For read operations with high real-time requirements, you only need to simply add a type annotation indicating the type of the main database to the operation request, and the operation request can be automatically assigned to the main database server to avoid the occurrence of not being able to find the requested data Or a problem reading an older version of the data.
另外,根据本发明的实施例,在确定了要将操作请求分配到的数据库服务器之后,还可以检查该数据库服务器,并根据检查结果将该操作请求分配给相应的数据库服务器或者返回错误提示。这样,在数据库服务器集群中的某一台或者多台数据库服务器发生故障时,可以自动检测到该故障,不再把操作请求分配给存在故障的数据库服务器。其中,在主数据库服务器出现故障的情况下,写操作无法执行,但读操作不受影响;而在从数据库服务器出现故障的情况下,可以转而将读操作分配给主数据库服务器,从而读写操作均不受影响。这一过程对于应用程序完全透明,应用程序员不在不需要对应用程序作出任何修改,降低了应用程序的维护成本。In addition, according to the embodiment of the present invention, after the database server to which the operation request is assigned is determined, the database server can be checked, and the operation request is assigned to the corresponding database server or an error prompt is returned according to the inspection result. In this way, when one or more database servers in the database server cluster fail, the failure can be automatically detected, and the operation request is no longer allocated to the failed database server. Among them, in the case of failure of the primary database server, the write operation cannot be performed, but the read operation is not affected; and in the case of a failure of the secondary database server, the read operation can be assigned to the primary database server instead, so as to read and write Operations are not affected. This process is completely transparent to the application program, and the application programmer does not need to make any modification to the application program, which reduces the maintenance cost of the application program.
与上述方法100相对应,本发明还提供了一种分配数据库操作请求的设备200。图3示意性地图示了根据本发明的实施例的分配数据库操作请求的设备200。参见图3,设备200主要包括网络接口201、操作请求解析器203、操作请求分配器207。Corresponding to the
根据本发明的实施例,网络接口201适于接收对于数据库的操作请求。操作请求解析器203适于解析操作请求,以检测操作请求中的类型注释。操作请求解析器203还适于确定与类型注释相对应的数据库服务器。操作请求分配器207适于将操作请求分配给所确定的数据库服务器。网络接口201、操作请求解析器203、操作请求分配器207可以分别用于执行上述分配数据库操作请求的方法100中的步骤S101、S103和S105、S107。According to an embodiment of the present invention, the network interface 201 is adapted to receive operation requests for the database. The
根据本发明的实施例,操作请求解析器203解析该操作请求,从而检测操作请求中的类型注释。根据本发明的实施例,该操作请求可以包括数据库程序语言语句,该数据库程序语言可以是SQL,即,该操作请求包括SQL语句。在操作请求解析器203解析操作请求时,例如可以检测SQL语句的开头是否包含类型注释,即是否包含例如“/*master*/”的主数据库类型注释。如果包含,即操作请求解析器203检测到操作请求中的类型注释。随后,操作请求解析器203确定与该检测到的类型注释相对应的数据库服务器。可选地,在此之前,操作请求解析器203可以将该类型注释从操作请求中删除。According to an embodiment of the present invention, the
根据本发明的实施例,数据库服务器可以包括主数据库服务器和从数据库服务器。操作请求解析器203检测该类型注释是否表示主数据库服务器类型,如果是,即,例如类型注释为“/*master*/”,则操作请求解析器203可以确定与该类型注释相对应的数据库服务器为主数据库服务器。这样,随后操作请求分配器207就可以将操作请求分配给主数据库服务器。According to an embodiment of the present invention, the database server may include a master database server and a slave database server. The
然而,当操作请求解析器203未检测到操作请求中的类型注释时,解析操作请求,以判断操作请求的类型。However, when the
根据本发明的实施例,操作请求的类型包括写操作和读操作。操作请求解析器203可以根据SQL语句中的关键字,来判断操作请求的类型。例如,操作请求解析器203可以检测SQL语句中的第一个单词,如果该单词为例如INSERT、UPDATE、REPLACE等表示写操作的单词,则判断操作请求的类型为写操作;而如果该单词为不表示写操作的其它单词,则操作请求解析器203判断操作请求的类型为读操作。然后,操作请求解析器203确定与操作请求类型相对应的数据库服务器。根据本发明的实施例,对应于写操作的数据库服务器是主数据库服务器,对应于读操作的数据库服务器是从数据库服务器。According to an embodiment of the present invention, types of operation requests include write operations and read operations. The
可选地,如果操作请求解析器203检测到操作请求中存在类型注释、但注释类型不表示主数据库服务器类型,则操作请求解析器203解析操作请求,判断操作请求的类型,并且操作请求解析器203确定与该类型相对应的数据库服务器。随后,操作请求分配器207将该操作请求分配给与操作请求的类型相对应的数据库服务器,即,如果操作请求的类型是写操作,则操作请求分配器207将操作请求分配给主数据库服务器;而如果操作请求的类型是读操作,则操作请求分配器207将操作请求分配给从数据库服务器。Optionally, if the
根据本发明的实施例,操作请求解析器203在确定数据库服务器之后,由数据库检查器205检查数据库服务器,随后,操作请求分配器207根据检查结果将操作请求分配给相应的数据库服务器或者返回错误提示。其中,在操作请求解析器203所确定的是从数据库服务器的情况下,在检查结果表示从数据库服务器状态正常时,操作请求分配器207将操作请求分配给从数据库服务器;在检查结果表示从数据库服务器状态不正常时,数据库检查器205检查主数据库服务器,在主数据库服务器状态正常时,操作请求分配器207将操作请求分配给主数据库服务器,在主数据库服务器状态不正常时,操作请求分配器207返回表示数据库服务器不可用的错误提示。而在操作请求解析器203所确定的数据库服务器是主数据库服务器的情况下,在检查结果表示主数据库服务器状态正常时,操作请求分配器207将操作请求分配给主数据库服务器;在检查结果表示主数据库服务器状态不正常时,操作请求分配器207返回表示数据库服务器不可用的错误提示。According to an embodiment of the present invention, after the
由于上述各设备(装置)实施例与前述各方法实施例相对应,因此不再对各装置实施例进行详细描述。Since the foregoing device (device) embodiments correspond to the aforementioned method embodiments, detailed descriptions of the respective device embodiments are omitted.
根据本发明的又一方面,还提供了一种分配数据库操作请求的系统1000。参见图3,系统1000包括上述设备200;一个或者多个应用程序服务器300-1、…、300-n,适于向设备200发送对于数据库的操作请求;以及主数据库服务器400a以及一个或者多个从数据库服务器400b1、…、400bn,适于响应于设备200的检查,向设备200返回其状态,并且接收设备200分配的操作请求。According to yet another aspect of the present invention, a
在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The algorithms and displays presented herein are not inherently related to any particular computer, virtual system, or other device. Various generic systems can also be used with the teachings based on this. The structure required to construct such a system is apparent from the above description. Furthermore, the present invention is not specific to any particular programming language. It should be understood that various programming languages can be used to implement the content of the present invention described herein, and the above description of specific languages is for disclosing the best mode of the present invention.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure the understanding of this description.
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, in order to streamline this disclosure and to facilitate an understanding of one or more of the various inventive aspects, various features of the invention are sometimes grouped together in a single embodiment, figure, or its description. This method of disclosure, however, is not to be interpreted as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the Detailed Description are hereby expressly incorporated into this Detailed Description, with each claim standing on its own as a separate embodiment of this invention.
本领域那些技术人员可以理解,可以对实施例中的装置中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个装置中。可以把实施例中的若干模块组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者模块中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的替代特征来代替。Those skilled in the art can understand that the modules in the device in the embodiment can be adaptively changed and arranged in one or more devices different from the embodiment. Several modules in an embodiment can be combined into one module or unit or assembly, and further they can be divided into a plurality of sub-modules or sub-units or sub-assemblies. All features disclosed in this specification (including accompanying claims, abstract and drawings) and any method or method so disclosed may be used in any combination, except that at least some of such features and/or procedures or modules are mutually exclusive. All processes or units of equipment are combined. Each feature disclosed in this specification (including accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
此外,本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。Furthermore, those skilled in the art will understand that although some embodiments described herein include some features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention. and form different embodiments. For example, in the claims, any one of the claimed embodiments can be used in any combination.
本发明的各个装置实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的装置中的一些或者全部模块的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various apparatus embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all functions of some or all modules in the apparatus according to the embodiment of the present invention. The present invention can also be implemented as an apparatus program (for example, a computer program and a computer program product) for performing a part or all of the methods described herein. Such a program for realizing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet site, or provided on a carrier signal, or provided in any other form.
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means can be embodied by one and the same item of hardware. The use of the words first, second, and third, etc. does not indicate any order. These words can be interpreted as names.
Claims (9)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2012104833443A CN102982145A (en) | 2012-11-23 | 2012-11-23 | System for allocating database operating requests |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2012104833443A CN102982145A (en) | 2012-11-23 | 2012-11-23 | System for allocating database operating requests |
Publications (1)
Publication Number | Publication Date |
---|---|
CN102982145A true CN102982145A (en) | 2013-03-20 |
Family
ID=47856162
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2012104833443A Pending CN102982145A (en) | 2012-11-23 | 2012-11-23 | System for allocating database operating requests |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102982145A (en) |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103390041A (en) * | 2013-07-18 | 2013-11-13 | 杭州东信北邮信息技术有限公司 | Method and system for providing data service based on middleware |
CN104866597A (en) * | 2015-05-29 | 2015-08-26 | 北京奇虎科技有限公司 | Method and apparatus for analyzing database access request |
CN106970934A (en) * | 2017-01-16 | 2017-07-21 | 平安银行股份有限公司 | Trading processing control method and system |
CN111078802A (en) * | 2019-12-31 | 2020-04-28 | 叮当快药科技集团有限公司 | Database reading and writing method and related device |
CN114077751A (en) * | 2020-08-17 | 2022-02-22 | 中国电信股份有限公司 | Method, system and storage medium for separating database read and write |
CN114791918A (en) * | 2022-03-16 | 2022-07-26 | 阿里云计算有限公司 | Data operation method, device, equipment and storage medium |
CN118503319A (en) * | 2024-07-18 | 2024-08-16 | 飞狐信息技术(天津)有限公司 | Database operation method, device, equipment, storage medium and product |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US2000321A (en) * | 1933-10-20 | 1935-05-07 | North American Chemical Compan | Magazine shoe filler unit |
US20030217064A1 (en) * | 2002-05-17 | 2003-11-20 | Walters Arthur P. | Separation of database transactions |
CN102033912A (en) * | 2010-11-25 | 2011-04-27 | 北京北纬点易信息技术有限公司 | Distributed-type database access method and system |
CN102129434A (en) * | 2010-01-13 | 2011-07-20 | 腾讯科技(北京)有限公司 | Method and system for reading and writing separation database |
CN102591964A (en) * | 2011-12-30 | 2012-07-18 | 北京新媒传信科技有限公司 | Implementation method and device for data reading-writing splitting system |
-
2012
- 2012-11-23 CN CN2012104833443A patent/CN102982145A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US2000321A (en) * | 1933-10-20 | 1935-05-07 | North American Chemical Compan | Magazine shoe filler unit |
US20030217064A1 (en) * | 2002-05-17 | 2003-11-20 | Walters Arthur P. | Separation of database transactions |
CN102129434A (en) * | 2010-01-13 | 2011-07-20 | 腾讯科技(北京)有限公司 | Method and system for reading and writing separation database |
CN102033912A (en) * | 2010-11-25 | 2011-04-27 | 北京北纬点易信息技术有限公司 | Distributed-type database access method and system |
CN102591964A (en) * | 2011-12-30 | 2012-07-18 | 北京新媒传信科技有限公司 | Implementation method and device for data reading-writing splitting system |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103390041A (en) * | 2013-07-18 | 2013-11-13 | 杭州东信北邮信息技术有限公司 | Method and system for providing data service based on middleware |
CN103390041B (en) * | 2013-07-18 | 2016-05-04 | 杭州东信北邮信息技术有限公司 | A kind of method and system that data, services is provided based on middleware |
CN104866597A (en) * | 2015-05-29 | 2015-08-26 | 北京奇虎科技有限公司 | Method and apparatus for analyzing database access request |
CN104866597B (en) * | 2015-05-29 | 2019-04-23 | 北京奇虎科技有限公司 | Method and device for analyzing database access request |
CN106970934A (en) * | 2017-01-16 | 2017-07-21 | 平安银行股份有限公司 | Trading processing control method and system |
CN111078802A (en) * | 2019-12-31 | 2020-04-28 | 叮当快药科技集团有限公司 | Database reading and writing method and related device |
CN114077751A (en) * | 2020-08-17 | 2022-02-22 | 中国电信股份有限公司 | Method, system and storage medium for separating database read and write |
CN114791918A (en) * | 2022-03-16 | 2022-07-26 | 阿里云计算有限公司 | Data operation method, device, equipment and storage medium |
CN118503319A (en) * | 2024-07-18 | 2024-08-16 | 飞狐信息技术(天津)有限公司 | Database operation method, device, equipment, storage medium and product |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102982145A (en) | System for allocating database operating requests | |
US9317555B2 (en) | Query method for a distributed database system and query apparatus | |
US7937455B2 (en) | Methods and systems for modifying nodes in a cluster environment | |
EP3944082A1 (en) | Extending the kubernetes api in-process | |
CN103678354B (en) | Local relation type database node scheduling method and device based on cloud computing platform | |
US20150277993A1 (en) | Task Processing Method and Virtual Machine | |
US8196100B2 (en) | Content management system for computer software with dynamic traceability between code and design documents | |
US20160364317A1 (en) | Method for debugging a computer program | |
CN103455368B (en) | A kind of deadlock detection method, node and system | |
JP2019516171A (en) | Service processing method, device and system | |
CN116601606A (en) | Multi-tenant control plane management on a computing platform | |
US20090150859A1 (en) | Dynamic validation of models using constraint targets | |
US20220109605A1 (en) | Implementing Affinity and Anti-Affinity with Kubernetes | |
JP5652480B2 (en) | Database update notification method | |
CN105550306A (en) | Multi-copy data reading/writing method and system | |
KR20180044579A (en) | System and method for managing container-based distributed application | |
CN109426544A (en) | Virtual machine deployment method and device | |
CN110555317A (en) | Application file change processing method, device and system | |
US20090182877A1 (en) | Ineligible group member status | |
CN108897865A (en) | The index copy amount appraisal procedure and device of distributed type assemblies | |
US11366743B2 (en) | Computing resource coverage | |
RU2721235C2 (en) | Method and system for routing and execution of transactions | |
RU2606877C1 (en) | System and method of processing data in executed on computer system | |
CN110825487A (en) | Management method for preventing split brain of virtual machine and main server | |
CN102999392B (en) | The method and apparatus of allocation database operation requests |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20130320 |