WO2016177130A1 - 通讯节点的选择方法及装置 - Google Patents

通讯节点的选择方法及装置 Download PDF

Info

Publication number
WO2016177130A1
WO2016177130A1 PCT/CN2016/076647 CN2016076647W WO2016177130A1 WO 2016177130 A1 WO2016177130 A1 WO 2016177130A1 CN 2016076647 W CN2016076647 W CN 2016076647W WO 2016177130 A1 WO2016177130 A1 WO 2016177130A1
Authority
WO
WIPO (PCT)
Prior art keywords
connection
node
module
database
database cluster
Prior art date
Application number
PCT/CN2016/076647
Other languages
English (en)
French (fr)
Inventor
王苑
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016177130A1 publication Critical patent/WO2016177130A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/40Support for services or applications

Definitions

  • the present invention relates to the field of communications, and in particular to a method and apparatus for selecting a communication node.
  • Zookeeper is a very good distributed cache database. Its essence is a distributed small file system. When all Zookeeper nodes are hanged, the data will not be lost. After restarting the server, the data can be recovered, and Zookeeper Nodes are atomic, updates are not successful and fail, and election algorithms and cluster replication can also avoid single points of failure.
  • the Zookeeper cluster has three main roles: leader, follower, and observer. In a cluster, a node is elected as a leader.
  • the leader node receives the client request, is responsible for voting initiation and resolution, and All follower and observer perform internal data exchange; the follower node and the observer node receive the client connection, and forward the write request to the leader node to return the result to the client.
  • the only difference between the follower and the observer is that the follower will participate in the election of the leader. And the observer will not.
  • Zookeeper enters recovery mode. The recovery mode needs to re-elect a new leader, so that all servers are restored to the correct state.
  • the client can access any cluster node that is functioning properly and can access the cluster. Since there are multiple nodes in the ZooKeeper cluster, that is, multiple nodes can access, which causes the problem of the client accessing the cluster node with the distributed shared session.
  • a main object of the embodiments of the present invention is to provide a method and an apparatus for selecting a communication node, so as to at least solve the problem of selecting a client access cluster node of a distributed shared session in the related art.
  • a device for selecting a communication node comprising: a session management module, a database communication module, and a communication node selection module; the session management module is configured to receive a user request Calling the database communication module to obtain information of a node in the database cluster; the communication node selection module is configured to acquire information of the node from the database communication module, and according to the point of the node The information communicates with the database cluster by selecting an available connection from a connection pool by a predetermined rule, wherein the connection pool is for storing a connection between the device and a node in the database cluster.
  • the manner in which the communication node selection module communicates with the database cluster by using a predetermined rule includes: the communication node selection module determines whether there is a connection carrying the specified session identifier; when the determination result is no, The preset algorithm selects an available and unidentified first connection from the connection pool to communicate with the database cluster, and adds the specified session identifier to the first connection; when the determination result is yes, select A connection corresponding to the specified session identifier performs communication with the database cluster.
  • the communication node selection module is further configured according to the The preset algorithm reselects an available second connection from the connection pool to communicate with the database cluster and adds the specified session identifier to the first connection.
  • the preset algorithm includes: a random allocation algorithm, a polling algorithm, a weighted rounding algorithm, and a consistent hash algorithm.
  • the device further includes: a connection pool management module, configured to perform a management operation on the connection in the connection pool, wherein the management operation includes: creating a connection, adding a connection, destroying a connection, deleting a connection, and detecting a connection status.
  • a connection pool management module configured to perform a management operation on the connection in the connection pool, wherein the management operation includes: creating a connection, adding a connection, destroying a connection, deleting a connection, and detecting a connection status.
  • the device further includes: a cluster node loading module, configured to record a node value of the database cluster configured by the device; and a dynamic chain building module, configured to reload the database cluster configuration in the cluster node loading module When the actual node value is used, the connection to the database cluster is periodically updated dynamically.
  • a cluster node loading module configured to record a node value of the database cluster configured by the device
  • a dynamic chain building module configured to reload the database cluster configuration in the cluster node loading module
  • the manner in which the dynamic link building module dynamically updates the connection with the database cluster includes: the dynamic chain building module, and the number of available connections between the device and the database cluster node is N/2+1, Wherein, the N is the number of nodes of the database cluster; or, establishing a connection between the device and each node in the database cluster; or establishing the device when there is only one node in the database cluster
  • the number of available connections with the database cluster node is 1; when the node of the database cluster is greater than or equal to 2, the number of available connections between the device and the database cluster node is 2.
  • the device further includes: a cluster node configuration reverse write module, configured to periodically detect consistency between an actual node value of the database cluster configuration and a node value of the database cluster configured by the device; In case of inconsistency, the actual node value of the database cluster node is obtained by writing back in the configuration file of the device, and the cluster node loading module is called to reload the actual node value.
  • a cluster node configuration reverse write module configured to periodically detect consistency between an actual node value of the database cluster configuration and a node value of the database cluster configured by the device. In case of inconsistency, the actual node value of the database cluster node is obtained by writing back in the configuration file of the device, and the cluster node loading module is called to reload the actual node value.
  • the device further includes: a connection pool timing detection module, configured to periodically detect whether the connection state of the connection pool and the connection number of the connection pool meet a preset number; and when detecting that a connection is unavailable, triggering the The connection pool management module deletes the unavailable connection; when detecting that the number of connections does not meet the preset number, triggering the dynamic chain building module to update the connection pool.
  • a connection pool timing detection module configured to periodically detect whether the connection state of the connection pool and the connection number of the connection pool meet a preset number; and when detecting that a connection is unavailable, triggering the The connection pool management module deletes the unavailable connection; when detecting that the number of connections does not meet the preset number, triggering the dynamic chain building module to update the connection pool.
  • a method for selecting a communication node in any of the foregoing devices includes: a session management module, a database communication module, and a communication node selection module, where the method includes: Upon receiving the session processing request requested by the user, the session management module invokes the database communication module to acquire information of a node in the database cluster; the communication node selection module acquires information of the node from the database communication module, And communicating with the database cluster by selecting an available connection from the connection pool according to the information of the node, where the connection pool is used to store a connection between the device and a node in the database cluster.
  • the communication node selection module communicates with the database cluster by using a predetermined rule selection node, wherein the communication node selection module determines whether there is a connection carrying a specified session identifier; when the determination result is no, the communication node selects The module selects an available and unidentified first connection from the connection pool to communicate with the database cluster according to a preset algorithm, and adds the specified session identifier to the first connection; when the determination result is yes And the communication node selection module selects a connection corresponding to the specified session identifier to perform communication with the database cluster.
  • the method further includes: if the connection corresponding to the specified session identifier is abnormal, the communication node selection module is based on The preset algorithm reselects an available second connection from the connection pool to communicate with the database cluster, and adds the specified session identifier to the second connection.
  • a computer storage medium is further provided, and the computer storage medium may store an execution instruction for executing a selection method of the communication node in the foregoing embodiment.
  • the session management module when receiving the session processing request requested by the user, invokes the database communication module to acquire the information of the node in the database cluster, and the communication node selection module is configured to acquire the node from the database communication module. And, according to the information of the node, select an available connection from the connection pool according to the information of the node to communicate with the database cluster; in this embodiment, the communication node selection module selects a connection available in the connection pool through a predetermined rule to perform communication, thereby making the request.
  • the pressure of the connection is not too concentrated in the cluster's single On each node, the pressure of reaching the cluster nodes is balanced as much as possible, which solves the problem of selecting the client access cluster nodes of the distributed shared session in the related art.
  • FIG. 1 is a block diagram showing the structure of a selection device of a communication node according to an embodiment of the present invention
  • FIG. 2 is a block diagram 1 of an optional structure of a selection device of a communication node according to an embodiment of the present invention
  • FIG. 3 is a block diagram 2 of an optional structure of a selection device of a communication node according to an embodiment of the present invention
  • FIG. 4 is a block diagram 3 of an optional structure of a selection device of a communication node according to an embodiment of the present invention.
  • FIG. 5 is a block diagram 4 of an optional structure of a selection device of a communication node according to an embodiment of the present invention.
  • FIG. 6 is a flowchart of a method for selecting a communication node according to an embodiment of the present invention.
  • FIG. 7 is a structural block diagram of a container client that acquires a database cluster service according to an alternative embodiment of the present invention.
  • FIG. 8 is a flow diagram of a distributed shared session storage in a container client startup sequence in accordance with an alternate embodiment of the present invention.
  • FIG. 9 is a flow diagram of distributed shared session access in accordance with an alternate embodiment of the present invention.
  • FIG. 10 is a flow diagram of the operation of a database cluster node configuration write-back module in accordance with an alternate embodiment of the present invention.
  • FIG. 1 is a structural block diagram of a communication node selection device according to an embodiment of the present invention. As shown in FIG. 1, the device includes: a session management module 101, a database communication module 102, and Communication node selection module 103;
  • the session management module 101 is coupled to the database communication module 102, and is configured to, when receiving the session processing request requested by the user, invoke the database communication module 102 to acquire information of the node in the database cluster; wherein the session processing request may be A request to generate, update, or read a session.
  • the communication node selection module 103 is coupled to the database communication module 102, configured to acquire information of the node from the database communication module 102, and select an available connection from the connection pool to communicate with the database cluster according to the information of the node, wherein A connection pool is used to connect a storage device to a node in a database cluster.
  • the session management module when receiving the session processing request requested by the user, invokes the database communication module to acquire the information of the node in the database cluster, and the communication node selection module is configured to obtain the information from the database communication module.
  • the information of the node selects an available connection from the connection pool to communicate with the database cluster according to the predetermined rule; in this embodiment, the communication node selection module selects a connection available in the connection pool for communication by using a predetermined rule, thereby
  • the pressure of requesting the connection is not excessively concentrated on a single node of the cluster, and the pressure of the cluster node is balanced as much as possible, which solves the problem of selecting the client access cluster node of the distributed shared session in the related art.
  • the communication node selection module 103 selects an available connection from the connection pool to communicate with the database cluster according to the node information.
  • the communication node selection module 103 adopts The method is: determining whether there is a connection carrying the specified session identifier; when the determination result is no, selecting an available and unidentified first connection from the connection pool to communicate with the database cluster according to a preset algorithm, and is the first connection The specified session identifier is added; when the judgment result is yes, the connection corresponding to the specified session identifier is selected to perform communication with the database cluster.
  • the communication node selection module is configured according to a preset algorithm. Reselect an available second connection from the connection pool to communicate with the database cluster and update the identity of the second connection by specifying the session ID.
  • the communication node selection module 103 is configured to select an available connection from the connection pool and communicate with the database cluster according to the node information according to the node information.
  • Application scenario 1 Extracting an available connection from the connection pool by randomly assigning a +Session ID (corresponding to the specified session identifier) algorithm, that is, when the session ID is the first communication behavior, the random allocation algorithm is used to connect from the connection pool. Randomly take out an unmarked available connection for communication, and mark the connection as the flag used by the Session ID. When the session is destroyed, the flag used by the connection is cleared; if it is not the first communication, the Session ID will be used. The previously assigned connection communicates. If the previous connection is not available or the connection is unavailable or other read exceptions, a random allocation algorithm is used to reselect a flag that is not marked for available communication, and the flag used by the session ID is marked. If the connection is flagged and the unmarked connection is still not assigned, then a random allocation algorithm is still used to allocate an available connection to the session and update the flag used for the session ID.
  • a +Session ID corresponding to the specified session identifier
  • FIG. 2 is a block diagram of an optional structure of a selection device of a communication node according to an embodiment of the present invention.
  • the device further includes: a connection pool management module 104, and the database communication module 102 is coupled and configured to perform a connection pool.
  • Management operations in a connection where management operations include: creating a connection, adding a connection, destroying a connection, deleting a connection, and detecting a connection status.
  • FIG. 3 is a block diagram showing an optional structure of a selection device of a communication node according to an embodiment of the present invention.
  • the device further includes a cluster node loading module 105 coupled to the dynamic chain building module 106 and configured as a recording device.
  • the node value of the configured database cluster; the dynamic chain building module 106 is coupled to the database communication module 102, and is configured to dynamically update the connection with the database cluster when the cluster node loading module reloads the actual node value.
  • the dynamic link building module 106 dynamically updates the connection with the database cluster.
  • the dynamic link building module 106 is implemented by: establishing the device and the database cluster node.
  • the number of connections is N/2+1, where N is the number of nodes of the database cluster; or, the connection between the device and each node in the database cluster is established; or, when there is only one node in the database cluster, the device and the database are established.
  • the number of available connections for the cluster node is 1. When the node of the database cluster is greater than or equal to 2, the number of available connections between the establishment device and the database cluster node is 2.
  • the device further includes: a cluster node configuration reverse write module 107 coupled to the cluster node loading module 105, and configured to be Periodically detecting the consistency between the actual node value of the library cluster configuration and the node value of the database cluster configured by the device; when an inconsistency is detected, obtaining the actual node value of the database cluster node is reversed as in the configuration file of the device, and calling the cluster node
  • the load module reloads the actual node value.
  • FIG. 5 is a block diagram showing an optional structure of a selection device of a communication node according to an embodiment of the present invention.
  • the device further includes: a connection pool timing detection module 108 coupled to the connection pool management module 104 and configured to be cycled. Checking the connection status of the connection pool and the number of connections in the connection pool to meet the preset number; when detecting that a connection is unavailable, triggering the connection pool management module to delete the unavailable connection; when detecting that the number of connections does not satisfy the preset number, Trigger the dynamic link building module to update the connection pool.
  • FIG. 6 is a flowchart of a method for selecting a communication node according to an embodiment of the present invention. As shown in FIG. 6, the steps of the method include:
  • Step S602 Upon receiving the session processing request requested by the user, the session management module invokes the database communication module to acquire information of the node in the database cluster;
  • Step S604 The communication node selection module acquires the information of the node from the database communication module, and selects an available connection from the connection pool to communicate with the database cluster according to the node information according to the node information;
  • connection pool is used for the connection between the storage device and the nodes in the database cluster.
  • the manner in which the communication node selection module selects a node to communicate with the database cluster by using a predetermined rule may be implemented in the following manner in an optional implementation manner of the embodiment:
  • Step S11 The communication node selection module determines whether there is a connection carrying the specified session identifier
  • Step S12 When the determination result is no, the communication node selection module selects an available and unidentified first connection from the connection pool to communicate with the database cluster according to a preset algorithm, and adds a specified session identifier to the first connection;
  • Step S13 When the judgment result is YES, the communication node selection module selects the connection corresponding to the specified session identifier to perform communication with the database cluster.
  • Step S14 After the communication node selection module selects the connection corresponding to the specified session identifier to perform communication with the database cluster, if the connection corresponding to the specified session identifier is abnormal, the communication node selection module reselects one from the connection pool according to a preset algorithm. The second connection available communicates with the database cluster and adds a specified session token for the second connection.
  • the manner in which the communication node selection module in the device embodiment of the present invention communicates with the database cluster through the predetermined rule is corresponding to the steps S11 to S13 in the present embodiment, and therefore, details are described herein.
  • the method step of this embodiment may further include:
  • Step S21 The cluster node loading module records the node value of the database cluster configured by the device;
  • Step S22 When the cluster node loading module reloads the actual node value, the dynamic chain building module periodically updates the connection with the database cluster.
  • the method for dynamically updating the connection with the database cluster in the dynamic chain building module involved in step S22 can be implemented as follows: a dynamic chain building module, and the number of available connections between the establishing device and the database cluster node is N/2+1 Where N is the number of nodes in the database cluster; or, establishing a connection between the device and each node in the database cluster; or, when there is only one node in the database cluster, the number of available connections between the establishing device and the database cluster node is 1; When the node of the database cluster is greater than or equal to 2, the number of available connections between the establishing device and the database cluster node is 2.
  • Step S23 The cluster node configuration reverse writing module periodically detects the consistency between the actual node value of the library cluster configuration and the node value of the database cluster configured by the device; when the inconsistency is detected, the actual node value of the database cluster node is reversed as the device In the configuration file, and call the cluster node load module to reload the actual node value.
  • FIG. 7 is a structural block diagram of a container client for acquiring a database cluster service according to an alternative embodiment of the present invention.
  • the container client includes: a cluster node loading module, a cluster node configuration reverse writing module, and a dynamic chain building module. , a connection pool timing detection module, a connection pool management module, a database communication node selection module, and a communication processing module;
  • the cluster node loading module is set to load the cluster node value configured by the container, and invokes the dynamic chain building module to establish a chain;
  • the cluster node is configured with the anti-write module, and is configured to periodically check the consistency between the actual configuration value of the database cluster node and the configuration value of the container client. When the cluster node configuration and the container client configuration are inconsistent, the actual configuration of the cluster node is read and reversed. Go to the container's configuration file and call the cluster node configuration load module to reload the configuration value.
  • the dynamic link building module is configured to dynamically update the connection with the database cluster according to the loaded database cluster node configuration.
  • each container client establishes one and only one connection with each node in the database cluster, and after successful establishment of the chain Place the connection in the connection pool for unified management and maintenance.
  • the chain-building strategy provides configurability.
  • policy a When the configuration policy is available, the client establishes the number of available connections with the cluster node as n/2+1 connections; policy b: when the configuration policy is all, the container side and each database node are Establish a connection; policy c: When configured as the minimum available number, if the configuration is only 1 Zookeeper node, the number of connections between the container client and the cluster node is 1, otherwise the number of available connections between the container client and the cluster database node is 2. After the connection is successfully established, the communication between the client and the database node of the cluster is completed by taking the connection of the connection pool.
  • the connection pool timing detection module is configured to periodically detect the connection of the connection pool and detect whether the connection of the connection pool satisfies the link establishment policy. When the timing detection finds that the connection is unavailable, the unavailable connection is deleted from the connection pool in time; when the number of connected connections is found to be insufficient to meet the link-building policy, the dynamic link-building module is invoked to update the connection pool; for example, when the unsatisfied policy is available When it is time, it needs to call the dynamic link building module, re-establish the connection and join the connection pool, and maintain the number of connections available to meet the policy requirements.
  • the connection pool management module is configured to uniformly manage the connections in the connection pool and provide common operations for the connection pool.
  • the common operations include: providing connection creation, addition, destruction, deletion, and connection status detection.
  • the communication node selection module is configured to: when the container end needs to communicate with the nodes in the database cluster to read the shared session data, the request pressure for avoiding the container segment is concentrated on a single node in the cluster;
  • a method in which a random allocation + a session ID is combined is used to select a node in the database cluster for communication. That is, an available connection is obtained from the connection pool by randomly assigning the +Session ID algorithm, that is, when the session ID is the first communication behavior, a random allocation algorithm is used to randomly take an unmarked available connection from the connection pool. Communication, and mark the connection used as the logo used by the Session ID. When the Session is destroyed, the logo used by the connection is cleared; if it is not the first communication, the Session ID will communicate with the previously assigned connection.
  • connection or connection is not available or other read exceptions, then a random assignment algorithm will be used to reselect a flag that is not marked for available communication and flag the session ID. If the connection is flagged and still not assigned. When the connection is made, a random allocation algorithm is still used to allocate an available connection to the session and update the flag used for the session ID.
  • the selection algorithm may also be: providing a polling algorithm, a weighted rounding algorithm, and a consistent hashing algorithm.
  • the database communication module is configured to use the connection to perform data transfer with the nodes in the database cluster, mainly requesting information from the cluster node and obtaining response information, and transmitting the obtained response information to the corresponding other modules, for example, transmitting the obtained shared session information to
  • the session management module passes the obtained actual configuration information of the cluster node to the cluster node configuration reverse writing module.
  • the method for selecting a database cluster communication node by the equalization provided by the alternative embodiment fills in the blank of the related technology.
  • the introduced cluster node configuration anti-write module can automatically and instantly obtain the latest information of the cluster size, and can dynamically synchronize to the configuration of the container without manual configuration and without restarting the container;
  • the building chain module provides a customizable chain-building strategy, which can fully meet the needs of different scenarios. It can not affect the normal operation of the container end when the node fails in the cluster but other nodes can still provide normal services.
  • the random allocation algorithm is adopted.
  • Selecting the connection of the connection pool can make the request pressure not be concentrated on the single Zookeeper node of the cluster, so that the pressure of the cluster nodes is balanced as much as possible, improving the overall information processing capability of the cluster and reducing the probability of single point of failure.
  • the same session ID is used. Connections avoid frequent switching of connections and improve client information processing.
  • the communication node in the balanced selection database cluster in the related art is solved, the database node request pressure is excessively concentrated, the database node in the cluster is abnormally fault tolerant, and the node scale in the database cluster is difficult to automatically adapt.
  • FIG. 8 is a flowchart of a distributed shared session storage in a container client startup sequence according to an alternative embodiment of the present invention. As shown in FIG. 8, the startup sequence includes:
  • Step S802 Manually configuring related information.
  • the related information includes: configuring a container to use a shared session, configuring database cluster node information, configuring a cluster node dynamic link establishment policy, and configuring a node selection policy;
  • Step S804 trigger loading of the corresponding module of the container client
  • Step S806 Loading the configured database cluster node value
  • Step S808 Start a cluster node write-back module
  • the module periodically detects the consistency between the cluster configured in the container and the actual cluster value, and if not, updates the configuration value of the loaded cluster, and reverses the actual value to the configuration file of the container;
  • Step S810 Start a dynamic chain building module, and load a configured chain building strategy
  • the generating connection is stored in the connection pool according to the foregoing policy, such as a maximum available number, an available number, or a minimum number policy;
  • Step S812 Start the connection pool management module and the connection pool timing detection module to manage and maintain the connection in the connection pool.
  • FIG. 9 is a flow chart of distributed shared session access according to an alternative embodiment of the present invention.
  • the session management module invokes database communication.
  • the processing module processes the access of the Session at the database node and returns the result to the Session Management Module.
  • the database communication processing module needs to call the communication node selection module according to a certain algorithm, and the certain algorithm includes: random allocation + Session ID algorithm, polling, weighted polling or consistency hash to obtain the database node.
  • the connection is processed.
  • FIG. 10 is a flowchart of the operation of the database cluster node configuration reverse writing module according to an optional embodiment of the present invention.
  • the reverse writing module is configured to invoke database communication.
  • the processing module communicates with the database cluster to obtain the actual configuration information, and then determines the consistency of the configuration of the container loading. When the determination is inconsistent, the configuration file is updated and the configuration loading module is triggered. When the configuration loading module reloads the configuration file, the configuration is restarted. Call the dynamic load module to update the connection pool.
  • the optional embodiment has the function of disaster tolerance, that is, regardless of any abnormality of the nodes in the database cluster, as long as the cluster as a whole can still provide normal services, the container client The terminal can still use the services provided by the database cluster to perform normal operations; in addition, the manner of the alternative embodiment has relatively good stability, that is, in the absence of large pressure, the container client requests excessive pressure and causes the database node to provide the capability. Unbalanced situation; this alternative embodiment also has the scalability function, that is, whether the size of the cluster is expanded or reduced, the container client can still need to manually modify the configuration without restarting. Next, continue to automatically use nodes that scale up or downsize.
  • a storage medium is further provided, wherein the software includes the above-mentioned software, including but not limited to: an optical disk, a floppy disk, a hard disk, an erasable memory, and the like.
  • modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device such that they may be stored in the storage device for execution by the computing device and, in some cases, may be performed in a different order than herein.
  • the steps shown or described are either made separately into individual integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software.
  • the session management module when receiving the session processing request requested by the user, invokes the database communication module to acquire the information of the node in the database cluster, and the communication node selection module is configured to acquire the node from the database communication module. And, according to the information of the node, select an available connection from the connection pool according to the information of the node to communicate with the database cluster; in this embodiment, the communication node selection module selects a connection available in the connection pool through a predetermined rule to perform communication, thereby making the request.
  • the connection pressure is not concentrated on a single node of the cluster, and the pressure of the cluster nodes is balanced as much as possible, which solves the problem of selecting the client access cluster nodes of the distributed shared session in the related art.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

