WO2016095644A1 - High availability solution method and device for database - Google Patents
High availability solution method and device for database Download PDFInfo
- Publication number
- WO2016095644A1 WO2016095644A1 PCT/CN2015/094813 CN2015094813W WO2016095644A1 WO 2016095644 A1 WO2016095644 A1 WO 2016095644A1 CN 2015094813 W CN2015094813 W CN 2015094813W WO 2016095644 A1 WO2016095644 A1 WO 2016095644A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- connection
- address
- database
- client
- port number
- 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.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
- G06F16/252—Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2458—Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
- G06F16/2471—Distributed queries
Definitions
- the present invention relates to the field of computers, and in particular, to a high availability solution and apparatus for a database.
- MongoDB is a non-relational database (NoSQL) that is very popular in the IT industry. Its flexible data storage method is favored by current IT practitioners. With the rise of the Internet Web2.0 website, NoSQL has set off a boom in China, and the most powerful one is MongoDB. More and more industry companies have put MongoDB into the actual application environment, and many startup teams have used MongoDB as their preferred database to create a lot of mobile Internet applications.
- NoSQL non-relational database
- the client and the database are directly connected.
- the client requests a service from the MongoDB database, it directly sends a connection request to the IP address of the corresponding MongoDB database, and obtains the required data after the connection is established.
- the client accesses the MongoDB database for the first time, it establishes a connection for the client and saves the established connection in the connection manager of the MongoDB driver.
- the client accesses for the second time, it can be in the connection manager.
- the saved connections are multiplexed.
- the present invention has been made in order to provide a highly available solution and corresponding apparatus for a database that overcomes the above problems or at least partially solves the above problems.
- a highly available solution for a database comprising:
- connection manager Detecting, in the connection manager, a connection corresponding to an IP address and a port number of the corresponding database
- connection is used by the client to access the corresponding database.
- a high availability solution for a database comprising:
- the conversion module is adapted to receive the incoming LVS IP address and port number of the client, and parse the LVS IP address and port number into an IP address and a port number of the corresponding database by using the LVS;
- connection management module configured to detect whether a connection corresponding to an IP address and a port number of the corresponding database exists in the connection manager
- a result returning module adapted to return the connection to the client when there is a connection corresponding to an IP address and a port number of the corresponding database
- connection is used by the client to access the corresponding database.
- the embodiment of the present invention provides a high-availability solution and device for a database.
- the LVS IP address is converted into an IP address of a corresponding database, so that the corresponding database driver can obtain a corresponding response according to the conversion.
- the IP address of the database is searched for the corresponding connection in the connection manager, and the connection is reused.
- This solves the problem that when the LVS is combined with the corresponding database, the database driver cannot find the connection corresponding to the LVS IP address and needs to re-establish the connection.
- the problem is very effective in reducing the performance overhead incurred when the client accesses the database, and avoids the problem that the corresponding database cannot provide services due to the full number of concurrent connections when there are a large number of concurrent requests.
- a computer program comprising computer readable code, when said computer readable code is run on a computing device, causing said computing device to perform a high database as described above A workaround is available.
- a computer readable medium storing the above computer program is provided.
- FIG. 1 is a schematic diagram of an access structure of a client and a database according to an embodiment of the present invention
- FIG. 2 is a schematic flowchart of a high availability solution method of a MongoDB database according to an embodiment of the present invention
- FIG. 3 is a detailed architectural diagram of an access system of an existing MongoDB database
- FIG. 4 is a schematic structural diagram of an improved access system of a MongoDB database according to an embodiment of the present invention.
- FIG. 5 is a schematic flowchart of a high availability solution of a MongoDB database according to an embodiment of the present invention.
- FIG. 6 is a schematic structural diagram of a high availability solution device for a database according to an embodiment of the present invention.
- Figure 7 is a schematic block diagram of a computing device for performing a highly available solution for a database in accordance with the present invention.
- Fig. 8 schematically shows a storage unit for holding or carrying program code implementing a highly available solution of a database according to the invention.
- Embodiments of the present invention provide a solution for making a database highly available, which can be implemented by establishing a connection control device (also referred to as an intermediate layer) between a client and a database or by improving the connection manager.
- the connection control device can be implemented by a server deployed between the client and the database.
- FIG. 1 is a schematic diagram of an access structure of a client and a database provided by the present invention.
- connection control device is not limited to being implemented by a server, and those skilled in the art may implement the connection control device in other manners on the basis of reading the present invention, which are all included in the scope of the present invention. .
- the embodiment of the invention provides a high availability solution of the MongoDB database. It can be improved by the connection manager, so that the IP address of the LVS can also reuse the existing connection in the connection manager, so that the access system of the MongoDB database is highly available.
- FIG. 2 is a flowchart of a high availability solution of a MongoDB database provided by this embodiment. The method specifically includes steps S202 to S206.
- S202 Receive the LVS IP address and port number of the incoming client, and resolve the LVS IP address and port number to the MongoDB IP address and port number through the LVS.
- connection is used for the client to connect to the MongoDB database.
- the embodiment of the present invention provides a high-availability solution for the MongoDB database.
- the LVS IP address is converted into a corresponding MongoDB IP address, so that the MongDB driver can obtain the MongoDB IP according to the conversion.
- the address in the connection manager finds the corresponding connection, and then multiplexes the connection, which solves the problem that when the LVS is combined with the MongoDB database, the MongDB driver cannot find the connection corresponding to the LVS IP address and needs to re-establish the connection. It effectively reduces the performance overhead incurred when the client accesses the MongoDB database, and avoids the problem that the MongoDB database cannot have a full number of concurrent requests due to the full number of MongoDB service connections.
- This embodiment is a specific application scenario of the foregoing first embodiment. Through the embodiment, the method provided by the present invention can be more clearly and specifically illustrated.
- Figure 3 shows the detailed architecture of the access system of the existing MongoDB database, including:
- the client is the device that initiates access to the MongoDB database, and can be a client or other terminal with front-end services.
- an access request may be initiated to the MongoDB database
- the server of the online game needs to retrieve data of multiple users in the MongoDB database.
- LVS is a virtual server cluster system, which can be responsible for load balancing of cluster servers of MongoDB database. It can allocate access requests from different clients to different nodes in the cluster server of MongoDB database, so that some of the cluster servers in MongoDB database A node does not crash due to excessive load.
- the MongoDB driver is responsible for establishing a connection between the client and the nodes in the cluster server of the MongoDB database, and saving the available connections for reuse when the client accesses the MongoDB database again.
- the MongoDB driver includes a connection manager for saving the established connection.
- MongoDB IP address the IP address of the node in the cluster server of the MongoDB database
- the MongoDB database is a relational database that can be used to store more complex data types.
- the MongoDB database can be deployed on a server or deployed on a cluster server.
- Each server used to deploy the MongoDB database can be considered as a database node.
- the LVS since the LVS is used in the access system of the MongoDB database shown in FIG. 3, after receiving the access request from the client, the LVS transmits the LVS IP address to the MongoDB driver, and the MongoDB IP address is saved in the connection manager. Correspondence with the connection, so for this client, even if the connection is saved in the connection manager, the connection cannot be found and reused because the LVS IP cannot be recognized. Therefore, the MongoDB driver needs to re-establish the connection for the client. In the access system of the MongoDB database, it takes a lot of computing resources to establish a connection each time. When the concurrent access to the MongoDB database is too high, it may cause the MongoDB service. The problem is that the connection is full and the service cannot be provided.
- FIG. 4 is an architecture diagram of an improved access system of the MongoDB database provided by the embodiment of the present invention, between the client and the MongoDB database.
- a conversion module you can use the connection in the Multiplex Connection Manager by converting the incoming LVS IP address to the MongoDB IP address. Therefore, the calculation amount of the access system of the MongoDB database is greatly reduced, and the downtime caused by concurrency is avoided to the utmost extent.
- the conversion module can be driven independently of MongoDB or reside in a MongoDB driver.
- the conversion module resides in the MongoDB driver, it can also be independent of the connection manager or in the connection manager.
- the conversion module shown in FIG. 4 is located in the MongoDB driver and is independent of the connection manager, the invention is not limited thereto.
- FIG. 5 is a flowchart of a high-availability solution specific method of a MongoDB database according to an embodiment of the present invention. The method is applicable to the apparatus shown in FIG. 4, and the method includes steps S501 to S506.
- step S501 the client initiates an access request to the MongoDB database through the LVS.
- the access request for the MongoDB database can be a request for a service that can be provided by any MongoDB database.
- the client When the client is a browser, the user may log in to the website corresponding to the network storage, initiate a query or download a request for personal data;
- the client When the client is a game program, it is possible to obtain the attribute information, the number of battles, etc. of the character of the user in the game. Upon request.
- the LVS is responsible for performing a load balancing operation, and shifting the user's request to its assigned LVS IP address and port number.
- the LVS After receiving the user's access request to the MongoDB database, the LVS forwards the request of the user to the corresponding LVS IP address and port number, and performs step S502 to drive the access request carrying the LVS IP address and port number to the MongoDB driver.
- the IP address and the port number are two necessary elements, and in addition, the user name, password, and the like associated with the access request may be included.
- the MongoDB driver After receiving the incoming LVS IP address, the MongoDB driver performs step S503, and MongoDB converts the above LVS IP address and port number into a MongoDB IP address and port number through LVS.
- step S503 The operation performed in this step S503 is completed by the conversion module shown in FIG. 4.
- the MongoDB driver cannot query the connection according to the connection manager, and a new connection is established for the request for the LVS IP address. A new connection establishment process.
- the correspondence between the LVS IP address and the MongoDB IP address is stored in the LVS. Therefore, the conversion module can resolve the LVS IP address to the MongoDB IP address through the LVS.
- step S504 is executed, and the MongoDB driver detects whether the connection corresponding to the MongoDB IP address and port number is stored in the connection manager.
- step S505 is executed to return the connection to the client, and the client performs read and write operations according to the connection.
- step S506 is executed to initiate a process of establishing a new connection for the incoming LVS IP address and port number.
- the method for establishing a new connection for the incoming LVS IP address and port number may include the following steps:
- the method for detecting whether the incoming LVS IP address matches the IP address of MongoDB may be:
- step (3) can be performed at this time.
- step (6) is performed.
- step (7) can be performed as follows:
- the client service is a data write operation or a data modification operation, returning a second connection corresponding to the primary data node to the client;
- a second connection corresponding to the primary data node or from the data node is returned to the client according to the read priority policy.
- the method may further include the following steps:
- the new connection (ie, the second connection in the above steps) is saved to the connection manager for reuse by the client next time.
- the method further includes:
- connection If the connection is ok, establish a connection between the client and the data node;
- connection manager If the connection is not available, the data node is added to the blacklist and the connection manager re-establishes a new connection for the client.
- the method of pinging the data node may be used to observe whether the data is returned normally.
- the embodiment of the present invention provides a high-availability solution for the MongoDB database.
- the LVS IP address is converted into a corresponding MongoDB IP address, so that the MongDB driver can obtain the MongoDB IP according to the conversion.
- the address in the connection manager finds the corresponding connection, and then reuses the connection, which solves the problem that the MongDB driver cannot find the LVS IP when the LVS is combined with the MongoDB database.
- the connection corresponding to the address needs to re-establish the connection problem, which effectively reduces the performance overhead incurred when the client accesses the MongoDB database, and avoids the large number of concurrent requests of the MongoDB database. Service problem.
- FIG. 6 is a structural block diagram of a high availability solution device for a database according to an embodiment of the present invention.
- the device 600 includes:
- the conversion module 610 is adapted to receive an incoming LVS IP address and a port number of the client, and parse the LVS IP address and the port number into an IP address and a port number of the corresponding database by using a Linux virtual server LVS;
- the connection management module 620 is configured to detect whether a connection corresponding to an IP address and a port number of the corresponding database exists in the connection manager.
- the result returning module 630 is adapted to return the connection to the client when there is a connection corresponding to the IP address and the port number of the corresponding database;
- the above connection is used for the client to access the corresponding database.
- the apparatus 600 further includes:
- the first creating module 640 is configured to: when there is no connection corresponding to the IP address and the port number of the corresponding database, create a first connection corresponding to the LVS IP address and the port number, and register the first connection in the connection manager. .
- the device further includes an address matching module 650, where the address matching module specifically includes:
- the determining unit 651 is adapted to determine whether the LVS IP address matches the IP address of the corresponding database after establishing the first connection corresponding to the LVS IP address and the port number in the connection manager;
- the deleting unit 652 is configured to delete the first connection after the determining unit 651 determines that the matching is not performed.
- the device further includes a second creating module 660, where the second creating module 660 includes:
- the obtaining unit 661 is configured to obtain an IP address and a port number of all available data nodes in the corresponding database after determining that the incoming LVS IP address does not match the IP address of the corresponding database;
- the detecting unit 662 is adapted to detect whether there is a connection in the connection manager corresponding to an IP address and a port number of the available data node;
- the creating unit 663 is adapted to, when not present, create a second connection corresponding to an IP address and a port number of each of the available data nodes, and register the second connection in the connection manager;
- the second creating module 660 further includes:
- the returning unit 664 is adapted to return the second connection corresponding to the client service to the client according to the preset condition.
- the database is a master-slave structure
- the returning unit 664 is adapted to return the second connection corresponding to the client service to the client in the following manner:
- the client service is a data write operation or a data modification operation, returning a second connection corresponding to the primary data node to the client;
- the second connection corresponding to the primary data node or from the data node is returned to the client according to the read priority policy.
- the device 600 further includes a test module 670, the test module 670 includes:
- the testing unit 671 is adapted to test whether the returned data node corresponding to the second connection is available after returning the second connection corresponding to the client service to the client according to the preset condition;
- the recording unit 672 is adapted to add the data node to the preset blacklist when the data node is unavailable.
- the embodiment of the present invention can achieve the following beneficial effects:
- the embodiment of the present invention provides a high-availability solution for a database.
- the LVS IP address is converted into an IP address of a corresponding database, so that the corresponding database driver can be converted according to the corresponding database.
- the IP address finds the corresponding connection in the connection manager, and then multiplexes the connection, which solves the problem that when the LVS is combined with the corresponding database, the database driver cannot find the connection corresponding to the LVS IP address and needs to re-establish the connection.
- the performance overhead incurred when the client accesses the database is effectively reduced, and the problem that the corresponding database cannot provide the service due to the full number of concurrent connections is avoided.
- modules in the devices of the embodiments can be adaptively changed and placed in one or more devices different from the embodiment.
- the modules or units or components in the embodiments may be combined into one module or unit or component, and further, they may be divided into multiple sub-modules or sub-units. Or subcomponents.
- any combination of the features disclosed in the specification, including the accompanying claims, the abstract and the drawings, and any methods so disclosed, or All processes or units of the device are combined.
- the various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof.
- Those skilled in the art will appreciate that some or all of the functionality of some or all of the high availability resolution devices of the database in accordance with embodiments of the present invention may be implemented in practice using a microprocessor or digital signal processor (DSP).
- DSP digital signal processor
- the invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein.
- Such a program implementing the invention may be stored on a computer readable medium or may be in the form of one or more signals. Such signals may be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.
- Figure 7 illustrates a computing device that can implement a highly available solution for a database.
- the computing device traditionally includes a computer program product or computer readable medium in the form of a processor 710 and a memory 720.
- Memory 720 can be an electronic memory such as a flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM.
- Memory 720 has a storage space 730 that stores program code 731 for performing any of the method steps described above.
- storage space 730 storing program code may include various program code 731 for implementing various steps in the above methods, respectively.
- the program code can be read from or written to one or more computer program products.
- Such computer program products include program code carriers such as hard disks, compact disks (CDs), memory cards or floppy disks.
- Such a computer program product is typically a portable or fixed storage unit such as that shown in FIG.
- the storage unit may have storage segments, storage spaces, and the like that are similarly arranged to memory 720 in the computing device of FIG.
- the program code can be compressed, for example, in an appropriate form.
- the storage unit includes computer readable code 731' for performing the method steps of the present invention, ie, code that can be read by a processor, such as 710, that when executed by the computing device causes the computing device to execute Each of the steps in the method described above.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Fuzzy Systems (AREA)
- Mathematical Physics (AREA)
- Probability & Statistics with Applications (AREA)
- Software Systems (AREA)
- Computational Linguistics (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
本发明涉及计算机领域,具体涉及一种数据库的高可用解决方法和装置。The present invention relates to the field of computers, and in particular, to a high availability solution and apparatus for a database.
MongoDB,是目前在IT行业非常流行的一种非关系型数据库(NoSQL),其灵活的数据存储方式,备受当前IT从业人员的青睐。随着互联网Web2.0网站的兴起,NoSQL在国内掀起一阵热潮,其中风头最劲的莫过于MongoDB了。越来越多的业界公司已经将MongoDB投入实际的应用环境,很多创业团队也将MongoDB作为自己的首选数据库,创造出非常之多的移动互联网应用。MongoDB is a non-relational database (NoSQL) that is very popular in the IT industry. Its flexible data storage method is favored by current IT practitioners. With the rise of the Internet Web2.0 website, NoSQL has set off a boom in China, and the most powerful one is MongoDB. More and more industry companies have put MongoDB into the actual application environment, and many startup teams have used MongoDB as their preferred database to create a lot of mobile Internet applications.
在目前的MongoDB数据库中,客户端与数据库是直接连接的,客户端向MongoDB数据库请求某种服务时,直接向对应的MongoDB数据库的IP地址发送连接请求,并在连接建立后获取所需数据。In the current MongoDB database, the client and the database are directly connected. When the client requests a service from the MongoDB database, it directly sends a connection request to the IP address of the corresponding MongoDB database, and obtains the required data after the connection is established.
当客户端第一次访问MongoDB数据库时,会为客户端建立连接,并将建立好的连接保存在MongoDB驱动的连接管理器中,当客户端第二次访问时,即可对连接管理器中已保存的连接进行复用。When the client accesses the MongoDB database for the first time, it establishes a connection for the client and saves the established connection in the connection manager of the MongoDB driver. When the client accesses for the second time, it can be in the connection manager. The saved connections are multiplexed.
但是,当对于MongoDB数据库的数据节点发生变化时,会造成已有连接无法复用,从而因连接失败而需要重新建立针对数据节点的连接的操作,产生大量的性能消耗以及重复操作。而目前并未有有效技术能够解决这一技术问题。However, when the data nodes of the MongoDB database change, the existing connections cannot be reused, and the connection to the data nodes needs to be re-established due to the connection failure, resulting in a large amount of performance consumption and repeated operations. There is currently no effective technology to solve this technical problem.
发明内容Summary of the invention
鉴于上述问题,提出了本发明以便提供一种克服上述问题或者至少部分地解决上述问题的一种数据库的高可用解决方法和相应地装置。In view of the above problems, the present invention has been made in order to provide a highly available solution and corresponding apparatus for a database that overcomes the above problems or at least partially solves the above problems.
根据本发明的一方面,提供了一种数据库的高可用解决方法,包括:According to an aspect of the present invention, a highly available solution for a database is provided, comprising:
接收客户端传入的LVS(Linux Virtual Server,Linux虚拟服务器)IP地址、端口号,并通过LVS将所述LVS IP地址、端口号解析为对应数据库的IP地址、端口号;Receiving the IP address and port number of the incoming LVS (Linux Virtual Server) of the client, and parsing the LVS IP address and port number into the IP address and port number of the corresponding database through the LVS;
检测连接管理器中是否存在与所述对应数据库的IP地址、端口号对应的连接;以及Detecting, in the connection manager, a connection corresponding to an IP address and a port number of the corresponding database;
当存在与所述对应数据库的IP地址、端口号对应的连接时,将所述连接返回给所述客户端;When there is a connection corresponding to the IP address and the port number of the corresponding database, returning the connection to the client;
其中,所述连接用于所述客户端访问所述对应数据库。 The connection is used by the client to access the corresponding database.
根据本发明的另一方面,还提供了一种数据库的高可用解决装置,包括:According to another aspect of the present invention, there is also provided a high availability solution for a database, comprising:
转换模块,适于接收客户端传入的LVS IP地址、端口号,并通过LVS将所述LVS IP地址、端口号解析为对应数据库的IP地址、端口号;The conversion module is adapted to receive the incoming LVS IP address and port number of the client, and parse the LVS IP address and port number into an IP address and a port number of the corresponding database by using the LVS;
连接管理模块,适于检测连接管理器中是否存在与所述对应数据库的IP地址、端口号对应的连接;a connection management module, configured to detect whether a connection corresponding to an IP address and a port number of the corresponding database exists in the connection manager;
结果返回模块,适于当存在与所述对应数据库的IP地址、端口号对应的连接时,将所述连接返回给所述客户端;a result returning module adapted to return the connection to the client when there is a connection corresponding to an IP address and a port number of the corresponding database;
其中,所述连接用于所述客户端访问所述对应数据库。The connection is used by the client to access the corresponding database.
本发明的有益效果为:The beneficial effects of the invention are:
本发明实施例提供了一种数据库的高可用解决方法和装置,通过在接收传入的LVS IP地址后,将LVS IP地址转换为对应数据库的IP地址,使得对应数据库驱动可根据转换得到的对应数据库的IP地址在连接管理器中查找与其对应的连接,进而复用该连接,解决了在LVS与对应数据库在结合使用时,数据库驱动不能查找与LVS IP地址对应的连接从而需要重新建立连接的问题,进而非常有效的减少了客户端对数据库进行访问时产生的性能开销,避免了对应的数据库存在大量并发请求时由于服务连接数满而无法提供服务的问题。The embodiment of the present invention provides a high-availability solution and device for a database. After receiving an incoming LVS IP address, the LVS IP address is converted into an IP address of a corresponding database, so that the corresponding database driver can obtain a corresponding response according to the conversion. The IP address of the database is searched for the corresponding connection in the connection manager, and the connection is reused. This solves the problem that when the LVS is combined with the corresponding database, the database driver cannot find the connection corresponding to the LVS IP address and needs to re-establish the connection. The problem, in turn, is very effective in reducing the performance overhead incurred when the client accesses the database, and avoids the problem that the corresponding database cannot provide services due to the full number of concurrent connections when there are a large number of concurrent requests.
根据本发明的又一方面,提供了一种计算机程序,其包括计算机可读代码,当所述计算机可读代码在计算设备上运行时,导致所述计算设备执行如上文所述的数据库的高可用解决方法。According to still another aspect of the present invention, there is provided a computer program comprising computer readable code, when said computer readable code is run on a computing device, causing said computing device to perform a high database as described above A workaround is available.
根据本发明的再一方面,提供了一种计算机可读介质,其中存储了上述的计算机程序。According to still another aspect of the present invention, a computer readable medium storing the above computer program is provided.
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。The above description is only an overview of the technical solutions of the present invention, and the above-described and other objects, features and advantages of the present invention can be more clearly understood. Specific embodiments of the invention are set forth below.
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those skilled in the art from a The drawings are only for the purpose of illustrating the preferred embodiments and are not to be construed as limiting. Throughout the drawings, the same reference numerals are used to refer to the same parts. In the drawing:
图1是本发明一个实施例提供的客户端与数据库的访问结构示意图;1 is a schematic diagram of an access structure of a client and a database according to an embodiment of the present invention;
图2是本发明一个实施例提供的一种MongoDB数据库的高可用解决方法流程示意图; 2 is a schematic flowchart of a high availability solution method of a MongoDB database according to an embodiment of the present invention;
图3是现有的MongoDB数据库的访问系统的详细架构示意图;3 is a detailed architectural diagram of an access system of an existing MongoDB database;
图4是本发明一个实施例提供的一种改进的MongoDB数据库的访问系统的架构示意图;4 is a schematic structural diagram of an improved access system of a MongoDB database according to an embodiment of the present invention;
图5是本发明一个实施例提供的一种MongoDB数据库的高可用解决方法具体流程示意图;FIG. 5 is a schematic flowchart of a high availability solution of a MongoDB database according to an embodiment of the present invention; FIG.
图6是本发明一个实施例提供的一种数据库的高可用解决装置结构示意图;FIG. 6 is a schematic structural diagram of a high availability solution device for a database according to an embodiment of the present invention; FIG.
图7示意性地示出了用于执行根据本发明的数据库的高可用解决方法的计算设备的框图;以及Figure 7 is a schematic block diagram of a computing device for performing a highly available solution for a database in accordance with the present invention;
图8示意性地示出了用于保持或者携带实现根据本发明的数据库的高可用解决方法的程序代码的存储单元。Fig. 8 schematically shows a storage unit for holding or carrying program code implementing a highly available solution of a database according to the invention.
下面结合附图和具体的实施方式对本发明作进一步的描述。The invention is further described below in conjunction with the drawings and specific embodiments.
本发明实施例提供了一种使数据库高可用的解决方案,其可以通过在客户端和数据库之间建立连接控制装置(亦可称为中间层)或通过对连接管理器进行改进来实现。其中,该连接控制装置可以通过部署在客户端与数据库之间的服务器来实现。Embodiments of the present invention provide a solution for making a database highly available, which can be implemented by establishing a connection control device (also referred to as an intermediate layer) between a client and a database or by improving the connection manager. Wherein, the connection control device can be implemented by a server deployed between the client and the database.
LVS是一个虚拟的服务器集群系统,其中IP负载均衡技术是在负载调度器的实现技术中效率最高的。在本发明中,MongoDB数据库集群的部署中采用LVS+MongoDB的方式。如图1所示,为本发明提供的客户端与数据库的访问结构示意图。LVS is a virtual server cluster system, in which IP load balancing technology is the most efficient in the implementation of load scheduler. In the present invention, the deployment of the MongoDB database cluster adopts the LVS+MongoDB approach. FIG. 1 is a schematic diagram of an access structure of a client and a database provided by the present invention.
应可理解,本发明并不限定数据库的类型,只要可以应用本发明下述方案以达到高可用目的的数据库都适用于此。此外,所述连接控制装置也不限定于通过服务器来实现,本领域技术人员在阅读本发明的基础上亦可以其他方式来实施所述的连接控制装置,其皆应涵盖在本发明的范围内。It should be understood that the present invention does not limit the type of database, as long as a database to which the following scheme of the present invention can be applied to achieve high availability is applicable. In addition, the connection control device is not limited to being implemented by a server, and those skilled in the art may implement the connection control device in other manners on the basis of reading the present invention, which are all included in the scope of the present invention. .
以下,将以MongoDB数据库为例说明本发明的技术方案:Hereinafter, the technical solution of the present invention will be described by taking the MongoDB database as an example:
实施例一Embodiment 1
本发明实施例提供了一种MongoDB数据库的高可用解决方法。其可以通过对连接管理器进行改进实现,使得LVS的IP地址也可以复用连接管理器中的已有连接,从而达到MongoDB数据库的访问系统的高可用。The embodiment of the invention provides a high availability solution of the MongoDB database. It can be improved by the connection manager, so that the IP address of the LVS can also reuse the existing connection in the connection manager, so that the access system of the MongoDB database is highly available.
图2是本实施例提供的一种MongoDB数据库的高可用解决方法流程图。该方法具体包括步骤S202至步骤S206。FIG. 2 is a flowchart of a high availability solution of a MongoDB database provided by this embodiment. The method specifically includes steps S202 to S206.
S202:接收客户端传入的LVS IP地址、端口号,并通过LVS将该LVS IP地址、端口号解析为MongoDB IP地址、端口号。 S202: Receive the LVS IP address and port number of the incoming client, and resolve the LVS IP address and port number to the MongoDB IP address and port number through the LVS.
S204:检测连接管理器中是否存在与MongoDB IP地址、端口号对应的连接。S204: Detect whether there is a connection corresponding to the MongoDB IP address and port number in the connection manager.
S206:当存在与MongoDB IP地址、端口号对应的连接时,将连接返回给客户端。S206: When there is a connection corresponding to the MongoDB IP address and port number, the connection is returned to the client.
其中,连接用于客户端连接MongoDB数据库。Among them, the connection is used for the client to connect to the MongoDB database.
本发明实施例提供了一种MongoDB数据库的高可用解决方法,在接收客户端传入的LVS IP地址后,将LVS IP地址转换为对应的MongoDB IP地址,使得MongDB驱动可根据转换得到的MongoDB IP地址在连接管理器中查找与其对应的连接,进而复用该连接,解决了在LVS与MongoDB数据库结合使用时,MongDB驱动不能查找与LVS IP地址对应的连接从而需要重新建立连接的问题,进而非常有效的减少了客户端对MongoDB数据库进行访问时产生的性能开销,避免了MongoDB数据库存在大量并发请求时由于MongoDB服务连接数满而无法提供服务的问题。The embodiment of the present invention provides a high-availability solution for the MongoDB database. After receiving the incoming LVS IP address of the client, the LVS IP address is converted into a corresponding MongoDB IP address, so that the MongDB driver can obtain the MongoDB IP according to the conversion. The address in the connection manager finds the corresponding connection, and then multiplexes the connection, which solves the problem that when the LVS is combined with the MongoDB database, the MongDB driver cannot find the connection corresponding to the LVS IP address and needs to re-establish the connection. It effectively reduces the performance overhead incurred when the client accesses the MongoDB database, and avoids the problem that the MongoDB database cannot have a full number of concurrent requests due to the full number of MongoDB service connections.
实施例二Embodiment 2
本实施例为上述实施例一的一种具体应用场景,通过本实施例,能够更加清楚、具体地阐述本发明所提供的方法。This embodiment is a specific application scenario of the foregoing first embodiment. Through the embodiment, the method provided by the present invention can be more clearly and specifically illustrated.
为了能够更加清楚的对本发明的改进进行说明,在对本实施例进行说明之前,首先说明一下现有的MongoDB数据库的访问系统的架构。图3所示为现有的MongoDB数据库的访问系统的详细架构图,包括:In order to explain the improvement of the present invention more clearly, before explaining the present embodiment, the architecture of the access system of the existing MongoDB database will be first described. Figure 3 shows the detailed architecture of the access system of the existing MongoDB database, including:
客户端、LVS、MongoDB驱动和MongoDB数据库。Client, LVS, MongoDB driver and MongoDB database.
下面分别对客户端、LVS、MongoDB驱动和MongoDB数据库进行介绍。The following describes the client, LVS, MongoDB driver and MongoDB database.
客户端即为对MongoDB数据库发起访问的设备,可以是客户端或其他具有前端业务的终端。The client is the device that initiates access to the MongoDB database, and can be a client or other terminal with front-end services.
例如:当用户手机中内置的某个APP需要调取后台数据的时候,可能会向MongoDB数据库发起访问请求;For example, when an APP built in the user's mobile phone needs to retrieve background data, an access request may be initiated to the MongoDB database;
或,当用户进行网络游戏时,网络游戏的服务器需要在MongoDB数据库中调取多个用户的数据。Or, when the user conducts a network game, the server of the online game needs to retrieve data of multiple users in the MongoDB database.
LVS为虚拟的服务器集群系统,可负责对于MongoDB数据库的集群服务器的负载均衡,可以将来自不同客户端的访问请求分配到MongoDB数据库的集群服务器中的不同节点上,使得MongoDB数据库的集群服务器中的某一个节点不会因为负载过大而导致宕机。LVS is a virtual server cluster system, which can be responsible for load balancing of cluster servers of MongoDB database. It can allocate access requests from different clients to different nodes in the cluster server of MongoDB database, so that some of the cluster servers in MongoDB database A node does not crash due to excessive load.
MongoDB驱动,负责为建立客户端与MongoDB数据库的集群服务器中的节点建立连接,并保存可用连接,以供客户端再次访问MongoDB数据库时进行复用。其中,MongoDB驱动中包括有连接管理器,用于保存在已建立的连接。 The MongoDB driver is responsible for establishing a connection between the client and the nodes in the cluster server of the MongoDB database, and saving the available connections for reuse when the client accesses the MongoDB database again. Among them, the MongoDB driver includes a connection manager for saving the established connection.
其中,需要说明的是,MongoDB驱动在连接管理器中保存连接时,是根据MongoDB数据库的集群服务器中的节点的IP地址(后续简称MongoDB IP地址)与连接的对应关系进行保存的。It should be noted that when the MongoDB driver saves the connection in the connection manager, it is saved according to the correspondence between the IP address of the node in the cluster server of the MongoDB database (hereinafter referred to as MongoDB IP address) and the connection.
MongoDB数据库,是一种关系型数据库,可以用于存储较复杂的数据类型。在本实施例中,MongoDB数据库可以部署在一台服务器上,也可以是部署在集群服务器上,其中,每台用于部署MongoDB数据库的服务器均可以认为是一个数据库节点。The MongoDB database is a relational database that can be used to store more complex data types. In this embodiment, the MongoDB database can be deployed on a server or deployed on a cluster server. Each server used to deploy the MongoDB database can be considered as a database node.
但是,由于在图3所示的MongoDB数据库的访问系统中使用的是LVS,其接收客户端的访问请求后,LVS向MongoDB驱动传递的为LVS IP地址,而连接管理器中保存的为MongoDB IP地址与连接的对应关系,所以对于该客户端,即使连接管理器中保存有连接,由于不能识别LVS IP,也不能找到连接进行复用。因此,MongoDB驱动需要为该客户端重新建立连接,而在MongoDB数据库的访问系统中,每次建立连接需要耗费大量的计算资源当对于MongoDB数据库的并发访问量过高时,就有可能造成MongoDB服务连接数满而无法提供服务的问题。However, since the LVS is used in the access system of the MongoDB database shown in FIG. 3, after receiving the access request from the client, the LVS transmits the LVS IP address to the MongoDB driver, and the MongoDB IP address is saved in the connection manager. Correspondence with the connection, so for this client, even if the connection is saved in the connection manager, the connection cannot be found and reused because the LVS IP cannot be recognized. Therefore, the MongoDB driver needs to re-establish the connection for the client. In the access system of the MongoDB database, it takes a lot of computing resources to establish a connection each time. When the concurrent access to the MongoDB database is too high, it may cause the MongoDB service. The problem is that the connection is full and the service cannot be provided.
为了解决上述问题,本发明实施例提供了一种解决方案,如图4所示,为本发明实施例提供的一种改进的MongoDB数据库的访问系统的架构图,在客户端和MongoDB数据库之间增加转换模块,可以将传入的LVS IP地址转换为MongoDB IP地址,从而使用复用连接管理器中的连接。从而大量减少了MongoDB数据库的访问系统的计算量,最大限度的避免并发时导致的宕机问题。本领域技术人员应可理解,所述转换模块可以独立于MongoDB驱动,或驻留于MongoDB驱动中。进一步来说,若转换模块驻留在MongoDB驱动中,其也可以独立于连接管理器,或位于连接管理器中。虽然图4中所示转换模块位于MongoDB驱动中且独立于连接管理器,但本发明并不以此为限。In order to solve the above problem, the embodiment of the present invention provides a solution, as shown in FIG. 4, which is an architecture diagram of an improved access system of the MongoDB database provided by the embodiment of the present invention, between the client and the MongoDB database. By adding a conversion module, you can use the connection in the Multiplex Connection Manager by converting the incoming LVS IP address to the MongoDB IP address. Therefore, the calculation amount of the access system of the MongoDB database is greatly reduced, and the downtime caused by concurrency is avoided to the utmost extent. Those skilled in the art will appreciate that the conversion module can be driven independently of MongoDB or reside in a MongoDB driver. Further, if the conversion module resides in the MongoDB driver, it can also be independent of the connection manager or in the connection manager. Although the conversion module shown in FIG. 4 is located in the MongoDB driver and is independent of the connection manager, the invention is not limited thereto.
为了更清楚的说明本发明,下面以在改进的MongoDB数据库的访问架构下客户端访问MongoDB数据库的方法进行详细说明。In order to more clearly illustrate the present invention, the following is a detailed description of a method for a client to access a MongoDB database under the improved access framework of the MongoDB database.
图5是本发明一个实施例提供的一种MongoDB数据库的高可用解决具体方法流程图,所述方法可应用于图4所示的装置,该方法包括步骤S501至S506。FIG. 5 is a flowchart of a high-availability solution specific method of a MongoDB database according to an embodiment of the present invention. The method is applicable to the apparatus shown in FIG. 4, and the method includes steps S501 to S506.
首先,执行步骤S501,客户端通过LVS发起向MongoDB数据库的访问请求。First, in step S501, the client initiates an access request to the MongoDB database through the LVS.
其中,对于MongoDB数据库的访问请求,可以是针对任意MongoDB数据库所能提供的服务的请求。Among them, the access request for the MongoDB database can be a request for a service that can be provided by any MongoDB database.
例如:E.g:
当客户端为浏览器时,可能是用户登录网络存储器对应的网站,发起的查询或下载个人数据的请求;When the client is a browser, the user may log in to the website corresponding to the network storage, initiate a query or download a request for personal data;
当客户端为游戏程序时,则可能获取用户在游戏中的人物的属性信息、对战等的数 据请求。When the client is a game program, it is possible to obtain the attribute information, the number of battles, etc. of the character of the user in the game. Upon request.
具体地,在客户端通过LVS发起向MongoDB数据库的访问请求时,由LVS负责执行负载均衡操作,将用户的请求转向其分配的LVS IP地址、端口号。Specifically, when the client initiates an access request to the MongoDB database through the LVS, the LVS is responsible for performing a load balancing operation, and shifting the user's request to its assigned LVS IP address and port number.
在LVS接收到用户对MongoDB数据库的访问请求后,将该用户的请求转向对应的LVS IP地址、端口号,执行步骤S502,向MongoDB驱动传入携带有LVS IP地址、端口号的访问请求。After receiving the user's access request to the MongoDB database, the LVS forwards the request of the user to the corresponding LVS IP address and port number, and performs step S502 to drive the access request carrying the LVS IP address and port number to the MongoDB driver.
其中,在客户端与MongoDB数据库的集群服务器的节点建立连接时,IP地址和端口号为两个必要元素,除此之外,还可以包括与访问请求相关联的用户名、密码等。Wherein, when the client establishes a connection with the node of the cluster server of the MongoDB database, the IP address and the port number are two necessary elements, and in addition, the user name, password, and the like associated with the access request may be included.
MongoDB驱动接收到传入的LVS IP地址后,执行步骤S503,MongoDB通过LVS将上述LVS IP地址、端口号转换为MongoDB IP地址、端口号。After receiving the incoming LVS IP address, the MongoDB driver performs step S503, and MongoDB converts the above LVS IP address and port number into a MongoDB IP address and port number through LVS.
其中,本步骤S503所执行的操作即由图4所示的转换模块完成。在现有技术情况下,当传入MongoDB驱动中的为LVS IP地址时,MongoDB驱动是无法根据其在连接管理器中查询连接的,会将针对该LVS IP地址的请求建立新的连接,执行一个新的连接建立流程。The operation performed in this step S503 is completed by the conversion module shown in FIG. 4. In the prior art, when the LVS IP address is passed into the MongoDB driver, the MongoDB driver cannot query the connection according to the connection manager, and a new connection is established for the request for the LVS IP address. A new connection establishment process.
在本发明中实施例中,在LVS中保存有LVS IP地址和MongoDB IP地址的对应关系,因此,转换模块可以通过LVS将LVS IP地址解析为MongoDB IP地址。In the embodiment of the present invention, the correspondence between the LVS IP address and the MongoDB IP address is stored in the LVS. Therefore, the conversion module can resolve the LVS IP address to the MongoDB IP address through the LVS.
在转换得到与LVS IP地址、端口号对应的MongoDB IP地址和端口号之后,执行步骤S504,MongoDB驱动检测连接管理器中是否保存有与该MongoDB IP地址、端口号对应的连接。After the conversion of the MongoDB IP address and the port number corresponding to the LVS IP address and the port number, step S504 is executed, and the MongoDB driver detects whether the connection corresponding to the MongoDB IP address and port number is stored in the connection manager.
若在连接管理器中保存有与该MongoDB IP地址、端口号对应的连接时,执行步骤S505,将该连接返回给客户端,客户端根据该连接进行读写操作。If the connection corresponding to the MongoDB IP address and port number is stored in the connection manager, step S505 is executed to return the connection to the client, and the client performs read and write operations according to the connection.
若在连接管理器中未保存有与该MongoDB IP地址、端口号对应的连接时,执行步骤S506,为传入的LVS IP地址、端口号启动建立新的连接的流程。If the connection corresponding to the MongoDB IP address and port number is not stored in the connection manager, step S506 is executed to initiate a process of establishing a new connection for the incoming LVS IP address and port number.
其中,为传入的LVS IP地址、端口号建立新的连接的方法具体可以包括如下步骤:The method for establishing a new connection for the incoming LVS IP address and port number may include the following steps:
(1)创建与传入的LVS IP地址、端口号对应的第一连接,并将该第一连接注册在连接管理器中。(1) Create a first connection corresponding to the incoming LVS IP address, port number, and register the first connection in the connection manager.
(2)检测传入的LVS IP地址是否与MongoDB的IP地址匹配。(2) Check if the incoming LVS IP address matches the IP address of MongoDB.
其中,检测传入的LVS IP地址是否与MongoDB的IP地址匹配的方式可以为:The method for detecting whether the incoming LVS IP address matches the IP address of MongoDB may be:
获取MongoDB中的全部节点的IP地址,判断传入的LVS IP地址是否在其中,如果不在,则说明不匹配。Obtain the IP addresses of all the nodes in MongoDB, and determine whether the incoming LVS IP address is in it. If not, it means no match.
在本实施例中,由于传入的为LVS IP地址,因此不匹配,此时可执行步骤(3)。In this embodiment, since the incoming LVS IP address does not match, step (3) can be performed at this time.
(3)删除上述创建的第一连接。 (3) Delete the first connection created above.
(4)获取MongoDB中的全部可用数据节点的IP地址和端口号。(4) Obtain the IP address and port number of all available data nodes in MongoDB.
(5)检测连接管理器中是否存在与上述可用数据节点的IP地址和端口号对应的连接。(5) Detecting whether there is a connection in the connection manager corresponding to the IP address and port number of the above-mentioned available data node.
在本实施例中,若存在对应的连接,则将该连接返回给客户端,若不存在,则执行步骤(6)。In this embodiment, if there is a corresponding connection, the connection is returned to the client, and if not, step (6) is performed.
(6)创建与每一可用数据节点的IP地址、端口号对应的第二连接,并将第二连接注册在连接管理器中。(6) Create a second connection corresponding to the IP address and port number of each available data node, and register the second connection in the connection manager.
(7)根据预设条件将对应于客户端业务的第二连接返回给客户端。(7) Returning the second connection corresponding to the client service to the client according to the preset condition.
其中,由于数据库一般采用主从结构,因此,且该步骤(7)可以按照如下方式进行:Wherein, since the database generally adopts a master-slave structure, the step (7) can be performed as follows:
当客户端业务为数据写入操作或数据修改操作时,将对应于主数据节点的第二连接返回给所述客户端;When the client service is a data write operation or a data modification operation, returning a second connection corresponding to the primary data node to the client;
当客户端业务为数据读取操作时,根据读优先策略将对应于主数据节点或者从数据节点的第二连接返回给所述客户端。When the client service is a data read operation, a second connection corresponding to the primary data node or from the data node is returned to the client according to the read priority policy.
在步骤S506为上述MongoDB IP地址、端口号建立新的连接之后,本方法还可以包括如下步骤:After the new connection is established for the MongoDB IP address and the port number in the step S506, the method may further include the following steps:
将该新的连接(也即上述步骤中的第二连接)保存到连接管理器中,供下次该客户端进行复用。The new connection (ie, the second connection in the above steps) is saved to the connection manager for reuse by the client next time.
进一步地,在MongoDB数据库的使用过程中,由于机器故障等会造成集群服务器中的某一节点不可使用,这时就会影响连接管理器中的连接的复用,因此,在将连接返回给客户端之后,本方法还包括:Further, during the use of the MongoDB database, a node in the cluster server is unusable due to a machine failure, etc., which affects the multiplexing of connections in the connection manager, and therefore returns the connection to the client. After the end, the method further includes:
测试与所述连接中的数据节点是否可用;Testing whether a data node in the connection is available;
若连接可以,则建立客户端与该数据节点之间的连接;If the connection is ok, establish a connection between the client and the data node;
若连接不可用,则将该数据节点加入到黑名单中,并由连接管理器为该客户端重新建立新的连接。If the connection is not available, the data node is added to the blacklist and the connection manager re-establishes a new connection for the client.
其中,在测试连接中的数据节点是否可用时,可以采用向ping该数据节点的方法,观测其是否正常返回数据。Wherein, when the data node in the test connection is available, the method of pinging the data node may be used to observe whether the data is returned normally.
更进一步地,若该数据节点恢复可用状态时,则将其从黑名单中删除。Further, if the data node resumes the available state, it is removed from the blacklist.
本发明实施例提供了一种MongoDB数据库的高可用解决方法,在接收客户端传入的LVS IP地址后,将LVS IP地址转换为对应的MongoDB IP地址,使得MongDB驱动可根据转换得到的MongoDB IP地址在连接管理器中查找与其对应的连接,进而复用该连接,解决了在LVS与MongoDB数据库结合使用时,MongDB驱动不能查找与LVS IP 地址对应的连接从而需要重新建立连接的问题,进而非常有效的减少了客户端对MongoDB数据库进行访问时产生的性能开销,避免了MongoDB数据库存在大量并发请时求由于MongoDB服务连接数满而无法提供服务的问题。The embodiment of the present invention provides a high-availability solution for the MongoDB database. After receiving the incoming LVS IP address of the client, the LVS IP address is converted into a corresponding MongoDB IP address, so that the MongDB driver can obtain the MongoDB IP according to the conversion. The address in the connection manager finds the corresponding connection, and then reuses the connection, which solves the problem that the MongDB driver cannot find the LVS IP when the LVS is combined with the MongoDB database. The connection corresponding to the address needs to re-establish the connection problem, which effectively reduces the performance overhead incurred when the client accesses the MongoDB database, and avoids the large number of concurrent requests of the MongoDB database. Service problem.
实施例三Embodiment 3
图6是本发明一个实施例提供的一种数据库的高可用解决装置结构框图,该装置600包括:FIG. 6 is a structural block diagram of a high availability solution device for a database according to an embodiment of the present invention. The device 600 includes:
转换模块610,适于接收客户端传入的LVS IP地址、端口号,并通过Linux虚拟服务器LVS将LVS IP地址、端口号解析为对应数据库的IP地址、端口号;The conversion module 610 is adapted to receive an incoming LVS IP address and a port number of the client, and parse the LVS IP address and the port number into an IP address and a port number of the corresponding database by using a Linux virtual server LVS;
连接管理模块620,适于检测连接管理器中是否存在与对应数据库的IP地址、端口号对应的连接;The connection management module 620 is configured to detect whether a connection corresponding to an IP address and a port number of the corresponding database exists in the connection manager.
结果返回模块630,适于当存在与对应数据库的IP地址、端口号对应的连接时,将连接返回给客户端;The
其中,上述连接用于客户端访问对应的数据库。The above connection is used for the client to access the corresponding database.
可选地,该装置600进一步包括:Optionally, the apparatus 600 further includes:
第一创建模块640,适于当不存在与对应数据库的IP地址、端口号对应的连接时,创建与LVS IP地址、端口号对应的第一连接,并将第一连接注册在连接管理器中。The first creating module 640 is configured to: when there is no connection corresponding to the IP address and the port number of the corresponding database, create a first connection corresponding to the LVS IP address and the port number, and register the first connection in the connection manager. .
可选地,该装置进一步包括地址匹配模块650,该地址匹配模块具体包括:Optionally, the device further includes an address matching module 650, where the address matching module specifically includes:
判断单元651,适于在连接管理器中建立与上述LVS IP地址、端口号对应的第一连接之后,确定该LVS IP地址是否与对应数据库的IP地址匹配;The determining unit 651 is adapted to determine whether the LVS IP address matches the IP address of the corresponding database after establishing the first connection corresponding to the LVS IP address and the port number in the connection manager;
删除单元652,用于在判断单元651确定不匹配后,删除该第一连接。The deleting unit 652 is configured to delete the first connection after the determining unit 651 determines that the matching is not performed.
可选地,该装置进一步包括第二创建模块660,该第二创建模块660包括:Optionally, the device further includes a second creating module 660, where the second creating module 660 includes:
获取单元661,适于在确定上述传入的LVS IP地址与对应数据库的IP地址不匹配后,获取对应数据库中的全部可用数据节点的IP地址、端口号;The obtaining unit 661 is configured to obtain an IP address and a port number of all available data nodes in the corresponding database after determining that the incoming LVS IP address does not match the IP address of the corresponding database;
检测单元662,适于检测连接管理器中是否存在与可用数据节点的IP地址、端口号对应的连接;The detecting unit 662 is adapted to detect whether there is a connection in the connection manager corresponding to an IP address and a port number of the available data node;
创建单元663,适于当不存在时,创建与每一所述可用数据节点的IP地址、端口号对应的第二连接,并将第二连接注册在连接管理器中;The creating unit 663 is adapted to, when not present, create a second connection corresponding to an IP address and a port number of each of the available data nodes, and register the second connection in the connection manager;
可选地,第二创建模块660进一步包括:Optionally, the second creating module 660 further includes:
返回单元664,适于根据预设条件将对应于客户端业务的第二连接返回给客户端。The returning unit 664 is adapted to return the second connection corresponding to the client service to the client according to the preset condition.
可选地,上述数据库为主从式结构,且返回单元664适于按照如下方式将对应于客户端业务的第二连接返回给客户端: Optionally, the database is a master-slave structure, and the returning unit 664 is adapted to return the second connection corresponding to the client service to the client in the following manner:
当客户端业务为数据写入操作或数据修改操作时,将对应于主数据节点的第二连接返回给客户端;以及When the client service is a data write operation or a data modification operation, returning a second connection corresponding to the primary data node to the client;
当客户端业务为数据读取操作时,根据读优先策略将对应于主数据节点或者从数据节点的第二连接返回给客户端。When the client service is a data read operation, the second connection corresponding to the primary data node or from the data node is returned to the client according to the read priority policy.
可选地,该装置600进一步包括测试模块670,测试模块670包括:Optionally, the device 600 further includes a test module 670, the test module 670 includes:
测试单元671,适于根据预设条件将对应于客户端业务的第二连接返回给客户端之后,测试返回的第二连接对应的数据节点是否可用;The testing unit 671 is adapted to test whether the returned data node corresponding to the second connection is available after returning the second connection corresponding to the client service to the client according to the preset condition;
记录单元672,适于当数据节点不可用时,将数据节点加入到预设的黑名单中。The recording unit 672 is adapted to add the data node to the preset blacklist when the data node is unavailable.
本领域技术人员应可理解,上述装置600可以应用/执行本文前述的各种方法,其具体细节在此不另赘述。It should be understood by those skilled in the art that the foregoing apparatus 600 can apply/execute various methods described herein, and specific details thereof are not described herein.
根据上述任意一个优选实施例或多个优选实施例的组合,本发明实施例能够达到如下有益效果:According to any one of the preferred embodiments or the combination of the preferred embodiments, the embodiment of the present invention can achieve the following beneficial effects:
本发明实施例提供了一种数据库的高可用解决装置,通过在接收传入的LVS IP地址后,将LVS IP地址转换为对应数据库的IP地址,使得对应数据库驱动可根据转换得到的对应数据库的IP地址在连接管理器中查找与其对应的连接,进而复用该连接,解决了在LVS与对应数据库在结合使用时,数据库驱动不能查找与LVS IP地址对应的连接从而需要重新建立连接的问题,进而非常有效的减少了客户端对数据库进行访问时产生的性能开销,避免了对应的数据库存在大量并发请求时由于服务连接数满而无法提供服务的问题。The embodiment of the present invention provides a high-availability solution for a database. After receiving an incoming LVS IP address, the LVS IP address is converted into an IP address of a corresponding database, so that the corresponding database driver can be converted according to the corresponding database. The IP address finds the corresponding connection in the connection manager, and then multiplexes the connection, which solves the problem that when the LVS is combined with the corresponding database, the database driver cannot find the connection corresponding to the LVS IP address and needs to re-establish the connection. In addition, the performance overhead incurred when the client accesses the database is effectively reduced, and the problem that the corresponding database cannot provide the service due to the full number of concurrent connections is avoided.
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood that the embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of the description.
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, the various features of the invention are sometimes grouped together into a single embodiment, in the above description of the exemplary embodiments of the invention, Figure, or a description of it. However, the method disclosed is not to be interpreted as reflecting the intention that the claimed invention requires more features than those recited in the claims. Rather, as the following claims reflect, inventive aspects reside in less than all features of the single embodiments disclosed herein. Therefore, the claims following the specific embodiments are hereby explicitly incorporated into the embodiments, and each of the claims as a separate embodiment of the invention.
本领域那些技术人员可以理解,可以对实施例中的设备中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个设备中。可以把实施例中的模块或单元或组件组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元 或子组件。除了这样的特征和/或过程或者单元中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的的替代特征来代替。Those skilled in the art will appreciate that the modules in the devices of the embodiments can be adaptively changed and placed in one or more devices different from the embodiment. The modules or units or components in the embodiments may be combined into one module or unit or component, and further, they may be divided into multiple sub-modules or sub-units. Or subcomponents. In addition to such features and/or at least some of the processes or units being mutually exclusive, any combination of the features disclosed in the specification, including the accompanying claims, the abstract and the drawings, and any methods so disclosed, or All processes or units of the device are combined. Each feature disclosed in this specification (including the accompanying claims, the abstract and the drawings) may be replaced by alternative features that provide the same, equivalent or similar purpose.
此外,本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在下面的权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features that are included in other embodiments and not in other features, combinations of features of different embodiments are intended to be within the scope of the present invention. Different embodiments are formed and formed. For example, in the following claims, any one of the claimed embodiments can be used in any combination.
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的数据库的高可用解决装置中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that some or all of the functionality of some or all of the high availability resolution devices of the database in accordance with embodiments of the present invention may be implemented in practice using a microprocessor or digital signal processor (DSP). The invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein. Such a program implementing the invention may be stored on a computer readable medium or may be in the form of one or more signals. Such signals may be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.
例如,图7示出了可以实现数据库的高可用解决方法的计算设备。该计算设备传统上包括处理器710和存储器720形式的计算机程序产品或者计算机可读介质。存储器720可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。存储器720具有存储用于执行上述方法中的任何方法步骤的程序代码731的存储空间730。例如,存储程序代码的存储空间730可以包括分别用于实现上面的方法中的各种步骤的各个程序代码731。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。这些计算机程序产品包括诸如硬盘,紧致盘(CD)、存储卡或者软盘之类的程序代码载体。这样的计算机程序产品通常为例如图8所示的便携式或者固定存储单元。该存储单元可以具有与图7的计算设备中的存储器720类似布置的存储段、存储空间等。程序代码可以例如以适当形式进行压缩。通常,存储单元包括用于执行本发明的方法步骤的计算机可读代码731’,即可以由诸如710之类的处理器读取的代码,当这些代码由计算设备运行时,导致该计算设备执行上面所描述的方法中的各个步骤。For example, Figure 7 illustrates a computing device that can implement a highly available solution for a database. The computing device traditionally includes a computer program product or computer readable medium in the form of a processor 710 and a memory 720. Memory 720 can be an electronic memory such as a flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM. Memory 720 has a storage space 730 that stores
本文中所称的“一个实施例”、“实施例”或者“一个或者多个实施例”意味着,结合实施例描述的特定特征、结构或者特性包括在本发明的至少一个实施例中。此外, 请注意,这里“在一个实施例中”的词语例子不一定全指同一个实施例。"an embodiment," or "an embodiment," or "an embodiment," In addition, Please note that the examples of the words "in one embodiment" are not necessarily all referring to the same embodiment.
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It is to be noted that the above-described embodiments are illustrative of the invention and are not intended to be limiting, and that the invention may be devised without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as a limitation. The word "comprising" does not exclude the presence of the elements or steps that are not recited in the claims. The word "a" or "an" The invention can be implemented by means of hardware comprising several distinct elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means can be embodied by the same hardware item. The use of the words first, second, and third does not indicate any order. These words can be interpreted as names.
此外,还应当注意,本说明书中使用的语言主要是为了可读性和教导的目的而选择的,而不是为了解释或者限定本发明的主题而选择的。因此,在不偏离所附权利要求书的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。对于本发明的范围,对本发明所做的公开是说明性的,而非限制性的,本发明的范围由所附权利要求书限定。 In addition, it should be noted that the language used in the specification has been selected for the purpose of readability and teaching, and is not intended to be construed or limited. Therefore, many modifications and changes will be apparent to those skilled in the art without departing from the scope of the invention. The disclosure of the present invention is intended to be illustrative, and not restrictive, and the scope of the invention is defined by the appended claims.
Claims (16)
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201410800009.0A CN104462488B (en) | 2014-12-19 | 2014-12-19 | The High Availabitity of database solves method and apparatus |
| CN201410800009.0 | 2014-12-19 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2016095644A1 true WO2016095644A1 (en) | 2016-06-23 |
Family
ID=52908523
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2015/094813 Ceased WO2016095644A1 (en) | 2014-12-19 | 2015-11-17 | High availability solution method and device for database |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN104462488B (en) |
| WO (1) | WO2016095644A1 (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109792596A (en) * | 2016-10-31 | 2019-05-21 | 华为技术有限公司 | System and method for unified data management in a communication network |
Families Citing this family (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104462488B (en) * | 2014-12-19 | 2018-05-11 | 北京奇虎科技有限公司 | The High Availabitity of database solves method and apparatus |
| CN105141683B (en) * | 2015-08-19 | 2018-10-23 | 成都康赛信息技术有限公司 | A kind of MongoDB load balance optimization methods |
| CN109992531B (en) * | 2019-04-15 | 2020-11-10 | 成都四方伟业软件股份有限公司 | Data storage method and device |
| CN118295816A (en) * | 2024-05-15 | 2024-07-05 | 成都虚谷伟业科技有限公司 | Method for realizing load balance of driving layer |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102110099A (en) * | 2009-12-28 | 2011-06-29 | 五邑大学 | Heterogeneous database middleware access technique based on endowment insurance warning system |
| CN102982141A (en) * | 2012-11-20 | 2013-03-20 | 北京搜狐新媒体信息技术有限公司 | Method and device for realizing distributed database agent |
| CN104462488A (en) * | 2014-12-19 | 2015-03-25 | 北京奇虎科技有限公司 | Database high reliability solution method and device |
Family Cites Families (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2011057057A1 (en) * | 2009-11-06 | 2011-05-12 | Certified Cyber Solutions, Inc. | System and method for secure access of a remote system |
| CN103023942B (en) * | 2011-09-27 | 2016-08-03 | 北京奇虎科技有限公司 | A kind of server load balancing method, Apparatus and system |
| CN102722575A (en) * | 2012-06-05 | 2012-10-10 | 河北世窗信息技术有限公司 | System and method for managing multi-type database connection pool |
| CN103678547A (en) * | 2013-12-04 | 2014-03-26 | 蓝盾信息安全技术股份有限公司 | Self-learning database security auditing system and method |
| CN104038376A (en) * | 2014-06-30 | 2014-09-10 | 浪潮(北京)电子信息产业有限公司 | Method and device for managing real servers and LVS clustering system |
-
2014
- 2014-12-19 CN CN201410800009.0A patent/CN104462488B/en active Active
-
2015
- 2015-11-17 WO PCT/CN2015/094813 patent/WO2016095644A1/en not_active Ceased
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102110099A (en) * | 2009-12-28 | 2011-06-29 | 五邑大学 | Heterogeneous database middleware access technique based on endowment insurance warning system |
| CN102982141A (en) * | 2012-11-20 | 2013-03-20 | 北京搜狐新媒体信息技术有限公司 | Method and device for realizing distributed database agent |
| CN104462488A (en) * | 2014-12-19 | 2015-03-25 | 北京奇虎科技有限公司 | Database high reliability solution method and device |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109792596A (en) * | 2016-10-31 | 2019-05-21 | 华为技术有限公司 | System and method for unified data management in a communication network |
| US10785302B2 (en) | 2016-10-31 | 2020-09-22 | Huawei Technologies Co., Ltd. | Systems and methods for unified data management in a communication network |
Also Published As
| Publication number | Publication date |
|---|---|
| CN104462488B (en) | 2018-05-11 |
| CN104462488A (en) | 2015-03-25 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US20190196875A1 (en) | Method, system and computer program product for processing computing task | |
| CN104020961B (en) | Distributed data storage method, apparatus and system | |
| CN106302595B (en) | Method and equipment for carrying out health check on server | |
| US20170003997A1 (en) | Compute Cluster Load Balancing Based on Memory Page Contents | |
| CN106909595B (en) | A data migration method and device | |
| WO2017157156A1 (en) | Method and apparatus for processing user requests | |
| CN111353773A (en) | Method and device for processing identifier, storage medium and electronic device | |
| CN107666493B (en) | Database configuration method and equipment thereof | |
| WO2016095644A1 (en) | High availability solution method and device for database | |
| WO2017084348A1 (en) | Management method and apparatus for ip hard disk | |
| US10089131B2 (en) | Compute cluster load balancing based on disk I/O cache contents | |
| US9971726B2 (en) | Session-level-restriction for universal serial bus storage devices | |
| CN117692322A (en) | Network card configuration method, device, electronic equipment and storage medium | |
| US20160124885A1 (en) | Systems and methods for providing protocol independent disjoint drive letter sets | |
| WO2016101662A1 (en) | Data processing method and relevant server | |
| CN103544151A (en) | Method and system for processing data in linux system | |
| CN111771191B (en) | Cross-domain inline event handlers | |
| CN108062224B (en) | Data reading and writing method, device and computing device based on file handle | |
| CN104462514B (en) | High Availabitity solution, connection control device and the system of database | |
| US9904475B2 (en) | Systems and methods for setting the operating system properties for a storage device | |
| US9256648B2 (en) | Data handling in a cloud computing environment | |
| CN105144073A (en) | Removable storage device identity and configuration information | |
| US20230161664A1 (en) | Method of responding to operation, electronic device, and storage medium | |
| CN104836689A (en) | Server fault transfer method and system | |
| CN115499314B (en) | Cluster node IP modification method and device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 15869153 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 15869153 Country of ref document: EP Kind code of ref document: A1 |