Disclosure of Invention
The invention aims to provide a method, a system, computer equipment and a storage medium for realizing a connection pool under a multi-HiveServer 2 server scene, which can realize load balancing, fault detection, alarm, automatic recovery and the like of a multi-HiveServer 2 server.
The technical solution for realizing the purpose of the invention is as follows: a method for implementing a connection pool in a multi-HiveServer 2 server scenario includes:
constructing a HiveServer2 server state list, wherein HiveServer2 servers in the list correspond to the working states one by one;
receiving a user request;
and performing load balancing distribution on the plurality of HiveServer2 servers, and returning connection information or connection error information of the user request and the HiveServer2 server.
Further, the working state of the HiveServer2 server includes the number of times the HiveServer2 server executes a user request, the time consumed for executing the user request, whether the user request is currently being executed, and whether a failure occurs.
Further, the performing load balancing distribution on the multiple HiveServer2 servers includes the following processes:
detecting whether each HiveServer2 server in the HiveServer2 server state list fails or not, and constructing an available HiveServer2 server list by all HiveServer2 servers which do not fail;
for each HiveServer2 server in the list of available HiveServer2 servers, collecting the operating state of the HiveServer2 server from the HiveServer2 server state list;
arranging the priorities of all HiveServer2 servers in the available HiveServer2 server list according to the collected working state, thereby constructing an available HiveServer2 server ordered list;
and sequentially traversing the ordered list of available HiveServer2 servers until the user requests to successfully establish connection with a certain HiveServer2 server or the traversal is finished.
Further, the detecting whether each HiveServer2 server fails is specifically realized by an independent single thread a, and the single thread a detects whether each HiveServer2 server fails in real time in the running process of the method for realizing the connection pool under the multi-HiveServer 2 server scenario, and updates the state list of the HiveServer2 server in real time.
Further, in the sequentially traversing the ordered list of available HiveServer2 servers:
aiming at the currently traversed HiveServer2 server which is not connected with the user request, collecting abnormal connection information, and changing the working state of the HiveServer2 server in the HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library set by a user, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuously traversing the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed to be temporarily abnormal fails through another independent single thread B, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list to be failed, and otherwise, changing the working state to be normal.
A system for implementing connection pools in a multi-hieveserver 2 server scenario, the system comprising:
the multi-HiveServer 2 server management module is used for constructing a HiveServer2 server state list, and HiveServer2 servers in the list correspond to the working states one by one;
the information interaction module is used for receiving a user request;
and the response module is used for executing load balancing distribution on the plurality of HiveServer2 servers and returning the connection or connection error information of the user request and the HiveServer2 server.
Further, the response module includes:
a failure detection unit, configured to detect whether each HiveServer2 server in the HiveServer2 server state list fails;
the usable HiveServer2 server list construction unit is used for constructing a usable HiveServer2 server list by using all the non-failed HiveServer2 servers detected by the fault detection unit;
an available HiveServer2 server information collecting unit, configured to collect, from the HiveServer2 server state list, a working state of each HiveServer2 server in the available HiveServer2 server list;
an available HiveServer2 server ordered list construction unit, configured to arrange priorities of all HiveServer2 servers in the available HiveServer2 server list according to the working state acquired by the available HiveServer2 server information acquisition unit, thereby constructing an available HiveServer2 server ordered list;
and traversing the HiveServer2 server unit, wherein the HiveServer2 server unit is used for sequentially traversing the available HiveServer2 server ordered list until the user request successfully establishes connection with a certain HiveServer2 server or the traversal is finished.
Further, the traversing the HiveServer2 server unit includes:
the connection abnormal information acquisition subunit is used for acquiring the connection abnormal information of the currently traversed HiveServer2 server which is not connected with the user request, and changing the working state of the HiveServer2 server in the HiveServer2 server state list into a temporary abnormal state;
the abnormal connection information judging subunit is used for judging whether the abnormal connection information is contained in an abnormal library set by a user, if so, the abnormal connection information is fed back to the user and is processed by the user; otherwise, continuously traversing the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed to be temporarily abnormal fails, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list to be a failure, and otherwise, changing the working state to be normal.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:
constructing a HiveServer2 server state list, wherein HiveServer2 servers in the list correspond to the working states one by one;
receiving a user request;
and performing load balancing distribution on the plurality of HiveServer2 servers, and returning connection or connection error information of the user request and the HiveServer2 server.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of:
constructing a HiveServer2 server state list, wherein HiveServer2 servers in the list correspond to the working states one by one;
receiving a user request;
and performing load balancing distribution on the plurality of HiveServer2 servers, and returning connection or connection error information of the user request and the HiveServer2 server.
Compared with the prior art, the invention has the following remarkable advantages: 1) the proposed load balancing distribution strategy solves the problem of load balancing of multiple HiveServer2 servers; 2) the proposed load balancing distribution strategy can distribute the user request task executed by the HiveServer2 server to other HiveServer2 servers when a certain HiveServer2 server fails, so that the user task is ensured to be timely and effectively executed, and the efficiency of executing the user task is improved; 3) the proposed load balancing distribution strategy is combined with an independent single thread A, so that the work of the repaired HiveServer2 server can be automatically recovered, and the resource of the HiveServer2 server is saved and fully utilized; 4) the proposed load balancing distribution strategy is easy to realize and can be realized through interface functions and classes, and the load balancing distribution strategy can be changed only by realizing the interface functions, so that the expandability of the load balancing distribution strategy is high.
The present invention is described in further detail below with reference to the attached drawing figures.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The method for realizing the connection pool in the multi-HiveServer 2 server scene can be applied to the application environment shown in FIG. 1, and can realize the management of files such as HDFS by the multi-HiveServer 2 server.
In one embodiment, in combination with fig. 2, there is provided a method for implementing a connection pool in a multi-hieveserver 2 server scenario, including the following steps:
s01, constructing a HiveServer2 server state list, wherein HiveServer2 servers in the list correspond to the working states one by one;
here, the order of the HiveServer2 servers in the HiveServer2 server status list is arbitrarily set without limitation. The operating status includes all information that the HiveServer2 server is operating.
Step S02, receiving a user request;
here, the request specifically refers to a user task connection request.
And step S03, performing load balancing distribution on the plurality of HiveServer2 servers, and returning the connection or connection error information of the user request and the HiveServer2 servers.
It should be noted that steps S01 to S03 may be executed in a sequential order, or may be executed simultaneously.
In the method for realizing the connection pool under the multi-HiveServer 2 server scene, a HiveServer2 server state list is firstly constructed, and HiveServer2 servers in the list correspond to the working states one by one; then receiving a user request; load balancing distribution is then performed on the multiple HiveServer2 servers, returning user requests for connections or connection error information with the HiveServer2 servers. Therefore, the connection pool under the scene of multiple HiveServer2 servers can be realized under the condition of not adopting virtual IP, and further, the management of files such as HDFS by multiple HiveServer2 servers is realized.
Further, in one embodiment, the operating status of the HiveServer2 server includes the number of times the HiveServer2 server executes the user request, the time consumed for executing the user request, whether the user request is currently being executed, whether the user request fails, and the like.
Here, the higher the priority when the HiveServer2 server performs a user request the less times, performs a user request the less time consuming, does not currently perform a user request, does not fail.
By adopting the scheme of the embodiment, the optimal HiveServer2 server can be selected to establish connection with the user request, and the efficiency and the effect of executing the user task request are improved.
Further, in one embodiment, in conjunction with fig. 3, the above-described performing load balancing distribution on multiple HiveServer2 servers includes the following processes:
detecting whether each HiveServer2 server in the HiveServer2 server state list fails or not, and constructing an available HiveServer2 server list by all HiveServer2 servers which do not fail;
for each HiveServer2 server in the available HiveServer2 server list, collecting the working state of the HiveServer2 server from the HiveServer2 server state list;
arranging the priorities of all HiveServer2 servers in the available HiveServer2 server list according to the collected working state, thereby constructing an available HiveServer2 server ordered list;
and sequentially traversing the ordered list of available HiveServer2 servers until the user requests to successfully establish connection with a certain HiveServer2 server or the traversal is finished.
By adopting the scheme of the embodiment, the problem of load balancing of the plurality of HiveServer2 servers can be solved, and the efficiency and the effect of the HiveServer2 server for executing the user task request are improved. The scheme of the embodiment is easy to implement, can be implemented through interface functions and classes, and the load balancing allocation strategy can be changed only by implementing the interface functions, so that the expandability of the load balancing allocation strategy is high.
Further, in one embodiment, with reference to fig. 3, the detecting whether each HiveServer2 server fails is specifically implemented by an independent single thread checkallserver thread, which detects whether each HiveServer2 server fails in real time during the operation of the method for implementing a connection pool in the multi-HiveServer 2 server scenario of the present invention, and updates the HiveServer2 server state list in real time.
By adopting the scheme of the embodiment, the working state of the HiveServer2 server can be detected in real time by combining a load balancing distribution strategy and an independent single-thread CheckAllServer thread, and the fault HiveServer2 server can automatically recover after being repaired, so that resources are saved and fully utilized, the sustainable reutilization property of the HiveServer2 server is improved, and the resource consumption and waste are reduced.
Further, in one embodiment, in conjunction with fig. 3, in traversing the ordered list of available HiveServer2 servers in turn, the above process:
aiming at the currently traversed HiveServer2 server which is not connected with the user request, collecting abnormal connection information, and changing the working state of the HiveServer2 server in the HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library set by a user, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuously traversing the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed to be temporarily abnormal fails through another independent single thread CheckAliveThread, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list to be failed, and otherwise, changing the working state to be normal.
By adopting the scheme of the embodiment, the connection abnormity introduced by the user side and the connection abnormity introduced by the fault of the HiveServer2 server can be better distinguished, so that the fault check of the HiveServer2 server when the connection abnormity is introduced by the user side is avoided, and the time and resource cost are saved. In addition, whether the HiveServer2 server breaks down is judged through multiple detection, the accuracy of the detection result is improved, the false detection rate is reduced, and when a certain HiveServer2 server breaks down, the user request task executed by the HiveServer2 server can be distributed to other HiveServer2 servers, so that the user request task can be timely and accurately executed.
In one embodiment, in conjunction with fig. 4, there is provided a system for implementing connection pools in a multi-hieveserver 2 server scenario, the system including:
the multi-HiveServer 2 server management module 101 is used for constructing a HiveServer2 server state list, and HiveServer2 servers in the list correspond to the working states thereof one by one;
the information interaction module 102 is used for receiving a user request;
and the response module 103 is used for performing load balancing distribution on the multiple HiveServer2 servers and returning connection or connection error information of the user request and the HiveServer2 server.
Further, in one embodiment, the operating status includes the number of times the HiveServer2 server executes the user request, the time it takes to execute the user request, whether the user request is currently being executed, whether it is failed, and the like.
Further, in one embodiment, the response module includes:
the system comprises a fault detection unit, a fault detection unit and a fault detection unit, wherein the fault detection unit is used for detecting whether each HiveServer2 server in a HiveServer2 server state list fails;
the usable HiveServer2 server list construction unit is used for constructing a usable HiveServer2 server list by using all the non-failed HiveServer2 servers detected by the fault detection unit;
the available HiveServer2 server information acquisition unit is used for acquiring the working state of each HiveServer2 server in the available HiveServer2 server list from the HiveServer2 server state list;
the usable HiveServer2 server ordered list construction unit is used for arranging the priorities of all the HiveServer2 servers in the usable HiveServer2 server list according to the working state acquired by the usable HiveServer2 server information acquisition unit, thereby constructing the usable HiveServer2 server ordered list;
and traversing the HiveServer2 server unit, wherein the HiveServer2 server unit is used for sequentially traversing the available HiveServer2 server ordered list until the user requests to successfully establish connection with a certain HiveServer2 server or the traversal is finished.
Further, in one embodiment, the traversing the HiveServer2 server unit includes:
the connection abnormal information acquisition subunit is used for acquiring the connection abnormal information of the currently traversed HiveServer2 server which is not connected with the user request, and changing the working state of the HiveServer2 server in the HiveServer2 server state list into temporary abnormality;
the abnormal connection information judging subunit is used for judging whether the abnormal connection information is contained in an abnormal library set by a user in a user-defined mode, if so, the abnormal connection information is fed back to the user and is processed by the user; otherwise, continuously traversing the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed to be temporarily abnormal fails, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list to be a failure, and otherwise, changing the working state to be normal.
For specific limitations of the system for implementing the connection pool in the multi-HiveServer 2 server scenario, reference may be made to the above limitations of the method for implementing the connection pool in the multi-HiveServer 2 server scenario, and details are not described here again. The modules in the system for implementing the connection pool in the multi-HiveServer 2 server scenario can be implemented in whole or in part by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:
constructing a HiveServer2 server state list, wherein HiveServer2 servers in the list correspond to the working states one by one;
receiving a user request;
and performing load balancing distribution on the plurality of HiveServer2 servers, and returning connection or connection error information of the user request and the HiveServer2 server.
Further, in one embodiment, the processor executes a computer program to implement load balancing distribution for multiple HiveServer2 servers, including the following processes:
detecting whether each HiveServer2 server in the HiveServer2 server state list fails or not, and constructing an available HiveServer2 server list by all HiveServer2 servers which do not fail;
for each HiveServer2 server in the available HiveServer2 server list, collecting the working state of the HiveServer2 server from the HiveServer2 server state list;
arranging the priorities of all HiveServer2 servers in the available HiveServer2 server list according to the collected working state, thereby constructing an available HiveServer2 server ordered list;
and sequentially traversing the ordered list of available HiveServer2 servers until the user requests to successfully establish connection with a certain HiveServer2 server or the traversal is finished.
Further, in one embodiment, the processor executes the computer program to detect whether each HiveServer2 server fails, specifically implemented by an independent single thread checkallserver thread, which detects whether each HiveServer2 server fails in real time during the operation of the method for implementing the connection pool in the multi-HiveServer 2 server scenario, and updates the HiveServer2 server state list in real time.
Further, in one embodiment, the processor executes the computer program to perform the steps of, in sequence, traversing the ordered list of available HiveServer2 servers:
aiming at the currently traversed HiveServer2 server which is not connected with the user request, collecting abnormal connection information, and changing the working state of the HiveServer2 server in the HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library set by a user, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuously traversing the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed to be temporarily abnormal fails through another independent single thread CheckAliveThread, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list to be failed, and otherwise, changing the working state to be normal.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of:
constructing a HiveServer2 server state list, wherein HiveServer2 servers in the list correspond to the working states one by one;
receiving a user request;
and performing load balancing distribution on the plurality of HiveServer2 servers, and returning connection or connection error information of the user request and the HiveServer2 server.
Further, in one embodiment, the computer program executed by the processor implements load balancing distribution for multiple HiveServer2 servers, comprising the processes of:
detecting whether each HiveServer2 server in the HiveServer2 server state list fails or not, and constructing an available HiveServer2 server list by all HiveServer2 servers which do not fail;
for each HiveServer2 server in the available HiveServer2 server list, collecting the working state of the HiveServer2 server from the HiveServer2 server state list;
arranging the priorities of all HiveServer2 servers in the available HiveServer2 server list according to the collected working state, thereby constructing an available HiveServer2 server ordered list;
and sequentially traversing the ordered list of available HiveServer2 servers until the user requests to successfully establish connection with a certain HiveServer2 server or the traversal is finished.
Further, in one embodiment, the implementation of the computer program executed by the processor to detect whether each HiveServer2 server fails is specifically implemented by an independent single thread checkallserver thread, which detects whether each HiveServer2 server fails in real time during the operation of the implementation method of the connection pool in the scenario of multiple hiveservers 2 servers, and updates the state list of the hiveservers 2 server in real time.
Further, in one embodiment, the computer program is executed by the processor to perform the process of traversing the ordered list of available HiveServer2 servers in turn:
aiming at the currently traversed HiveServer2 server which is not connected with the user request, collecting abnormal connection information, and changing the working state of the HiveServer2 server in the HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library set by a user, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuously traversing the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed to be temporarily abnormal fails through another independent single thread CheckAliveThread, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list to be failed, and otherwise, changing the working state to be normal.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.