本发明提供了一种通讯节点的选择方法及装置,其中,该装置包括:会话管理模块、数据库通讯模块以及通讯节点选择模块;会话管理模块,设置为在接收到用户触发的用于生成、更新或读取会话的请求时,调用数据库通讯模块获取会话在数据库集群中的节点信息;通讯节点选择模块,设置为从数据库通讯模块中获取节点信息,并依据节点信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯,其中,连接池用于存储装置与数据库集群中节点的连接。通过本发明,解决了相关技术中分布式共享Session的客户端接入集群节点的选择问题。

Description

通讯节点的选择方法及装置 技术领域
本发明涉及通信领域,具体而言,涉及一种通讯节点的选择方法及装置。
背景技术
随着互联网规模的极速扩大,网站的页面浏览量和访问用户数成线性甚至是指数倍的增加,单服务器单数据库早已不能满足实际需求。目前绝大多数的大型网站的服务器都采用了分布式服务集群的部署方式,所谓集群,就是让一组服务器协同工作,解决大并发、大数据量瓶颈的问题。分布式集群带来的棘手的问题是跨服务器Session(会话)共享的问题,即不同的服务器共享同一个Session数据,实现不同服务器应用同一个Session,为解决该问题,目前业界比较流行的做法是采用容器+高性能分布式缓存数据库,即把本地的Session数据的序列化存储到缓存数据库中实现不同的服务器进行共享,这个方法能很好的解决Session的共享问题。常用的高性能分布式缓存数据库有Zookeeper,Memcached,Redis等。其中Zookeeper是个非常好的分布式缓存数据库,它的本质是一个分布式小文件系统,即当所有的Zookeeper节点全部挂掉,数据也不会丢失,重启服务器之后,数据即可恢复,而且Zookeeper的节点是原子的,更新不是成功便是失败,另外通过选举算法和集群复制还可以避免单点故障。Zookeeper集群主要有三个角色leader(领导者)、follower(跟随者)和observer(观察者),一个集群中会选举一个节点为leader,leader节点接收客户端请求、负责进行投票的发起和决议并与所有的follower和observer进行内部的数据交换;follower节点和observer节点接收客户端连接,并将写请求转发给leader节点向客户端返回结果,其中follower和observer的唯一区别是follower会参与leader的选举,而observer不会。当集群中leader宕机后,Zookeeper进入恢复模式,恢复模式需要重新选举出一个新的leader,让所有的server都恢复到一个正确的状态。在集群的正常运行过程中,客户端连接任一运行正常的角色节点都可以接入集群。由于Zookeeper集群的节点存在着多个,即有多个节点可以接入,导致存在分布式共享Session的客户端接入集群节点的选择问题。
针对相关技术中分布式共享Session的客户端接入集群节点的选择问题,目前尚未提出有效的解决方案。
发明内容
本发明实施例的主要目的在于提供一种通讯节点的选择方法及装置,以至少解决相关技术中分布式共享Session的客户端接入集群节点的选择问题。
根据本发明实施例的一个方面,提供了一种通讯节点的选择装置,所述装置包括:会话管理模块、数据库通讯模块以及通讯节点选择模块;所述会话管理模块,设置为在接收到用户请求的会话处理请求时,调用所述数据库通讯模块获取数据库集群中节点的信息;所述通讯节点选择模块,设置为从所述数据库通讯模块中获取所述节点的信息,并依据所述节的点信息通过预定规则从连接池中选择可用连接与所述数据库集群进行通讯,其中,所述连接池用于存储所述装置与所述数据库集群中节点之间的连接。
进一步地,所述通讯节点选择模块通过预定规则选择节点与所述数据库集群进行通讯的方式包括:所述通讯节点选择模块,判断是否有携带指定会话标识的连接;在判断结果为否时,依据预设算法从所述连接池中选择一个可用且未被标识的第一连接与所述数据库集群进行通讯,并为所述第一连接增加所述指定会话标识;在判断结果为是时,选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯。
进一步地,在选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯之后,若与所述指定会话标识对应的连接异常时,所述通讯节点选择模块,还设置为依据所述预设算法从所述连接池中重新选择一个可用的第二连接与所述数据库集群进行通讯,并为所述第一连接增加所述指定会话标识。
进一步地,所述预设算法包括:随机分配算法、轮询算法,加权轮询算法以及一致性哈希算法。
进一步地,所述装置还包括:连接池管理模块,设置为执行对所述连接池中连接的管理操作,其中,所述管理操作包括:创建连接、增加连接、销毁连接、删除连接以及检测连接状态。
进一步地,所述装置还包括:集群节点加载模块,设置为记载所述装置配置的数据库集群的节点值;动态建链模块,设置为在所述集群节点加载模块重新加载所述数据库集群配置的实际节点值时,周期性动态更新与所述数据库集群的连接。
进一步地,所述动态建链模块动态更新与所述数据库集群的连接的方式包括:所述动态建链模块,建立所述装置与所述数据库集群节点可用连接数为N/2+1个,其中,所述N为所述数据库集群的节点数;或,建立所述装置与所述数据库集群中的每一个节点的连接;或,在所述数据库集群中只有一个节点时,建立所述装置与所述数据库集群节点可用连接数为1;在所述数据库集群的节点大于或等于2时,建立所述装置与所述数据库集群节点可用连接数为2。
进一步地,所述装置还包括:集群节点配置反写模块,设置为周期性检测所述数据库集群配置的实际节点值与所述装置配置的所述数据库集群的节点值的一致性;在检测到不一致时,获取所述数据库集群节点的实际节点值反写如所述装置的配置文件中,并调用所述集群节点加载模块重新加载所述实际节点值。
进一步地,所述装置还包括:连接池定时检测模块,设置为周期性检测所述连接池的连接状态以及连接池的连接数是否满足预设数量;在检测到有连接不可用时,触发所述连接池管理模块删除该不可用连接;在检测到连接数不满足预设数量时,触发所述动态建链模块更新所述连接池。
根据本发明实施例的另一个方面,提供了一种应用于上述任一装置中通讯节点的选择方法,所述装置包括:会话管理模块、数据库通讯模块以及通讯节点选择模块,所述方法包括:在接收到用户请求的会话处理请求时,所述会话管理模块调用所述数据库通讯模块获取数据库集群中节点的信息;所述通讯节点选择模块从所述数据库通讯模块中获取所述节点的信息,并依据所述节点的信息通过预定规则从连接池中选择可用连接与所述数据库集群进行通讯,其中,所述连接池用于存储所述装置与所述数据库集群中节点之间的连接。
进一步地,所述通讯节点选择模块通过预定规则选择节点与所述数据库集群进行通讯包括:所述通讯节点选择模块判断是否有携带指定会话标的连接;在判断结果为否时,所述通讯节点选择模块依据预设算法从所述连接池中选择一个可用且未被标识的第一连接与所述数据库集群进行通讯,并为所述第一连接增加所述指定会话标识;在判断结果为是时,所述通讯节点选择模块选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯。
进一步地,在选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯之后,所述方法还包括:若与所述指定会话标识对应的连接异常时,所述通讯节点选择模块依据所述预设算法从所述连接池中重新选择一个可用的第二连接与所述数据库集群进行通讯,并为所述第二连接增加所述指定会话标识。
在本发明实施例中,还提供了一种计算机存储介质,该计算机存储介质可以存储有执行指令,该执行指令用于执行上述实施例中的通讯节点的选择方法。
通过本发明实施例,在接收到用户请求的会话处理请求时,会话管理模块调用数据库通讯模块获取会话在数据库集群中节点的信息,而通讯节点选择模块,用于从数据库通讯模块中获取该节点的信息,并依据节点的信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯;可见,本实施例中通讯节点选择模块通过预定规则选择连接池中可用的连接进行通讯,从而使得请求连接的压力不过分集中在集群的单 个节点上,达到集群节点的压力尽量均衡,解决了相关技术中分布式共享Session的客户端接入集群节点的选择问题。
附图说明
此处所说明的附图用来提供对本发明的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:
图1是根据本发明实施例的通讯节点的选择装置结构框图;
图2是根据本发明实施例的通讯节点的选择装置可选结构框图一;
图3是根据本发明实施例的通讯节点的选择装置可选结构框图二;
图4是根据本发明实施例的通讯节点的选择装置可选结构框图三;
图5是根据本发明实施例的通讯节点的选择装置可选结构框图四;
图6是根据本发明实施例的通讯节点的选择方法的流程图;
图7是根据本发明可选实施例的获取数据库集群服务的容器客户端的结构框图;
图8是根据本发明可选实施例的分布式共享Session存储在容器客户端启动顺序的流程图;
图9是根据本发明可选实施例的分布式共享Session存取的流程图;
图10是根据本发明可选实施例的数据库集群节点配置反写模块工作的流程图。
具体实施方式
需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。下面将参考附图并结合实施例来详细说明本发明。
本实施例提供了一种通讯节点的选择装置,图1是根据本发明实施例的通讯节点的选择装置结构框图,如图1所示,该装置包括:会话管理模块101、数据库通讯模块102以及通讯节点选择模块103;
其中,会话管理模块101,与数据库通讯模块102耦合连接,设置为在接收到用户请求的会话处理请求时,调用数据库通讯模块102获取数据库集群中节点的信息;其中,该会话处理请求可以是用于生成、更新或读取会话的请求。
通讯节点选择模块103,与数据库通讯模块102耦合连接,设置为从数据库通讯模块102中获取节点的信息,并依据节点的信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯,其中,连接池用于存储装置与数据库集群中节点的连接。
通过本发明实施例装置,在接收到用户请求的会话处理请求时,会话管理模块调用数据库通讯模块获取会话在数据库集群中节点的信息,而通讯节点选择模块,设置为从数据库通讯模块中获取该节点的信息,并依据该节点的信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯;可见,本实施例中通讯节点选择模块通过预定规则选择连接池中可用的连接进行通讯,从而使得请求连接的压力不过分集中在集群的单个节点上,达到集群节点的压力尽量均衡,解决了相关技术中分布式共享Session的客户端接入集群节点的选择问题。
对于本实施例中,通讯节点选择模块103依据节点信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯方式,在本实施例一个可选实施例中,该通讯节点选择模块103采取的方式为,判断是否有携带指定会话标识的连接;在判断结果为否时,依据预设算法从连接池中选择一个可用且未被标识的第一连接与数据库集群进行通讯,并为第一连接增加指定会话标识;而在判断结果为是时,选择与指定会话标识对应的连接执行与数据库集群的通讯。
而在本实施例的另一个可选实施方式中,在选择与指定会话标识对应的连接执行与数据库集群的通讯之后,若与指定会话标识对应的连接异常时,通讯节点选择模块依据预设算法从连接池中重新选择一个可用的第二连接与数据库集群进行通讯,并通过指定会话标识更新第二连接的标识。
需要说明的是,本实施例中涉及到的预设算法可以是随机分配算法、轮询算法,加权轮询算法以及一致性哈希算法等等,下面以随机分配算法为例的应用场景一,对上述通讯节点选择模块103依据节点信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯方式进行举例说明;
应用场景一:从连接池中通过随机分配+Session ID(对应于指定会话标识)算法取出一条可用连接进行通讯,即当Session ID是第一次发生通讯行为时,采用随机分配算法从连接池中随机取出一条未被标志的可用连接进行通讯,并标志该连接为该Session ID使用的标志,Session(会话)在销毁时,清除连接使用的标志;若不是第一次通讯则Session ID将会采用之前分配的连接进行通讯,若取不到之前的连接或者连接不可用或者其它读取异常,那么将采用随机分配算法重新选择一条未被标志可用连接进行通讯,并标志该Session ID使用的标志,若连接都被标志且依然分配不到未被标志的连接时,则依然采用随机分配算法分配一条可用连接给该Session,并更新为该会话ID使用的标志
图2是根据本发明实施例的通讯节点的选择装置可选结构框图一,如图2所示,该装置还包括:连接池管理模块104,数据库通讯模块102耦合连接,设置为执行对连接池中连接的管理操作,其中,管理操作包括:创建连接、增加连接、销毁连接、删除连接以及检测连接状态。
图3是根据本发明实施例的通讯节点的选择装置可选结构框图二,如图3所示,该装置还包括:集群节点加载模块105,与动态建链模块106耦合连接,设置为记载装置配置的数据库集群的节点值;动态建链模块106,与数据库通讯模块102耦合连接,设置为在集群节点加载模块重新加载实际节点值时,动态更新与数据库集群的连接。
可选地,动态建链模块106动态更新与数据库集群的连接的方式,在本实施例的一个可选实施方式中,该动态建链模块106通过如下方式来实现,建立装置与数据库集群节点可用连接数为N/2+1个,其中,N为数据库集群的节点数;或,建立装置与数据库集群中的每一个节点的连接;或,在数据库集群中只有一个节点时,建立装置与数据库集群节点可用连接数为1;在数据库集群的节点大于或等于2时,建立装置与数据库集群节点可用连接数为2。
图4是根据本发明实施例的通讯节点的选择装置可选结构框图三,如图4所示,该装置还包括:集群节点配置反写模块107,与集群节点加载模块105耦合连接,设置为周期性检测库集群配置的实际节点值与装置配置的数据库集群的节点值的一致性;在检测到不一致时,获取数据库集群节点的实际节点值反写如装置的配置文件中,并调用集群节点加载模块重新加载实际节点值。
图5是根据本发明实施例的通讯节点的选择装置可选结构框图四,如图5所示,该装置还包括:连接池定时检测模块108,与连接池管理模块104耦合连接,设置为周期性检测连接池的连接状态以及连接池的连接数是否满足预设数量;在检测到有连接不可用时,触发连接池管理模块删除该不可用连接;在检测到连接数不满足预设数量时,触发动态建链模块更新连接池。
图6是根据本发明实施例的通讯节点的选择方法的流程图,如图6所示,该方法的步骤包括:
步骤S602:在接收到用户请求的会话处理请求时,会话管理模块调用数据库通讯模块获取数据库集群中节点的信息;
步骤S604:通讯节点选择模块从数据库通讯模块中获取节点的信息,并依据该节点信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯;
其中,连接池用于存储装置与数据库集群中节点之间的连接。
可选地,通讯节点选择模块通过预定规则选择节点与数据库集群进行通讯的方式,在本实施例的可选实施方式中可以通过如下方式来实现:
步骤S11:通讯节点选择模块判断是否有携带指定会话标识的连接;
步骤S12:在判断结果为否时,通讯节点选择模块依据预设算法从连接池中选择一个可用且未被标识的第一连接与数据库集群进行通讯,并为第一连接增加指定会话标识;
步骤S13:在判断结果为是时,通讯节点选择模块选择与指定会话标识对应的连接执行与数据库集群的通讯。
步骤S14:在通讯节点选择模块选择与指定会话标识对应的连接执行与数据库集群的通讯之后,若与指定会话标识对应的连接异常时,通讯节点选择模块依据预设算法从连接池中重新选择一个可用的第二连接与数据库集群进行通讯,并为第二连接增加指定会话标。
需要说明的是,此处的步骤S11至步骤S13与本发明的装置实施例中的通讯节点选择模块通过预定规则选择节点与数据库集群进行通讯的方式是对应的,因此,在此就再赘述。
可选地,本实施例的方法步骤还可以包括:
步骤S21:集群节点加载模块记载装置配置的数据库集群的节点值;
步骤S22:在集群节点加载模块重新加载实际节点值时,动态建链模块周期性动态更新与数据库集群的连接。
而对于步骤S22中涉及到的动态建链模块动态更新与数据库集群的连接的方式,可以通过如下方式来实现:动态建链模块,建立装置与数据库集群节点可用连接数为N/2+1个,其中,N为数据库集群的节点数;或,建立装置与数据库集群中的每一个节点的连接;或,在数据库集群中只有一个节点时,建立装置与数据库集群节点可用连接数为1;在数据库集群的节点大于或等于2时,建立装置与数据库集群节点可用连接数为2。
步骤S23:集群节点配置反写模块周期性检测库集群配置的实际节点值与装置配置的数据库集群的节点值的一致性;在检测到不一致时,获取数据库集群节点的实际节点值反写如装置的配置文件中,并调用集群节点加载模块重新加载实际节点值。
下面结合本发明的可选实施例对本发明进行举例说明;
本可选实施例提供了一种可靠的、稳定的、具有可伸缩性的获取数据库集群服务 的容器客户端(对应于本发明实施例中的装置),该容器客户端应用于分布式Session共享。图7是根据本发明可选实施例的获取数据库集群服务的容器客户端的结构框图,如图7所示,该容器客户端包括:集群节点加载模块、集群节点配置反写模块、动态建链模块、连接池定时检测模块、连接池管理模块、数据库通讯节点选择模块以及通讯处理模块;
其中,集群节点加载模块,设置为加载容器配置的集群节点值,并调用动态建链模块进行建链;
集群节点配置反写模块,设置为定时检测数据库集群节点实际配置值和容器客户端配置值的一致性,当存在集群节点配置和容器客户端配置不一致时,读取集群节点的实际配置并反写到容器的配置文件中,并调用集群节点配置加载模块重新加载该配置值。
动态建链模块,设置为根据加载的数据库集群节点配置,动态更新与数据库集群的连接。
对于动态更新于数据库集群的连接方式,在本可选实施例中包括:在数据库集群模块比较小时,每个容器客户端与数据库集群的中每个节点建立一条且仅一条连接,成功建链后将该连接放置到连接池中进行统一管理维护。而为避免当数据库集群规模比较大,节点数比较多,实际并不需要那么多连接时,建链策略提供可配置。比如:策略a:当配置策略为可用数时,客户端与集群节点建立可用连接数为n/2+1个连接;策略b:当配置策略为全部数时,容器端与每个数据库节点都建立一条连接;策略c:当配置为最小可用数时,若配置仅为1个Zookeeper节点,则容器客户端与集群节点建立连接数为1,否则容器客户端与集群数据库节点建立可用连接数为2。连接成功建立后,客户端与集群的数据库节点之间的通讯都是通过取连接池的连接来完成。当建链过程中若存在失败时,则跳过该Zookeeper节点的建链,选择下一个节点建链直到满足策略需求,如此循环超过一定次数(可选的该一定次数可以是2次),若仍然不满足策略需求时,则退出模块。
连接池定时检测模块,设置为定时检测连接池的连接和检测连接池的连接是否满足建链策略。当定时检测发现连接不可用时,及时从连接池中删除不可用的连接;当定时检测连接数发现不满足建链策略,则调用动态建链模块更新连接池;例如,当不满足的策略为可用数时,那需要调用动态建链模块,重新建立连接加入到连接池中,维持连接可用数达到策略要求。
连接池管理模块,设置为统一管理连接池中的连接,提供连接池常用的操作,该常用操作包括:提供连接创建、增加、销毁、删除、以及连接状态检测等功能。
通讯节点选择模块,设置为当容器端需要与数据库集群中的节点进行通讯读取共享的Session数据时,为避免容器段的请求压力都集中在集群中的单个节点上;
可选地,在本可选实施例中,采取随机分配+Session ID相结合的方法,选择数据库集群中的节点来进行通讯。即从连接池中通过随机分配+Session ID算法取出一条可用连接进行通讯,即当Session ID是第一次发生通讯行为时,采用随机分配算法从连接池中随机取出一条未被标志的可用连接进行通讯,并标志该连接为该Session ID使用的标志,Session在销毁时,清除连接使用的标志;若不是第一次通讯则Session ID将会采用之前分配的连接进行通讯,若取不到之前的连接或者连接不可用或者其它读取异常,那么将采用随机分配算法重新选择一条未被标志可用连接进行通讯,并标志该Session ID使用的标志,若连接都被标志且依然分配不到未被标志的连接时,则依然采用随机分配算法分配一条可用连接给该Session,并更新为该会话ID使用的标志。为了满足业务的定制化需求,选择算法还可以是:提供轮询算法,加权轮询算法以及一致性哈希算法等。
数据库通讯模块,设置为使用连接与数据库集群中节点进行数据传递,主要是向集群节点请求信息和获取响应信息,把获取的响应信息传递给相应的其它模块,例如把获取的共享Session信息传递给Session管理模块,把获取的集群节点实际配置信息传递给集群节点配置反写模块等。
通过本可选实施例提供的均衡选择数据库集群通讯节点的方法,填充了相关技术的空白。在本可选实施例中,引入的集群节点配置反写模块能自动且即时获取到集群规模的最新信息,能在无需手工配置、无需重启容器的情况下动态同步到容器的配置;此外,动态建链模块提供可自定义的建链策略,能全方位满足不同的场景需求,能在集群出现节点故障但其它节点依然能提供正常服务时,不影响容器端的正常运作;另外,采用随机分配算法选择连接池的连接,能使得请求压力不过分集中在集群的单个Zookeeper节点上,使得集群节点的压力尽量均衡,提高集群整体的信息处理能力和降低单点故障发生几率,采用同一Session ID使用同一连接能避免使用连接的频繁切换,提高客户端信息处理能力。
可见,通过本可选实施例解决了相关技术中均衡的选择数据库集群中的通讯节点,数据库节点请求压力过分集中,集群中数据库节点异常容错,以及数据库集群中节点规模难以自动适应的问题。
下面结合附图对本发明可选实施例进行详细说明;
图8是根据本发明可选实施例的分布式共享Session存储在容器客户端启动顺序的流程图,如图8所示,该启动的顺序包括:
步骤S802:手工配置相关信息;
其中,该相关信息包括:配置容器使用共享Session、配置数据库集群节点信息、配置集群节点动态建链策略、配置节点选择策略等;
步骤S804:触发该容器客户端相应模块的加载;
步骤S806:加载配置的数据库集群节点值;
步骤S808:启动集群节点反写模块;
其中,该模块定时检测容器中配置的集群和实际集群值的一致性,若不一致则更新加载集群的配置值,并反写实际值到容器的配置文件;
步骤S810:启动动态建链模块,加载配置的建链策略;
其中,根据上述策略,如最大可用数、可用数或最小数策略,生成连接存储到连接池中;
步骤S812:启动连接池管理模块和连接池定时检测模块,以管理维护连接池中的连接。
图9是根据本发明可选实施例的分布式共享Session存取的流程图,如图9所示,在容器有接收到用户请求需要生成、更新或者读取Session时,Session管理模块调用数据库通讯处理模块,处理Session在数据库节点的存取,并返回结果给Session管理模块。数据库通讯处理模块在与数据库通讯过程中,需要调用通讯节点选择模块根据一定算法,该一定算法包括:随机分配+Session ID算法、轮询、加权轮询或者一致性哈希等,以获取数据库节点的连接来进行处理。
图10是根据本发明可选实施例的数据库集群节点配置反写模块工作的流程图,如图10所示,在容器定时器定时触发集群节点配置反写模块时,配置反写模块调用数据库通讯处理模块与数据库集群进行通讯,获取实际配置信息,然后进行容器加载的配置一致性进行判定,当判定不一致时,更新配置文件并触发配置加载模块,当配置加载模块重新加载配置文件后,会重新调用动态加载模块更新连接池。
由上述图7至图10,以及相应的说明可知,本可选实施例具有容灾的功能,即无论数据库集群中的节点出现何种异常,只要集群整体仍然能提供正常的服务,则容器客户端依然能使用数据库集群提供的服务进行正常运作;此外,本可选实施例的方式具有比较好的稳定性,即不存在大压力情况下,容器客户端请求压力过分集中而导致数据库节点提供能力不均衡的情况;本可选实施例还具有可伸缩性的功能,即集群的规模无论是扩大还是缩小,容器客户端依然能在无需手工修改配置、无需重启的情况 下,继续自动使用扩大规模或缩小规模的节点。
在另外一个实施例中,还提供了一种软件,该软件用于执行上述实施例及优选实施方式中描述的技术方案。
在另外一个实施例中,还提供了一种存储介质,该存储介质中存储有上述软件,该存储介质包括但不限于:光盘、软盘、硬盘、可擦写存储器等。
显然,本领域的技术人员应该明白,上述本发明的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。
上述仅为本发明的可选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
工业实用性
通过本发明实施例,在接收到用户请求的会话处理请求时,会话管理模块调用数据库通讯模块获取会话在数据库集群中节点的信息,而通讯节点选择模块,用于从数据库通讯模块中获取该节点的信息,并依据节点的信息通过预定规则从连接池中选择可用连接与数据库集群进行通讯;可见,本实施例中通讯节点选择模块通过预定规则选择连接池中可用的连接进行通讯,从而使得请求连接的压力不过分集中在集群的单个节点上,达到集群节点的压力尽量均衡,解决了相关技术中分布式共享Session的客户端接入集群节点的选择问题。

