A kind of real-time data base ordering system and method
Technical field
The present invention relates to a kind of data processing technique, especially relate to a kind of efficiency is high, cost is low real-time data base ordering system and method.
Background technology
In traditional real-time dataBase system, the many employings of item data of client-requested are directly inquired about or overall subscription, oneself are preserved the mode of whole subscription information by service.Direct search efficiency is low, and does not support change is sent, waste network traffics; Overall subscription is the method that current most of real-time data base adopts; although support change is sent; but time subscription information amount is larger; be difficult to safeguard subscription information; and when subscription service exception or after restarting; client need be subscribed to again; lose time; and this scheme is when master-slave redundancy; two subscription service do not know the other side mutually, and client is overall subscribes to item data to 2 subscription service, judges to adopt which data when above sending by client; wasting space efficiency, adds client cost.
Summary of the invention
The present invention mainly solves the problem that item ordering system in prior art exists waste network traffics, wasting space efficiency, increase cost, provides the real-time data base ordering system that a kind of efficiency is high, cost is low.
Present invention also offers a kind of real-time data base method for subscribing.
Above-mentioned technical problem of the present invention is mainly solved by following technical proposals: a kind of real-time data base ordering system, comprise some clients, master server, cache database, described master server comprises some real-time data bases, item subscribes to distribution services module, client subscribes to distribution services model calling with item respectively by system bus, real-time data base subscribes to distribution services model calling with item respectively, and item is subscribed to distribution services module and is connected with cache database;
Client: initiate or the request of cancelling subscriptions, stores and subscribes to item data block;
Item subscribes to distribution services module: accept data and client subscription that real-time data base real-time change is sent or cancelling subscriptions request, and foundation has n slot data, for depositing the subscription information of client;
Buffer DB: set up and have n slot data, for depositing the subscription information of client.This cache database adopts distributed key-value cache database, has another name called NoSQL(Not only SQL) database, a kind of can the index data base of fast access character or binary data structure, support redundancy and distributed.Subscription information divides groove to place by present system, segmentation subscription information, the information of every block is minimized, solve redundancy and the storage problem of subscription information, even if servers off-line or machine of delaying, subscription information is still stored in cache database, under redundancy services, uses a point groove algorithm effectively to reduce and carries out synchronous data volume because of the change of client subscription item.The algorithm dividing groove to deposit reduces time complexity, and make service reach the subscription visit capacity of 1,000,000 ranks, than existing concentrated storage, the access mode of order traversal improves very large efficiency.
As a kind of preferred version, also include some standby servers, standby server includes some real-time data bases, item subscribes to distribution services module, client subscribes to distribution services model calling with item respectively by system bus, real-time data base subscribes to distribution services model calling with item respectively, and item subscribes to distribution services module and distributed caching DataBase combining.Standby server has one or more, and the real-time data base that it comprises is the same with master server, other real-time data bases for server, and namely the item of master server, some servers is subscribed to distribution services and is connected to same real-time data base.The many services of this programme Structure composing the hot standby pattern of depositing: client item of forgetting it subscribes to quantity and its health status of distribution services module, as long as have an item to subscribe to the existence of distribution services module just can provide service, improve and data send and subscribes to successful reliability, compared with there is with traditional active-standby switch the neutral gear phase that can not serve, fail safe improves further.This programme makes network and amount of calculation load average simultaneously, when the item of existence 2 or more subscribes to distribution services module distribution in different server, delta data can be subscribed to distribution services module by different server through different item and be sent to client, improve and send efficiency and resource utilization, compared with the complete idle idle state of traditional standby server, take full advantage of existing resource.In addition, because subscription information is placed in distributed cache system, what add between active and standby subscription service is synchronous, and makes the same time only have a subscription service to change data to client, the amount of sending in the data decreasing 50%, directly reduces client cost and network cost.
A kind of real-time data base method for subscribing, comprises subscription step, the step that cancels subscriptions, step is sent in change;
Subscription step comprises: process client pulls subscription the slot data number that item obtains putting into, and subscriptions item and client-side information is written in cache database slot data, finally informs that this item of real-time data base send on needing to change;
The step that cancels subscriptions comprises: the process client item that pulls subscription obtains slot data number, checks in local data groove whether have this item, if existed, deletes and the associating of this client-side information, and synchronization caching database data groove;
Change is sent step comprise: real-time data base carries out delta data send to the item subscribed to, after subscription distribution services module receives item data, process this item and obtain slot data number, check in cache database slot data whether there is this item, if there is this item, travel through all clients associated by this item, send the data to client successively, if do not existed, then send on stopping, abandoning data.Subscription information divides groove to place by the present invention, segmentation subscription information, the information of every block is minimized, solve redundancy and the storage problem of subscription information, even if servers off-line or machine of delaying, subscription information is still stored in cache database, under redundancy services, uses a point groove algorithm effectively to reduce and carries out synchronous data volume because of the change of client subscription item.The algorithm dividing groove to deposit reduces time complexity, and make service reach the subscription visit capacity of 1,000,000 ranks, than existing concentrated storage, the access mode of order traversal improves very large efficiency.
As a kind of preferred version, subscription step, the step that cancels subscriptions and change are sent in step and processes the pull subscription process of item of client and be: will subscribe to item Hash, and obtain a cryptographic Hash s, more than cryptographic Hash s, remove an Integer n, obtain integer value a, integer value a corresponding data groove number.Here Integer n is corresponding with n slot data of foundation.N sets according to the needs of the network user and bandwidth.
As a kind of preferred version, also comprise synchronizing process in subscription step, synchronizing process is:
A., after obtaining slot data number, check that whether local data groove is consistent with the digital signature of data cached database data groove; Local data groove refers to server data groove.
If b. consistent, then will subscribe to item and client-side information writes local data groove, recalculate local data groove digital signature and stored in local data groove simultaneously, then synchronously local data groove and data cached database data groove content; Here in synchronous local data groove and data cached database data groove content and above-mentioned subscription step, subscription item and client-side information are written in cache database slot data, also digital signature are also written in cache database slot data in addition.
If c. inconsistent, then delete local data groove content, local data groove is loaded into cache database slot data content, then continues step b.
As a kind of preferred version, also comprising in the step that cancels subscriptions and check whether this item also has other client associate, if any then not doing other operations, after preserving, passing through not cache database, as then do not deleted all information of this item, and inform that real-time data base stops the change of this item is sent.
Therefore, advantage of the present invention is: 1. divide groove to place subscription information, segmentation subscription information, the information of every block is minimized, solve redundancy and the storage problem of subscription information, even if servers off-line or machine of delaying, subscription information is still stored in cache database, under redundancy services, use a point groove algorithm effectively to reduce and carry out synchronous data volume because of the change of client subscription item.The algorithm dividing groove to deposit reduces time complexity, and make service reach the subscription visit capacity of 1,000,000 ranks, than existing concentrated storage, the access mode of order traversal improves very large efficiency.2. serve and the hot standby pattern of depositing more, client item of forgetting it subscribes to quantity and its health status of distribution services module, as long as have an item to subscribe to the existence of distribution services module just can provide service, improve and data send and subscribes to successful reliability, compared with there is with traditional active-standby switch the neutral gear phase that can not serve, fail safe improves further.3. network and amount of calculation load average, when the item of existence 2 or more subscribes to distribution services module distribution in different server, delta data can be subscribed to distribution services module by different server through different item and be sent to client, improve and send efficiency and resource utilization, compared with the complete idle idle state of traditional standby server, take full advantage of existing resource.4. because subscription information is placed in distributed cache system, what add between active and standby subscription service is synchronous, and make the same time only have a subscription service to change data to client, the amount of sending in the data decreasing 50%, directly reduces client cost and network cost.
Accompanying drawing explanation
Accompanying drawing 1 is a kind of structural framing schematic diagram of present system;
Accompanying drawing 2 is a kind of schematic flow sheets of subscription step in the inventive method;
Accompanying drawing 3 is a kind of schematic flow sheets of step of cancelling subscriptions in the inventive method;
Accompanying drawing 4 is a kind of schematic flow sheets in the inventive method, change being sent step.
1-client 2-master server 3-subscribes to distribution services module 6-real-time data base for server 4-cache database 5-item.
Embodiment
Below by embodiment, and by reference to the accompanying drawings, technical scheme of the present invention is described in further detail.
Embodiment:
A kind of real-time data base ordering system of the present embodiment, as shown in Figure 1, comprise some clients 1, master server 2, cache database 4 and standby server 2, standby server can have multiple, here for a standby server, master server and standby server all include item and subscribe to distribution services module 5, two items are subscribed to distribution services module and are connected with some real-time data bases 6 respectively, cache database is subscribed to distribution services module with two items respectively and is connected, some clients are then be connected respectively to two items by system bus to subscribe in distribution services module.
Client is used for initiating or the request of cancelling subscriptions, and stores and subscribes to item data.
Item subscribes to distribution services module for accepting data and client subscription that real-time data base real-time change is sent or cancelling subscriptions request, and item subscribes to the foundation of distribution services module has n slot data, for depositing the subscription information of client.
Buffer DB: set up and have n slot data, for depositing the subscription information of client.Cache database adopts distributed key-value cache database, has another name called NoSQL(Not only SQL) database, a kind of can the index data base of fast access character or binary data structure, support redundancy and distributed.
The method for subscribing of real-time data base ordering system comprises subscription step, the step that cancels subscriptions, change on send step.
As shown in Figure 2, subscription step comprises:
Step 11: client initiates subscribe request, the item pulled subscription and customer terminals send to item in master server or standby server to subscribe to distribution services module by client;
Step 12: after item subscription distribution services module receives subscribe request, first check in real-time data base whether there is this item;
Step 13: as otherwise put back to step 11, if then this item of Hash, obtain a cryptographic Hash s, by more than cryptographic Hash s except an Integer n, obtain integer value a, this integer a be exactly will stored in slot data number; Suppose that master server, standby server, cache database set up 10 slot datas, as Hash obtains cryptographic Hash 10003, remaining remove 10 after obtain integer 3, then obtain slot data numbers 3.
Step 14: find corresponding slot data position according to slot data number, checks that whether local data groove is consistent with the digital signature of data cached database data groove;
Step 15: if, then will subscribe to item and client-side information write local data groove, recalculate local data groove digital signature simultaneously, data signature is stored in local data groove, then synchronous local data groove and data cached database data groove content, finally informs that this item of real-time data base needs change is sent;
Step 16: if not, then delete local data groove content, and local data groove is loaded into cache database slot data content, then returns step 15.
As shown in Figure 3, cancel subscriptions step:
Step 21: client initiates the request of cancelling subscriptions, the item pulled subscription and customer terminals send to item in master server or standby server to subscribe to distribution services module by client;
Step 22: check whether local data groove exists this item;
Step 23: if not, then cannot cancel subscriptions, if so, then this item of Hash, obtain a cryptographic Hash s, more than cryptographic Hash s, remove an Integer n, obtain integer value a, this integer a be exactly will stored in slot data number, find corresponding local data groove, delete associating of this item and this client-side information;
Step 24: check whether this item also has and other client associate;
Step 25: if so, then do not do other operations, synchronization caching database after preserving, if not, then deletes all information of this item, and inform that real-time data base stops the change of this item is sent.
As shown in Figure 4, change is sent step comprise:
Step 31: real-time data base change is sent, the item that delta data is sent to master server or standby server subscribes to distribution services module;
Step 32: this item of Hash, obtains a cryptographic Hash s, by more than cryptographic Hash s except an Integer n, obtain integer value a, this integer a be exactly will stored in slot data number;
Step 33: find this slot data number groove in cache database, check whether slot data exists this item;
Step 34: if not, stopping is sent, and abandons data, if so, then travels through all clients associated by this item, sends the data to client successively.
Specific embodiment described herein is only to the explanation for example of the present invention's spirit.Those skilled in the art can make various amendment or supplement or adopt similar mode to substitute to described specific embodiment, but can't depart from spirit of the present invention or surmount the scope that appended claims defines.
Although more employ the terms such as client, master server, standby server, cache database, item subscription distribution services module herein, do not get rid of the possibility using other term.These terms are used to be only used to describe and explain essence of the present invention more easily; The restriction that they are construed to any one additional is all contrary with spirit of the present invention.