A kind of node alteration notification method and device
Technical field
The application is related to field of computer technology, more particularly to a kind of node alteration notification method and device.
Background technology
In a distributed system, multiple application systems can be by the shared money of computer network access identical
Source.In order that each application system can correctly and efficiently be run, it is necessary to which the multiple application systems of control are to same
The concurrently access of one shared resource, resource data is destroyed to prevent interfering with each other between different application systems
Uniformity.
In order to control concurrently access of multiple application systems to same shared resource, it is possible to use Distributed Application
The distributed lock service that Program Coordination service (namely ZooKeeper) is provided.Flow is implemented mainly to wrap
Include:Client is that the client creates shared resource to be visited under one's name to ZooKeeper server requests
After transient node, whether the transient node for judging the client is that shared resource to be visited under one's name all face
The minimum transient node of Shi Jiedian interior joints sequence number, if, then it is assumed that client gets distributed lock, can
To carry out resource access, otherwise, into wait state, and changed to ZooKeeper server registrations node
Event;When node altering event arrives, then judge whether the transient node of oneself is that current correspondence is treated
The minimum transient node of the sequence number of the shared resource of access.
In superincumbent flow, node altering event not only include obtain distributed lock client release lock,
Delete corresponding transient node, including other also do not obtain the client of distributed lock due to ZooKeeper
Server is disconnected and causes correspondence transient node passively to delete, and this results in client and can receive for no reason very
Many node altering events, so as to can perform judge whether to obtain distributed lock every time, increased much not
Necessary overhead.In this way, under large-scale cluster environment, it will cause very big shadow to systematic function
Ring.
The content of the invention
The embodiment of the present application provides a kind of node alteration notification method and device, is used to solve existing distribution
Node change mode in system increased many unnecessary overheads, cause very big to systematic function
The problem of influence.
The embodiment of the present application provides a kind of node alteration notification method, including:
Client in distributed system sends interim section when needing to access shared resource to coordination service device
Point request to create, is the shared resources to be obtained such as the client establishment for asking coordination service device
The transient node of distributed lock;
Multiple transient nodes of the client according to the distributed lock of the shared resource to be obtained such as current
Nodal information, judge whether the transient node of the client meets the condition for obtaining the distributed lock;
If it is not, then sending the note of the node altering event for previous transient node to the coordination service device
Volume request, for asking coordination service device to notify the client after the previous transient node is deleted
End;Wherein, the previous transient node is the multiple in the distributed lock for waiting the shared resource to be obtained
In transient node, last of the distributed lock can be obtained before the transient node of the client
Transient node.
Alternatively, the condition for meeting the acquisition distributed lock is specifically included:
The shared resource to be obtained such as current distributed lock multiple transient node interior joint sequence numbers most
It is small.
Alternatively, the client is it is determined that the transient node of the client meets obtains the distributed lock
Condition after, including:
The client accesses the shared resource using the distributed lock for obtaining, and after the completion of access,
The transient node of the client is deleted to coordination service device request.
Alternatively, the client is faced according to the multiple of the distributed lock of the shared resource to be obtained such as current
The nodal information of Shi Jiedian, judges whether the transient node of the client meets and obtains the distributed lock
Condition, including:
The client obtains the node of the multiple transient nodes under the corresponding lock catalogue of the shared resource
Information;
The client is based on the nodal information of the multiple transient nodes under the lock catalogue for obtaining, and judges institute
Whether the transient node for stating client meets the condition for obtaining the distributed lock.
Alternatively, the client is faced according to the multiple of the distributed lock of the shared resource to be obtained such as current
The nodal information of Shi Jiedian, judges whether the transient node of the client meets and obtains the distributed lock
Condition, including:
The transient node created for the client that the client receives that the coordination service device sends
Nodal information, and other etc. the transient node of the distributed lock of the shared resource to be obtained node letter
Breath;
The client is based on the node letter of the transient node of the client that the coordination service device sends
Breath, and it is described other etc. the transient node of the distributed lock of the shared resource to be obtained nodal information,
Judge whether the transient node of the client meets the condition for obtaining the distributed lock.
Alternatively, the client sends the node change for previous transient node to the coordination service device
After the registration request of more event, also include:
After node altering event is received, return judges that the transient node of the client is worked as to the client
Before the step of can obtain the distributed lock.
Another embodiment of the application provides a kind of node alteration notification method, including:
Coordination service device in distributed system receives client when request shared resource is needed, and transmission is faced
Shi Jiedian requests to create;
The coordination service device is the distributed lock of the shared resources to be obtained such as the client establishment
Transient node;
The coordination service device receives the node change for previous transient node that the client sends
The registration request of event, the registration request is used to ask coordination service device to be deleted in the previous transient node
The client is notified after removing;Wherein, the previous transient node is to wait the shared resource to be obtained
Distributed lock multiple transient nodes in, described point can be obtained before the transient node of the client
Last transient node of cloth lock;
The coordination service device sends after it is determined that the previous transient node is deleted to the client
Node altering event, is used to indicate previous transient node described in the client to be deleted.
Alternatively, the coordination service device is the distribution of the shared resources to be obtained such as the client establishment
After the transient node of formula lock, also include:
The nodal information of the transient node that the coordination service device will be created for the client is added described
Under the corresponding lock catalogue of shared resource.
Alternatively, the coordination service device is the distribution of the shared resources to be obtained such as the client establishment
After the transient node of formula lock, also include:
The nodal information of the transient node that the coordination service device will be created for the client, and other etc.
The nodal information of the transient node of the distributed lock of the shared resource to be obtained is sent to the client.
The embodiment of the present application provides a kind of node Notification of Changes device, including:
First sending module, for when client needs to access shared resource, being sent to coordination service device and being faced
Shi Jiedian requests to create, are the shared resources to be obtained such as client establishment for asking coordination service device
The transient node of distributed lock;
Judge module, for the interim section of multiple of the distributed lock according to the shared resource to be obtained such as current
The nodal information of point, judges whether the transient node of the client meets the bar for obtaining the distributed lock
Part;
Second sending module, for it is determined that the transient node of the client is unsatisfactory for obtaining the distribution
After the condition of lock, the note of the node altering event for previous transient node is sent to the coordination service device
Volume request, for asking coordination service device to notify the client after the previous transient node is deleted
End;Wherein, the previous transient node is the multiple in the distributed lock for waiting the shared resource to be obtained
In transient node, last of the distributed lock can be obtained before the transient node of the client
Transient node.
Another embodiment of the application provides a kind of node Notification of Changes device, including:
First receiver module, for receive client need request shared resource when, the transient node of transmission
Request to create;
Creation module, for facing for the distributed lock for shared resources to be obtained such as client establishments
Shi Jiedian;
Second receiver module, becomes for receiving the node for previous transient node that the client sends
The registration request of more event, the registration request is used to ask coordination service device in the previous transient node quilt
The client is notified after deletion;Wherein, the previous transient node is to wait the shared money to be obtained
In multiple transient nodes of the distributed lock in source, can obtain described before the transient node of the client
Last transient node of distributed lock;
Sending module, for after it is determined that the previous transient node is deleted, being sent to the client
Node altering event, is used to indicate previous transient node described in the client to be deleted.
In the embodiment of the present application, client in distributed system when needing to access shared resource, to coordination
Server sends transient node request to create;Distributed lock according to the shared resource to be obtained such as current
The nodal information of multiple transient nodes, judges whether the transient node of the client meets the acquisition distribution
The condition of formula lock;If it is not, then sending the node altering event for previous transient node to coordination service device
Registration request, for ask coordination service device the previous transient node be deleted after notify the visitor
Family end.Using the embodiment of the present application, client only after previous transient node is deleted, can just be received
To node altering event, and do not interfere with client and obtain distributed lock in time, this way it is possible to avoid receiving
To many unnecessary node altering events, such that it is able to save overhead, there is provided systematic function.
Brief description of the drawings
Fig. 1 is the node alteration notification method flow chart that the embodiment of the present application one is provided;
Fig. 2 is the node alteration notification method flow chart that the embodiment of the present application two is provided;
Fig. 3 is the node Notification of Changes apparatus structure schematic diagram that the embodiment of the present application three is provided;
Fig. 4 is the node Notification of Changes apparatus structure schematic diagram that the embodiment of the present application four is provided.
Specific embodiment
In the embodiment of the present application, client in distributed system when needing to access shared resource, to coordination
Server sends transient node request to create;Distributed lock according to the shared resource to be obtained such as current
The nodal information of multiple transient nodes, judges whether the transient node of the client meets the acquisition distribution
The condition of formula lock;If it is not, then sending the node altering event for previous transient node to coordination service device
Registration request, for ask coordination service device the previous transient node be deleted after notify the visitor
Family end.Using the embodiment of the present application, client only after previous transient node is deleted, can just be received
To node altering event, and do not interfere with client and obtain distributed lock in time, this way it is possible to avoid receiving
To many unnecessary node altering events, such that it is able to save overhead, there is provided systematic function.
The embodiment of the present application is described in further detail with reference to Figure of description.
Embodiment one
As shown in figure 1, be the node alteration notification method flow chart of the offer of the embodiment of the present application one, including with
Lower step:
S101:Client in distributed system sends when needing to access shared resource to coordination service device
Transient node request to create, it is to be obtained described shared for client establishment etc. for asking coordination service device
The transient node of distribution of resource formula lock.
In the step, when client needs to access shared resource, first to coordination service device such as ZooKeeper
Server sends transient node request to create, wherein the information of the shared resource for needing request can be included, with
Just ZooKeeper servers are that it creates corresponding shared resource transient node under one's name.The transient node is used for
The distributed locks to be obtained such as sequence, so that corresponding client possesses the authority for accessing shared resource.
S102:Multiple transient nodes of the client according to the distributed lock of the shared resource to be obtained such as current
Nodal information, judge whether the transient node of the client meets the condition for obtaining the distributed lock,
If meeting, into S103, otherwise, into S104.
In specific implementation, the distributed lock of the shared resource to be obtained such as client is obtained first it is all
The nodal information of transient node, wherein can be faced according to these including node ID or nodal value count etc.
The nodal information of Shi Jiedian judges that can the transient node of client currently obtain distributed lock.In specific implementation
In, coordination service device can be followed successively by each interim section for successively creating according to the ascending order of node ID
Point distribution node sequence number, in this case, according to the principle that first obtains first is created, client may determine that
Whether the transient node of oneself is the node of wherein node ID minimum, if so, then confirming to get to need
The distributed lock of the shared resource to be accessed.That is, when the transient node of client is current etc. to be obtained
During the node of multiple transient node interior joint sequence numbers minimum of the distributed lock of the shared resource, it is considered as satisfaction
Obtain the condition of the distributed lock.Correspondingly, if coordination service device is according to descending suitable of node ID
Sequence is followed successively by each transient node distribution node sequence number for successively creating, and in this case, client then needs
Judge whether the transient node of oneself is the node of wherein node ID maximum, if so, then confirming to obtain
To the distributed lock of the shared resource for needing to access.
S103:Client accesses the shared resource using the distributed lock for obtaining, and after the completion of access,
The transient node of the client is deleted to coordination service device request.
Here, client is to wait for obtaining the distributed lock of the shared resource confirming the transient node of oneself
All transient nodes in, after the minimum node of node ID, use the distributed lock for obtaining to access shared money
Source, and after the completion of access, release profile formula lock, namely indicate to delete the client to the coordination service device
The transient node at end.
S104:Client sends the node altering event for previous transient node to the coordination service device
Registration request, for ask coordination service device the previous transient node be deleted after notify the visitor
Family end;Wherein, the previous transient node is to wait many of the distributed lock of the shared resource to be obtained
In individual transient node, last of the distributed lock can be obtained before the transient node of the client
Individual transient node.
Here, client only to the previous transient node of ZooKeeper server registrations node altering event,
Only when previous transient node is deleted, client just can be notified, is then back to S103 execution
Step is judged, because only that after previous transient node is deleted, the client can just have an opportunity to get
Distributed lock.This way it is possible to avoid receive many unnecessary node altering events, can the system of saving open
Pin.Here previous transient node is that distributed lock can be obtained before the transient node of the client
Last transient node, if the order than coordination service device according to node ID from small to large, is followed successively by
Each transient node distribution node sequence number for creating, then the previous transient node is node ID than the client
Transient node node ID small 1 node;For another example, if coordination service device according to node ID from big
To small order, each transient node distribution node sequence number of establishment is followed successively by, then the previous transient node is
The node of node ID bigger than the node ID of the transient node of the client 1.
The thought of the embodiment of the present application is described further below by a specific embodiment.
Embodiment two
As shown in Fig. 2 be the node alteration notification method flow chart of the offer of the embodiment of the present application two, including with
Lower step:
S201:Client in distributed system sends when needing to access shared resource to coordination service device
Transient node request to create, it is to be obtained described shared for client establishment etc. for asking coordination service device
The transient node of distribution of resource formula lock.
S202:Coordination service device is the distributed lock of the shared resources to be obtained such as the client establishment
Transient node.
Here, coordination service device, can be by the transient node after transient node is created for the client
Nodal information is added under the lock catalogue (/lock) of corresponding shared resource.
S203:Client judges all transient nodes in the distributed lock for waiting the shared resource to be obtained
In, whether the transient node of the client is the wherein minimum node of node ID, if so, then entering
S204, otherwise, into S205.
Here, client can be after transient node request to create be sent, based on precognition to coordination service device
Access path, actively accesses multiple of the coordination service device storage under the corresponding lock catalogue of the shared resource and faces
The nodal information of Shi Jiedian;That is, client obtains the multiple under the corresponding lock catalogue of the shared resource
The nodal information of transient node;Based on the nodal information of the multiple transient nodes under the lock catalogue for obtaining, sentence
Whether the transient node of the client of breaking meets the condition for obtaining the distributed lock, in this embodiment,
Namely judge whether the transient node of the client is minimum the multiple transient node interior joint sequence number
Node;If, it is determined that the transient node of the client can obtain the distributed lock, otherwise, it determines
The transient node of the client can not obtain the distributed lock.
Or, client to coordination service device send transient node request to create after, coordination service device for
After the client creates transient node, can directly by the transient node created for the client and the client
The nodal information of the shared resource for accessing other transient nodes under one's name is asked to send jointly to the client.
That is, after transient node request to create is sent, that receive the coordination service device transmission is the visitor to client
Family end create transient node nodal information, and other etc. the shared resource to be obtained distributed lock
Transient node nodal information;The node of the transient node of the client sent based on coordination service device
Information, and it is described other etc. the transient node of the distributed lock of the shared resource to be obtained node letter
Breath, judge whether the transient node of the client meets the condition for obtaining the distributed lock, here namely
Judge the multiple of the distributed lock whether transient node of the client is to wait for obtaining the shared resource
The minimum node of transient node interior joint sequence number;If, it is determined that the transient node of the client can be obtained
The distributed lock, otherwise, it determines the transient node of the client can not obtain the distributed lock.
S204:Client accesses the shared resource using the distributed lock for obtaining, and after the completion of access,
The transient node of the client is deleted to coordination service device request.
Here, client can send to ZooKeeper servers and delete interim after resource access is completed
The order of node discharges the distributed lock of acquisition, so that other clients are used.
S205:Client sends the node altering event for previous transient node to the coordination service device
Registration request, for ask coordination service device the previous transient node be deleted after notify the visitor
Family end, the previous transient node is all interim section in the distributed lock for waiting the shared resource to be obtained
In point, the node of node ID smaller than the node ID of the transient node of the client 1.
In the step, client is not the minimum transient node of present node sequence number in the transient node of oneself
When, into wait, and previous transient node is registered to coordination service device (ZooKeeper servers)
Node altering event, namely indicate ZooKeeper servers to notify to be somebody's turn to do after previous transient node is deleted
Client.
Such as, the node ID of the transient node of client is n, and client is noted to ZooKeeper servers
Volume node ID for n-1 transient node node altering event, now, though other transient nodes whether
Have altered, client would only receive the altering event of node n-1.
S206:Coordination service device is sent out after it is determined that the previous transient node is deleted to the client
Node altering event is sent, is used to indicate previous transient node described in the client to be deleted.
Here node altering event can include that previous transient node completes release profile after resource is accessed
The event of formula lock (namely deleting the previous transient node), it is also possible to including previous transient node and institute
State the event being deleted after coordination service device is disconnected.
S207:Client returns to S203 after node altering event is received.
A kind of and node alteration notification method pair is additionally provided based on same inventive concept, in the embodiment of the present application
The node Notification of Changes device answered, because principle and the embodiment of the present application node of the device solve problem are changed
Notification Method is similar, therefore the implementation of the device may refer to the implementation of method, repeats part and repeats no more.
Embodiment three
As shown in figure 3, being the node Notification of Changes apparatus structure schematic diagram of the offer of the embodiment of the present application three, bag
Include:
First sending module 31, for when client needs to access shared resource, being sent to coordination service device
Transient node request to create, is the shared resources to be obtained such as client establishment for asking coordination service device
Distributed lock transient node;
Judge module 32, the multiple for the distributed lock according to the shared resource to be obtained such as current is interim
The nodal information of node, judges whether the transient node of the client meets the bar for obtaining the distributed lock
Part;
Second sending module 33, for it is determined that the transient node of the client is unsatisfactory for obtaining the distribution
After the condition of formula lock, the node altering event for previous transient node is sent to the coordination service device
Registration request, for asking coordination service device to notify the client after the previous transient node is deleted
End;Wherein, the previous transient node is the multiple in the distributed lock for waiting the shared resource to be obtained
In transient node, last of the distributed lock can be obtained before the transient node of the client
Transient node.
Alternatively, the condition for meeting the acquisition distributed lock is specifically included:
The shared resource to be obtained such as current distributed lock multiple transient node interior joint sequence numbers most
It is small.
Alternatively, described device also includes:
Access modules 34, the transient node satisfaction for determining the client in the judge module 32 is obtained
After taking the condition of the distributed lock, using the distributed lock for obtaining, the shared resource is accessed, and
After the completion of access, the transient node of the client is deleted to coordination service device request.
Alternatively, the judge module 32 specifically for:
Obtain the nodal information of the multiple transient nodes under the corresponding lock catalogue of the shared resource;Based on obtaining
The nodal information of the multiple transient nodes under the lock catalogue for taking, judging the transient node of the client is
It is no to meet the condition for obtaining the distributed lock.
Alternatively, the judge module 32 specifically for:
The nodal information of the transient node created for the client for receiving that the coordination service device sends, with
And other wait the nodal information of the transient node of the distributed lock for obtaining the shared resource;Based on the association
Adjust server send the client transient node nodal information, and it is described other etc. institute to be obtained
The nodal information of the transient node of the distributed lock of shared resource is stated, judging the transient node of the client is
It is no to meet the condition for obtaining the distributed lock.
Alternatively, the judge module 32 is additionally operable to, in the second sending module 33 to the coordination service device
Send and be directed to after the registration request of the node altering event of previous transient node, if receiving node change
Event, then return judges the step of can the transient node of the client currently obtain the distributed lock.
Example IV
As shown in figure 4, being the node Notification of Changes apparatus structure schematic diagram of the offer of the embodiment of the present application four, bag
Include:
First receiver module 41, for receive client need request shared resource when, the interim section of transmission
Point request to create;
Creation module 42, for the distributed lock for shared resources to be obtained such as client establishments
Transient node;
Second receiver module 43, for receiving the node for previous transient node that the client sends
The registration request of altering event, the registration request is used to ask coordination service device in the previous transient node
The client is notified after being deleted;Wherein, the previous transient node is to wait to be obtained described shared
In multiple transient nodes of distribution of resource formula lock, institute can be obtained before the transient node of the client
State last transient node of distributed lock;
Sending module 44, for after it is determined that the previous transient node is deleted, being sent out to the client
Node altering event is sent, is used to indicate previous transient node described in the client to be deleted.
Alternatively, the sending module 44 is additionally operable to:
The nodal information that the creation module 42 is the transient node that the client is created is added described
Under the corresponding lock catalogue of shared resource.
Alternatively, the sending module 44 is additionally operable to:
By the nodal information that the creation module 42 is the transient node that the client is created, and other
Nodal information etc. the transient node of the distributed lock of the shared resource to be obtained is sent to the client.
It should be understood by those skilled in the art that, embodiments herein can be provided as method, system or meter
Calculation machine program product.Therefore, the application can be using complete hardware embodiment, complete software embodiment or knot
Close the form of the embodiment in terms of software and hardware.And, the application can be used and wherein wrapped at one or more
Containing computer usable program code computer-usable storage medium (including but not limited to magnetic disk storage,
CD-ROM, optical memory etc.) on implement computer program product form.
The application is produced with reference to the method according to the embodiment of the present application, device (system) and computer program
The flow chart and/or block diagram of product is described.It should be understood that can by computer program instructions realize flow chart and
/ or block diagram in each flow and/or the flow in square frame and flow chart and/or block diagram and/
Or the combination of square frame.These computer program instructions to all-purpose computer, special-purpose computer, insertion can be provided
The processor of formula processor or other programmable data processing devices is producing a machine so that by calculating
The instruction of the computing device of machine or other programmable data processing devices is produced for realizing in flow chart one
The device of the function of being specified in individual flow or multiple one square frame of flow and/or block diagram or multiple square frames.
These computer program instructions may be alternatively stored in can guide computer or the treatment of other programmable datas to set
In the standby computer-readable memory for working in a specific way so that storage is in the computer-readable memory
Instruction produce include the manufacture of command device, the command device realization in one flow of flow chart or multiple
The function of being specified in one square frame of flow and/or block diagram or multiple square frames.
These computer program instructions can be also loaded into computer or other programmable data processing devices, made
Obtain and series of operation steps is performed on computer or other programmable devices to produce computer implemented place
Reason, so as to the instruction performed on computer or other programmable devices is provided for realizing in flow chart one
The step of function of being specified in flow or multiple one square frame of flow and/or block diagram or multiple square frames.
Although having been described for the preferred embodiment of the application, those skilled in the art once know base
This creative concept, then can make other change and modification to these embodiments.So, appended right will
Ask and be intended to be construed to include preferred embodiment and fall into having altered and changing for the application scope.
Obviously, those skilled in the art can carry out various changes and modification without deviating from this Shen to the application
Spirit and scope please.So, if the application these modification and modification belong to the application claim and
Within the scope of its equivalent technologies, then the application is also intended to comprising these changes and modification.