Background technology
Data screening algorithm is applied under the environment of multi-user, distributed and wide area networking, its data center is often at network tip, resource is large, interconnected bandwidth is low, also certain constraints policy is there is between resource and user, local user directly can manage local resource, and long-distance user then needs to link resource end by comprehensive utilization server.
Be different from the feature of general distributed system " decentralization ", data screening algorithm requires a management and control/arbitration role, has carried out the concentrated examination & approval to rule, to realize the screening to regular legitimacy.This just needs us to design a centralized management scheme.Distributed wide area networking is very unreliable, there is shortcomings such as interrupting, low, the packet loss of bandwidth, delay are large, if Distributed-solution design is unreasonable, in order to global coherency, just local availability may be sacrificed, even cause user to use obstacle on local resource, and local availability is preferentially the primary demand of user.
CAP (Consistency, Availability, Partition tolerance) law tells us: in a distributed system, and these the three kinds of guarantees of consistance, availability and subregion fault-tolerance cannot be met simultaneously.For distributed system, subregion fault-tolerance is basic demand, therefore design can only make balance between consistance and availability, Here it is has the reason of the design pattern such as CP system, AP system and BASE model system [i.e. substantially available (Basically Available), flexible consistent (Soft state) and finally consistent (Eventually consistent)].
In distributed system (here mainly refer to geographic distributed), Data Consistency mainly comes from many copies, namely there is multiple copy in system, the amendment of data can carry out usually on the different copies.In order to solve distributed in consistency problem, existing several typical algorithm mainly contains: Two-phase commitment algorithm, Lamport bakery algorithm, Paxos algorithm, Gossip algorithm and employing optimism lock principle realize the method for synchronization etc.Three sections of papers about " chubby locks service " of Google in 2006 are pointed out, other distributed algorithms all can regard the specify form of Paxos as.Given this, Paxos algorithm is only introduced below:
Paxos algorithm is distributed consensus algorithm by the problem solving a distributed system and how to reach an agreement with regard to certain value (resolution).A typical scene is, in a distributed data base system, if the original state of each node is consistent, each node performs the identical sequence of operation, and so they finally can obtain a consistent state.For ensureing that each node performs identical command sequence, need to perform one " consistency algorithm " in each instruction consistent with the instruction ensureing each node and see.Paxos algorithm is the consistency algorithm of a more efficient, with traditional distributed lock algorithm or not quite alike, such as RA algorithm, locking and de-locking on it and unit has a maximum common ground to be exactly the process of " request--wait for " clearly, and it is relatively independent between each example of Paxos algorithm, election process can parallel execution, and the example of rear generation is decided by vote before being the example that can first occur again, not significantly the sensation of " request--wait for ".When concrete application, distributed lock algorithm is more the sensation of " mutual exclusion ", and consistency algorithm is more the sensation of " synchronously ".Whole Paxos algorithm can be regarded as multiple intersection and performs and interactional Two-phase commitment algorithm, and this algorithm has following characteristics:
1,3 hypothesis of Effect-based operation transmission, namely do not have Byzantium general problem (Byzantinefailure); As long as wait time enough, message will be transferred to; And the Congressman on Paxos island is the resolution can not opposing that other Congressmen propose.
2, be less than half lost efficacy at nodal point number and still can work normally, node fails at any time can occur and not affect algorithm and normally perform; Before proposer proposes a motion, first want to communicate with the acceptors being enough to be formed majority, obtain the motion of the last time acceptance that they carry out.
3, whole algorithm is exactly carrying out round motion numbering substantially: proposer is busy with selecting larger numbering to submit proposal to, whether the numbering that acceptor then compares the proposal of submission has been maximum, as long as numbering determines, corresponding value also just determines.
4, a distributed problem is converted into a single-point problem, and the robustness of single-point ensures by election mechanism, its solution elects a proposer to make leader, and all proposal are submitted to by leader, elects other Leader when Leader delays machine more at once.
5, be bound to when proposer, acceptor, learner can not promise to undertake that others needs in Paxos algorithm occur, also cannot promise to undertake the time of approval resolution or pass-along message.
Paxos algorithm is widely used in distributed consensus, but towards our algorithm application demand, Paxos algorithm still exists following problem to be difficult to overcome:
1, the message in algorithm may occur to lose in transmission (storage forwarding) process, and Paxos algorithm requires that message all must reliably arrive.
2, algorithm requires under wide area network breaks down situation, and this resource user still can manage this resource apparatus, but Paxos algorithm cannot normally work under nodes is more than half failure conditions, also just cannot realize the management of this resource user to this resource apparatus.
3, algorithm needs regular center to examine rule, and Paxos algorithm has the feature of decentralization, complete equity between node, without any need for Centroid, so examination & approval function cannot be performed.
4, algorithm adopts centralized regular center to play the part of " grand justice " role, and Paxos algorithm uses random or timeout mechanism to realize election algorithm.
Summary of the invention
The invention provides a kind of distributed consensus implementation method of data screening algorithm, avoiding centralized fashion causes the disabled situation of the system overall situation to occur because the node at regular center is abnormal, guarantees again that rule that all establishments come into force is all through examining simultaneously.
Technical scheme of the present invention is as follows:
A distributed consensus implementation method for data screening algorithm, comprises the following steps:
Step one, subscription client by WebService by rule set R
ube sent to user agent, user agent is by R
uresolve to R
u={ M
1r
u, M
2r
u..., M
nr
u, wherein M represents means, M
ir
ufor meta-rule, user agent by database unique constraints respectively centralized and distributed on storage rule;
Step 2, using the resource of meta-rule and means classification as theme, distributed user agency by DDS middleware " publish/subscribe to " pattern by M
ir
ube delivered to corresponding resource broker service device; Meanwhile, meta-rule is also committed to regular center by DDS middleware by centralized user agent; If deliver unsuccessfully, asynchronously return mistake, successful synchronization state then continues flow process;
Step 3, regular center, by database unique constraints storage rule, build strictly all rules view, examine simultaneously to rule; The meta-rule warehouse-in that distributed resource agency will receive, and they are submitted to centralized resources and act on behalf of into library storage, all meta-rule is disposed to corresponding resource apparatus simultaneously;
Approval results is delivered to centralized resources agency by DDS middleware by step 4, regular center; If deliver unsuccessfully, asynchronously return mistake, successful synchronization state then continues flow process;
Step 5, centralized resources agency revises meta-rule state according to approval results, and revised rule state is submitted to distributed resource respectively acts on behalf of Sum fanction center; Distributed resource agent waits resource apparatus returns deployment message and centralized resources agency returns examination & approval message, if resource apparatus and centralized resources agency all return validation message, distributed resource agency acts on behalf of Feedback Rule to distributed user and comes into force; Otherwise as long as wherein any one returns Pending The Entry Into Force message for resource apparatus and centralized resources agency, distributed resource agency then acts on behalf of Feedback Rule Pending The Entry Into Force to distributed user;
Step 6, distributed resource agency acts on behalf of Feedback Rule respectively to distributed user agency and centralized resources and whether to come into force message; Meanwhile, centralized resources agency is to regular center feedback taking effect rules whether message, to come into force situation to centralized user agent's Feedback Rule again in regular center;
Step 7, distributed user agency is to centralized user agent's co-ordination principle consistance, and subscription client obtains the state of rule from distributed user agency, is mutually coordinated, reach the final consistency of rule state by Distribution and Centralization two kinds of frameworks.
Beneficial effect of the present invention:
1, the present invention is directed to the application scenarios of multi-user, distributed and wide area networking, analyze the application demand of data screening algorithm, have studied relevant distributed consensus algorithm, draw a conclusion that can substitute science solution with engineering solution, finally give a concrete Project Realization scheme.
2, in the environment integrated at many Autonomous Domains, the thought of inner inconsistency is not externally transmitted based on information, under the prerequisite substantially meeting user's needs, be " autonomous consistance " in territory by the consistency problem Mandatory Decomposition on multiple territory, and finally guarantee that two territories are at borderline " coordinative coherence ", a large problem space can be decomposed and defeats in detail like this.
3, adopt a kind of solution of " centralized+distributed " two trestle structure, two stacks run in wide area network aspect simultaneously, non-interference, end points is in harmonious proportion the inconsistent state of result on two stacks, achieve concentrate examination & approval function and local availability preferential.
4, examine as condition of grant with generation of auditing, support part available priority retrains.Audit needs people to participate in, long hang-up is unfavorable for that consistance is in harmonious proportion, after analysing in depth user's request, find examination & approval in advance completely can substitute by audit afterwards, and this alternative meeting makes the realization of local availability preference strategy more unsophisticated.
Embodiment
Below in conjunction with accompanying drawing, the invention will be described further.
In order to avoid centralized fashion because the node at regular center causes the disabled situation of the system overall situation to occur extremely, guarantee that rule that all establishments come into force is all through examining, and proposes a kind of centralized and distributed two trestle structures (see Fig. 1) combined herein again simultaneously.Wherein, thick dashed line represents the connection of distributed structure/architecture, and heavy line represents the connection of centralized architecture, and system adopts Message-Passing Model.
System is made up of user agent, regular center, Resource Broker and resource apparatus four layers, and wherein user agent and Resource Broker adopt centralized and the distributed and way to manage of depositing.In new algorithm, centralized user agent, regular center and centralized resources are acted on behalf of and are formed centralized architecture, and the interconnected formation distributed structure/architecture of equity of distributed user agency, distributed resource agency, centralized and distributed pair of stack parallel running, communication aspect does not interfere with each other.
When increasing rule, the Rule content of establishment sends to distributed user to act on behalf of by user, directly rule is issued to distributed resource and acts on behalf of, then rule is delivered to corresponding resource apparatus by it, and rule need not be examined and first be come into force temporarily in distributed structure/architecture; Rule is then sent to regular center by centralized user agent, is examined the rule received by regular center, and approval results is handed down to centralized resources agency, centralized receive message after this content to be issued in same level again distributed; Distributed resource agency revise according to the state of approval results to rule, and revised rule state is passed in the form of a message simultaneously distributed user agency, centralized resources agency and resource apparatus; Message is upwards passed to centralized user agent, same level distributed to centralized coordinative coherence by centralized resources agency step by step; User then knows taking effect rules whether specifying information from distributed user agency.
During deletion rule, distributed structure/architecture issues the Rule content of deletion step by step, then need not examine the rule of deleting in centralized architecture again, directly issue step by step, meanwhile, on user agent and Resource Broker layer, same level distributed to centralized coordinative coherence; User still knows the concrete condition of redundant rule elimination from distributed user Agency.
In algorithm, no matter be distributed or centralized architecture, when establishment or deletion rule, message is all transmit step by step from top to bottom, and taking effect rules or the message of whether deleting are then transmit step by step from lower to upper.
Whole algorithm framework designs based on following principle:
1. being functionally main in a distributed manner, effectiveness is in a centralized main
Distributed upper strictly all rules need not be examined and first come into force temporarily, waits for the approval results at regular center, if center examination & approval are not passed through, be Pending The Entry Into Force state, and reason feedback is to terminal user by this rule chosen that resource comes into force.Even if like this when regular center occurs abnormal, distributed structure/architecture is running as usual, system still normally can complete increase, the deletion work of rule, thus guarantees that system is not functionally subject to too large impact.
In new algorithm, centralized and distributed two cover solutions exist in wide area network aspect simultaneously, and both coordinating at two ends (resource end and user side), effectiveness is inconsistent simultaneously, and regular center is in a centralized main.
2. externally do not transmit the thought of inner inconsistency based on information, realize the reliable delivery step by step of message
2012, Poulin proposes a kind of thought that identity is not transmitted in SOA (Services Oriented Achitecture) and cloud, Given this thought, based on security and the managerial demand of system, in cascaded form network environment, tandem node encapsulates needing the message transmitted on the border of cascade, by the coherency management in cascade (point territory), ensure the consistance on border, two territories, thus under a large consistency problem is tied to little environment.
In this rule system, user applies networking and wide area internetwork message encapsulates on the two border and transmits, wide area network and resource group internetwork message also only encapsulate on the two border and transmit, user and resource networking then cannot carry out Message Transmission by border, so just the network environment of whole cascade is divided into two points of territories, the consistent performance on border, territory accesses guarantee, and message does not externally transmit inner inconsistency.
3. examine as condition of grant with generation of auditing, support part available priority strategy
According to original system requirement, the examination & approval function of executing rule is not only wanted at rule center, also want the audit that can realize rule, if audit and examination & approval function are separately formed two kinds of management modes, the local availability of system will be destroyed, in order to avoid this problem, this rule system was examined as condition of grant with generation of auditing, thus supported the local available priority strategy of system.
One, the implementation method of algorithm
1, by state machine migration pattern, the coherence request of implementation rule distributed deployment
The state that state machine describes has two kinds of large classes, logic when a class is task run.The second type is algorithm logic, and the characteristic of utilization state machine clear logic describes complicated algorithm.
This rule system adopts first kind state machine, is carried out the consistance of implementation rule distributed deployment by the migration of state machine.The state of this constitutional diagram normally task reaches in certain condition of wait, and namely task is in " waiting status ".Usual task itself is the engine directly promoting state machine running, and task itself checks that the event of state machine reaches situation and distributes.The transition of task status reach triggering by certain event, require that between task, synchronization mechanism has readjustment ability, to be pressed into event when condition is set up in state machine events queue.
User is by regular R
ube issued to user agent, user agent creates rule thereon and by R
uresolve to R
u={ M
1r
u, M
2r
u..., M
nr
u(wherein M represents means, M
ir
ufor atomic rule), user agent carrys out regulation rule state according to the atomic rule status message of regular center and Resource Broker feedback: when increasing rule, as long as there is an atomic rule M
ir
ucome into force by the upper regular R of user agent
ustate be adjusted to and come into force, and to the concrete condition of other Pending The Entry Into Force atomic rule of user's feedback; During deletion rule, only have all atomic rule M
ir
uall delete successfully, user agent is just by R regular on it
ustate be adjusted to deletion, for the atomic rule that part is not deleted, then adopt persistence deleting mechanism till it all deletes successfully.
This rule system adopts two cover state machine modes, as shown in Figure 2, wherein each level is expressed as its atomic rule state machine transition graph: distributed user Agent layer-DUL, centralized user agent layer-CUL, rule central core-RCL, distributed resource Agent layer-DPL; Centralized resources Agent layer-CPL, treatment facility layer-EL.Migration is defined as: trigger event E| state of operation (outgoing event E '); Trigger event defines: event generation level _ event-action; Except completing local operation, send message and need determine that the other side receives and stores, at this moment just the state of rule can be considered as steady state (SS).
The state machine migration flow process of atomic rule during to create rule, in distributed structure/architecture, after distributed user agency receives the rule creation U_create message that user sends, namely 1. create this atomic rule in a database, and this rule state is set to DUL_created (establishment); 2. export DUL_create message to act on behalf of to distributed resource, need to determine that DPL receives and stores, DUL_create message is sent to centralized user agent simultaneously.According to state transition definition, Fig. 2 represents aforesaid operations with " U_create|UP1 (DUL_create) ".After distributed resource agency receives DUL_create message, 1. create this atomic rule in a database, and this rule state is set to DPL_created; 2. DPL_create message is sent to CPL, is sent to EL simultaneously, need to determine that EL receives and stores.Be similar to distributed user agency, we represent aforesaid operations with " DUL_create|PP1 (DPL_create) ".After resource apparatus receives DPL_create message, create this atomic rule at resource apparatus, represent with " DPL_create|EP1 ".
In centralized architecture, 1. centralized user agent creates this atomic rule in a database, and this rule state is set to CUL_created after receiving the DUL_create message from distributed user agency; 2. CUL_create message is sent to regular center, needs to determine that RCL receives and stores.Aforesaid operations represents with " DUL_create|UCP1 (CUL_create) ".After rule center receives CUL_create message, 1. create this atomic rule in a database, and this rule state is set to RCL_created; 2. RCL_create message is sent to CPL, needs to determine that CPL receives and stores.Represent with " CUL_create|RCP1 (RCL_create) ".Centralized resources agency, after receiving RCL_create message, 1. creates this atomic rule in a database, and this rule state is set to CPL_created; 2. CPL_create is sent to the distributed of same layer.Represent with " RCL_create|PCP1 (CPL_create) " at this.
When creating rule, if break down in regular center, centralized resources agency can not receive RCL_create message, but can receive the DPL_create message from distributed resource agency; If wan communication occurs abnormal, distributed resource agency may can not receive DUL_create message, but does not affect the centralized resources receiving same layer and act on behalf of the CPL_create message sent.
To sum up, overlapped contrast and the correction of state machine by Distribution and Centralization two, this rule system achieve the concentrated examination & approval function that proposes in application demand and local availability preferential.
2, based on the publish/subscribe model of DDS, reliable communication under wide area network distributed environment is realized
In publish/subscribe model, publisher and subscriber are associated by theme, and both sides need not know the other side wherein, also need not be simultaneously online, achieve the multidimensional loose coupling of communicating pair time, space and data communication.
Existing Publish/Subscribe Middleware product is a lot, as Java messenger service (Javamessage service, JMS) specification solves the interconnect problem between each vendor product substantially, but this specification is used in distributed real time environment also exists a lot of problem: it adopts Java to realize, and have impact on the real-time of system; Do not propose QoS constraint in JMS, user according to self needing designated communication mode, can not limit the dirigibility of communication; In JMS, adopt fixing node server to preserve theme or queue, can not equally loaded or failed transfering node server, presence server bottleneck and potential safety hazard.
Data distributing (data distribution service, DDS) be that OMG is after release CORBA specification, specially for the latest specification that data publication in distributed real-time systems/subscribe model is promulgated, it is purely data-centered carries out Data dissemination, and by resource situation, all describe with qos parameter the expectation degree, network condition etc. of resource, greatly strengthen real-time and the dirigibility of communication.
3, based on the reconciliation mechanism of checkpoint, realize revising the consistance of rule state
Data screening algorithm need to ensure local data forever available, can not lose, once run into loss of data, the situation of memory disk array corrupted, above-mentioned requirements does not just ensure, this just requires that we must carry out reconciliation.
Reconciliation is acted on behalf of and Resource Broker centralized initiation reconciliation request to distributed user agency, centralized user agent, distributed resource by regular center, from this, obtain according to checkpoint point the rule state sequence that in certain hour, (time of not carrying out reconciliation before checkpoint point is interior to checkpoint point) has completed, then the rule state sequence at Sum fanction center is compared.When rule state sequence order occurs inconsistent, " establishment " state is as the criterion with user agent, and " coming into force ", " Pending The Entry Into Force " and " deletion " state are as the criterion with Resource Broker.