Disclosure of Invention
The application 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, wherein the method, the system, the computer equipment and the storage medium can realize load balancing, fault detection, alarm, automatic recovery and the like of the multi-HiveServer 2 server.
The technical solution for realizing the purpose of the application is as follows: a method for implementing a connection pool in a multi-HiveServer 2 server scenario, the method comprising:
constructing a HiveServer2 server state list, wherein the HiveServer2 servers in the list correspond to the working states thereof one by one;
receiving a user request;
and executing load balancing distribution on the multi-HiveServer 2 server, and returning the connection information or the 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 the user request, the time consumed for executing the user request, whether the user request is currently being executed, and whether the user request fails.
Further, the load balancing allocation is executed on the multi-HiveServer 2 server, which comprises the following steps:
detecting whether each HiveServer2 server in the HiveServer2 server state list is faulty or not, and constructing an available HiveServer2 server list by all the HiveServer2 servers which are not faulty;
collecting the working state of the HiveServer2 server from the HiveServer2 server state list aiming at each HiveServer2 server in the available HiveServer2 server list;
arranging the priority 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 traversing the available HiveServer2 server ordered list in turn until the user request and a certain HiveServer2 server are successfully connected or the traversing is finished.
Further, the detecting whether each HiveServer2 server fails is specifically implemented by an independent single thread a, and the single thread a detects whether each HiveServer2 server fails in real time and updates the state list of the HiveServer2 server in real time in the running process of the implementation method of the connection pool under the scenario of the multi-HiveServer 2 servers.
Further, in the process of traversing the ordered list of available HiveServer2 servers in turn:
aiming at a HiveServer2 server which is currently traversed and is not connected with a user request, acquiring connection abnormality information, and changing the working state of the HiveServer2 server in a HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library which is set by a user in a self-defining way, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuing to traverse the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed into temporary abnormality is faulty through another independent single thread B, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, simultaneously sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list into the fault, and otherwise, changing the working state into normal.
A system for implementing a connection pool in a multi-HiveServer 2 server scenario, the system comprising:
the multi-HiveServer 2 server management module is used for constructing a HiveServer2 server state list, wherein the HiveServer2 servers in the list are in one-to-one correspondence with the working states of the HiveServer2 servers;
the information interaction module is used for receiving a user request;
and the response module is used for executing load balancing distribution on the multi-HiveServer 2 server and returning the connection or connection error information between the user request and the HiveServer2 server.
Further, the response module includes:
the fault detection unit is used for detecting whether each HiveServer2 server in the HiveServer2 server state list is faulty or not;
the available HiveServer2 server list construction unit is used for constructing an available HiveServer2 server list by utilizing all the HiveServer2 servers which are not failed and detected by the failure 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 available HiveServer2 server ordered list construction unit is used for arranging the 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 traversing HiveServer2 server unit is used for traversing the available HiveServer2 server ordered list in turn until the user request and a certain HiveServer2 server are successfully connected or the traversing is finished.
Further, the traversing HiveServer2 server unit includes:
the connection abnormality information acquisition subunit is used for acquiring connection abnormality information of the HiveServer2 server which is currently traversed and 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 connection abnormal information judging subunit is used for judging whether the connection abnormal information is contained in an abnormal library which is set by a user in a user-defined mode, if yes, the connection abnormal information is fed back to the user, and the user processes the connection abnormal information; otherwise, continuing to traverse the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed into temporary abnormality fails, if so, removing the HiveServer2 server from an available HiveServer2 server ordered list, simultaneously sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list into failure, otherwise, changing the working state into 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 the HiveServer2 servers in the list correspond to the working states thereof one by one;
receiving a user request;
and executing load balancing distribution on the multi-HiveServer 2 server, and returning connection or connection error information of the user request and the HiveServer2 server.
A computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
constructing a HiveServer2 server state list, wherein the HiveServer2 servers in the list correspond to the working states thereof one by one;
receiving a user request;
and executing load balancing distribution on the multi-HiveServer 2 server, and returning connection or connection error information of the user request and the HiveServer2 server.
Compared with the prior art, the application has the remarkable advantages that: 1) The proposed load balancing and distributing strategy solves the problem of load balancing of the multi-HiveServer 2 server; 2) The proposed load balancing allocation strategy can allocate the user request task executed by a HiveServer2 server to other HiveServer2 servers when a certain HiveServer2 server fails, so that the user task is ensured to be executed effectively in time, 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 fault HiveServer2 server can automatically recover to work after being repaired, and the resources of the HiveServer2 server are saved and fully utilized; 4) The load balancing distribution strategy is easy to realize, can be realized through interface functions and classes, can be changed only by realizing the interface functions, and has high expandability.
The application is described in further detail below with reference to the accompanying drawings.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The method for realizing the connection pool under the scene of the multi-HiveServer 2 server can be applied to the application environment shown in the figure 1, and can realize the management of the files such as HDFS by the multi-HiveServer 2 server.
In one embodiment, in conjunction with fig. 2, a method for implementing a connection pool in a multi-HiveServer 2 server scenario is provided, including the following steps:
step S01, a HiveServer2 server state list is constructed, wherein the HiveServer2 servers in the list correspond to the working states thereof one by one;
here, the order of the HiveServer2 servers in the HiveServer2 server state list is set at will, without limitation. The operational 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 S03, carrying out load balancing distribution on the multi-HiveServer 2 server, and returning connection or connection error information of the user request and the HiveServer2 server.
The steps S01 to S03 may be executed not only in the above order, but also simultaneously.
In the method for realizing the connection pool under the scene of the multi-HiveServer 2 server, a HiveServer2 server state list is firstly constructed, and the HiveServer2 servers in the list correspond to the working states thereof one by one; then receiving a user request; and then load balancing distribution is carried out on the multi-HiveServer 2 server, and connection or connection error information of the user request and the HiveServer2 server is returned. Therefore, the connection pool under the scene of the multi-HiveServer 2 server can be realized under the condition that virtual IP is not adopted, and further, the management of files such as HDFS and the like by the multi-HiveServer 2 server is realized.
Further, in one embodiment, the working state of the HiveServer2 includes the number of times the HiveServer2 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 so on.
Here, the higher the priority the HiveServer2 server performs the user request the fewer times, the less time it takes to perform the user request, the current user request is not performed, and no failure occurs.
By adopting the scheme of the embodiment, the optimal HiveServer2 server can be selected to be connected with the user request, and the efficiency and the effect of executing the user task request are improved.
Further, in one embodiment, in connection with fig. 3, the above-mentioned load balancing allocation is performed on the multi-HiveServer 2 server, which includes the following procedures:
detecting whether each HiveServer2 server in the HiveServer2 server status list is faulty or not, and constructing an available HiveServer2 server list by all the HiveServer2 servers which are not faulty;
collecting the working state of the HiveServer2 server from the HiveServer2 server state list aiming at each HiveServer2 server in the available HiveServer2 server list;
arranging the priority 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 traversing the available HiveServer2 server ordered list in turn until the user requests to successfully establish connection with a certain HiveServer2 server or the traversing is finished.
By adopting the scheme of the embodiment, the problem of load balancing of the HiveServer2 servers can be solved, and the efficiency and the effect of executing the user task request by the HiveServer2 servers are improved. The scheme of the embodiment is easy to realize, can be realized through the interface function and the class, and can change the load balance distribution strategy only by realizing the interface function, and the load balance distribution strategy has high expandability.
Further, in one embodiment, referring to fig. 3, the above-mentioned detection of whether each HiveServer2 server fails is specifically implemented by a single-thread checkallrerverthread, and the thread checkallrerverthread detects whether each HiveServer2 server fails in real time and updates the status list of the HiveServer2 server in real time during the running process of the implementing method of the connection pool under the scenario of multiple hiveservers 2 of the present application.
By adopting the scheme of the embodiment, the working state of the HiveServer2 server can be detected in real time by combining a load balance distribution strategy and an independent single-thread checkAllServerthread, and the fault HiveServer2 server can automatically recover after being repaired, so that resources are saved and fully utilized, the sustainable reusability of the HiveServer2 server is improved, and the resource consumption and waste are reduced.
Further, in one embodiment, in conjunction with FIG. 3, the above is in the process of traversing the ordered list of available HiveServer2 servers in turn:
aiming at a HiveServer2 server which is currently traversed and is not connected with a user request, acquiring connection abnormality information, and changing the working state of the HiveServer2 server in a HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library which is set by a user in a self-defining way, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuing to traverse the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed into temporary abnormality is in fault or not through another independent single-thread checkAlveThread, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, simultaneously sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list into fault, and otherwise, changing the working state into normal.
By adopting the scheme of the embodiment, the connection abnormality introduced by the user side and the connection abnormality introduced by the fault of the HiveServer2 server can be better distinguished, so that the fault detection of the HiveServer2 server when the connection abnormality is introduced by the user side is avoided, and the time and the resource cost are saved. In addition, whether the HiveServer2 server fails or not is judged through multiple detection, the accuracy of a detection result is improved, the false detection rate is reduced, and when a certain HiveServer2 server fails, user request tasks executed by the HiveServer2 server can be distributed to other HiveServer2 servers, so that the user request tasks are guaranteed to be executed timely and accurately.
In one embodiment, in connection with fig. 4, there is provided a system for implementing a connection pool in a multi-HiveServer 2 server scenario, where the system includes:
the multi-HiveServer 2 server management module 101 is configured to construct a HiveServer2 server status list, where the HiveServer2 servers in the list are in one-to-one correspondence with their working statuses;
an information interaction module 102, configured to receive a user request;
and the response module 103 is used for executing load balancing distribution on the multi-HiveServer 2 server and returning connection or connection error information of the user request and the HiveServer2 server.
Further, in one embodiment, the working states include the number of times the HiveServer2 server executes the user request, the time consumed to execute the user request, whether the user request is currently being executed, whether the user request is faulty, and so on.
Further, in one embodiment, the response module includes:
the fault detection unit is used for detecting whether each HiveServer2 server in the HiveServer2 server state list has a fault or not;
the available HiveServer2 server list construction unit is used for constructing an available HiveServer2 server list by utilizing all the HiveServer2 servers which are not failed and detected by the failure 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 available HiveServer2 server ordered list construction unit is used for arranging the priorities of all HiveServer2 servers in the available HiveServer2 server list according to the working states 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 traversing HiveServer2 server unit is used for traversing the available ordered list of HiveServer2 servers in turn until the user requests to successfully establish connection with a certain HiveServer2 server or the traversing is finished.
Further, in one embodiment, the traversing HiveServer2 server unit includes:
the connection abnormality information acquisition subunit is used for acquiring connection abnormality information of the HiveServer2 server which is currently traversed and 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 connection abnormal information judging subunit is used for judging whether the connection abnormal information is contained in an abnormal library which is set by a user in a self-defining way, if so, the connection abnormal information is fed back to the user and is processed by the user; otherwise, continuing to traverse the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed into the temporary abnormality fails, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, simultaneously sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list into the failure, otherwise, changing the working state into the normal state.
For specific limitation of the implementation system of the connection pool in the multi-HiveServer 2 server scenario, reference may be made to the limitation of the implementation method of the connection pool in the multi-HiveServer 2 server scenario hereinabove, and the description thereof is omitted herein. All or part of the modules in the system for realizing the connection pool under the multi-HiveServer 2 server scene can be realized by software, hardware and the combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above 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 steps of when executing the computer program:
constructing a HiveServer2 server state list, wherein the HiveServer2 servers in the list correspond to the working states thereof one by one;
receiving a user request;
and executing load balancing distribution on the multi-HiveServer 2 server, and returning connection or connection error information of the user request and the HiveServer2 server.
Further, in one embodiment, the execution of the computer program by the processor implements load balancing distribution to the multi-HiveServer 2 server, comprising the following processes:
detecting whether each HiveServer2 server in the HiveServer2 server status list is faulty or not, and constructing an available HiveServer2 server list by all the HiveServer2 servers which are not faulty;
collecting the working state of the HiveServer2 server from the HiveServer2 server state list aiming at each HiveServer2 server in the available HiveServer2 server list;
arranging the priority 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 traversing the available HiveServer2 server ordered list in turn until the user requests to successfully establish connection with a certain HiveServer2 server or the traversing is finished.
Further, in one embodiment, the processor executes a computer program to implement detecting whether each HiveServer2 server fails, specifically by implementing a single-thread checkallrerverthread, where the thread checkallrerverthread detects whether each HiveServer2 server fails in real time during the running of the implementation method of the connection pool in the scenario of multiple hiveservers 2 servers, and updates the HiveServer2 server status list in real time.
Further, in one embodiment, the processor executes the computer program to implement the process of traversing the ordered list of available HiveServer2 servers in sequence:
aiming at a HiveServer2 server which is currently traversed and is not connected with a user request, acquiring connection abnormality information, and changing the working state of the HiveServer2 server in a HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library which is set by a user in a self-defining way, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuing to traverse the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed into temporary abnormality is in fault or not through another independent single-thread checkAlveThread, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, simultaneously sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list into fault, and otherwise, changing the working state into 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 the HiveServer2 servers in the list correspond to the working states thereof one by one;
receiving a user request;
and executing load balancing distribution on the multi-HiveServer 2 server, and returning connection or connection error information of the user request and the HiveServer2 server.
Further, in one embodiment, the execution of the computer program by the processor implements load balancing distribution to the multi-HiveServer 2 server, including the following procedures:
detecting whether each HiveServer2 server in the HiveServer2 server status list is faulty or not, and constructing an available HiveServer2 server list by all the HiveServer2 servers which are not faulty;
collecting the working state of the HiveServer2 server from the HiveServer2 server state list aiming at each HiveServer2 server in the available HiveServer2 server list;
arranging the priority 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 traversing the available HiveServer2 server ordered list in turn until the user requests to successfully establish connection with a certain HiveServer2 server or the traversing is finished.
Further, in one embodiment, the computer program is executed by the processor to implement detecting whether each HiveServer2 server fails, specifically by implementing a single-thread CheckAllServerThread, where the thread CheckAllServerThread detects whether each HiveServer2 server fails in real time during the running of the implementation method of the connection pool in the scenario of multiple hiveservers 2 servers, and updates the HiveServer2 server status list 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 sequence:
aiming at a HiveServer2 server which is currently traversed and is not connected with a user request, acquiring connection abnormality information, and changing the working state of the HiveServer2 server in a HiveServer2 server state list into temporary abnormality;
judging whether the connection abnormal information is contained in an abnormal library which is set by a user in a self-defining way, if so, feeding the connection abnormal information back to the user, and processing the connection abnormal information by the user; otherwise, continuing to traverse the next HiveServer2 server, detecting whether the HiveServer2 server with the working state changed into temporary abnormality is in fault or not through another independent single-thread checkAlveThread, if so, removing the HiveServer2 server from the available HiveServer2 server ordered list, simultaneously sending alarm information, changing the working state of the HiveServer2 server in the HiveServer2 server state list into fault, and otherwise, changing the working state into normal.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile 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), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples illustrate only a few embodiments of the application, which are described in detail and are not to be construed as limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of protection of the present application is to be determined by the appended claims.