Claims (12)

  1. 一种通讯节点的选择装置,所述装置包括:会话管理模块、数据库通讯模块以及通讯节点选择模块;
    所述会话管理模块,设置为在接收到用户请求的会话处理请求时,调用所述数据库通讯模块获取数据库集群中节点的信息;
    所述通讯节点选择模块,设置为从所述数据库通讯模块中获取所述节点的信息,并依据所述节点的信息通过预定规则从连接池中选择可用连接与所述数据库集群进行通讯,其中,所述连接池用于存储所述装置与所述数据库集群中节点之间的连接。
  2. 根据权利要求1所述的装置,其中,所述通讯节点选择模块通过预定规则选择节点与所述数据库集群进行通讯的方式包括:
    所述通讯节点选择模块,判断是否有携带指定会话标识的连接;在判断结果为否时,依据预设算法从所述连接池中选择一个可用且未被标识的第一连接与所述数据库集群进行通讯,并为所述第一连接增加所述指定会话标识;在判断结果为是时,选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯。
  3. 根据权利要求2所述的装置,其中,
    在选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯之后,若与所述指定会话标识对应的连接异常时,所述通讯节点选择模块,还设置为依据所述预设算法从所述连接池中重新选择一个可用的第二连接与所述数据库集群进行通讯,并为所述第二连接增加所述指定会话标识。
  4. 根据权利要求2所述的装置,其中,所述预设算法包括:随机分配算法、轮询算法,加权轮询算法以及一致性哈希算法。
  5. 根据权利要求2所述的装置,其中,所述装置还包括:
    连接池管理模块,设置为执行对所述连接池中连接的管理操作,其中,所述管理操作包括:创建连接、增加连接、销毁连接、删除连接以及检测连接状态。
  6. 根据权利要求5所述的装置,其中,所述装置还包括:
    集群节点加载模块,设置为记载所述装置配置的数据库集群的节点值;
    动态建链模块,设置为在所述集群节点加载模块重新加载所述数据库集群配置的实际节点值时,周期性动态更新与所述数据库集群的连接。
  7. 根据权利要求6所述的装置,其中,所述动态建链模块动态更新与所述数据库集 群的连接的方式包括:
    所述动态建链模块,建立所述装置与所述数据库集群节点可用连接数为N/2+1个,其中,所述N为所述数据库集群的节点数;或,
    建立所述装置与所述数据库集群中的每一个节点的连接;或,
    在所述数据库集群中只有一个节点时,建立所述装置与所述数据库集群节点可用连接数为1;在所述数据库集群的节点大于或等于2时,建立所述装置与所述数据库集群节点可用连接数为2。
  8. 根据权利要求6所述的装置,其中,所述装置还包括:
    集群节点配置反写模块,设置为周期性检测所述数据库集群配置的实际节点值与所述装置配置的所述数据库集群的节点值的一致性;在检测到不一致时,获取所述数据库集群节点的实际节点值反写如所述装置的配置文件中,并调用所述集群节点加载模块重新加载所述实际节点值。
  9. 根据权利要求8所述的装置,其中,所述装置还包括:
    连接池定时检测模块,设置为周期性检测所述连接池的连接状态以及连接池的连接数是否满足预设数量;在检测到有连接不可用时,触发所述连接池管理模块删除不可用的连接;在检测到连接数不满足预设数量时,触发所述动态建链模块更新所述连接池。
  10. 一种应用于权利要求1至9任一项装置的通讯节点的选择方法,所述装置包括:会话管理模块、数据库通讯模块以及通讯节点选择模块,所述方法包括:
    在接收到用户请求的会话处理请求时,所述会话管理模块调用所述数据库通讯模块获取数据库集群中节点的信息;
    所述通讯节点选择模块从所述数据库通讯模块中获取所述节点的信息,并依据所述节点的信息通过预定规则从连接池中选择可用连接与所述数据库集群进行通讯,其中,所述连接池用于存储所述装置与所述数据库集群中节点之间的连接。
  11. 根据权利要求10所述的方法,其中,所述通讯节点选择模块通过预定规则选择节点与所述数据库集群进行通讯包括:
    所述通讯节点选择模块判断是否有携带指定会话标识的连接;
    在判断结果为否时,所述通讯节点选择模块依据预设算法从所述连接池中选择一个可用且未被标识的第一连接与所述数据库集群进行通讯,并为所述第一连 接增加所述指定会话标识;在判断结果为是时,所述通讯节点选择模块选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯。
  12. 根据权利要求11所述的方法,其中,在选择与所述指定会话标识对应的连接执行与所述数据库集群的通讯之后,所述方法还包括:
    若与所述指定会话标识对应的连接异常时,所述通讯节点选择模块依据所述预设算法从所述连接池中重新选择一个可用的第二连接与所述数据库集群进行通讯,并为所述第二连接增加所述指定会话标识。
