WO2011120452A2 - 更新数据的方法和控制装置 - Google Patents

更新数据的方法和控制装置 Download PDF

Info

Publication number
WO2011120452A2
WO2011120452A2 PCT/CN2011/073611 CN2011073611W WO2011120452A2 WO 2011120452 A2 WO2011120452 A2 WO 2011120452A2 CN 2011073611 W CN2011073611 W CN 2011073611W WO 2011120452 A2 WO2011120452 A2 WO 2011120452A2
Authority
WO
WIPO (PCT)
Prior art keywords
resource manager
data
transaction log
transaction
primary
Prior art date
Application number
PCT/CN2011/073611
Other languages
English (en)
French (fr)
Other versions
WO2011120452A3 (zh
Inventor
陶建波
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to PCT/CN2011/073611 priority Critical patent/WO2011120452A2/zh
Priority to CN2011800006943A priority patent/CN102203779B/zh
Publication of WO2011120452A2 publication Critical patent/WO2011120452A2/zh
Publication of WO2011120452A3 publication Critical patent/WO2011120452A3/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1474Saving, restoring, recovering or retrying in transactions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1471Saving, restoring, recovering or retrying involving logging of persistent data for recovery

Definitions

  • the present invention relates to the field of data management and, more particularly, to a method and control apparatus for updating data in the field of data management. Background technique
  • the two-phase commit protocol is currently mainly used.
  • the transaction manager sends pre-execution commands to all devices.
  • the transaction manager sends a corresponding command to all resource managers involved in the transaction, based on the resource manager's response to the pre-execution operation. That is, when any resource manager pre-execution operation fails and a negative response is made, the transaction manager sends a rollback command to all resource managers involved, returning to the state before the data update; when all resource managers pre-execute the operation successfully When a positive response is made, all resource managers involved in the transaction manager command commit the transaction and update the data.
  • the two-phase commit protocol can reduce the probability of data inconsistency caused by partial failure due to data structure, primary key conflicts, etc., there is still the possibility of data inconsistency. Because in the second phase, when the transaction manager sends a commit command to the resource manager, a network exception or resource manager exception may occur, causing some resource manager submission failures. Thus, although the pre-execution is successful, the commit error does not guarantee data consistency. Especially when the network quality is low and the equipment involved is large, it is more likely to cause data inconsistency.
  • the embodiment of the invention provides a method and a control device for updating data, which can solve the problem of data inconsistency caused by an error in the submission process, so that the existence of the error can be easily found in the submission process, and the inconsistent data can be repaired. Ensure data consistency across multiple devices.
  • an embodiment of the present invention provides a method for updating data, including: when a pre-execution operation of a primary resource manager and a secondary resource manager is successful, recording a transaction log on a primary resource manager; to a secondary resource manager Sending a commit command, and determining whether the commit is successful from the resource manager; if any one from the resource manager is not successfully submitted, retaining the transaction log to match the transaction log and the data of the primary resource manager
  • the data of the main resource manager is inconsistent and is corrected from the data of the resource manager.
  • an embodiment of the present invention provides a control apparatus for updating data, including: a recording module, configured to record on a primary resource manager when a pre-execution operation of a primary resource manager and a resource manager is successful a transaction log; a determination module, configured to send a commit command to the slave resource manager, and determine whether the commit is successful from the resource manager; the first retention module is configured to reserve the transaction if any one of the resource managers does not commit successfully The log, to correct the data from the resource manager that is inconsistent with the data of the main resource manager according to the transaction log and the data of the main resource manager.
  • the transaction log of the auxiliary correction since the transaction log of the auxiliary correction is recorded on the primary resource manager, the existence of data inconsistency in the submission process can be easily found based on the transaction log, and can be based on the transaction log and the main resource management. Data from the device for data correction. In this way, the data from the resource manager that is inconsistent with the data of the main resource manager can be corrected, so that even if an error occurs during the submission process, the data from the resource manager can be restored to the same state as the data of the main resource manager. To ensure data consistency.
  • FIG. 1 is a schematic structural diagram of a system for performing distributed transaction processing according to an embodiment of the present invention.
  • FIG. 2 is a flow chart of a method of updating data in accordance with an embodiment of the present invention.
  • FIG. 3 is a flow chart of another method of updating data in accordance with an embodiment of the present invention.
  • FIG. 4 is a flow diagram of a transaction processing method including updating a transaction log, in accordance with an embodiment of the present invention.
  • FIG. 5 is a sequence diagram showing an example of a normal execution of a commit operation according to an embodiment of the present invention.
  • FIG. 6 is a flow chart of a method of processing a transaction log in accordance with an embodiment of the present invention.
  • FIG. 7 is a structural block diagram of a control apparatus for updating data according to an embodiment of the present invention.
  • FIG. 8 is a block diagram showing the structure of another control device for updating data according to an embodiment of the present invention. detailed description
  • system 100 includes control device 110, a plurality of resource managers, and a transaction initiator 130.
  • the same data is stored in a plurality of resource managers which perform operations of the same transaction based on the control of the control device 110, that is, these resource managers are resource managers involved in the same transaction.
  • these resource managers are resource managers involved in the same transaction.
  • the control device 110 needs to perform updates such as modification, addition, deletion, etc. on the data in the resource manager, since the resource manager manages the same data, it is necessary to perform the same operation in synchronization to maintain data consistency.
  • These resource managers can be divided into a primary resource manager 120 and a secondary resource manager 1 to N (N is an integer greater than or equal to 1).
  • the resource manager in the same logical subnet as the device where the transaction initiator 130 is located may be set as the primary resource manager 120, or may be The resource manager with the closest physical distance of the device where the transaction initiator 130 is located is set as the main resource manager 120.
  • any one of the resource managers may be set as the main resource manager 120.
  • the master resource manager 120 and the slave resource managers 1 to N each manage their own databases, and add, delete, insert, modify, substitute, and the like update operations on the data therein.
  • a transaction log is stored on the main resource manager 120. The data from the resource manager can be corrected by the transaction to achieve data consistency, which will be described in detail below.
  • Control device 110 can be further divided into transaction manager 112 and transaction log processor
  • control device 110 is still described as a main body without being limited by the functional division of the control device 110.
  • the transaction initiator 130 is responsible for business processing and is the initiator of the transaction.
  • the transaction initiator 130 can provide a user interface to the user; the data can be written to the resource manager by the transaction manager 112 in the control device 110; the transaction-related information can be communicated to the transaction manager 112 to command the primary resource manager 120 records the transaction log; the correction command can also be constructed based on the information extracted from the transaction log by the transaction log manager 114 in the control device 110, and then corrected by the transaction manager 112.
  • the method 200 includes: in S210, when the pre-execution operation of the primary resource manager and the secondary resource manager is successful, the control device 110 commands the transaction log to be recorded on the primary resource manager; in S220, the control device 110 proceeds to the secondary resource manager Sending a commit command, and determining whether the commit is successful from the resource manager; in S230, if any one from the resource manager is not successfully submitted, the transaction log is retained to be based on the transaction log and the data of the primary resource manager, Corrected from the resource manager's data that is inconsistent with the primary resource manager's data.
  • the control device 110 commands the primary resource manager 120 and performs pre-execution operations from the resource managers 1 to N.
  • the control device 110 instructs the main resource manager 120 to record the transaction log, and instructs the resource manager 1 to N to perform the commit operation, thereby according to the slave resource manager.
  • the response returned by 1 to N determines whether the submission from Resource Manager 1 to N is successful. If there is an unsuccessful submission from the resource manager 1 to N, the control device 110 instructs the main resource manager 120 to retain the recorded transaction log so that it can be based on the transaction log and based on the data of the main resource manager.
  • the data of the main resource manager is inconsistent and is corrected from the data of the resource manager to maintain data consistency.
  • the method for updating data provided by the embodiment of the present invention, since the transaction log of the auxiliary correction is recorded on the primary resource manager, the existence of data inconsistency in the submission process can be easily found based on the transaction log, and can be based on the transaction log to the main
  • the data of the resource manager is subject to data correction. In this way, the data from the resource manager that is inconsistent with the data of the main resource manager can be corrected, so that even if an error occurs during the submission process, the data from the resource manager can be restored to the same state as the data of the main resource manager. To ensure data consistency.
  • the transaction log can characterize the characteristics of the currently executing transaction.
  • the current transaction is which tables in the database, which records are updated, and so on.
  • the data type and data identification information of the current transaction may be recorded as a transaction log on the primary resource manager 120.
  • the control device 110 can instruct the primary resource manager 120 to record the data type and data identification information of the current transaction as a transaction log.
  • the data type and data identification information may be information that is transmitted by the transaction initiator 130 to the control device 110, or may be information that is actively extracted by the control device 110 based on the transaction.
  • the data type can indicate which tables in the database are being manipulated (e.g., update operations), and the data identification information can indicate which records in the table are being manipulated.
  • the data type of the transaction is a table of subscriber information
  • the data identification information of the transaction is the telephone number of the subscriber
  • the record is identified by the telephone number.
  • the data type is Object1 and the data identification information is 1.
  • the data type and data identification information can be extracted directly by the control device 110. By recording the data type and data identification information, it is possible to determine what the current transaction is, so that the transaction log can be recorded based on this.
  • a commit command is sent to the slave resource manager, and it is determined whether all submissions from the resource manager are successful.
  • the control device 110 commands the submission operation from the resource managers 1 to N, and receives responses from the resource managers 1 to N, and determines whether the submission is successful by the response.
  • S220 is executed after S210 in this example, S220 can also be executed before S210, and can also be executed simultaneously with S210. S210 and S220 may be executed after the pre-execution operations of the primary resource manager 120 and the resource managers 1 to N are successful. Therefore, the scope of protection of the invention of S210 is not limited.
  • control device 110 may determine the corresponding slave resource management.
  • the submission was unsuccessful. This unsuccessful may be due to a network exception that does not receive a commit command or a commit command error from the resource manager, or it may be due to an unsuccessful commit from a resource manager exception (such as a power outage, a crash, etc.).
  • the subsequent correction may be a correction made manually by the transaction log.
  • the existence of data inconsistency can be automatically and conveniently determined according to the record of the transaction log, and the data log can be used to find out which data needs to be corrected, thereby simplifying the data modification process. .
  • the subsequent correction may also be an automatic correction by the control device 120 based on the transaction log, so that the efficiency of data correction can be improved without manual participation.
  • the data type and the data identification information can be extracted from the transaction log, so that it is possible to determine what transaction needs to be completed, thereby constructing and correspondingly The corresponding correction command.
  • the correction command may first delete the data in the corresponding record of the corresponding table, and then insert the new data into the corresponding record of the corresponding table.
  • the correction command may be constructed by the transaction initiator 130 or may be constructed by the control device 110 (e.g., the same interface is supported from the resource manager such that a generic correction command may be constructed by the control device 110). Since the correction command constructed by the transaction initiator 130 also needs to be executed by the control device 110, the execution of the data correction is controlled by the control device 110. From the perspective of the resource managers 1 to N, the source of the correction command can be considered to be the control device 110.
  • the data in the main resource manager 120 needs to be utilized, and the data managed by the main resource manager 120 is taken as the standard. For example, based on the data type and data identification information in the transaction log, corresponding data can be found in the primary resource manager 120, and the data managed from the resource manager is corrected based on the data.
  • the data that is valid may be the data submitted by the primary resource manager, or may be the data that is rolled back by the primary resource manager.
  • control device 110 can transmit a correction command to all of the slave resource managers 1 to N to instruct it to correct or re-execute the data update operation and the like. For the sub-resources that have been successfully submitted, only the submitted data needs to be overwritten, and for the sub-resources that have not been submitted successfully, the data will be corrected.
  • the control device 110 may also send a correction command from the resource manager only to the data that is inconsistent with the data of the primary resource manager 120. At this time, the control device 110 may consider that the slave resource manager submitting the response exception is a slave resource manager that is inconsistent with the master resource manager 120.
  • the transaction log with the auxiliary correction since the transaction log with the auxiliary correction is recorded on the primary resource manager, it is possible to determine which tables are based on the data type and the data identifier in the transaction log when the error occurs in the submission. Which records are corrected, and based on the data managed by the main resource manager, which data is corrected, thereby completing the correction of the data managed from the resource manager. In this way, even if an error occurs during the submission process, the data managed from the resource manager can be automatically restored to the same state as the data of the main resource manager by means of the transaction log, thereby ensuring data consistency and due to the control device. Automatic data repair based on transaction log Positive, the efficiency of data correction is improved.
  • FIG. 3 is a flow diagram of another method 300 of updating data in accordance with an embodiment of the present invention.
  • S310 and S320 of method 300 of FIG. 3 are substantially identical to S210 and S220 of method 200 of FIG.
  • the transaction log is retained in S330 to be corrected based on the transaction log and the data of the main resource manager 120.
  • control device 110 sends a rollback command to primary resource manager 120.
  • the data from the resource manager can be corrected according to the transaction log retained in S330 and the data that is rolled back by the main resource manager 120.
  • control device 110 corrects the data from the resource manager that is inconsistent with the data of the main resource manager 120 based on the transaction log and the data that the main resource manager 120 rolls back.
  • the correction process can refer to the description in S230 above.
  • control device 110 determines whether the correction is successful. For example, control device 110 may receive a response from a resource manager that performs a corrective action, may carry information on whether the correction was successful, or may carry the corrected result. Based on the response returned, determine if the correction was successful.
  • the transaction log may store a transaction with an error in the submission process. If the modification is successful, it indicates that the data managed by the primary resource manager 120 is consistent with the data managed from the resource managers 1 to N, and the transaction log may be deleted, thereby indicating that the transaction log The transaction corresponding to the transaction log has completed successfully. If the correction is unsuccessful and the data inconsistency still exists, you need to keep the transaction log to process the transaction corresponding to the transaction log again in subsequent operations.
  • the control device 110 transmits a commit command to the main resource manager 120 in S360. Since the submission from both resource managers 1 to N is successful, the primary resource manager 120 also needs to perform the commit operation.
  • the primary resource manager 120 commits successfully while deleting the transaction log, preventing erroneous logging of correctly executed transactions.
  • control device 110 may first send a pre-execution command to delete the transaction log to the main resource manager 120.
  • the main resource manager 120 performs the commit operation again, and deletes the transaction log while the commit is successful.
  • the process of submitting data is executed concurrently with the process of deleting the transaction log.
  • control device 110 periodically checks whether there is a transaction log.
  • the primary resource manager 120 can store the transaction log in a transaction log table, and the transaction log in the transaction log table can be updated and changed as the operation proceeds, as will be described in conjunction with FIG.
  • Control device 110 can check if there is a transaction log in it by looking up the transaction log table.
  • the control device 110 may perform periodic inspections at equal time intervals or periodically at variable time intervals.
  • the control device 110 reads a transaction log from the transaction log table, and in accordance with the transaction indicated by the transaction log, the primary resource manager 120 indicates in the transaction log. Under the data, the corresponding data from the resource manager is corrected.
  • S370 and S375 are executed after S310 in Fig. 3, S370 and S375 can also be executed at any time.
  • the transaction log since the auxiliary modified transaction log is recorded on the primary resource manager, the transaction log is retained in the case where the data inconsistency still exists, and the transaction log is deleted if the data inconsistency is resolved. , the transaction log is dynamically changed, so that the data can be corrected based on the existing transaction log and subject to the data indicated by the main resource manager in the transaction log. In this way, even if the transaction log is not processed or processed in time, it can be processed in subsequent operations, thus ensuring data consistency. And, with the help of the transaction log For automatic correction, you can improve the efficiency of data recovery without manual intervention.
  • FIG. 4 shows a flow diagram of a transaction processing method 400 including updating a transaction log, in accordance with an embodiment of the present invention.
  • the transaction initiator 130 initiates a transaction such as a data update, and the transaction begins.
  • the control device 110 transmits a pre-execution command to the primary resource manager 120 and the secondary resource managers 1 to N, thereby pre-executing data operations on the primary resource manager 120 and the secondary resource managers 1 to N.
  • control device 110 determines whether the pre-execution operations of the primary resource manager 120 and the secondary resource managers 1 to N are successful based on the returned response.
  • control device 110 sends a rollback command to the pre-executed resource manager to return to the state before the pre-execution.
  • control device 110 returns a transaction execution failure to transaction initiator 130. And in S470, the transaction initiated by the transaction initiator 130 ends.
  • control device 110 sends a commit command to the slave resource managers 1 to N to commit the transactions from the resource managers 1 to N.
  • control device 110 receives the responses from the resource managers 1 to N, and determines whether all of the submissions from the resource managers 1 to N are successful.
  • the transaction manager 112 sends a rollback command to the primary resource manager 120 to roll back the transaction on the primary resource manager 120.
  • the delete operation of the transaction log is pre-executed on 120.
  • control device 110 sends a commit command to the primary resource manager 120, commits the transaction on the primary resource manager 120, and deletes the transaction log while the submission is successful.
  • control device 110 returns to transaction initiator 130 that the transaction was successful. And in S470, the transaction initiated by the transaction initiator 130 ends.
  • FIG. 1 A method 600 of processing a transaction log in accordance with an embodiment of the present invention is described in conjunction with FIG. Further, in conjunction with FIG. 1, a more detailed description is made by the transaction manager 112 and the transaction log processor 114 included in the control device 110.
  • the transaction manager 112 can be used to control and manage the operation of the resource manager, send commands to the resource manager, and receive responses from the resource manager.
  • the transaction log processor 114 can be used to manage the transaction log, extract information from the transaction log, submit the extracted information to the transaction initiator 130 to construct a revision command, or submit the extracted information to the transaction manager 112 to construct a modification command.
  • the transaction initiator 130 submits data and data type and data identification information to the transaction manager 112.
  • the data has good structuring such as XML, SQL (Structured Query Language)
  • the data type and data identification information may not be submitted to the transaction manager 112, but the transaction manager 112 may Data is automatically extracted.
  • transaction manager 112 saves the data type and data identification information to the transaction.
  • transaction manager 112 sends data to primary resource manager 120 for pre-execution operations.
  • the transaction manager 112 sends data from the resource managers 1 to N for pre-execution operations.
  • the S550 can also be executed before S540, and can also be executed simultaneously with S540.
  • the transaction manager 112 commands the main resource manager in the new transaction. 120 saves transaction-related context information (eg, data type and data identification information) in the transaction log.
  • transaction-related context information eg, data type and data identification information
  • the transaction manager 112 sends a commit command to the slave resource managers 1 through N to commit the transactions from the resource managers 1 through N.
  • the transaction manager 112 instructs the primary resource manager 120 to pre-delete in the transaction initiated by the transaction initiator 130. Current affairs.
  • transaction manager 112 sends a commit command to primary resource manager 120 to commit the transaction in primary resource manager 120.
  • the operation of deleting the transaction log is performed in the transaction of the main resource manager 120, so that the deletion operation is completed together with the commit operation.
  • the transaction manager 112 returns to the transaction initiator 130. Perform a successful response.
  • transaction log processor 114 can periodically scan the transaction log table to process transaction logs that are still present for more than a certain period of time.
  • the transaction processor 114 sequentially reads a transaction log from the transaction table.
  • transaction log processor 114 extracts the data type and data identification information in the transaction log.
  • the transaction log processor 114 may take the data type and the data identification information as parameters by which the transaction initiator 130 is used to construct an interface for modifying the command or pass to the transaction manager 112.
  • the transaction initiator 130 or transaction manager 112 constructs a correction command to repair the data based on the data of the primary resource manager 120.
  • the transaction initiator 130 can know the type or interface of the different slave resource manager, if the transaction has a good structure, such as in the case where the data has no complicated association or cascade deletion, the transaction log processor 114 can take the data.
  • the type and data identification information is passed to the transaction manager 112, which constructs the revision commands common to the resource manager without having to call back the interface of the transaction initiator 130.
  • the control device 110 (specifically, the transaction manager 112) can control the execution of the correction command from the resource manager. Therefore, it can be considered that the control device 110 manages according to the transaction log and the main resource. The data managed by the device to correct the data managed from the resource manager.
  • the transaction manager 112 transmits a correction command received from the transaction initiator 130 or constructed by itself, and performs a data correction operation on the slave resource manager.
  • transaction manager 112 determines if the data modification from the resource manager was successful. If the corrective operation from the resource manager is successful, then in S660, the transaction log processor 114 deletes the current transaction log, otherwise in S670, the transaction log processor 114 does not delete the transaction log for retrying again in the next cycle.
  • FIG. 7 is a block diagram showing the structure of a control apparatus 700 for updating data according to an embodiment of the present invention.
  • the control device 700 includes a recording module 710, a determination module 720, and a first retention module 730.
  • the logging module 710 can be configured to log the transaction log on the primary resource manager when the primary resource manager and the pre-execution operation from the resource manager are successful.
  • the determination module 720 can be configured to send a commit command to the slave resource manager and determine if the commit is successful from the resource manager.
  • the first reservation module 730 can be configured to retain the transaction log if any one of the resource managers does not commit successfully, to inconsistent with the data of the primary resource manager according to the transaction log and the data of the primary resource manager. The data is corrected.
  • the foregoing and other operations and/or functions of the recording module 710, the determining module 720, and the first retaining module 730 may refer to S210, S220, and S230 in the method 200 of updating data described above. To avoid repetition, details are not described herein again.
  • the control apparatus can record the auxiliary corrected transaction log on the primary resource manager, so that the existence of data inconsistency in the submission process can be easily found based on the transaction log, and can be based on the transaction log to the primary resource manager.
  • the data is subject to correction for inconsistent data. In this way, the data from the resource manager that is inconsistent with the data of the main resource manager can be corrected, so that even if an error occurs during the submission process, the data from the resource manager can be restored to the same state as the data of the main resource manager. To ensure data consistency.
  • Figure 8 is a block diagram showing the structure of a control device 800 for updating data according to an embodiment of the present invention.
  • the recording module 810, the determining module 820, and the first retention module 830 of the control device 800 are substantially the same as the recording module 710, the determination module 720, and the first retention module 730 of the control device 700 of FIG.
  • the recording module 810 can be configured to record the data type and data identification information of the current transaction as a transaction message on the primary resource manager.
  • Control device 800 may also include a first transmitting module 840, in accordance with an embodiment of the present invention.
  • the first sending module 840 can be configured to send a rollback command to the primary resource manager after the first reservation module 830 retains the transaction log. In this way, the data from the resource manager can be corrected based on the transaction log and the data after the main resource manager rolls back, thereby maintaining the data managed by the resource manager in a state before the transaction is executed.
  • control device 800 may further include a first deletion module 850 and a second retention module 860.
  • the first delete module 850 can be used to delete the transaction log if the correction is successful.
  • the second reservation module 860 can be used to retain the transaction log if the correction is unsuccessful.
  • control device 800 may further include a second sending module 870 and a second deleting module 880.
  • the second sending module 870 can be configured to send a submit command to the primary resource manager if the submission is successful from the resource manager.
  • the second deletion module 880 can be used in the main resource management The transaction log is deleted when the processor submits successfully.
  • Control device 800 may also include an inspection module 890 and a correction module 895, in accordance with an embodiment of the present invention.
  • Inspection module 880 can be used to periodically check for the existence of a transaction log.
  • the correction module 890 can be used to modify the data from the resource manager that is inconsistent with the data of the primary resource manager based on the transaction log and the data of the primary resource manager if the transaction log exists.
  • the above and other operations and/or functions of the first sending module 840, the first deleting module 850, the second deleting module 860, the second sending module 870, the second deleting module 880, the checking module 890, and the correcting module 895 may refer to the above update.
  • Corresponding descriptions in S310 to S375 and method 400 in the method 300 of the data are not described herein again in order to avoid redundancy.
  • the recording module 810 of the control device records the data type and the data identification information on the main resource manager as a transaction log, so that the correction module 895 can be based on the data type and data of the transaction log when an error occurs in the submission.
  • the identification determines which records of which tables are corrected, and based on the data managed by the primary resource manager, determines which data is modified, thereby completing the automatic correction of the data managed from the resource manager.
  • the first reservation module 830 and the second reservation module 860 in the control device retain the transaction log if the data inconsistency still exists, and the first deletion module 850 and the second deletion module 880 delete the transaction log if the data inconsistency is resolved.
  • the transaction log is dynamically changed, so that the correction module 895 can correct the data based on the existing transaction log and subject to the data indicated by the primary resource manager in the transaction log.
  • the data managed by the resource manager can be automatically restored to the same state as the data of the main resource manager by means of the transaction log, thereby ensuring data consistency. And even if the transaction log is not processed or processed in time, it can be processed in subsequent operations, and the consistency of the data is greatly guaranteed.
  • the automatic correction by means of the transaction log can improve the efficiency of data recovery without manual intervention.
  • RAM random access memory
  • ROM read only memory
  • electrically programmable ROM electrically erasable programmable ROM
  • registers hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art. in.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

公开了更新数据的方法和控制装置。该方法包括:当主资源管理器和从资源管理器的预执行操作成功时,在主资源管理器上记录事务日志;向从资源管理器发送提交命令,并确定从资源管理器是否都提交成功;如果从资源管理器存在任何一个没有提交成功,则保留所述事务日志,以根据事务日志和所述主资源管理器的数据,对与主资源管理器的数据不一致的从资源管理器的数据进行修正。基于该技术方案,由于在主资源管理器上记录有辅助修正的事务日志,可以基于事务日志和主资源管理器的数据来进行数据修正。即使在提交过程中出现错误,该方法可以将从资源管理器的数据恢复到与主资源管理器的数据相同的状态,从而保证数据的一致性。

Description

更新数据的方法和控制装置 技术领域
本发明涉及数据管理领域, 并且更具体地, 涉及数据管理领域中更新数 据的方法和控制装置。 背景技术
随着计算机系统越来越复杂, 为了提高数据的可靠性或者读取数据时的 性能, 常常将一份数据保存在多个设备上。 例如, 在现有的电信系统中, 不 仅需要将用户签约信息保存在计费系统中,还需要将其保存在呼叫控制系统 中。 即使在同一个系统, 在容灾组网、 负载均衡组网的情况下, 也会把相同 的数据存放在多个设备上。
当把数据存放在多个设备上时, 会面临数据一致性的问题。 当需要在多 个设备上同时更新数据时, 需要该数据更新操作在这些设备上要么都成功、 要么都失败, 以保持数据的一致性。 这种操作方式通常被称为分布式事务处 理。
在分布式事务处理中, 目前主要是使用两阶段提交协议。在第一阶段中, 事务管理器向所有设备发送预执行命令。 在第二阶段中, 事务管理器根据资 源管理器对预执行操作的响应, 向该事务中涉及的所有资源管理器发送相应 命令。 即, 当任一资源管理器预执行操作失败而作出否定响应时, 事务管理 器向涉及的所有资源管理器发送回滚命令, 返回到数据更新前的状态; 当所 有资源管理器预执行操作成功而作出肯定响应时, 事务管理器命令涉及的所 有资源管理器提交该事务, 对数据进行更新。
虽然两阶段提交协议能够降低由于数据结构、主键沖突等原因导致的部 分失败而引起的数据不一致的几率, 但是依旧存在数据不一致的可能。 因为 在第二阶段中, 事务管理器向资源管理器发送提交命令时, 可能出现网络异 常或资源管理器异常, 从而导致部分资源管理器提交失败。 这样, 虽然预执 行都成功, 但是提交错误, 仍然不能保证数据的一致性。 特别是在网络质量 比较低、 所涉及的设备较多时, 更容易造成数据不一致的问题。
针对在提交过程中出现的数据不一致, 目前很难自动发现这种错误的存 在, 也很难确定需要对哪些数据进行修正, 并且在修复的情况下也只能通过 手工修复而不能自动修复, 从而使得修复过程繁瑣 发明内容
本发明实施例提供了更新数据的方法和控制装置, 能够解决提交过程出 现错误而导致的数据不一致的问题,使得可以在提交过程中容易地发现错误 的存在, 并使不一致的数据得以修复, 从而保证多个设备上数据的一致性。
一方面, 本发明实施例提供了一种更新数据的方法, 包括: 当主资源管 理器和从资源管理器的预执行操作成功时, 在主资源管理器上记录事务曰 志; 向从资源管理器发送提交命令, 并确定从资源管理器是否都提交成功; 如果从资源管理器存在任何一个没有提交成功, 则保留所述事务日志, 以根 据事务日志和所述主资源管理器的数据,对与主资源管理器的数据不一致的 从资源管理器的数据进行修正。
另一方面, 本发明实施例提供了一种用于更新数据的控制装置, 包括: 记录模块, 用于当主资源管理器和从资源管理器的预执行操作成功时, 在主 资源管理器上记录事务日志;确定模块,用于向从资源管理器发送提交命令, 并确定从资源管理器是否都提交成功; 第一保留模块, 用于如果从资源管理 器存在任何一个没有提交成功, 则保留事务日志, 以根据事务日志和主资源 管理器的数据,对与主资源管理器的数据不一致的从资源管理器的数据进行 修正。
基于本发明实施例提供的上述技术方案, 由于在主资源管理器上记录有 辅助修正的事务日志,基于事务日志可以容易地发现提交过程中数据不一致 的存在,并可以基于事务日志和主资源管理器的数据来进行数据修正。这样, 与主资源管理器的数据不一致的从资源管理器的数据可以得以修正,使得即 便在提交过程中出现错误,从资源管理器的数据也可以恢复到与主资源管理 器的数据相同的状态, 从而保证数据的一致性。 附图说明
为了更清楚地说明本发明实施例的技术方案, 下面将对实施例中所需要 使用的附图作筒单地介绍, 显而易见地, 下面描述中的附图仅仅是本发明的 一些实施例, 对于本领域技术人员来讲, 在不付出创造性劳动的前提下, 还 可以根据这些附图获得其他的附图。 图 1是根据本发明实施例的用于进行分布式事务处理的系统的结构示意 图。
图 2是根据本发明实施例的更新数据的方法的流程图。
图 3是根据本发明实施例的更新数据的另一方法的流程图。
图 4 是根据本发明实施例的包括更新事务日志的事务处理方法的流程 图。
图 5是根据本发明实施例的正常执行提交操作时的例子的时序图。
图 6是根据本发明实施例的处理事务日志的方法的流程图。
图 7是根据本发明实施例的用于更新数据的控制装置的结构框图。
图 8是根据本发明实施例的用于更新数据的另一控制装置的结构框图。 具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例是本发明的一部分实施例, 而不是 全部实施例。 基于本发明中的所述实施例, 本领域技术人员在没有做出创造 性劳动的前提下所获得的所有其他实施例, 都应属于本发明保护的范围。
首先, 结合图 1描述根据本发明实施例的用于进行分布式事务处理的系 统 100。
如图 1所示, 系统 100包括控制装置 110、 多个资源管理器和事务发起 者 130。
在多个资源管理器中存储有相同的数据, 它们基于控制装置 110的控制 而执行同一事务的操作, 即这些资源管理器是同一事务所涉及的资源管理 器。 当控制装置 110需要对资源管理器中的数据进行诸如修改、 添加、 删除 之类的更新时, 这些资源管理器由于管理着相同的数据, 需要同步进行相同 的操作, 以保持数据的一致性。
可以将这些资源管理器划分为主资源管理器 120和从资源管理器 1至 N ( N是大于等于 1的整数)。 例如, 当用户通过事务发起者 130提供的用户 接口输入操作数据时,可以将与事务发起者 130所在的设备处于同一逻辑子 网中的资源管理器设置为主资源管理器 120, 也可以将与事务发起者 130所 在的设备具有最近的物理距离的资源管理器设置为主资源管理器 120,当然, 还可以将其中任意一个资源管理器设置为主资源管理器 120。 主资源管理器 120和从资源管理器 1至 N各自管理自己的数据库,对其 中的数据进行添加、 删除、 插入、 修改、 替代等更新操作。 另外, 在主资源 管理器 120上, 除了存储有数据之外, 还存储有事务日志。 可以通过事务曰 志来修正从资源管理器中的数据以实现数据的一致, 这将在下文详细描述。
控制装置 110可以被进一步划分为事务管理器 112和事务日志处理器
114, 其具体操作将结合图 5和图 6进行描述。 在描述数据更新的方法时, 仍以控制装置 110作为主体进行描述, 而不受控制装置 110的功能划分的限 制。
事务发起者 130负责业务处理, 是事务的发起者。 事务发起者 130可以 向用户提供用户接口; 可以通过控制装置 110中的事务管理器 112将数据写 到资源管理器中; 可以把与事务有关的信息告诉事务管理器 112, 以命令主 资源管理器 120记录事务日志; 还可以根据控制装置 110中的事务日志管理 器 114从事务日志中提取的信息, 来构造修正命令, 再通过事务管理器 112 进行修正。
下面, 结合图 1的系统, 描述图 2中示出的根据本发明实施例的更新数 据的方法 200。
方法 200包括: 在 S210中, 当主资源管理器和从资源管理器的预执行 操作成功时, 控制装置 110命令在主资源管理器上记录事务日志; 在 S220 中, 控制装置 110向从资源管理器发送提交命令, 并确定从资源管理器是否 都提交成功; 在 S230中, 如果从资源管理器存在任何一个没有提交成功的, 则保留事务日志, 以根据事务日志和主资源管理器的数据, 对与主资源管理 器的数据不一致的从资源管理器的数据进行修正。
当主资源管理器 120和从资源管理器 1至 N需要执行数据更新事务时, 控制装置 110命令主资源管理器 120和从资源管理器 1至 N进行预执行操作。 当这些资源管理器返回的响应告诉控制装置 110预执行操作成功时, 控制装 置 110命令主资源管理器 120记录事务日志,并命令从资源管理器 1至 N执 行提交操作,从而根据从资源管理器 1至 N返回的响应来确定从资源管理器 1至 N是否都提交成功。如果有从资源管理器 1至 N提交不成功, 则控制装 置 110命令主资源管理器 120保留所记录的事务日志, 以使得可以根据事务 日志, 并以主资源管理器的数据为准, 对与主资源管理器的数据不一致的从 资源管理器的数据进行修正, 从而保持数据的一致性。 根据本发明实施例提供的更新数据的方法, 由于在主资源管理器上记录 有辅助修正的事务日志,基于事务日志可以容易地发现提交过程中数据不一 致的存在, 并可以基于事务日志, 以主资源管理器的数据为准, 来进行数据 修正。 这样, 与主资源管理器的数据不一致的从资源管理器的数据可以得以 修正, 使得即便在提交过程中出现错误, 从资源管理器的数据也可以恢复到 与主资源管理器的数据相同的状态, 从而保证数据的一致性。
接下来, 详细描述根据本发明实施例的 S210至 S230。
在 S210中, 当主资源管理器和从资源管理器的预执行操作成功时, 在 主资源管理器上记录事务曰志。
事务日志可以表征当前所执行的事务的特征。 例如, 当前事务是对数据 库中哪些表格、 哪些记录的数据进行更新等。
根据本发明的一个实施例, 可以在主资源管理器 120上将当前事务的数 据类型和数据标识信息记录为事务曰志。
控制装置 110可以命令主资源管理器 120将当前事务的数据类型和数据 标识信息记录为事务日志。 数据类型和数据标识信息可以是由事务发起者 130传递给控制装置 110的信息, 也可以是由控制装置 110根据事务而主动 提取出的信息。 数据类型可以指示是对数据库中的哪些表格进行操作(例如 更新操作), 数据标识信息可以指示是对表格中的哪些记录进行操作。
例如, 在电信系统中, 当需要更新与订户签约信息有关的数据时, 该事 务的数据类型是订户信息的表格, 该事务的数据标识信息是用户的电话号 码, 通过电话号码来标识记录。
再例如, 在以 XML ( Extensible Markup Language, 扩展标记语言)格式 化表达的数据中, 如下所示:
<Objectl>
<Keyl>l</Keyl>
<Fieldl>a</Fieldl>
<Field2>b</Field2>
<Field3>c</Field3>
</Objectl>
由该格式化的数据可知, 数据类型是 Objectl , 数据标识信息是 1。 该数 据类型和数据标识信息可以直接由控制装置 110提取出来。 通过记录数据类型和数据标识信息, 就可以确定当前的事务是什么, 从 而可以基于此来记录事务日志。
在 S220中, 向从资源管理器发送提交命令, 并确定从资源管理器是否 都提交成功。
控制装置 110命令从资源管理器 1至 N执行提交操作,并接收来自从资 源管理器 1至 N的响应, 通过响应来确定是否提交成功。
虽然在该例子中 S220在 S210之后执行,但是 S220也可以在 S210之前 执行, 还可以与 S210同时执行。 只要在主资源管理器 120和从资源管理器 1至 N的预执行操作都成功之后, 执行 S210和 S220即可。 所以, S210的 发明的保护范围不构成限制。
在 S230中, 如果从资源管理器存在任何一个没有提交成功的, 则保留 事务日志, 以根据事务日志和主资源管理器的数据, 对与主资源管理器的数 据不一致的从资源管理器的数据进行修正。
如果控制装置 110从任一从资源管理器接收到提交不成功的响应、 或者 没有接收到任何响应、 或者接收响应的时间超时、 或者返回响应内容错误, 则控制装置 110可以确定相应的从资源管理器提交不成功。 该不成功可能是 由于网络异常造成的从资源管理器没有接收到提交命令或提交命令错误,也 可能是由于从资源管理器异常 (例如断电、 死机等)造成的提交不成功。
当从资源管理器 1至 N没有都提交成功,所记录的事务日志就被保留下 来, 以辅助之后的修正。 根据事务日志, 可以容易地确定在提交过程中出现 了数据不一致, 并且可以容易地定位是哪些数据出现了不一致, 例如是哪些 表格中的哪些记录出现了不一致。
根据本发明的实施例, 之后的修正可以是人工参考事务日志进行的修 正。 此时, 相比于目前人工修正的方法, 可以根据事务日志的记载来自动且 方便地确定数据不一致的存在, 并可以基于事务日志来找到需要对哪些数据 进行修正, 从而筒化了数据修正过程。
根据本发明的实施例,之后的修正也可以是控制装置 120根据事务日志 进行的自动修正, 从而无需人工的参与, 可以提高数据修正的效率。
在控制装置 120进行的数据修正中, 可以从事务日志中提取数据类型和 数据标识信息, 从而可以确定需要完成什么事务, 由此可以构造出与相应事 务对应的修正命令。 例如, 修正命令可以是先删除对应表格的对应记录中的 数据, 再将新的数据插入到对应表格的对应记录中。 修正命令可以由事务发 起者 130来构造, 也可以由控制装置 110来构造(例如, 从资源管理器支持 相同的接口, 从而可以由控制装置 110构造通用的修正命令)。 由于事务发 起者 130构造的修正命令也需要交由控制装置 110来执行, 所以数据修正的 执行都是由控制装置 110来控制进行的。 从从资源管理器 1至 N的角度看, 修正命令的来源可以认为都是控制装置 110。
而用什么数据进行修正, 则需要借助于主资源管理器 120中的数据, 以 主资源管理器 120管理的数据为准。 例如, 根据事务日志中的数据类型和数 据标识信息, 可以在主资源管理器 120中找到相应的数据, 以该数据为准, 对从资源管理器管理的数据进行修正。 根据本发明的实施例, 为准的数据可 以是主资源管理器提交后的数据, 也可以是主资源管理器回滚后的数据。
进行修正时,控制装置 110可以向所有的从资源管理器 1至 N发送修正 命令以指示其修正或重新执行数据更新操作等。对于已提交成功的从资源管 理器只需对提交的数据进行覆盖即可, 而对于未提交成功的从资源管理器则 会对其中的数据进行修正。
控制装置 110也可以仅仅向与主资源管理器 120的数据不一致的从资源 管理器发送修正命令。 此时, 控制装置 110可以认为提交响应异常的从资源 管理器都是与主资源管理器 120不一致的从资源管理器。
另外, 进行修正时, 有可能从资源管理器管理着不同类型的数据库, 或 者其数据库具有不同的接口, 使得需要根据不同的资源管理器, 构造出与其 接口相适应的修正命令。 当然, 如果从资源管理器的数据库接口相同或可以 识别通用的命令, 则可以只构造一种修正命令或构成数据更新操作的通用命 令, 再分别发送给它们以执行修正。
根据本发明实施例提供的更新数据的方法, 由于在主资源管理器上记录 有辅助修正的事务日志, 可以在提交出现错误时, 基于事务日志中的数据类 型和数据标识来确定对哪些表格的哪些记录进行修正, 并基于主资源管理器 管理的数据来确定修正为哪些数据,从而完成对从资源管理器管理的数据的 修正。 这样, 即便在提交过程中出现错误, 借助于事务日志, 从资源管理器 管理的数据也可以自动恢复到与主资源管理器的数据相同的状态,从而可以 保证数据的一致性, 并且由于控制装置可以根据事务日志自动进行数据修 正, 使得数据修正的效率得以提高。
图 3是根据本发明实施例的更新数据的另一方法 300的流程图。 图 3的 方法 300的 S310和 S320与图 2的方法 200的 S210和 S220基本相同。
当在 S320中确定从资源管理器 1至 N存在任何一个没有提交成功时, 在 S330中保留事务日志, 以根据该事务日志和主资源管理器 120的数据来 进行纠正。
在 S335中, 控制装置 110向主资源管理器 120发送回滚命令。
这样, 可以根据 S330中保留的事务日志和主资源管理器 120回滚后的 数据, 对从资源管理器的数据进行修正。
由于从资源管理器 1至 N没有都提交成功,这可能意味着部分提交成功、 部分提交失败,也可能意味着都没有提交成功,这将造成数据不一致的风险。 此时, 由于主资源管理器 120还没有执行提交操作, 因此可以让主资源管理 器 120回滚到预执行操作前的状态, 从而以该状态为准进行数据的修复, 使 得无论从资源管理器 1至 N是否提交成功, 都可以保持在主资源管理器 120 回滚所恢复的状态中, 从而实现数据的一致。
在 S340中, 控制装置 110根据事务日志和主资源管理器 120回滚到的 数据,对与主资源管理器 120的数据不一致的从资源管理器的数据进行修正。 修正过程可以参考上述 S230中的描述。
修正之后, 在 S345中, 控制装置 110确定修正是否成功。 例如, 控制 装置 110可以接收来自进行修正操作的从资源管理器的响应, 在响应中可以 携带修正是否成功的信息, 也可以携带修正后的结果。 根据返回的响应, 确 定修正是否成功。
如果修正成功,则在 S350中删除事务日志。如果修正不成功,则在 S360 中保留事务曰志。
在事务日志中可以存储提交过程有错误的事务, 如果修正成功, 则说明 主资源管理器 120管理的数据和从资源管理器 1至 N管理的数据相一致,可 以删除该事务日志, 从而表明该事务日志对应的事务已成功完成。 而如果修 正不成功, 说明数据不一致还存在, 则还需要保留事务日志, 以在后续操作 中, 再次对该事务日志对应的事务进行处理。
当在 S320中确定从资源管理器 1至 N都提交成功时, 在 S360中, 控 制装置 110向主资源管理器 120发送提交命令。 由于从资源管理器 1至 N都提交成功,则主资源管理器 120也需要进行 提交操作。
在 S365中, 在主资源管理器 120提交成功时删除事务曰志。
主资源管理器 120提交成功的同时删除事务日志, 可以防止错误地记录 下正确执行的事务。
例如, 控制装置 110可以先向主资源管理器 120发送删除事务日志的预 执行命令, 当删除预执行成功时, 主资源管理器 120再进行提交操作, 并在 提交成功的同时删除事务日志。提交数据的进程与删除事务日志的进程并发 执行。
根据本发明的一个实施例, 在 S310之后, 在 S370中, 控制装置 110周 期性检查是否存在事务曰志。
主资源管理器 120可以将事务日志存储在事务日志表中, 该事务日志表 中的事务日志可以随着操作的进行而得以更新和改变, 这将结合图 4来进行 描述。
控制装置 110 可以通过查找事务日志表来检查是否在其中存在事务曰 志。 控制装置 110可以以等长的时间间隔来进行周期性检查, 也可以以变长 的时间间隔来进行周期性检查。
在 S375 中, 如果存在事务日志, 则根据该事务日志和主资源管理器的 数据, 对与主资源管理器的数据不一致的从资源管理器的数据进行修正。
事务日志的存在说明还有数据不一致的问题, 因此, 控制装置 110从事 务曰志表中读取一条事务曰志, 根据该事务曰志指示的事务, 结合主资源管 理器 120在该事务日志指示下的数据,对从资源管理器中的相应数据进行修 正。
虽然在图 3中 S370和 S375在 S310之后执行, 但是 S370和 S375也可 以在任何时刻执行。
根据本发明实施例提供的更新数据的方法, 由于在主资源管理器上记录 辅助修正的事务日志, 在数据不一致仍存在的情况下保留事务日志, 而在数 据不一致得以解决的情况下删除事务日志, 使得事务日志动态改变, 从而可 以基于现存的事务日志, 并以主资源管理器在事务日志指示下的数据为准, 来修正数据。 这样, 即便事务日志没有得到及时处理或处理错误, 也可以在 后续操作中继续处理, 从而可以保证数据的一致性。 并且, 借助于事务日志 来进行自动修正, 无需人工的干预, 可以提高数据修复的效率。
图 4示出了根据本发明实施例的包括更新事务日志的事务处理方法 400 的流程图。
在 S405中, 事务发起者 130启动诸如数据更新之类的事务, 事务开始。 在 S410中, 控制装置 110向主资源管理器 120和次资源管理器 1至 N 发送预执行命令,从而在主资源管理器 120和次资源管理器 1至 N上预执行 数据操作。
在 S415中, 控制装置 110根据返回的响应, 确定主资源管理器 120和 次资源管理器 1至 N的预执行操作是否都成功。
如果预执行存在任何一个没有成功, 则在 S420中, 控制装置 110向预 执行成功的资源管理器发送回滚命令, 以返回预执行前的状态。
在 S425中, 控制装置 110向事务发起者 130返回事务执行失败。 并在 S470中, 事务发起者 130启动的事务结束。
如果在 S415中确定预执行都成功, 则在 S430中, 在主资源管理器 120 上创建一个新事务。
在 S435 中, 在该新事务中执行事务日志的记录操作并提交该新事务, 以将事务日志写到事务日志表中。
在 S440中, 控制装置 110向从资源管理器 1至 N发送提交命令, 以提 交从资源管理器 1至 N上的事务。
在 S445中, 控制装置 110接收从资源管理器 1至 N的响应, 确定从资 源管理器 1至 N是否都提交成功。
如果从资源管理器 1至 N存在任何一个没有提交成功, 则在 S450中, 事务管理器 112向主资源管理器 120发送回滚命令, 回滚主资源管理器 120 上的事务。
如果从资源管理器 1至 N都提交成功, 则在 S455中, 在主资源管理器
120上预执行事务日志的删除操作。
在 S460中, 控制装置 110向主资源管理器 120发送提交命令, 提交主 资源管理器 120上的事务, 并在提交成功的同时删除事务日志。
在 S465中, 控制装置 110向事务发起者 130返回事务执行成功。 并在 S470中, 事务发起者 130启动的事务结束。
接下来, 结合图 5描述根据本发明实施例的正常执行提交操作时的时序 图, 并结合图 6描述根据本发明实施例的处理事务日志的方法 600。 此外, 结合图 1 , 通过控制装置 110包含的事务管理器 112和事物日志处理器 114 来进行更加详细的描述。
事务管理器 112可用于控制和管理资源管理器的操作, 向资源管理器发 送命令,从资源管理器接收响应。事务日志处理器 114可用于管理事务日志, 从事务日志中提取信息,将提取的信息提交给事务发起者 130以构造修正命 令, 或者将提取的信息提交给事务管理器 112以构造修正命令。
如图 5所示, 在 S510中, 事务发起者 130向事务管理器 112提交数据 以及数据类型和数据标识信息。其中,在数据具有诸如 XML、 SQL( Structured Query Language, 结构化查询语言)之类的良好的结构化时, 可以不向事务 管理器 112提交数据类型和数据标识信息, 而由事务管理器 112根据数据来 自动提取。
在 S520中, 事务管理器 112开始事务。
在 S530中, 事务管理器 112将数据类型和数据标识信息保存到事务上。 在 S540中, 事务管理器 112向主资源管理器 120发送数据以进行预执 行操作。
在 S550中, 事务管理器 112向从资源管理器 1至 N发送数据以进行预 执行操作。 S550也可以在 S540之前执行, 还可以与 S540同时执行。
当从资源管理器 1至 N和主资源管理器 120返回的响应(在图中未示出) 表明预执行都成功时, 在 S560中, 事务管理器 112在新的事务中命令主资 源管理器 120将与事务有关的上下文信息(例如,数据类型和数据标识信息) 保存在事务日志中。
在 S570中, 事务管理器 112向从资源管理器 1至 N发送提交命令, 以 提交从资源管理器 1至 N中的事务。
当从资源管理器 1至 N返回的响应(在图中未示出)表明提交都成功时, 在 S580中, 事务管理器 112在事务发起者 130启动的事务中命令主资源管 理器 120预删除当前的事务曰志。
在 S590中, 事务管理器 112向主资源管理器 120发送提交命令, 以提 交主资源管理器 120中的事务。 同时, 在主资源管理器 120的事务中执行删 除事务日志的操作, 使得该删除操作与提交操作一起完成。
在 S95中, 由于提交都成功, 事务管理器 112向事务发起者 130返回事 务执行成功的响应。
如图 6所示, 事务日志处理器 114可以定期扫描事务日志表, 对超过一 定时间仍然存在的事务日志进行处理。
在 S610中, 事务曰志处理器 114从事务曰志表中顺序地读取一条事务 日志。
在 S620中, 事务日志处理器 114提取事务日志中的数据类型和数据标 识信息。
在 S630中, 事务日志处理器 114可以将数据类型和数据标识信息作为 参数, 通过该参数回调事务发起者 130用于构造修正命令的接口, 或者传递 给事务管理器 112。 事务发起者 130或事务管理器 112以主资源管理器 120 的数据为准, 构造修复数据的修正命令。
由于事务发起者 130可以知晓不同从资源管理器的类型或接口, 所以事 具有良好结构化的情况下, 例如数据没有复杂的关联关系或者级联删除的情 况下, 事务日志处理器 114可以将数据类型和数据标识信息传递给事务管理 器 112, 由事务管理器 112来构造从资源管理器通用的修正命令, 而无需回 调事务发起者 130的接口。
无论修正命令由谁构造, 都由控制装置 110 (具体地, 可以为事务管理 器 112 ) 来控制从资源管理器执行修正命令, 因此, 都可以认为是由控制装 置 110根据事务日志和主资源管理器管理的数据来对从资源管理器管理的数 据进行修正。
在 S640中, 事务管理器 112发送从事务发起者 130接收或自己构造的 修正命令, 在从资源管理器上执行数据修正操作。
在 S650中, 事务管理器 112确定从资源管理器的数据修正是否成功。 如果从资源管理器的修正操作成功,则在 S660中,事务日志处理器 114 删除当前事务日志, 否则在 S670中, 事务日志处理器 114不删除事务曰志, 以供下一周期再次重试。
上面描述了根据本发明实施例的更新数据的方法, 接下来, 结合图 7和 图 8描述根据本发明实施例的用于更新数据的控制装置。
图 7是根据本发明实施例的用于更新数据的控制装置 700的结构框图。 控制装置 700包括记录模块 710、 确定模块 720和第一保留模块 730。 记录模块 710可用于当主资源管理器和从资源管理器的预执行操作成功时, 在主资源管理器上记录事务日志。确定模块 720可用于向从资源管理器发送 提交命令, 并确定从资源管理器是否都提交成功。 第一保留模块 730可用于 如果从资源管理器存在任何一个没有提交成功, 则保留事务日志, 以根据事 务日志和主资源管理器的数据,对与主资源管理器的数据不一致的从资源管 理器的数据进行修正。
记录模块 710、确定模块 720和第一保留模块 730的上述和其他操作和 / 或功能可以参考上述更新数据的方法 200中的 S210、 S220和 S230, 为了避 免重复, 在此不再赘述。
本发明实施例提供的控制装置通过在主资源管理器上记录辅助修正的 事务日志,使得可以基于事务日志来容易地发现提交过程中数据不一致的存 在, 并可以基于事务日志, 以主资源管理器的数据为准, 对不一致的数据进 行修正。 这样, 与主资源管理器的数据不一致的从资源管理器的数据可以得 以修正, 使得即便在提交过程中出现错误, 从资源管理器的数据也可以恢复 到与主资源管理器的数据相同的状态, 从而保证数据的一致性。
图 8是根据本发明实施例的用于更新数据的控制装置 800的结构框图。 控制装置 800的记录模块 810、 确定模块 820和第一保留模块 830与图 7的 控制装置 700的记录模块 710、确定模块 720和第一保留模块 730基本相同。
根据本发明的一个实施例,记录模块 810可用于在主资源管理器上将当 前事务的数据类型和数据标识信息记录为事务曰志。
根据本发明的一个实施例,控制装置 800还可以包括第一发送模块 840。 第一发送模块 840可用于在第一保留模块 830保留事务日志之后, 向主资源 管理器发送回滚命令。 这样, 可以根据事务日志和主资源管理器回滚后的数 据, 对从资源管理器的数据进行修正, 从而将资源管理器管理的数据维持在 事务执行前的状态。
根据本发明的一个实施例, 控制装置 800还可以包括第一删除模块 850 和第二保留模块 860。 第一删除模块 850可用于如果修正成功, 则删除事务 日志。 第二保留模块 860可用于如果修正不成功, 则保留事务日志。
根据本发明的一个实施例, 控制装置 800还可以包括第二发送模块 870 和第二删除模块 880。 第二发送模块 870可用于如果从资源管理器都提交成 功, 则向主资源管理器发送提交命令。 第二删除模块 880可用于在主资源管 理器提交成功时删除事务日志。
根据本发明的一个实施例,控制装置 800还可以包括检查模块 890和修 正模块 895。 检查模块 880可用于周期性检查是否存在事务日志。 修正模块 890可用于如果存在事务日志, 则根据该事务日志和主资源管理器的数据, 对与主资源管理器的数据不一致的从资源管理器的数据进行修正。
第一发送模块 840、 第一删除模块 850、 第二保留模块 860、 第二发送模 块 870、 第二删除模块 880、 检查模块 890和修正模块 895的上述和其他操 作和 /或功能可以参考上述更新数据的方法 300中的 S310至 S375以及方法 400中的相应描述, 为了避免重复, 在此不再赘述。
本发明实施例提供的控制装置的记录模块 810通过将数据类型和数据标 识信息记录在主资源管理器上作为事务日志, 可以在提交出现错误时, 使修 正模块 895基于事务日志的数据类型和数据标识来确定对哪些表格的哪些记 录进行修正, 并基于主资源管理器管理的数据来确定修正为哪些数据, 从而 完成对从资源管理器管理的数据的自动修正。
控制装置中的第一保留模块 830和第二保留模块 860在数据不一致仍存 在的情况下保留事务日志, 而第一删除模块 850和第二删除模块 880在数据 不一致得以解决的情况下删除事务日志, 使得事务日志动态改变, 从而修正 模块 895可以基于现存的事务日志, 并以主资源管理器在事务日志指示下的 数据为准, 来修正数据。
这样, 在提交过程中出现错误时, 借助于事务日志, 从资源管理器管理 的数据可以自动恢复到与主资源管理器的数据相同的状态,从而保证数据的 一致性。 并且即便事务日志没有得到及时处理或处理错误, 也可以在后续操 作中继续处理, 数据的一致性得到了极大地保证。 另外, 借助于事务日志进 行的自动修正, 无需人工的干预, 还可以提高数据修复的效率。
本领域技术人员可以意识到,结合本文中所公开的实施例中描述的各方 法步骤和单元, 能够以电子硬件、 计算机软件或者二者的结合来实现, 为了 清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描 述了各实施例的步骤及组成。 这些功能究竟以硬件还是软件方式来执行, 取 决于技术方案的特定应用和设计约束条件。本领域技术人员可以对每个特定 的应用使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发 明的范围。 结合本文中所公开的实施例描述的方法步骤可以用硬件、处理器执行的 软件程序、 或者二者的结合来实施。 软件程序可以置于随机存取存储器
( RAM ), 内存、 只读存储器 (ROM )、 电可编程 ROM、 电可擦除可编程 ROM, 寄存器、 硬盘、 可移动磁盘、 CD-ROM或技术领域内所公知的任意 其它形式的存储介质中。
尽管已示出和描述了本发明的一些实施例, 但本领域技术人员应该理 解,在不脱离本发明的原理和精神的情况下,可对这些实施例进行各种修改, 这样的修改应落入本发明的范围内。

Claims

权利要求
1. 一种更新数据的方法, 其特征在于, 包括:
当主资源管理器和从资源管理器的预执行操作成功时,在所述主资源管 理器上记录事务曰志;
向所述从资源管理器发送提交命令, 并确定所述从资源管理器是否都提 交成功;
如果所述从资源管理器存在任何一个没有提交成功, 则保留所述事务曰 志, 以^^据所述事务日志和所述主资源管理器的数据, 对与所述主资源管理 器的数据不一致的从资源管理器的数据进行修正。
2. 根据权利要求 1所述的方法, 其特征在于, 所述在所述主资源管理 器上记录事务日志包括:
在所述主资源管理器上将当前事务的数据类型和数据标识信息记录为 事务日志。
3. 根据权利要求 1和 2所述的方法, 其特征在于, 所述保留所述事务 日志之后, 还包括:
向所述主资源管理器发送回滚命令。
4. 根据权利要求 1至 3所述的方法, 其特征在于, 所述对与所述主资 源管理器的数据不一致的从资源管理器的数据进行修正之后, 还包括: 如果修正成功, 则删除所述事务曰志;
如果修正不成功, 则保留所述事务日志。
5. 根据权利要求 1至 4所述的方法, 其特征在于, 还包括:
如果所述从资源管理器都提交成功, 则向所述主资源管理器发送提交命 令;
在所述主资源管理器提交成功时删除所述事务曰志。
6. 根据权利要求 1至 5所述的方法, 其特征在于, 还包括:
周期性检查是否存在事务曰志;
如果存在事务日志, 则根据该事务日志和所述主资源管理器的数据, 对 与所述主资源管理器的数据不一致的从资源管理器的数据进行修正。
7. 一种用于更新数据的控制装置, 其特征在于, 包括:
记录模块, 用于当主资源管理器和从资源管理器的预执行操作成功时, 在所述主资源管理器上记录事务曰志;
确定模块, 用于向所述从资源管理器发送提交命令, 并确定所述从资源 管理器是否都提交成功;
第一保留模块, 用于如果所述从资源管理器存在任何一个没有提交成 功,则保留所述事务日志,以根据所述事务日志和所述主资源管理器的数据, 对与所述主资源管理器的数据不一致的从资源管理器的数据进行修正。
8. 根据权利要求 7所述的控制装置, 其特征在于, 所述记录模块用于 在所述主资源管理器上将当前事务的数据类型和数据标识信息记录为事务 曰志。
9. 根据权利要求 7和 8所述的控制装置, 其特征在于, 还包括: 第一发送模块, 用于在所述第一保留模块保留所述事务日志之后, 向所 述主资源管理器发送回滚命令。
10. 根据权利要求 7至 9所述的控制装置, 其特征在于, 还包括: 第一删除模块, 用于如果修正成功, 则删除所述事务日志;
第二保留模块, 用于如果修正不成功, 则保留所述事务曰志。
11. 根据权利要求 7至 10所述的控制装置, 其特征在于, 还包括: 第二发送模块, 用于如果所述从资源管理器都提交成功, 则向所述主资 源管理器发送提交命令;
第二删除模块, 用于在所述主资源管理器提交成功时删除所述事务日 志。
12. 根据权利要求 7至 11所述的控制装置, 其特征在于, 还包括: 检查模块, 用于周期性检查是否存在事务曰志;
修正模块, 用于如果存在事务日志, 则根据该事务日志和所述主资源管 理器的数据,对与所述主资源管理器的数据不一致的从资源管理器的数据进 行修正。
PCT/CN2011/073611 2011-05-03 2011-05-03 更新数据的方法和控制装置 WO2011120452A2 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2011/073611 WO2011120452A2 (zh) 2011-05-03 2011-05-03 更新数据的方法和控制装置
CN2011800006943A CN102203779B (zh) 2011-05-03 2011-05-03 更新数据的方法和控制装置

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2011/073611 WO2011120452A2 (zh) 2011-05-03 2011-05-03 更新数据的方法和控制装置

Publications (2)

Publication Number Publication Date
WO2011120452A2 true WO2011120452A2 (zh) 2011-10-06
WO2011120452A3 WO2011120452A3 (zh) 2012-03-08

Family

ID=44662783

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/073611 WO2011120452A2 (zh) 2011-05-03 2011-05-03 更新数据的方法和控制装置

Country Status (2)

Country Link
CN (1) CN102203779B (zh)
WO (1) WO2011120452A2 (zh)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9760584B2 (en) 2012-03-16 2017-09-12 Oracle International Corporation Systems and methods for supporting inline delegation of middle-tier transaction logs to database
US10289443B2 (en) 2012-03-16 2019-05-14 Oracle International Corporation System and method for sharing global transaction identifier (GTRID) in a transactional middleware environment
US9146944B2 (en) * 2012-03-16 2015-09-29 Oracle International Corporation Systems and methods for supporting transaction recovery based on a strict ordering of two-phase commit calls
CN103927236B (zh) 2013-01-11 2018-01-16 深圳市腾讯计算机系统有限公司 在线校验方法和装置
CN106503027B (zh) * 2015-09-08 2020-02-21 阿里巴巴集团控股有限公司 数据库操作方法及装置
CN105183879A (zh) * 2015-09-22 2015-12-23 浪潮集团有限公司 一种云计算下分布式数据库保持事务一致性的方法
CN106557530B (zh) * 2015-09-30 2019-10-11 腾讯科技(深圳)有限公司 业务系统、数据修复方法及装置
CN105610917B (zh) * 2015-12-22 2019-12-20 腾讯科技(深圳)有限公司 实现系统中同步数据修复的方法及系统
CN106503257B (zh) * 2016-11-15 2019-09-20 北京京东金融科技控股有限公司 基于binlog补偿机制的分布式事务服务方法及系统
TWI725110B (zh) * 2017-01-19 2021-04-21 香港商阿里巴巴集團服務有限公司 資料庫操作方法及裝置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101329670A (zh) * 2007-06-20 2008-12-24 诺基亚西门子通信公司 复制数据库环境下保持数据一致性的方法和系统
CN101567805A (zh) * 2009-05-22 2009-10-28 清华大学 并行文件系统发生故障后的恢复方法
US7725432B2 (en) * 2004-05-21 2010-05-25 Bea Systems, Inc. Logging last resource system
CN101853186A (zh) * 2008-12-31 2010-10-06 Sap股份公司 分布式事务恢复系统和方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7725432B2 (en) * 2004-05-21 2010-05-25 Bea Systems, Inc. Logging last resource system
CN101329670A (zh) * 2007-06-20 2008-12-24 诺基亚西门子通信公司 复制数据库环境下保持数据一致性的方法和系统
CN101853186A (zh) * 2008-12-31 2010-10-06 Sap股份公司 分布式事务恢复系统和方法
CN101567805A (zh) * 2009-05-22 2009-10-28 清华大学 并行文件系统发生故障后的恢复方法

Also Published As

Publication number Publication date
WO2011120452A3 (zh) 2012-03-08
CN102203779B (zh) 2013-04-17
CN102203779A (zh) 2011-09-28

Similar Documents

Publication Publication Date Title
WO2011120452A2 (zh) 更新数据的方法和控制装置
US8898109B2 (en) Automatic transaction retry after session failure
CN113396407A (zh) 用于利用区块链技术扩充数据库应用的系统和方法
JP6220851B2 (ja) 2フェーズコミットコールの厳密な順序付けに基づいたトランザクションリカバリをサポートするためのシステムおよび方法
US20060095478A1 (en) Consistent reintegration a failed primary instance
JP2015514247A (ja) データベースへの中間層トランザクションログのインライン委譲をサポートするためのシステムおよび方法
CN110413687B (zh) 基于节点互证校验的分布式事务故障处理方法及相关设备
WO2022001750A1 (zh) 数据同步处理方法、电子设备以及存储介质
CN109002462B (zh) 一种实现分布式事务的方法及系统
JP2007518195A (ja) リモートデータミラーリングを用いたクラスタデータベース
EP4276651A1 (en) Log execution method and apparatus, and computer device and storage medium
US20090193280A1 (en) Method and System for In-doubt Resolution in Transaction Processing
CN114268532A (zh) 一种基于Raft协议的竞选方法、分布式系统及存储介质
US9330153B2 (en) System, method, and computer readable medium that coordinates between devices using exchange of log files
CN112596801B (zh) 事务处理方法、装置、设备、存储介质、数据库
US20230315713A1 (en) Operation request processing method, apparatus, device, readable storage medium, and system
KR20140047448A (ko) 트랜잭션 재시작 가능한 클라이언트 장치와 데이터베이스 서버 및 방법
CN112632093A (zh) 工单处理方法、设备、系统、存储介质及程序产品
CN112995262B (zh) 分布式事务提交方法、系统及计算设备
WO2023134614A1 (zh) 事务的处理
CN114579406A (zh) 一种分布式事务一致性实现方法及装置
CN111130896A (zh) 一种nfs故障的切换方法、系统及双控存储系统
US20120191645A1 (en) Information processing apparatus and database system
CN110928532B (zh) 一种高一致性微服务架构及其数据更新方法
JP5515286B2 (ja) 分散トランザクション処理システム、サーバ装置及びそれらに用いる分散トランザクションの障害復旧方法

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 201180000694.3

Country of ref document: CN

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11762026

Country of ref document: EP

Kind code of ref document: A2

NENP Non-entry into the national phase in:

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11762026

Country of ref document: EP

Kind code of ref document: A2