Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for updating configuration information, which can solve the problem of inconsistent global configuration for a long time.
In order to achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a method for updating configuration information, applied to an update server, including:
sending latest configuration information to each application server, and receiving preparation completion messages returned by all application servers;
and sending an update preparation instruction to each application server, and if receiving update waiting messages returned by all the application servers within the first timeout, sending a submission instruction to each application server.
Optionally, the method further comprises:
and if the updating waiting messages returned by all the application servers are not received within the first timeout, sending a canceling instruction to all the application servers.
In addition, according to another aspect of the embodiments of the present invention, there is provided a method for updating configuration information, applied to an application server, including:
storing the latest configuration information sent by the updating server into a local pre-updating buffer area, and returning a preparation completion message to the updating server;
receiving an update preparation instruction sent by the update server, starting a timeout monitoring thread to monitor whether a commit instruction or a cancel instruction sent by the update server is received within a second timeout period, suspending the thread for locally acquiring the latest configuration information, and returning a waiting update message to the update server.
Optionally, the method further comprises:
if a submission instruction sent by the update server is received within the second timeout period, updating the configuration to the latest configuration information in the local pre-update buffer area, activating a thread for locally acquiring the latest configuration information, destroying the timeout monitoring thread, and returning a submission completion message to the update server;
and if a cancel instruction sent by the update server is received within the second timeout period, activating a thread for locally acquiring the latest configuration information, destroying the timeout monitoring thread, and returning a cancel completion message to the update server.
Optionally, the method further comprises:
after the update waiting message is returned to the update server, if a commit instruction or a cancel instruction sent by the update server is not received within the second timeout period, the latest configuration information is inquired in the database, the configuration information in the local pre-update buffer area is updated, a thread for locally acquiring the latest configuration information is activated, and the timeout monitoring thread is destroyed.
In addition, according to another aspect of the embodiments of the present invention, there is provided an update apparatus of configuration information, provided in an update server, including:
the preparation module is used for sending the latest configuration information to each application server and receiving preparation completion messages returned by all the application servers;
and the updating module is used for sending an updating preparation instruction to each application server, and sending a submission instruction to each application server if receiving the updating waiting messages returned by all the application servers within the first timeout.
Optionally, the update module is further configured to:
and if the updating waiting messages returned by all the application servers are not received within the first timeout, sending a canceling instruction to all the application servers.
In addition, according to another aspect of the embodiments of the present invention, there is provided an apparatus for updating configuration information, provided in an application server, including:
the storage module is used for storing the latest configuration information sent by the updating server into a local pre-updating buffer area and returning a preparation completion message to the updating server;
and the monitoring module is used for receiving an update preparation instruction sent by the update server, starting a timeout monitoring thread to monitor whether a submission instruction or a cancellation instruction sent by the update server is received within a second timeout period, suspending the thread for locally acquiring the latest configuration information, and returning a waiting update message to the update server.
Optionally, the apparatus further comprises a submission module configured to:
if a submission instruction sent by the update server is received within the second timeout period, updating the configuration to the latest configuration information in the local pre-update buffer area, activating a thread for locally acquiring the latest configuration information, destroying the timeout monitoring thread, and returning a submission completion message to the update server;
and if a cancel instruction sent by the update server is received within the second timeout period, activating a thread for locally acquiring the latest configuration information, destroying the timeout monitoring thread, and returning a cancel completion message to the update server.
Optionally, the apparatus further comprises a query module configured to:
after the update waiting message is returned to the update server, if a commit instruction or a cancel instruction sent by the update server is not received within the second timeout period, the latest configuration information is inquired in the database, the configuration information in the local pre-update buffer area is updated, a thread for locally acquiring the latest configuration information is activated, and the timeout monitoring thread is destroyed.
In addition, according to another aspect of the embodiments of the present invention, there is provided a configuration information updating system, including the updating apparatus provided in the updating server according to any of the above embodiments and the updating apparatus provided in the application server according to any of the above embodiments.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any of the embodiments described above.
According to another aspect of the embodiments of the present invention, there is also provided a computer readable medium, on which a computer program is stored, which when executed by a processor implements the method of any of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: because of the technical means of combining the overtime mechanism, the pull mode and the push mode, the technical problem of inconsistent global configuration in a long time is solved; the invention combines the overtime mechanism, the pull mode and the push mode, ensures that the old configuration information is on all the application servers before a certain time point, and the latest configuration information is on all the application servers after the certain time point. Therefore, the configuration information updating method provided by the embodiment of the invention can synchronously update the configuration information of each application server in a distributed environment, thereby achieving the purpose of strong global consistency.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a configuration information updating method according to an embodiment of the present invention. As shown in fig. 1, as an embodiment of the present invention, applied to an update server, the method for updating configuration information may include:
step 101, sending the latest configuration information to each application server, and receiving preparation completion messages returned by all application servers.
In this step, when a certain configuration needs to be updated, the update server first searches all application servers under the configuration, and then distributes the latest configuration information corresponding to the configuration to these servers. Optionally, before distributing the configuration information, the method may further include: and carrying out accessibility test on all the application servers under the configuration, if any one application server is not reachable, failing the updating, and if all the application servers are reachable, distributing the latest configuration information to each application server by the updating server.
The application server returns a ready message to inform the updating server that the updating server is ready, and the updating server receives ready messages returned by all the application servers, which indicate that all the application servers are ready. It should be noted that, if the preparation completion messages returned by all the application servers are not received within the preset time, the update fails.
Step 102, sending an update preparation instruction to each application server, and if receiving update waiting messages returned by all application servers within a first timeout period, sending a commit instruction to each application server.
After receiving the preparation completion messages returned by all the application servers, the updating server sends a preparation updating instruction to each application server, and if the updating server receives the updating waiting messages returned by all the application servers within the first timeout period, the updating server sends a submission instruction to each application server so as to enable each application server to carry out configuration updating.
Optionally, if the update server receives the update waiting messages returned by all the application servers within the first timeout period, the latest configuration information is updated into the database, and then a commit instruction is sent to each application server.
However, if the update server does not receive the update waiting messages returned by all the application servers within the first timeout period, a cancel instruction is sent to all the application servers (or a cancel instruction may be sent only to the application server that has returned the update waiting message) so that each application server stops updating.
Fig. 2 is a schematic diagram of a main flow of an update method of configuration information according to still another referential embodiment of the present invention. As shown in fig. 2, as an embodiment of the present invention, applied to an application server, the method for updating configuration information may include:
step 201, storing the latest configuration information sent by the update server into a local pre-update buffer, and returning a preparation completion message to the update server.
And each application server receives the latest configuration information sent by the updating server, stores the latest configuration information into a respective local pre-updating buffer area, then creates a timeout monitoring thread and returns a preparation completion message to the updating server to inform the updating server that the updating server is ready. In this step, the timeout monitoring thread is not started. It should be noted that the timeout monitoring thread is configured to listen whether a commit instruction or a cancel instruction sent by the update server is received within a second timeout period.
Step 202, receiving an update preparation instruction sent by the update server, starting a timeout monitoring thread to monitor whether a commit instruction or a cancel instruction sent by the update server is received within a second timeout period, suspending the thread for locally obtaining the latest configuration information, and returning a message waiting for update to the update server.
After receiving an update preparation instruction sent by an update server, an application server starts a timeout monitoring thread to monitor whether a commit instruction or a cancel instruction sent by the update server is received within a second timeout period, then suspends all local threads acquiring latest configuration information, and finally returns an update waiting message to the update server to inform the update server that I is ready.
It should be noted that the second timeout period may be the same as or different from the first timeout period, and the embodiment of the present invention is not limited thereto.
Step 203, if a commit instruction sent by the update server is received within a second timeout period, updating the configuration to the latest configuration information in the local pre-update buffer, activating a thread for locally acquiring the latest configuration information, destroying the timeout monitoring thread, and returning a commit completion message to the update server; and if a cancel instruction sent by the update server is received within the second timeout period, activating a thread for locally acquiring the latest configuration information, destroying the timeout monitoring thread, and returning a cancel completion message to the update server.
And monitoring whether the application server receives a submission instruction or a cancellation instruction sent by the updating server within a second timeout through the timeout monitoring thread. If the application server receives a commit instruction sent by the update server within the second timeout period, the configuration is updated to the latest configuration information in the local pre-update buffer area, then a thread for locally acquiring the latest configuration information is activated, the overtime monitoring thread is destroyed, and finally a commit completion message is returned to the update server to inform me that the configuration update is completed. If the application server receives a cancel instruction sent by the update server within the second timeout period, the application server firstly activates a thread for locally acquiring the latest configuration information, destroys the timeout monitoring thread, and then returns a cancel completion message to the update server to inform me that the configuration update is stopped.
Further, after the message waiting for updating is returned to the updating server, if the submitting instruction or the canceling instruction sent by the updating server is not received within the second timeout period, the latest configuration information is inquired in the database, the configuration information in the local pre-updating buffer area is updated, the thread for locally acquiring the latest configuration information is activated, and the timeout monitoring thread is destroyed.
According to the various embodiments described above, it can be seen that the present invention adopts a technical scheme that combines a timeout mechanism, a pull mode and a push mode, thereby solving the problem of inconsistent global configuration for a long time. That is to say, in the prior art, configuration updating is mainly realized through a pull mode or a push mode, and both the two modes have the problem of global configuration inconsistency in a long time. The invention combines the timeout mechanism, the pull mode and the push mode to ensure that before a certain time point (T), all the application servers are used with the old configuration information (old), and after the certain time point (T), all the application servers are used with the latest configuration information (new), as shown in fig. 3. Smaller T indicates stronger global consistency. Therefore, the configuration information updating method provided by the embodiment of the invention can synchronously update the configuration information of each application server in a distributed environment, thereby achieving the purpose of strong global consistency.
Fig. 4 is a schematic diagram of a main flow of an update method of configuration information according to another referential embodiment of the present invention. As another embodiment of the present invention, the method for updating configuration information mainly includes: registering (Register), pushing (Touch), preparing (Begin), submitting (Commit), canceling (Cancel) and monitoring (Monitor). Wherein server represents an update server and client represents an application server, and each step is described in detail in turn.
Registration step (Register): firstly, an application server creates a configuration update monitoring service on a ZooKeeper to allow an update server to push information, and then registers a configuration node on the ZooKeeper. In particular, the application server may be registered in various configurations, for example, the application server 172.24.126.12 registered in cib _ bus: 22002 and other application servers, registration application server 172.24.126.12 under cib _ service: 22002 and other application servers, as shown in figure 5. It should be noted that, multiple application servers may be registered in each configuration, and the present invention only exemplifies one application server, and moreover, the same application server may be registered in different configurations, and the embodiment of the present invention is not limited thereto.
Push step (Touch): as shown in fig. 6, when a certain configuration (e.g., cib _ bus) needs to be updated, the update server first searches all application servers under the configuration (cib _ bus) on the ZooKeeper, and then performs reachability test on the application servers, and if any one of the application servers is not reachable, the update fails. If all the application servers are reachable, the update server distributes the latest configuration information to each application server. And finally, storing the latest configuration information received by each application server into a respective local pre-update buffer area, creating a timeout monitoring thread (but not starting), and returning a preparation completion message to the update server to inform the update server that the update server is ready.
Preparation step (Begin): as shown in fig. 7, after receiving the preparation completion messages returned by all the application servers, the update server sends a preparation update instruction to each application server. After receiving the instruction, each application server first starts a timeout monitoring thread (Monitor), then suspends all local threads which are acquiring the latest configuration information of the configuration, and finally returns a message waiting for updating to the updating server.
Commit step (Commit): as shown in fig. 8, if the update server receives the update waiting messages returned by all application servers within the first timeout period, the latest configuration information of the configuration is updated to the ZooKeeper first, and then a commit instruction is sent to each application server. After receiving the submission instruction, each application server updates the configuration to the latest configuration information in the pre-update buffer, activates all local threads which are acquiring the latest configuration information of the configuration, destroys the overtime monitoring thread (Monitor), and returns a submission completion message to the update server.
Cancellation step (Cancel): as shown in fig. 9, after the Begin step, if the update server does not receive all the messages waiting for update returned by the application server within the first timeout period, this step is triggered. Specifically, the update server sends a cancel instruction to the application server that has returned a wait for update message. After receiving the cancel instruction, each application server activates all local threads which are acquiring the latest configuration information of the configuration, destroys the overtime monitoring thread (Monitor), and finally returns a cancel completion message to the update server.
Monitoring step (Monitor): as shown in fig. 10, after the Begin step, the timeout monitoring thread monitors whether any instruction (commit instruction or cancel instruction) sent by the update server is not received within the second timeout period, and if so, this step is triggered. Specifically, the application server firstly queries the latest configuration information of the configuration on the ZooKeeper and updates the local configuration, then activates all threads which are acquiring the latest configuration information of the configuration locally, and destroys the timeout monitoring thread (Monitor).
It should be noted that, in another embodiment of the present invention, the details of the implementation of the method for updating configuration information are already described in detail in the above method for updating configuration information, and therefore, the repeated contents are not described again.
FIG. 11 is a schematic diagram of the main blocks of an update apparatus according to one embodiment of the present invention. As shown in fig. 11, theupdate apparatus 1100 provided in the update server includes apreparation module 1101 and anupdate module 1102. Thepreparation module 1101 sends the latest configuration information to each application server, and receives preparation completion messages returned by all the application servers; theupdate module 1102 sends an update preparation instruction to each application server, and sends a commit instruction to each application server if receiving update waiting messages returned by all application servers within a first timeout period.
Optionally, if the update waiting messages returned by all the application servers are not received within the first timeout period, theupdate module 1102 sends a cancellation instruction to all the application servers.
Fig. 12 is a schematic diagram of main blocks of an apparatus for updating configuration information according to another embodiment of the present invention. As shown in fig. 12, theupdate apparatus 1200 provided in the application server includes astorage module 1201 and alistening module 1202. Thestorage module 1201 stores the latest configuration information sent by the update server into a local pre-update buffer, and returns a preparation completion message to the update server; themonitoring module 1202 receives an update preparation instruction sent by the update server, starts a timeout monitoring thread, so as to monitor whether a commit instruction or a cancel instruction sent by the update server is received within a second timeout period, suspends the thread that locally obtains the latest configuration information, and returns a wait update message to the update server.
Optionally, the apparatus further includes a submittingmodule 1203, where if a submitting instruction sent by the update server is received within a second timeout period, the submittingmodule 1203 updates the configuration to the latest configuration information in the local pre-update buffer, activates a thread that locally obtains the latest configuration information, destroys the timeout monitoring thread, and returns a submit completion message to the update server; if a cancel instruction sent by the update server is received within the second timeout period, thesubmission module 1203 activates a thread for locally obtaining the latest configuration information, destroys the timeout monitoring thread, and returns a cancel completion message to the update server.
Optionally, the apparatus further includes an inquiry module, after returning the waiting update message to the update server, if the commit instruction or the cancel instruction sent by the update server is not received within the second timeout period, the inquiry module inquires the latest configuration information in the database, updates the configuration information in the local pre-update buffer, activates a thread that locally obtains the latest configuration information, and destroys the timeout monitoring thread.
According to the various embodiments described above, it can be seen that the present invention adopts a technical scheme that combines a timeout mechanism, a pull mode and a push mode, thereby solving the problem of inconsistent global configuration for a long time. That is to say, in the prior art, configuration updating is mainly realized through a pull mode or a push mode, and both the two modes have the problem of global configuration inconsistency in a long time. The invention combines the overtime mechanism, the pull mode and the push mode, and ensures that the old configuration information is on all the application servers before a certain time point, and the latest configuration information is on all the application servers after the certain time point. Therefore, the configuration information updating device provided by the embodiment of the invention can synchronously update the configuration information of each application server in a distributed environment, thereby achieving the purpose of strong global consistency.
It should be noted that, in the implementation of the updating apparatus of the present invention, the above-mentioned method for updating configuration information has been described in detail, and therefore, the repeated content herein is not described again.
Fig. 13 illustrates anexemplary system architecture 1300 to which the method for updating configuration information or the method for updating configuration information of an embodiment of the present invention may be applied.
As shown in fig. 13, thesystem architecture 1300 may includeterminal devices 1301, 1302, 1303, anetwork 1304, and aserver 1305. Thenetwork 1304 is used to provide a medium for communication links between theterminal devices 1301, 1302, 1303 and theserver 1305. Thenetwork 1304 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may useterminal devices 1301, 1302, 1303 to interact with aserver 1305 over anetwork 1304 to receive or send messages or the like. Various messaging client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (examples only) may be installed on theterminal devices 1301, 1302, 1303.
Terminal devices 1301, 1302, 1303 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
Theserver 1305 may be a server that provides various services, such as a background management server (for example only) that provides support for shopping websites browsed by users using theterminal devices 1301, 1302, 1303. The background management server may analyze and process the received data such as the product information query request, and feed back a processing result (for example, target push information and product information — only an example) to the terminal device.
It should be noted that the method for updating configuration information provided by the embodiment of the present invention is generally executed in theserver 1305, and accordingly, the apparatus for updating configuration information is generally disposed in theserver 1305.
It should be understood that the number of terminal devices, networks, and servers in fig. 13 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 14, shown is a block diagram of acomputer system 1400 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 14 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 14, thecomputer system 1400 includes a Central Processing Unit (CPU)1401, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)1402 or a program loaded from astorage portion 1408 into a Random Access Memory (RAM) 1403. In theRAM 1403, various programs and data necessary for the operation of thesystem 1400 are also stored. TheCPU 1401,ROM 1402, andRAM 1403 are connected to each other via abus 1404. An input/output (I/O)interface 1405 is also connected tobus 1404.
The following components are connected to the I/O interface 1405: aninput portion 1406 including a keyboard, a mouse, and the like; anoutput portion 1407 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker and the like; astorage portion 1408 including a hard disk and the like; and acommunication portion 1409 including a network interface card such as a LAN card, a modem, or the like. Thecommunication section 1409 performs communication processing via a network such as the internet. Thedriver 1410 is also connected to the I/O interface 1405 as necessary. A removable medium 1411 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on thedrive 1410 as necessary, so that a computer program read out therefrom is installed into thestorage section 1408 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via thecommunication portion 1409 and/or installed from theremovable medium 1411. The computer program performs the above-described functions defined in the system of the present invention when executed by a Central Processing Unit (CPU) 1401.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a preparation module, an update module, a storage module, and a listening module, where the names of the modules do not in some cases constitute a limitation on the modules themselves.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: sending latest configuration information to each application server, and receiving preparation completion messages returned by all application servers; and sending an update preparation instruction to each application server, and if receiving update waiting messages returned by all the application servers within the first timeout, sending a submission instruction to each application server.
According to the technical scheme of the embodiment of the invention, because of the technical means of combining the overtime mechanism, the pull mode and the push mode, the technical problem of inconsistent global configuration within a long time is solved; the invention combines the overtime mechanism, the pull mode and the push mode, ensures that the old configuration information is on all the application servers before a certain time point, and the latest configuration information is on all the application servers after the certain time point. Therefore, the configuration information updating method provided by the embodiment of the invention can synchronously update the configuration information of each application server in a distributed environment, thereby achieving the purpose of strong global consistency.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.