PCT/CN2016/076647 2015-05-07 2016-03-17 通讯节点的选择方法及装置 WO2016177130A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510229101.0 2015-05-07
CN201510229101.0A CN106209943A (zh) 2015-05-07 2015-05-07 通讯节点的选择方法及装置

Publications (1)

Publication Number Publication Date
WO2016177130A1 true WO2016177130A1 (zh) 2016-11-10

Family

ID=57218473

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/076647 WO2016177130A1 (zh) 2015-05-07 2016-03-17 通讯节点的选择方法及装置

Country Status (2)

Country Link
CN (1) CN106209943A (zh)
WO (1) WO2016177130A1 (zh)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111107120A (zh) * 2018-10-29 2020-05-05 亿阳信通股份有限公司 一种Redis集群的构建方法及系统
CN111432011A (zh) * 2020-03-30 2020-07-17 百度国际科技(深圳)有限公司 区块链的网络通信方法和设备
CN111431999A (zh) * 2020-03-23 2020-07-17 杭州趣维科技有限公司 一种基于Paxos算法的云函数分布式系统
CN112231384A (zh) * 2020-10-30 2021-01-15 中国建设银行股份有限公司 适配多种数据源的分布式应用国产化改造方法及设备
CN112506610A (zh) * 2020-12-02 2021-03-16 北京大米科技有限公司 信息更新方法、装置、存储介质和电子设备
CN115617917A (zh) * 2022-12-16 2023-01-17 中国西安卫星测控中心 一种数据库集群多活控制的方法、装置、系统和设备

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109274641A (zh) * 2018-08-09 2019-01-25 广东神马搜索科技有限公司 客户端与服务节点之间的连接方法和装置、计算设备和存储介质
CN110134372A (zh) * 2019-07-10 2019-08-16 启迪云计算有限公司 一种基于规则的zookeeper session外部管理系统
CN110659463B (zh) * 2019-08-23 2021-11-12 苏州浪潮智能科技有限公司 一种无状态系统的分布式运行的方法及装置
CN112054919B (zh) * 2020-08-03 2022-08-16 华人运通(江苏)技术有限公司 容器集群无状态下的id生成方法、装置、存储介质及系统

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103078805A (zh) * 2012-12-31 2013-05-01 北京京东世纪贸易有限公司 使Zookeeper的读性能支持水平扩展的系统和方法
CN103795569A (zh) * 2014-01-22 2014-05-14 亿赞普(北京)科技有限公司 一种基于连接池的服务器连接方法和装置
US20140149489A1 (en) * 2012-11-26 2014-05-29 Facebook. Inc. On-demand session upgrade in a coordination service
CN104580226A (zh) * 2015-01-15 2015-04-29 上海瀚之友信息技术服务有限公司 一种共享会话数据的系统和方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140149489A1 (en) * 2012-11-26 2014-05-29 Facebook. Inc. On-demand session upgrade in a coordination service
CN103078805A (zh) * 2012-12-31 2013-05-01 北京京东世纪贸易有限公司 使Zookeeper的读性能支持水平扩展的系统和方法
CN103795569A (zh) * 2014-01-22 2014-05-14 亿赞普(北京)科技有限公司 一种基于连接池的服务器连接方法和装置
CN104580226A (zh) * 2015-01-15 2015-04-29 上海瀚之友信息技术服务有限公司 一种共享会话数据的系统和方法

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111107120A (zh) * 2018-10-29 2020-05-05 亿阳信通股份有限公司 一种Redis集群的构建方法及系统
CN111107120B (zh) * 2018-10-29 2022-09-02 亿阳信通股份有限公司 一种Redis集群的构建方法及系统
CN111431999A (zh) * 2020-03-23 2020-07-17 杭州趣维科技有限公司 一种基于Paxos算法的云函数分布式系统
CN111431999B (zh) * 2020-03-23 2022-11-25 杭州小影创新科技股份有限公司 一种基于Paxos算法的云函数分布式系统
CN111432011A (zh) * 2020-03-30 2020-07-17 百度国际科技(深圳)有限公司 区块链的网络通信方法和设备
CN111432011B (zh) * 2020-03-30 2023-02-17 百度国际科技(深圳)有限公司 区块链的网络通信方法和设备
CN112231384A (zh) * 2020-10-30 2021-01-15 中国建设银行股份有限公司 适配多种数据源的分布式应用国产化改造方法及设备
CN112231384B (zh) * 2020-10-30 2024-03-29 中国建设银行股份有限公司 适配多种数据源的分布式应用国产化改造方法及设备
CN112506610A (zh) * 2020-12-02 2021-03-16 北京大米科技有限公司 信息更新方法、装置、存储介质和电子设备
CN115617917A (zh) * 2022-12-16 2023-01-17 中国西安卫星测控中心 一种数据库集群多活控制的方法、装置、系统和设备

