Background technology
Cluster (Cluster) is a kind of loosely-coupled computing node set that is made up of two or many node machines (server); For the user provides services on the Internet or single client's view of application program (comprising database, Web service and file service etc.), the failover capability near fault-tolerant machine is provided simultaneously.Group system generally through two or many node server systems through relevant hardware and software interconnection, each clustered node all is the separate server of its own process of operation.These processes can communicate with one another, and concerning net computer similarly are to have formed a triangular web, work in coordination with to the user application program, system resource and data are provided.
Network Load Balance is exactly that two or more group of server become to troop, and the Internet (Internet) client is used an Internet Protocol (Internet Protocol is called for short IP) address or one group of IP accessed cluster.Network Load Balance uses certain distributed algorithm that the request of client is mapped on certain main frame in the cluster.Briefly; A copy that is exactly program operates on the All hosts in the cluster; Pass through balancing technique then; The request that the outside is sent is assigned to certain station server in the symmetrical structure equably, can both independently respond client's request and receive the requested service device, and Network Load Balance then distributes operating load between these main frames.
It should be noted that under clustered deploy(ment) the Database Requirements between each server is consistent.If the data in database change, the database on other servers also needs to keep data consistent synchronously with its so, and is as shown in Figure 1.
Among Fig. 1, the IP address that the user capture cluster is corresponding is shone upon user's request to server B through load balancing; Database on the server B is revised, server A, server C; Database on the server D need carry out synchronously, makes to be consistent with server B.
But, generally do not carry out database in the cluster and separate, all public database of Servers-all if this is with server; Because the identical table to database can not carry out read-write operation simultaneously, thus the occlusive effects performance can be produced, if this database goes wrong on the other hand; Whole service will can not move fully; Being kept at data of database will lose fully, produce more serious consequence, has also lost cluster improves reliability through redundancy meaning.
Database caches is meant the temporary container of database data in internal memory, and it has comprised the copy of database table data in internal memory, between database and data access layer.For the quite frequent system of Query Database operation, it is particularly important that good caching mechanism seems.Application system is at first inquired about in buffer memory carrying out data when reading, and has avoided the performance cost of data base call, and because internal memory operation is faster than disk operating, thereby also accelerated the inquiry velocity of database data greatly.
Database caches is the necessary means that guarantees server performance, and the position in server is as shown in Figure 2.
Database replication is one group of database technology, is realized by database self.It from a database replication be distributed to the another one database, carries out data and database object synchronously, to keep the consistance between the database then between database.
Application system when the data on the database of one station server change, then can be passed through database replication technology when the on-premise network load balancing cluster, make that the database on other servers is consistent.
Database caches is meant that synchronously database caches and database carry out making the content of database caches and database be consistent synchronously on the server.
Under traditional clustered deploy(ment), each node all comprises a database.In order to improve performance, also comprise a database caches on each node simultaneously.When database synchronization, must also carry out synchronously the data banked cache.
But database synchronization is mainly through database replication technology, and database replication technology can not guarantee that database caches and database on other servers are consistent.Therefore; Under the application of disposing cluster; Need to use some other extra mechanism to guarantee the synchronous of database caches; For example (number of patent application: 200810127364.0) propose when data-base content changes, the trigger in trigger data storehouse carries out data in the database caches and database synchronously through trigger patent " in the distributed system data cached synchronous configuration method and device "; For example can go the monitor database table whether to change at set intervals, if change then upgrade the synchrodata banked cache.But these class methods all need consume sizable performance; Particularly every table has a lot of records items in the database; If the data in certain record item change, then the database caches on the Servers-all all must be made corresponding change, is difficult to guarantee synchronous promptness like this.
Embodiment
The purpose of this invention is to provide a kind of database caches centralized management method and system, need carry out synchronous problem to the data banked cache when avoiding, save system resource database synchronization.
The present invention will be described below in conjunction with accompanying drawing, the invention provides a kind of database caches centralized management method, and Fig. 3 has provided a kind of database caches of the present invention centralized management method embodiment one synoptic diagram, and said method comprises:
Step S1, database server sends database manipulation message and gives the database caches server;
Comprise database on the said database server, said caching server is used for the part list item of cache database, is connected with one or more database server.
Said database manipulation message can comprise database table name, database list item major key, database manipulation sign indicating number and database list item.
Step S2, the database caches server carries out corresponding operating according to said database manipulation message to the data banked cache, and the return result gives database server;
Step S3, database server carries out corresponding operating according to operating result to database.
The present invention is through managing concentratedly the data banked cache; Many database servers are disposed a unified data banked cache server; Need on every database server, all not keep a database caches; Before database is operated, earlier the data banked cache is carried out corresponding operating, more a plurality of database caches are carried out synchronous problem when having avoided, practiced thrift system resource database synchronization.
When adding operation, said database manipulation sign indicating number is for adding operational code;
Said step S2 specifically can for: the database caches server adds the database list item in the database caches to according to database table name and database list item major key, and returns and add response of successful and give database server;
Said step S3 specifically can for: database server receive add response of successful after, in database, add operation.
For example when adding operation, database server can send the TCP message according to following form and give the database caches server:
Database list item major key is the value of unique identification data storehouse list item in the database, can be the general unique identifier (Universally Unique Identifier is called for short UUID) of database table item.
After the database caches server is received message; Go out database table name and database major key by as above format analysis; Form key word (key) value in the database caches; This database list item is joined in Hash (Hash) table of database caches, and send one and add response of successful to database server.
Database server adds the database list item in the database to after receiving and adding response of successful.
When carrying out query manipulation, said database manipulation sign indicating number is the query manipulation sign indicating number, and said database list item is empty;
Said step S2 specifically can inquire about whether there is corresponding database list item according to database table name and database list item major key for: database caches server in database caches; If inquire then return Query Result and give database server, otherwise database server is given in the response of sending the inquiry failure;
Said step S3 specifically can for: database server directly returns Query Result after receiving Query Result; After the response of receiving the inquiry failure, on database server, inquire about, and the database list item that inquires is added in the database caches.
For example when carrying out query manipulation, database server can send the TCP message according to following form and give the database caches server:
After the database caches server is received message; Go out database table name and database major key by as above format analysis; Form the key value; In Hash in the data query banked cache table, if inquire then Query Result is sent to database server, otherwise database server is given in the response of sending an inquiry failure.
Database server directly returns Query Result after receiving Query Result; After the response of receiving the inquiry failure, on database server, inquire about, and the database list item that inquires is added in the database caches according to top form.
When carrying out deletion action, said database manipulation sign indicating number is the deletion action sign indicating number, and said database list item is empty;
Said step S2 specifically can for: the database caches server carries out deletion action according to database table name and database list item major key in database caches, and returns the deletion response of successful and give database server;
Said step S3 specifically can carry out deletion action for after: database server receives the deletion response of successful in database.
For example when carrying out deletion action, database server can send the TCP message according to following form and give the database caches server:
After the database caches server is received message; Go out database table name and database major key by as above format analysis; Form key value, the Hash table of data query banked cache is if inquire then from Hash shows, delete this list item; Otherwise do not carry out any operation, and send a deletion response of successful and give database server.
Database server is deleted corresponding list item after receiving the deletion response of successful from database.
When making amendment operation, said database manipulation sign indicating number is the retouching operation sign indicating number;
Said step S2 is specially: the database caches server inquires about whether there is corresponding database list item according to database table name and database list item major key in database caches; If inquire then revise corresponding database list item; And send the response that is modified as merit and give database server, give database server otherwise send the response of revising failure;
Said step S3 is specially: database server receive revise response of successful after, the operation of in database, making amendment; After receiving the response of revising failure, on database server, carry out retouching operation, and the database list item of revising is added in the database caches.
For example when making amendment operation, database server can send the TCP message according to following form and give the database caches server:
After the database caches server is received message; Go out database table name and database major key by as above format analysis; Form key value, in the Hash table in the data query banked cache, if inquire then database list item during the Hash of database caches shown is updated to the database list item in the database manipulation message; And send the response that is modified as merit and give database server, give database server otherwise send a response of revising failure.
Database server receive revise response of successful after, the operation of in database, making amendment; After receiving the response of revising failure, on database server, carry out retouching operation, and the database list item of revising is added in the database caches.
Fig. 4 has provided a kind of database caches of the present invention centralized management method embodiment two synoptic diagram; Present embodiment is except the step that comprises method embodiment one; Before said step S1, also comprise step S4: whether the database server judgement is connected normal with the database caches server; If execution in step S1 then, otherwise directly database is operated.
Usually use TCP to connect between database caches server and the database server, occur interrupting if connect, the database caches server can detect, and this moment, it can all clear out all buffer memorys usually.Continue again the data in the database server are carried out buffer memory when connecting when recovering.
In common deployment, database caches server and database server are direct-connected through switch, network seldom occurs and connect the problem of interrupting.Interrupt if connect, generally because the database caches server breaks down or cuts off the power supply and causes, after restarting the database caches server or changing new engine, buffer memory will be cleared, and after the operate as normal data in the database server carried out buffer memory.
The present invention also provides a kind of database caches centralized management system, and Fig. 5 has provided a kind of database caches centralized management system of the present invention embodiment synoptic diagram, and said system comprises one or more database servers and a data banked cache server;
Said database server is used to send database manipulation message and gives the database caches server, and according to the operating result that the database caches server returns database is carried out corresponding operating
Said database manipulation message can comprise database table name, database list item major key, database manipulation sign indicating number and database list item.
Said database caches server is connected with one or more database servers; The partial database list item that is used for cache database; Be used for the data banked cache being carried out corresponding operating, and the return result gives database server according to said database manipulation message.
Said database server can also be used for whether normal judgement before is connected with the database caches server to the database caches server sending database manipulation message; Give the database caches server if send database manipulation message, otherwise directly database is operated.
When adding operation, said database manipulation sign indicating number is for adding operational code;
The database caches server can be used for adding the database list item to database caches according to database table name and database list item major key, and returns and add response of successful to database server;
Database server adds operation after can being used to receive the interpolation response of successful in database.
When carrying out query manipulation, said database manipulation sign indicating number is the query manipulation sign indicating number, and said database list item is empty;
The database caches server can be used for whether having corresponding database list item according to database table name and database list item major key in the database caches inquiry; If inquire then return Query Result and give database server, otherwise database server is given in the response of sending the inquiry failure;
Database server can be used for after receiving Query Result, directly returning Query Result; After the response of receiving the inquiry failure, on database server, inquire about, and the database list item that inquires is added in the database caches.
When carrying out deletion action, said database manipulation sign indicating number is the deletion action sign indicating number, and said database list item is empty;
The database caches server can be used for carrying out deletion action according to database table name and database list item major key at database caches, and returns the deletion response of successful and give database server;
Database server carries out deletion action after can being used to receive the deletion response of successful in database.
When making amendment operation, said database manipulation sign indicating number is the retouching operation sign indicating number;
The database caches server can be used for whether having corresponding database list item according to database table name and database list item major key in the database caches inquiry; If inquire then revise corresponding database list item; And send the response that is modified as merit and give database server, give database server otherwise send the response of revising failure;
Database server can be used for after receiving the modification response of successful, the operation of in database, making amendment; After receiving the response of revising failure, on database server, carry out retouching operation, and the database list item of revising is added in the database caches.
Fig. 6 has provided a kind of database caches centralized management system of the present invention deployment topologies synoptic diagram, and this topology has following characteristic:
1. disposed the Network Load Balance cluster, i.e. many database servers;
2. all be deployed with database on every database server;
3. dispose 1 database caches server;
4. database server directly is connected with the database caches server;
5. keep database consistent through database replication technology between the database
The present invention is through managing concentratedly the data banked cache; Many database servers are disposed a unified data banked cache server; Need on every database server, all not keep a database caches; Before database is operated, earlier the data banked cache is carried out corresponding operating, more a plurality of database caches are carried out synchronous problem when having avoided, practiced thrift system resource database synchronization.
Simultaneously, buffer memory by the management of database caches server centered, for example can be kept in the huge Hash table, improve the performance of data query banked cache.
The unified management of database caches, it is redundant also to have reduced unnecessary buffer memory, for every station server has been practiced thrift valuable memory source greatly.
What should explain at last is: above embodiment is only in order to explaining technical scheme of the present invention, but not to its restriction; Although with reference to previous embodiment the present invention has been carried out detailed explanation, those of ordinary skill in the art is to be understood that: it still can be made amendment to the technical scheme that aforementioned each embodiment put down in writing, and perhaps part technical characterictic wherein is equal to replacement; And these are revised or replacement, do not make the spirit and the scope of the essence disengaging various embodiments of the present invention technical scheme of relevant art scheme.