Summary of the invention
In view of this, technical matters to be solved by this invention is, a kind of data-updating method and device are provided, and can guarantee upgrading in time of data under the situation that high concurrent operations produces, the operational efficiency of raising system, guarantee system data consistance, safety, do not lose.
The invention provides a kind of data-updating method, comprising:step 102, the incremental data that the operation of at every turn specific data in the original table being carried out is produced is stored in the scratch list respectively;Step 104 is upgraded the value of the described specific data in the described original table according to described incremental data.By this technical scheme, use all incremental datas that specific data is upgraded by scratch list, can the raising system efficient of operation, guarantee the safety of system data.
In technique scheme, preferably, in describedstep 102, when the operation to described specific data was cancelled, the opposite number of the incremental data that the operation cancelled is produced was stored as new incremental data.By this technical scheme, simplified the algorithm and the operation of Data Update, improved operational efficiency simultaneously, guarantee the safety of data.
In technique scheme, preferably, describedstep 104 comprises: the incremental data that all operations of being stored to described specific data produces is sued for peace, and use the result of summation that the value of described specific data is upgraded.By this technical scheme, can realize only coming specific data is upgraded with single job, improved the efficient of Data Update.
In technique scheme, preferably, described renewal comprises: with between the value of the result of described summation and described specific data and as the value of described specific data.
In technique scheme, preferably, do not finish, and described user is during to the inquiry of described specific data in described renewal, with between the value of the result of described summation and described specific data with offer the user.In the technical program, be about to the data of described specific data in original table and scratch list and carry out addition, as user's Query Result.
In technique scheme, preferably, describedstep 104 also comprises: regularly or after the scheduled operation of described original table is finished, the described specific data that is arranged in described original table is upgraded, and after upgrading, with the described incremental data deletion in the described scratch list.By this technical scheme, can realize the timing of data is upgraded, can also improve the efficient of data run simultaneously.
By data-updating method provided by the invention, upgrading in time of the following assurance data that can produce at high concurrent operations improves the operational efficiency of system, guarantee system data consistance, safety, do not lose.
The present invention also provides a kind of data update apparatus, comprising: temporary module, and the incremental data that the operation of at every turn specific data in the original table being carried out is produced is stored in the scratch list respectively; Update module is upgraded the value of the described specific data in the described original table according to described incremental data.By this technical scheme, use all incremental datas that specific data is upgraded by scratch list, can the raising system efficient of operation, guarantee the safety of system data.
In technique scheme, preferably, when the operation to described specific data was cancelled, described temporary module was also stored the opposite number of being cancelled of operating the incremental data that produces of stating as new incremental data.By this technical scheme, simplified the algorithm and the operation of Data Update, improved operational efficiency simultaneously, guarantee the safety of data.
In technique scheme, preferably, the incremental data summation that described update module produces all operations of being stored to described specific data, and use the result of summation that the value of described specific data is upgraded.By this technical scheme, can realize only coming specific data is upgraded with single job, improved the efficient of Data Update.
In technique scheme, preferably, described update module with between the value of the result of described summation and described specific data and as the value of described specific data.
In technique scheme, preferably, do not finish, and described user is during to the inquiry of described specific data in described renewal, with between the value of the result of described summation and described specific data with offer the user.In the technical program, be about to the data of described specific data in original table and scratch list and carry out addition, as user's Query Result.
In technique scheme, preferably, described update module is upgraded the described specific data that is arranged in described original table regularly or after the scheduled operation of described original table is finished, and after upgrading, the described incremental data in the described scratch list is deleted by described temporary module.By this technical scheme, can realize the timing of data is upgraded, can also improve the efficient of data run simultaneously.
By data update apparatus provided by the invention, can under the situation that high concurrent operations produces, guarantee upgrading in time of data, improve the operational efficiency of system, guarantee system data consistance, safety, do not lose.
Embodiment
In order more to be expressly understood above-mentioned purpose of the present invention, feature and advantage, the present invention is further described in detail below in conjunction with the drawings and specific embodiments.
Set forth a lot of details in the following description so that fully understand the present invention, still, the present invention can also adopt other to be different from other modes described here and implement, and therefore, the present invention is not limited to the restriction of following public specific embodiment.
Fig. 1 shows data-updating method process flow diagram according to an embodiment of the invention.
As shown in Figure 1, the invention provides a kind of data-updating method, comprising:step 102, the incremental data that the operation of at every turn specific data in the original table being carried out is produced is stored in the scratch list respectively;Step 104 is upgraded the value of the specific data in the original table according to incremental data.By this technical scheme, use all incremental datas that specific data is upgraded by scratch list, can the raising system efficient of operation, guarantee the safety of system data.
In technique scheme, instep 102, when the operation to specific data was cancelled, the opposite number of the incremental data that the operation cancelled is produced was stored as new incremental data.By this technical scheme, simplified the algorithm and the operation of Data Update, improved operational efficiency simultaneously, guarantee the safety of data.
In technique scheme, comprise: the incremental data that all operations of being stored to specific data produces is sued for peace, and use the result of summation that the value of specific data is upgraded in step 104.By this technical scheme, can realize only coming specific data is upgraded with single job, improved the efficient of Data Update.
In technique scheme, renewal comprises: between the result that will sue for peace and the value of specific data and as the value of specific data.
In technique scheme, do not finish in described renewal, and described user is during to the inquiry of described specific data, with between the value of the result of described summation and described specific data with offer the user.In the technical program, be about to the data of described specific data in original table and scratch list and carry out addition, as user's Query Result.
In technique scheme,step 104 also comprises: regularly or after the scheduled operation of described original table is finished, the specific data that is arranged in original table is upgraded, and after upgrading, the incremental data in the scratch list is deleted.By this technical scheme, can realize the timing of data is upgraded, can also improve the efficient of data run simultaneously.
By data-updating method provided by the invention, can under the situation that high concurrent operations produces, guarantee upgrading in time of data, improve the operational efficiency of system, guarantee system data consistance, safety, do not lose.
Fig. 2 shows the block diagram of data update apparatus according to an embodiment of the invention.
As shown in Figure 2, the invention provides a kind of data update apparatus 200, comprising: temporary module 202, the incremental data that the operation of at every turn specific data in the original table being carried out is produced is stored in the scratch list respectively; Update module 204 is upgraded the value of the described specific data in the described original table according to described incremental data.By this technical scheme, use all incremental datas that specific data is upgraded by scratch list, can the raising system efficient of operation, guarantee the safety of system data.
In technique scheme, when the operation to specific data was cancelled, temporary module 202 was also stored the opposite number of being cancelled of operating the incremental data that produces of stating as new incremental data.By this technical scheme, simplified the algorithm and the operation of Data Update, improved operational efficiency simultaneously, guarantee the safety of data.
In technique scheme, the incremental data summation that update module 204 produces all operations of being stored to specific data, and use the result of summation that the value of specific data is upgraded.By this technical scheme, can realize only coming specific data is upgraded with single job, improved the efficient of Data Update.
In technique scheme, between the result that update module 204 will be sued for peace and the value of specific data and as the value of specific data.
In technique scheme, do not finish in described renewal, and described user is during to the inquiry of described specific data, with between the value of the result of described summation and described specific data with offer the user.In the technical program, be about to the data of described specific data in original table and scratch list and carry out addition, as user's Query Result.
In technique scheme, update module 204 is upgraded the specific data that is arranged in original table, and after upgrading, by temporary module 202 incremental data in the described scratch list is deleted regularly or after the scheduled operation of described original table is finished.By this technical scheme, can realize the timing of data is upgraded, can also improve the efficient of data run simultaneously.
By data update apparatus provided by the invention, can under the situation that high concurrent operations produces, guarantee upgrading in time of data, improve the operational efficiency of system, guarantee system data consistance, safety, do not lose.
Further describe the technical scheme of embodiments of the invention below in conjunction with Fig. 3 and Fig. 4.
Fig. 3 shows the Data Update process flow diagram of data-updating method according to an embodiment of the invention.
As shown in Figure 3, this programme mainly utilizes database technology to realize consistance and efficient.Main thought is that hot spot data is disperseed, and the operation of upgrading hot spot data is changed to operation to incremental data, can guarantee to increase not competition of operation like this, can guarantee operating efficiency.Simultaneously, the affairs that are saved in incremental data in the database are same affairs with the transaction operation, do not have the inconsistent situation of data.In addition, by modification, can guarantee the Data Update effect of reaction in time to the inquiry service of hot spot data.Regularly incremental data is gathered by the timed task service at last and merge the consistance that the back guarantees data.Its process flow diagram comprises as shown in Figure 3:
Step 302 is collected data variation increment in the transaction, and the operation that will upgrade hot spot data like this changes to the operation to incremental data, assurance operating efficiency;
Step 304, insert in trade transactions is convenient to specific data is upgraded to temporary center like this with the data variation increment;
Step 306, timed task is synchronized to temporal data in the raw data table, periodically incremental data is gathered by the timed task service and merges the consistance that the back guarantees data.
Technical scheme of the present invention mainly contains the following aspects:
First is the design of database
Come the separate data visit by the design scratch list structure similar to the focus critical data.The scratch list structure comprises the main information of hot spot data and event information takes place and the transaction unique identification.The list structure of account balance (supposition table name be called accountbal) as follows for example:
| Account (account) | Remaining sum (balance) |
| |
Corresponding scratch list structure (the supposition table name is accountbalbuf) as follows.
| Transaction unique identification (id) | Account (account) | Amount of money change (delta) | Running time (optime) |
| | | |
The unique identification of wherein concluding the business is the differentiation of each business, and amount of money change is that the increment of this transactions impact account balance, running time are the holding time of this transaction record.More than field in each attribute bracket represent field name.Following statement is used in the renewal of account balance: update accountbalset balance=balance+@mny where account=@acc; In scratch list, increase the statement of incremental data: insert into accountbalbuf (id, account, delta, optime) values (' trans000001 ', ' A0001 ', 100, ' 2010-09-0315:21:32 ').
Second is the renewal and the inquiry of data
Modification to data takes place in transaction, in a transaction, needs the numerical value of change hot spot data, finishes according to following steps:
1) determining in the transaction the more new increment content of data, is representing with positive number of increasing of record numerical value, makes the negative number representation of using that record reduces;
2) if exist a plurality of modifications to require situation to merge the incremental data that same object requires to an object, otherwise record respectively;
3) replace record in the update original table, with the 2 incremental data insert that obtain are in scratch list in steps, inferior operating in the trade transactions submitted to.
When transaction cancellation during to the modification of data, the influence of delete deletion transaction to data do not used in transaction cancellation operation, is that the New Transaction of increment is handled with the transaction cancellation as the increment opposite number with transaction, and the same transaction generation of process is described to the modification of data.
When data query, need comprise data in the original table and the data in the scratch list simultaneously, with the data addition in two tables as net result.The inquiry of for example going up the account balance in the example will be revised as select sum (balance) from (select banance from accountbal whereaccount=@acc union all select sum (delta) balance from accountbalbuf whereaccount=@acc); Can guarantee the result after the transaction data of having submitted to can be embodied as renewal like this.
The 3rd for guaranteeing the consistance of data
This programme provides the timed task service, carry out the scratch list data to original table synchronous (trace interval can be configured to satisfy the space requirement of different business generation frequency) in certain time interval (for example 1 minute), concrete operating process comprises as shown in Figure 4:
Step 402, timing services inquiry scratch list judges whether there are the generation data in the scratch list, data if there is no take place, then do not operate; If exist data taking place, then enters next step;
Whetherstep 404 exists corresponding data in the inquiry raw data table;
Step 406 if there is corresponding data in the original table, is updated in the original table after then incremental data being gathered;
Step 408, if there is not corresponding data in the original table, explanation is to occur first, then forms the insert statement data sink General Logistics Department in the scratch list is increased in the original table;
Step 410, after renewal is finished, corresponding data in the deletion scratch list.
When the timing services task is carried out, concurrent mistake occurs and cause deleting not synchrodata, need in inquiry and cancel statement, add time conditions and be controlled.The scanning statement is: selectaccount, sum (delda) from accountbalbuf where optime<@currtime; Cancel statement is delete from accountbalbuf where optime<@currtime, and wherein De @currtime is point at the same time in inspect statement and the cancel statement.
Below with form the technical scheme of embodiments of the invention is described in detail in conjunction with the accompanying drawings, by data-updating method provided by the invention and device, can under the situation that high concurrent operations produces, both guarantee operational efficiency, can guarantee data security again and not lose, and under the concurrent situation of height, obtain and the identical operational efficiency of single user's scene, thereby improved the availability of system greatly.The present invention can support the increase of the hot spot data that multiple business causes well and reduce operation, is applicable to the multiple scene that high concurrent renewal operation is arranged.
The above is the preferred embodiments of the present invention only, is not limited to the present invention, and for a person skilled in the art, the present invention can have various changes and variation.Within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.