Also Published As

Publication number Publication date
CN106209943A (zh) 2016-12-07

Similar Documents

Publication Publication Date Title
WO2016177130A1 (zh) 通讯节点的选择方法及装置
US11360854B2 (en) Storage cluster configuration change method, storage cluster, and computer system
JP6382454B2 (ja) 分散ストレージ及びレプリケーションシステム、並びに方法
US8631277B2 (en) Providing transparent failover in a file system
EP2695083B1 (en) Cluster unique identifier
CN113010496B (zh) 一种数据迁移方法、装置、设备和存储介质
US9424145B2 (en) Ensuring the same completion status for transactions after recovery in a synchronous replication environment
US10609123B2 (en) Hybrid quorum policies for durable consensus in distributed systems
WO2017152736A1 (zh) 一种分布式文件系统hdfs的管理方法、装置及系统
US10474493B2 (en) Systems and methods for semi-durable transaction log storage in two-phase commit protocol transaction processing
US10275400B1 (en) Systems and methods for forming a fault-tolerant federated distributed database
US9444885B2 (en) Workflow processing in a distributed computing environment
US10048983B2 (en) Systems and methods for enlisting single phase commit resources in a two phase commit transaction
US11892982B2 (en) Facilitating immediate performance of volume resynchronization with the use of passive cache entries
WO2017148297A1 (zh) 数据表连接方法及装置
US11397632B2 (en) Safely recovering workloads within a finite timeframe from unhealthy cluster nodes
WO2023071999A1 (zh) 一种用户匹配方法、装置、设备及存储介质
US10761881B2 (en) Managing a lifecycle of a software container
CN107547512B (zh) 一种多级云平台中的用户认证方法和装置
CN110830582B (zh) 一种基于服务器集群选主方法和装置
US10545667B1 (en) Dynamic data partitioning for stateless request routing
CN110069365B (zh) 管理数据库的方法和相应的装置、计算机可读存储介质
US20160050113A1 (en) Methods for managing storage virtual machine configuration changes in a distributed storage system and devices thereof
CN111291063B (zh) 主备副本选举方法、系统、计算机设备和存储介质
US11620273B2 (en) Message processing node and database in a message processing system and methods of operating the same

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

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

Country of ref document: EP

Kind code of ref document: A1