Summary of the invention
In view of this, the object of the present invention is to provide a kind of internal store data base transaction method and system.These method and system overcome the difficulty that lacks transacter in the existing memory database and can't satisfy transactional processing requirements in the distributed data system, for the consistance and the security of data in the memory database provides reliable guarantee, and significantly reduce the storage space of the shared memory database of data rewind.
The invention provides a kind of internal store data base transaction method, comprising:
Transaction management module creation, processing and submission affairs, and carry out affairs according to the daily record that log management module is created, in the affairs implementation, if exist and the corresponding subtransaction of these affairs, the transaction management module need be finished the implementation of these affairs after subtransaction is complete;
Log management module establishment and management and transaction management module creation, processing and the corresponding daily record of submission affairs; Wherein the described daily record of this method comprises Operation Log and data logging, wherein, and all operations of access memory database in the operation log recording affairs implementation; Data logging is distributed in the interior tables of data of memory database disposal system, is used to preserve the historical record of data, and the recording mode of data logging depends on the Operation Log corresponding with it.
The described processing transactions of this method comprises and reads, revises, deletes and insert what write down in the memory database.
The process of the described transaction management resume module of this method affairs comprises:
The transaction management module receives the transaction request message that the user sends, and returns acknowledge message and affairs and numbers to the user; The transaction management module receives the beginning processing transactions message that the user sends according to the affairs numbering, the beginning processing transactions.
The described transaction management module of this method submits to the process of affairs to comprise:
The transaction management module receives the affairs submission request message that the user sends, and carries out affairs and submits to;
The transaction management module is according to affairs numbering search operation daily record, and the operation note that all are relevant with these affairs is taken out;
The transaction management module is according to the tables of data of storing in operation note sign, and data recording number navigates to target record;
If the transaction operation of target record is designated the affairs deletion, then delete this target record;
If the transaction operation of target record is designated transactions modify, the then sign of the transaction operation in the delete data record number, and deletion and data recording number are expanded corresponding target record;
If the transaction operation of target record is designated affairs and reads, the sign of the transaction operation in the delete data record number then;
If the transaction operation of target record is designated affairs and inserts, the transaction operation sign in the delete data record number then;
The all operations log record of transaction management module deletion affairs correspondence, and deletion transaction information, affairs are submitted to and are finished.
After the failure of the described transaction management resume module of this method affairs, carry out data rewind, process is as follows:
The transaction management module receives the rollback request message that the user sends, and carries out rollback;
The transaction management module is according to affairs numbering search operation daily record, and the operation note that all are relevant with these affairs is taken out;
The transaction management module is according to the tables of data of storing in operation note sign, and data recording number navigates to target record;
If the transaction operation of target record is designated affairs and inserts, then delete this target record;
If the transaction operation of target record is designated transactions modify, then delete this target record, with the content replication in the data recording number expansion in data recording number, and the content in the delete data record expansion;
If the transaction operation of target record is designated affairs deletions, the transaction operation sign in the delete data record number then;
If the transaction operation of target record is designated affairs and reads, the sign of the transaction operation in the delete data record number then;
The all operations log record of transaction management module deletion affairs correspondence, and deletion transaction information, transaction rollback finishes.
After the described transaction management module of this method receives the request message of user's transmission, start the affairs keepalive mechanism, by the time-to-live of affairs time to live control affairs is set.
The described log management module admin log of this method comprises:
If target record has been carried out read operation, then the transaction operation sign with target record is changed to the affairs reading state, and records in the Operation Log;
If to the target record operation of making amendment, then preserve the duplicated record of a this target record earlier, on former target record, make amendment then, transaction operation sign at target record and duplicated record all is changed to the transactions modify state, and record in the Operation Log, and with the content replication in the duplicated record number in data recording number expansion;
If target record has been carried out deletion action, then the transaction operation sign with target record is changed to affairs deletion state, and records in the Operation Log;
If target record has been carried out inserting operation, then the transaction operation sign with target record is changed to affairs insertion state, and records in the Operation Log.
The present invention also provides a kind of internal store data base transaction system, comprising:
The transaction management module is used for creating, handles and submits to affairs, and carries out affairs according to the daily record that log management module is created, in the affairs implementation, if exist and the corresponding subtransaction of these affairs, the transaction management module need be finished the implementation of these affairs after subtransaction is complete;
Log management module is used for establishment and management and transaction management module creation, processing and the corresponding daily record of submission affairs; Wherein, the described log management module of this system comprises Operation Log Management module and data logging administration module, wherein,
The Operation Log Management module is used for writing down all operations of affairs implementation access memory database;
The data logging administration module is distributed in the tables of data in the memory database disposal system, is used to preserve the historical record of data, and the recording mode of data logging depends on the Operation Log corresponding with it.
Internal store data base transaction method of the present invention and system, solved the needs of problems that existing memory database system is handled the memory database transactional effectively, for the consistance and the security of data in the memory database provides reliable guarantee, for the flow chart of data processing of follow-up complexity provides reliable guarantee, and significantly reduced the storage space of the shared memory database of data rewind.
Embodiment
Below in conjunction with accompanying drawing the specific embodiment of the present invention is described.
Fig. 1 is the structural representation of internal store data base transaction of the present invention system, comprising:
Transaction management module 101, be used for creating, handle and submit to affairs, and carry out affairs according to the daily record that log management module 102 is created, in the affairs implementation, if exist and the corresponding subtransaction of these affairs, transaction management module 101 need be finished the implementation of these affairs after subtransaction is complete;
Log management module 102 is used for establishment and management and the corresponding daily record of affairs is created, handles and submitted to transaction management module 101.Log management module 101 comprises Operation Log Management module 1011 and data logging administration module 1012, wherein,
Operation Log Management module 1011 is used for writing down all operations of affairs implementation access memory database;
Data logging administration module 1012 is distributed in the tables of data in the memory database disposal system, is used to preserve the historical record of data, and the recording mode of data logging depends on the Operation Log corresponding with it.
The memory database transaction system is carried out processing transactions and is at first carried out the affairs establishment, when creating affairs, need store the information of these affairs.Fig. 2 is the structural representation of the transaction information of transaction management module in the internal store data base transaction of the present invention system, and transaction information comprises affairs numbering 201, affairs priority 2 02, affairs life cycle 203, affairs founder's information 204 and subtransaction information 205.
Affairs numbering 201 unique identifications as affairs, effective in the total system.
Affairs priority 2 02 is used for the processing sequencing of control affairs, the processing priority of reflection affairs.
Be used for the affairs keep-alive affairs life cycle 203, avoids the affairs deadlock problem that causes unusually.
Affairs founder's information 204 is used for store transaction founder's information, is needing this information by transaction system in that initiate and the interaction process process affairs founder.
Subtransaction information 205 is stored in the subtransaction of current memory database establishment.Below the relation of concise and to the point descriptor, father's affairs:
Father's affairs also can be called the root affairs, are created in the memory database transacter by the user.
Subtransaction is to carry out great-leap-forward when visit, the affairs of creating by father's affairs in purpose memory database transacter.
Concerning a memory database transacter, father's affairs can only be created unique subtransaction therein, and each subtransaction has and have only unique father's affairs.
As shown in Figure 3, Fig. 3 is the structural drawing of the Operation Log Management module of log management module in the internal store data base transaction of the present invention system, comprises affairs numbering 201, tables of data sign 301, data recording numbers 302 and data recording number expansion 303 among the figure.Wherein,
Tables of data sign 301 is used for identifying a tables of data of memory database transacter.
Data recording numbers 302 is the recording mechanisms in the tables of data 301, is used for identifying a transaction journal of a tables of data.
Data recording expansion 303 also is the recording mechanism in the tables of data 301, and the auxiliary data recording mechanism as data recording numbers 302 is used for identifying a transaction journal of a tables of data.
In the memory database, comprise a plurality of Transaction Information tables, comprise many transaction journals in each Transaction Information table, the user finds corresponding Transaction Information table by tables of data sign 301, then, find transaction journal corresponding in this tables of data by the data recording in this Transaction Information table numbers 302, therefore, tables of data sign 301 and data recording numbers 302 united a unique transaction journal in the expression memory database transacter, and this transaction journal is called target record.
Fig. 4 is the structural drawing of the data logging administration module of log management module in the internal store data base transaction of the present invention system, comprises among the figure:
Transaction operation sign 401 is used for the current state of recording operation record, comprises that affairs read, transactions modify, affairs deletion, affairs are inserted and do not have the affairs operation.Transaction operation sign 401 is used to finish follow-up affairs and submits operations such as data rewind to also as the data logging of every transaction operation.
Recorded content 402 is used to preserve the information of every transaction operation process, comprises the information of operating process such as affairs read, transactions modify, affairs deletion, affairs insertion.
In conjunction with Fig. 3 and structure shown in Figure 4, the log management module of whole affairs gets final product clear foundation, and transaction journal difference because of action type in management is different, specific as follows:
Affairs read: in the implementation of affairs, if target record has been carried out read operation, then the transaction operation sign with target record is changed to the affairs reading state, and records in the Operation Log.
Transactions modify: in the implementation of affairs, if to the target record operation of making amendment, then preserve the duplicated record of a this target record earlier, on former target record, make amendment then, transaction operation sign at target record and duplicated record all is changed to the transactions modify state, and record in the Operation Log, and with the content replication in the duplicated record number in data recording number expansion, when needs are carried out the data rolling back action, then the content in the data recording number expansion is copied to again in the data recording number, be about to data recording and number revert to the data recording carried out before the retouching operation number, after data rewind is complete, the content in the delete data record expansion.
The affairs deletion: in the implementation of affairs, if target record has been carried out deletion action, then the transaction operation sign with target record is changed to affairs deletion state, and records in the Operation Log.
Affairs are inserted: in the implementation of affairs, if target record has been carried out inserting operation, then the transaction operation sign with target record is changed to affairs insertion state, and records in the Operation Log.
After affairs finish, transaction journal need be removed, and no affairs action type on the relevant transaction operation identity marking of all these affairs.
Introduce the affairs keepalive mechanism, transaction commitment processing detailed rules and regulations and the transaction rollback that occur in the above-mentioned steps below respectively and handle detailed rules and regulations.
The keepalive mechanism of affairs: in the transacter that a plurality of memory databases constitute; the transactional deadlock that may exist some to cause unusually; particularly for striding processing unit or striding the situation that memory database carries out issued transaction; its potential danger is bigger, therefore needs a kind of keepalive mechanism to prevent the transactional deadlock.Detailed process is as follows:
The user provides the affairs time to live when creating affairs; When the time-to-live of affairs surpasses the affairs time to live, illustrate that then these affairs are overtime unusually, need carry out the affairs release and handle, promptly memory database will force these affairs to carry out rollback, realize release.
The transaction commitment processing detailed rules and regulations:
At first, the memory database disposal system is searched the transaction operation daily record according to the affairs numbering, and the operation note that all are relevant with these affairs is taken out.
Then, the memory database disposal system is according to the tables of data of storing in operation note sign, and data recording number navigates to target record.
If the transaction operation of target record is designated the affairs deletion, then delete this target record;
If the transaction operation of target record is designated transactions modify, the then sign of the transaction operation in the delete data record number, and deletion and data recording number are expanded corresponding target record;
If the transaction operation of target record is designated affairs and reads, the sign of the transaction operation in the delete data record number then;
If the transaction operation of target record is designated affairs and inserts, the transaction operation sign in the delete data record number then;
At last, all operations log record of memory database disposal system deletion affairs correspondence, and deletion transaction information, affairs are submitted to and are finished.
Transaction rollback is handled detailed rules and regulations:
At first, the memory database disposal system is searched the transaction operation daily record according to the affairs numbering, and the operation note that all are relevant with these affairs is taken out.
Then, the memory database disposal system is according to the tables of data of storing in operation note sign, and data recording number navigates to target record.
If the transaction operation of target record is designated affairs and inserts, then delete this target record;
If the transaction operation of target record is designated transactions modify, then delete this target record, with the content replication in the data recording number expansion in data recording number, and the content in the delete data record expansion;
If the transaction operation of target record is designated affairs deletions, the transaction operation sign in the delete data record number then;
If the transaction operation of target record is designated affairs and reads, the sign of the transaction operation in the delete data record number then;
At last, all operations log record of memory database disposal system deletion affairs correspondence, and deletion transaction information, transaction rollback finishes.
In DATA DISTRIBUTION formula system, under the unknowable situation of affairs user, transaction system is created corresponding subtransaction automatically, carries out the great-leap-forward visit, thereby finishes the overall process of issued transaction.Fig. 5 carries out the process flow diagram of issued transaction with the great-leap-forward access mode for internal store data base transaction system among the present invention.Concrete steps are as follows:
Step 501, the user sends to MDB_1 and creates first transaction request message.
Step 502, MDB_1 receives and creates first transaction request message, returns acknowledge message and affairs numbering, and the first affairs time to live that provides according to the user starts keepalive mechanism, preserves the information of these first affairs.
Step 503, the user receives first affairs numbering, sends to MDB_1 according to first affairs numbering to begin to carry out first transaction message.
Step 504, MDB_1 is in the first affairs implementation, and discovery need be carried out the great-leap-forward visit to MDB_2, so initiate to create second transaction request message to MDB_2.
Step 505, MDB_1 also need to find MDB_3 is carried out the great-leap-forward visit in the first affairs implementation, so initiate to create the 3rd transaction request message to MDB_3.
Step 506, MDB_3 receives and creates the 3rd transaction request message, carries out the processing of the 3rd affairs; In the 3rd issued transaction process, discovery need be carried out the great-leap-forward visit to MDB_4, so initiate to create the 4th transaction request message to MDB_4.
Step 507, MDB_4 receives and creates the 4th transaction request message, carries out the processing of the 4th affairs, after MDB4 finishes the processing of the 4th affairs, sends and finishes dealing with message to MDB_3.
Step 508, MDB_3 receives the message of finishing dealing with that MDB_4 sends, finish the processing of the 3rd affairs after, send and finish dealing with message to MDB_1.
Step 509 after MDB_2 finishes the processing of second affairs, sends and finishes dealing with message to MDB_1.
Step 510, MDB_1 receives the message of finishing dealing with of MDB_2 and MDB_3 transmission, finishes the processing of first affairs.
According to the definition of aforementioned father's affairs and subtransaction, in the above-mentioned steps, first affairs are father's affairs of second affairs and the 3rd affairs, and the 3rd affairs are father's affairs of the 4th affairs; In other words, second affairs and the 3rd affairs are subtransactions of first affairs, and the 4th affairs are subtransactions of the 3rd affairs.
Handle in the implementation procedure in actual transaction, can handle more subtransaction in the manner described above in conjunction with concrete condition, thereby finally finish processing first affairs.For subtransaction second affairs and the 3rd affairs that first affairs are created respectively in MDB_2 and MDB_3, both sides relation is a coordination, and after the two issued transaction was finished, what send to MDB_1 finished dealing with message in no particular order, following three kinds of situations all can:
MDB_3 sends earlier and finishes dealing with message to MDB_1, sends behind the MDB_2 and finishes dealing with message to MDB_1;
MDB_2 sends earlier and finishes dealing with message to MDB_1, sends behind the MDB_3 and finishes dealing with message to MDB_1;
MDB_2 and MDB_3 send the message of finishing dealing with simultaneously to MDB_1.
MDB_1 only after the message of finishing dealing with that the subtransaction place MDB that receives all first affairs returns, just can finish the processing of first affairs.
In memory database, the submission of affairs can only be initiated by the user, and for the user, have only first affairs as seen, therefore, the user at first notifies memory database to carry out the submission of first affairs, if there be the subtransaction corresponding, after then needing to finish the submission of this subtransaction earlier, finish the submission of these first affairs again with these first affairs, therefore, in actual transaction submission process, if there is multistage son, the situation that father's affairs are nested then must be carried out affairs by father's transaction notification at different levels subtransaction corresponding with it in order and submit to, after subtransactions at different levels are finished the affairs submission in order, finally finish the submission of whole affairs.
Fig. 6 carries out the process flow diagram that affairs are submitted to for internal store data base transaction system among the present invention.Concrete steps are as follows:
Step 601, the user sends first affairs to MDB_1 and submits request message to.
Step 602 after MDB_1 receives that first affairs are submitted request message to, is deleted the transaction journal of this memory database correspondence, notifies its second subtransaction and the 3rd subtransaction of creating respectively in MDB_2 and MDB_3 to submit to, and waits for its response.
Step 603 after MDB_2 and MDB_3 receive the submission request message of first affairs, is deleted the transaction journal of this memory database correspondence, carries out affairs and submits to, and return to submit to and finish message to MDB_1.
In this step, for there not being subtransaction second affairs, MDB_2 finishes to return after the submission to submit to and finishes message and give MDB_1.For the 3rd affairs, owing to there are corresponding subtransaction the 4th affairs, therefore, MDB_3 needs to send to MDB_4 earlier to submit request message to, receiving after MDB_4 finishes the submission of returning after the 4th affairs are submitted to and finish message, just can finish the affairs of himself and submit to, after MDB_3 finishes the submission of the 3rd affairs, return to submit to and finish message to MDB_1.
Step 604, MDB_1 receives that the submission of MDB_2 finishes message, but does not receive that as yet the submission of MDB_3 finishes message, continues to wait for that the submission of MDB_3 finishes message.
Step 605, MDB_4 finishes the submission of the 4th affairs, returns to submit to and finishes message to MDB_3.
Step 606, MDB_3 receives after MDB_4 finishes the submission of returning after the 4th affairs are submitted to and finish message, finishes the submission of the 3rd affairs, and returns to submit to and finish message and give MDB_1.
Step 607, MDB_1 receives that the submission that MDB_2 and MDB_3 return finishes message, carries out first affairs and submits to, thereby finish the submission of whole affairs.
In the above-mentioned steps, the asynchronous access owing to existing between a plurality of memory databases can adopt some security measures in the asynchronous access process, as adopting the affairs keepalive mechanism of memory database, deals with the abnormal conditions that may occur in the affairs submission process.
Fig. 7 be father office memory database MDB_1 on initiate the processing flow chart of transaction rollback.Its treatment scheme is similar to affairs and submits to, just need carry out data rewind according to transaction journal, deletes transaction journal then, and the deletion affairs are finished rollback.Concrete steps are as follows:
Step 701, the user sends the first transaction rollback request message to MDB_1.
Step 702 after MDB_1 receives the first transaction rollback request message, is deleted the transaction journal of this memory database correspondence, notifies its second subtransaction and the 3rd subtransaction of creating respectively in MDB_2 and MDB_3 to carry out rollback, and waits for its response.
Step 703, after MDB_2 and MDB_3 received second, third transaction rollback request message of MDB_1, transaction rollback was carried out in first transaction journal of correspondence among deletion MDB_2 and the MDB_3, and returned rollback and finish message to MDB_1.
In this step, for there not being subtransaction second affairs, MDB_2 finishes and returns rollback after the rollback and finish message and give MDB_1.For the 3rd affairs, owing to there are corresponding subtransaction the 4th affairs, therefore, MDB_3 needs to send the 4th transaction rollback request message to MDB_4 earlier, receiving after the 4th transaction rollback that returns after MDB_4 finishes the 4th transaction rollback finishes message, just can finish the transaction rollback of himself, after MDB_3 finishes the rollback of the 3rd affairs, return the 3rd transaction rollback and finish message to MDB_1.
Step 704, MDB_1 receives that second transaction rollback of MDB_2 finishes message, but does not receive that as yet the 3rd transaction rollback that MDB_3 returns finishes message, continues to wait for that MDB_3 returns the 3rd transaction rollback and finishes message.
Step 705, MDB_4 finishes the rollback of the 4th affairs, returns the 4th transaction rollback and finishes message to MDB_3.
Step 706, MDB_3 receives after MDB_4 finishes the 4th transaction rollback that returns behind the 4th transaction rollback and finish message, finishes the rollback of the 3rd affairs, and returns the 3rd transaction rollback and finish message and give MDB_1.
Step 707, MDB_1 receives that second, third rollback that MDB_2 and MDB_3 return finishes message, carries out first transaction rollback, thereby finishes the rollback of whole affairs.
Fig. 8 is the processing flow chart of initiating transaction rollback on the memory database MDB_3 at subtransaction place.Concrete steps are as follows:
Step 801, the user sends the 3rd transaction rollback request message to MDB_3.
Step 802 after MDB_3 receives the 3rd transaction rollback request message, sends the first transaction rollback request message to MDB_1, and sends the 4th transaction rollback request message to MDB_4.
Because there are father's affairs in the 3rd affairs, be first affairs among the MDB_1, and subtransaction the 4th affairs of in MDB_4, creating, therefore, MDB_3 need send the rollback request message to first office memory database MDB_1 and the 4th office memory database MDB_4, carry out the rollback of first affairs and the 4th affairs respectively, rollback for its subtransaction the 4th affairs, MDB_3 need wait for that the 4th transaction rollback that MDB_4 returns finishes message, and for the rollback of his father's affairs first affairs, MDB_3 does not need then to wait for that first transaction rollback that MDB_1 returns finishes message.
Step 803, MDB_1 receives the 3rd transaction rollback request message that MDB_3 sends, carry out the rollback of first affairs, because first affairs have also been created subtransaction second affairs in MDB_2, therefore, MDB_1 sends the rollback request message to MDB_2, carry out the rollback of second affairs, and wait for that second transaction rollback that MDB_2 returns finishes message, and receiving after second transaction rollback finishes message, MDB_1 just can carry out the rollback of first affairs.
In this step, MDB_1 will no longer send the rollback request message for the MDB_3 that initiates transaction rollback.
Step 804, MDB_4 receives the 4th transaction rollback request message that MDB_3 sends, and carries out the rollback of the 4th affairs, and returns the 4th transaction rollback and finish message to MDB_3.
Step 805, MDB_3 carries out the rollback of the 3rd affairs after receiving that the 4th transaction rollback is finished message, the 3rd transaction journal that deletion is wherein corresponding, and return the 3rd rollback and finish message to MDB_1.
Step 806, after MDB_2 received the second rollback request message of MDB_1, transaction rollback was carried out in second transaction journal that deletion is wherein corresponding, and returned second rollback and finish message to MDB_1.
Step 807, MDB_1 receives that second transaction rollback that MDB_2 returns finishes the 3rd transaction rollback that message and MDB_3 return and finish message, carries out the rollback of first affairs, thereby finishes the rollback of whole affairs.
The above only is preferred embodiment of the present invention, and is in order to restriction the present invention, within the spirit and principles in the present invention not all, any modification of being done, is equal to replacement, improvement etc., all should be included within protection scope of the present invention.