CN104793988B - The implementation method and device of integration across database distributed transaction - Google Patents

The implementation method and device of integration across database distributed transaction Download PDF

Info

Publication number
CN104793988B
CN104793988B CN201410025961.8A CN201410025961A CN104793988B CN 104793988 B CN104793988 B CN 104793988B CN 201410025961 A CN201410025961 A CN 201410025961A CN 104793988 B CN104793988 B CN 104793988B
Authority
CN
China
Prior art keywords
database
distributed transaction
database manipulation
manipulation
affairs
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201410025961.8A
Other languages
Chinese (zh)
Other versions
CN104793988A (en
Inventor
刘照星
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Advanced New Technologies Co Ltd
Original Assignee
Alibaba Group Holding Ltd
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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201410025961.8A priority Critical patent/CN104793988B/en
Publication of CN104793988A publication Critical patent/CN104793988A/en
Application granted granted Critical
Publication of CN104793988B publication Critical patent/CN104793988B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

This application discloses a kind of implementation methods of integration across database distributed transaction, comprising: receives the starting request of distributed transaction, and distributes Transaction Identifier for the distributed transaction;Receive the operation requests or operation requests set for database manipulation for being assigned the distributed transaction of Transaction Identifier;For each operation requests, the target database information of the database manipulation is obtained, and follows ACID principle and sends the target database execution for the database manipulation;It is finished to all database manipulations, removes the distributed transaction.The application provides a kind of realization device of integration across database distributed transaction simultaneously.Lightweight, integration across database distributed transaction easy to maintain and meeting ACID principle can be realized using method provided by the present application.

Description

The implementation method and device of integration across database distributed transaction
Technical field
This application involves distributing real time system fields, and in particular to a kind of realization side of integration across database distributed transaction Method.The application provides a kind of realization device of integration across database distributed transaction simultaneously.
Background technique
With the development of internet with the continuous variation of user demand, various applied business become increasingly complex.In order to give industry Business provides preferably support, and first floor system is more and more, and service is increasingly concentrated, and level is also deeper and deeper.For a business Request, is no longer that can be completed by the database accessed in some service sub-system, it usually needs two or two The cooperation of above service sub-system, and different subsystems uses different databases, that is to say, that in primary request, It may need to access the data in multiple target databases, and access operation is required to meet the needs of high real-time.
In the case where multiple integration across database service requests are concurrent, if be easy to cause by the way of asynchronous operation Entirely target database system data is inconsistent, in order to solve this problem, it usually needs design in the system of middle layer Retry mechanism guarantees that data are consistent and integrality, not only reduces the treatment effeciency of service request, while also increasing cost. In this context, in order to meet the concurrent requirements for access of multi-service integration across database, there is the concept of distributed transaction.
So-called affairs are an operating units in database, all operations or all successful in the operating unit, All fail, implementing result is irreversible, and affairs have four basic characteristics: atomicity, consistency, isolation, persistently Property, also referred to as the ACID characteristic of affairs.And distributed transaction then refers to the participant of affairs, the server for supporting affairs, money Source server and task manager are located on the different nodes of different distributed systems.Because distributed transaction across Multiple database resources, therefore distributed transaction is required to meet ACID attribute for safeguarding that the data on all database resources are consistent Property be critically important, therefore evaluate affairs and whether support distributed calling, mainly see in its distributed calling process whether meet The ACID principle of affairs.
In order to realize distributed transaction, the prior art is usually using two-phase commitment protocol.Stage one: transaction coordination person askes Ask whether (such as: each target database) can submit respective operation, each affairs participant to all affairs participants According to the resource situation of oneself, the response that whether can be submitted is sent to transaction coordination person.Stage two: as all affairs participants What is fed back in the first stage is all affirmative acknowledgement, then coordinator can just initiate this stage, that is, is notifying all affairs participants just Formula submits affairs, and all participants submit to finish can notify coordinator again.In order to realize distributed transaction, it is necessary to using a kind of Agreement transmits transaction context information between each participant of distributed transaction, such as: IIOP(Internet Inter- The internet ORB Protocol internal object request agency agreement) agreement, the affairs participant of different developers exploitation is also necessary It supports same standard agreement, is just able to achieve distributed affairs.
Specific to realization, the prior art generallys use CORBA(Common Object Request Broker Architecture, Common Object Request Broker Architecture) formulate a kind of standard object-oriented application program system Specification solves the interconnection of software systems in distributed processing environment.CORBA standard is broadly divided into three parts: interface defines language Interoperability Protocol IIOP between speech (IDL), Object Request Broker (ORB) and ORB.Using CORBA architecture, in isomery Provide interoperability under distributional environment for the application on different machines, and be seamlessly integrated with a variety of objective systems, pass through by Distributed object technology combines with Transaction processing technology, using two-phase commitment protocol and restores the technologies such as log, thus Guarantee the ACID property of distributed transaction.
The distributed transaction frame that the above-mentioned prior art uses, needs to build more complicated distributed treatment center, and And require distributed treatment center and destination server or target database system that must be configured to realize distributed operation All kinds of complex protocols, it is on the one hand more too fat to move, it is unfavorable for safeguarding and uses, on the other hand can not be also provided gently for different business The service of the customizable of magnitude.
Summary of the invention
The application provides a kind of implementation method of integration across database distributed transaction, to solve the realization of existing distributed transaction Frame is excessively complicated, is not easy to the problem of maintenance.In addition the application provides a kind of realization device of integration across database distributed transaction.
The application provides a kind of implementation method of integration across database distributed transaction, comprising:
The starting request of distributed transaction is received, and distributes Transaction Identifier for the distributed transaction;
Receive the operation requests or operation requests collection for database manipulation for being assigned the distributed transaction of Transaction Identifier It closes;
For each operation requests, the target database information of the database manipulation is obtained, and following ACID principle will The database manipulation is sent to the target database and executes;
It is finished to all database manipulations, removes the distributed transaction.
Optionally, the target database information for obtaining the database manipulation specifically refers to, according to the database The title of the specified target database of operation and/or table, searches pre-set database description information, therefrom obtain with it is described Target database and/or the corresponding target database information of the title of table.
Optionally, it is described follow ACID principle and send the target database for the database manipulation execute, comprising:
Obtain the type of the database manipulation;
The database manipulation is parsed, the line identifier that the database manipulation influences is obtained;
Obtain the current accessed state of the corresponding row of the line identifier;
According to the type of the current accessed state of the corresponding row of the line identifier and the database manipulation, judge whether to need Waiting the access of the corresponding row of the line identifier terminates;If so, waiting is executed, until the visit of the corresponding row of the line identifier It asks end, then executes following step;If it is not, continuing to execute following step;
According to the type of the database manipulation, judge whether to need to obtain the access control to the corresponding row of the line identifier System, if so, executing following step after adding access control for the corresponding row of the line identifier;If it is not, executing following step;
The database manipulation is sent to the target database to execute;
The implementing result of the database manipulation is returned to the requesting party of the distributed transaction.
Optionally, after executing the described the step of database manipulation is sent to target database execution, if The implementing result of target database return is not received within the preset time, then passes through active access target database Mode obtains the implementing result of the database manipulation.
Optionally, the type of the database manipulation includes: newly-increased operation, updates operation, delete operation or inquiry operation.
Optionally, the parsing database manipulation, obtains the line identifier that the database manipulation influences, comprising:
If the type of the database manipulation is newly-increased operation, distributing a unique identification for the newly-increased operation should Capable line identifier, and the line identifier is added in newly-increased operation;
Otherwise, following step is executed:
The database manipulation is resolved to the inquiry operation of the acquisition line identifier using the same terms;
The inquiry operation is sent to the target database to execute;
The line identifier that the target database returns is received, the line identifier of return is influenced as the database manipulation Line identifier.
Optionally, described according to the current accessed state of the corresponding row of the line identifier and the class of the database manipulation Type, judge whether to need to wait the access of the corresponding row of the line identifier terminate, in particular to:
If the type of the database manipulation is newly-increased operation or inquiry operation, it is judged to withouting waiting for described The access of the corresponding row of line identifier terminates;
If the type of the database manipulation is to update operation or delete operation, the line identifier is further judged Before the corresponding trade whether not by except current distributed transaction office access, though by current distributed transaction it Outer transactions access but without locked, if so, the access for being judged to withouting waiting for the corresponding row of the line identifier terminates; Otherwise, it is determined that need the access for waiting the corresponding row of the line identifier to terminate.
Optionally, the type according to the database manipulation judges whether to need to obtain corresponding to the line identifier Row access control, in particular to:
If the type of the database manipulation is newly-increased operation, updates operation or delete operation, it is judged to needing Obtain the access control to the corresponding row of the line identifier.
Correspondingly, it is described for the corresponding row of the line identifier add access control, in particular to, it is corresponding for the line identifier Row addition allow to execute inquiry operation but do not allow to execute newly-increased operation, update operation and the process lock of delete operation.
Optionally, the database manipulation is sent to described before the step of target database executes, is executed Operations described below: if the type of the database manipulation is inquiry operation, and exist in the line identifier by current distributed The row of affairs locking except affairs, then reconfigure inquiry operation using following step:
Obtain the type of the currently performed database manipulation of locked row;
If the type of the currently performed database manipulation of locked row is newly-increased operation, will be described locked Rower, which is denoted as, is unsatisfactory for querying condition;
If the type of the currently performed database manipulation of locked row is to update operation or delete operation, Further judge whether the locked row meets the inquiry before executing current update operation or delete operation The condition of operation, if so, record meets the row of the condition of the inquiry operation;Otherwise, the locked rower is denoted as It is unsatisfactory for querying condition;
It generates and eliminates the inquiry operation of the line identifier for being unsatisfactory for querying condition;
The database manipulation is sent to target database execution refers to correspondingly, described, by what is reconfigured Inquiry operation is sent to the target database and executes.
Correspondingly, the implementing result that the requesting party to the distributed transaction returns to the database manipulation refers to, By the implementing result of the inquiry operation, merge with the row of the condition for meeting the inquiry operation recorded, and will be after merging Result return to the requesting party of the distributed transaction.
Optionally, the method also includes:
The relevant information for the database manipulation for including by the relevant information of the distributed transaction and the distributed transaction It is written in internal storage data corresponding with distributed transaction mark.
Optionally, the relevant information of the distributed transaction includes: the Transaction Identifier of the distributed transaction, executes shape State and time-out setting;
The relevant information for the database manipulation that the distributed transaction includes includes: the row of target database information, influence Mark, lock status, executes state, Proactive authentication time difference, database at the content for updating the row before operation or delete operation execution The type of action statement and database manipulation.
Optionally, the removing distributed transaction includes:
The operation that unlocks is executed to the row of distributed transaction locking;
Delete the distributed transaction mark and internal storage data relevant to the distributed transaction.
Optionally, the method also includes:
Obtain database manipulation implementing result, if in the distributed transaction any database operation fail execute at Function then executes rollback operation to other database manipulations of the successful execution in the distributed transaction, is restored to described State before distributed transaction execution.
Optionally, the method also includes:
Judge the duration of the distributed transaction, if the duration is greater than the preset time, touches Hair exception handler is handled.
Optionally, the method also includes:
The modification that the implementation procedure of the distributed transaction and the distributed transaction make target database is write Enter in journal file.
Optionally, the method also includes:
The journal file is read, and according to the information of the distributed transaction recorded in the journal file, to not yet complete At distributed transaction in successful execution database manipulation execute rollback operation.
Correspondingly, the application also provides a kind of realization device of integration across database distributed transaction, comprising:
Affairs start unit, the starting for receiving distributed transaction is requested, and distributes affairs for the distributed transaction Mark;
Operate receiving unit, the operation for database manipulation of the distributed transaction for receiving assigned Transaction Identifier Request or operation requests set;
Operation execution unit, for obtaining the target database information of the database manipulation for each operation requests, And it follows ACID principle and sends the target database execution for the database manipulation;
Affairs clearing cell, for removing the distributed transaction after the distributed transaction is finished.
Optionally, the operation execution unit obtains the target database letter of the database manipulation in the following way Breath: the title of the target database and/or table specified according to the database manipulation searches pre-set database description letter Breath therefrom obtains target database information corresponding with the title of the target database and/or table.
Optionally, the operation execution unit includes:
Target data library inquiry subelement, target database and/or table for being specified according to the database manipulation Title searches pre-set database description information, therefrom obtains corresponding with the title of the target database and/or table Target database information;
Action type obtains subelement, for obtaining the type of the database manipulation;
Line identifier obtains subelement, for parsing the database manipulation, obtains the rower that the database manipulation influences Know;
Access state obtains subelement, for obtaining the current accessed state of the corresponding row of the line identifier;
Subelement is waited, for according to the current accessed state of the corresponding row of the line identifier and the database manipulation Type judges whether to need to wait the access of the corresponding row of the line identifier to terminate;If so, executing waiting, the row is waited until The access for identifying corresponding row terminates, then executes following step;If it is not, continuing to execute following step;
Access control subelement judges whether to need to obtain to the row for the type according to the database manipulation The access control of corresponding row is identified, if so, adding access control for the corresponding row of the line identifier;
Operation executes subelement, executes for the database manipulation to be sent to the target database;
As a result subelement is returned to, for returning to the execution knot of the database manipulation to the requesting party of the distributed transaction Fruit.
Optionally, the operation execution unit further include:
Operation overtime handles subelement, and holding for target database return is not received within the preset time for working as When row result, the implementing result of the database manipulation is obtained by way of active access target database.
Optionally, the action type obtains the action type that subelement obtains and includes: newly-increased operation, update operation, delete Except operation or read operation.
Optionally, the line identifier acquisition subelement includes:
Line identifier distributes subelement, for being the newly-increased behaviour when the type of the database manipulation is newly-increased operation Make to distribute the line identifier of the unique identification row, and the line identifier is added in newly-increased operation;
Line identifier inquires subelement, for the database manipulation to be resolved to the acquisition line identifier using the same terms Inquiry operation, and the inquiry operation is sent to the target database and is executed, the rower that the target database is returned Know the line identifier influenced as the database manipulation.
Optionally, the waiting subelement is specifically used for, when the type of the database manipulation is newly-increased operation or is looked into When asking operation, waiting is not executed;When the type of the database manipulation is to update operation or delete operation, if the row Corresponding row is identified currently without by the transactions access except current distributed transaction, though by except current distributed transaction Transactions access but without locked, then do not execute waiting, otherwise execute waiting.
Optionally, the access control subelement is specifically used for, when the type of the database manipulation is newly-increased operates, more When new operation or delete operation, allows to execute inquiry operation for the corresponding row addition of the line identifier but do not allow to execute newly-increased Operation, the process lock for updating operation and delete operation.
Optionally, the operation execution unit further include:
Inquiry operation reconstructs subelement, is inquiry operation and the rower for the type when the database manipulation When there is the row locked by the affairs except current distributed transaction in knowledge, inquiry operation is reconfigured.
The inquiry operation reconstructs subelement
Lock line action type obtains subelement, for obtaining the currently performed database manipulation of locked row Type;
Querying condition verifies subelement, is new for the type when the currently performed database manipulation of locked row When increasing operation, the locked rower is denoted as and is unsatisfactory for querying condition;When the currently performed data of locked row The type of library operation be update operation or delete operation and the locked row execute current update operate or When meeting the condition of the inquiry operation before delete operation, record meets the row of the condition of the inquiry operation, otherwise, by institute It states locked rower and is denoted as and be unsatisfactory for querying condition;
Inquiry operation generates subelement, eliminates the inquiry behaviour of the line identifier for being unsatisfactory for querying condition for generating Make;
Correspondingly, the operation, which executes the inquiry operation that subelement is specifically used for reconfigure, is sent to the number of targets It is executed according to library.
It is specifically used for correspondingly, the result returns to subelement, the implementing result of the inquiry operation and has recorded The row for meeting the condition of the inquiry operation merges, and the result after merging is returned to the requesting party of the distributed transaction.
Optionally, described device further include:
Data write unit, the data for including by the relevant information of the distributed transaction and the distributed transaction The relevant information of library operation is written in internal storage data corresponding with distributed transaction mark.
Optionally, the affairs clearing cell includes:
Unlock subelement, for executing the operation that unlocks to the row that the distributed transaction locks;
Data dump subelement, for deleting the distributed transaction mark and memory relevant to the distributed transaction Data.
Optionally, described device further include:
Rollback unit, for obtaining the implementing result of database manipulation, when some database in the distributed transaction When operation fails to run succeeded, rollback behaviour is executed to other database manipulations of the successful execution in the distributed transaction Make, is restored to the state before the distributed transaction executes.
Optionally, described device further include:
Exception processing unit, for judging the duration of the distributed transaction, if the distributed transaction fails It is completed within the preset time, then triggers exception handler and execute rolling back action.
Optionally, described device further include:
Log management unit, for by the implementation procedure of the distributed transaction and the distributed transaction to number of targets In the modification write-in journal file made according to library.
Optionally, described device further include:
Transaction recovery unit, for reading the journal file, and according to the distributed thing recorded in the journal file The information of business executes rolling back action to the distributed transaction not yet completed.
Compared with prior art, the application has the following advantages:
Using the implementation method of integration across database distributed transaction provided by the present application, by making in target database system The access operation of distributed transaction is managed collectively with unique line identifier, and using access control mechanisms, is avoided pair The problem that the asynchronous operation of target database causes data inconsistent, realize lightweight, it is easy to maintain and meet The integration across database distributed transaction of ACID principle.
A kind of preferred embodiment provided by the present application, by distributed transaction write operation (including newly-increased operation, Update operation and delete operation) plus process lock, it may be assumed that allow other distributed transactions read row that the write operation influences but not Write operation can be executed to the row, while additionally use the mode of reconstruct query statement, Fusion query result, avoid reading other The process data that affairs are not yet submitted, thus while " reading to submit " isolation level for realizing integration across database distributed transaction, Also preferable concurrency effect is obtained.
Detailed description of the invention
Fig. 1 is the flow chart of the embodiment of the implementation method of the integration across database distributed transaction of the application;
Fig. 2 is the schematic diagram of the embodiment of the realization device of the integration across database distributed transaction of the application.
Specific embodiment
Many details are explained in the following description in order to fully understand the application.But the application can be with Much it is different from other way described herein to implement, those skilled in the art can be without prejudice to the application intension the case where Under do similar popularization, therefore the application is not limited by following public specific implementation.
In this application, provide a kind of implementation method of integration across database distributed transaction, at the same additionally provide it is a kind of across The realization device of database distributed affairs, is described in detail one by one in the following embodiments.
Referring to FIG. 1, its process for a kind of embodiment of the implementation method of integration across database distributed transaction of the application Schematic diagram.Described method includes following steps:
Step 101: receiving the starting request of distributed transaction, and distribute Transaction Identifier for the distributed transaction.
The implementation method of integration across database distributed transaction provided by the present application passes through the concurrently visit to multiple target databases It asks and takes centralized control, realize the affair mechanism called based on distribution, meet the ACID principle of affairs.In order to preferably Understand the technical solution of the application, brief description first is made to the concept of affairs and distributed transaction.
So-called affairs operate form complete logical process by volume of data library, are one indivisible Operating unit.In relational database, an affairs can be a SQL statement, be also possible to one group of SQL statement, even Entire program.By affairs, the relevant one group of operation of logic is bound together, so as to keep the integrality of data with it is consistent Property.Such as bank transfer, from former account amount deducted, and to target account add the amount of money, the two database manipulations it is total With one complete logical process of composition, can not be split, this process is referred to as an affairs.
Affairs have to comply with four characteristics: atomicity (Atomicity), consistency (Consistency), isolation (Isolation, also known as independence), persistence (Durability), the ACID characteristic of abbreviation affairs.
So-called atomicity refers to that affairs must be atom-work unit, for its data modification or all executes, It does not execute all, an affairs can not only carry out half and just stop.Why affairs is required to meet atomicity, be because Usually there is common target with the associated operation of some affairs, and be complementary, if system only carries out these behaviour The a subset of work may then destroy the overall goal of affairs, lead to the inconsistent situation of data occur.Atomicity eliminates A possibility that system processing operation subset.But the requirement of actually atomic operation hardly results in guarantee, due to the damage of hardware Or other factors cause the operation in an affairs to be interrupted the problem of being through being commonly encountered, therefore in conventional Database Systems In, it generallys use transaction rollback mechanism and journaling techniques realizes the atomicity of affairs.On the one hand, if any one in affairs SQL statement executes failure, then the SQL statement to have run succeeded in the affairs must also cancel, database positioning is made to retract State to before execution affairs, this process are known as transaction rollback mechanism;On the other hand, using log recording affairs to data The update that library is done, if catastrophic event occurs for system, so that it may according to log, cancel affairs and database has been done more Newly, database is made to return to the original state before executing affairs, to guarantee the atomicity of affairs.
Consistency refers to, after terminating before the transaction started with affairs, the integrity constraint of database is not destroyed, Affairs are when completing, it is necessary to and so that all data is still maintained consistent state, for example, integrity constraint requires a+b=10, if One affairs changes a, then b should also be changed correspondingly.If broken down in Database Systems operation, some affairs are not yet Completion is forced to interrupt, some has been written into physical database for the modification that these affairs not yet completed make database, At this moment database is at a kind of incorrect state, or perhaps inconsistent state.It can be seen that the consistency and affairs of affairs Atomicity be it is closely related, be not present more transaction concurrencies in the case where, it may be considered that if each of affairs Database manipulation is correct to the processing of data, and the execution of affairs meets the requirement of atomicity, we can recognize It is not destroyed for the consistency of data, affairs meet the requirement of consistency.
However under the scene that multiple transaction concurrencies execute, even if each affairs can keep atomicity and consistency, by Identical data may be accessed in these affairs, and their operation may by it is not expected intersect in a manner of certain hold Row, causes data inconsistent state occur.Therefore affairs are had also been proposed with the requirement for meeting isolation.
Isolation refers in concurrent environment, when different affairs manipulate identical data simultaneously, each affairs There is respective relatively independent, relatively complete data space.The modification made by concurrent transaction must be with any other concurrent thing The done modification of business is isolated to a certain extent, it may be assumed that cannot interfere with each other between each affairs concurrently executed, each affairs There are other affairs executing in imperceptible system, thus also it is ensured that the consistency of database.Data base management system Lock mechanism is generallyd use to realize the isolation of affairs.The isolation level of affairs is generally divided into four classes: (read is not submitted in reading Uncommitted), read to submit (read committed), repeatable read (read repeatable), serializability (serializable).
Persistence refers to, after affairs are completed, its influence for system is permanent.Once that is: an affairs at Function terminates, the update that it does database just must persistence get off, even if system or medium break down, even occur The catastrophic events such as system crash, after system restarting, database can also be restored to the state at the end of affairs success.Persistently Property the redundant backup function that can be provided by Database Systems and Restoration Mechanism guarantee.
So-called distributed transaction be then the new concept occurred on the basis of above-mentioned affairs, in particular to, affairs Participant supports server, Resource Server and the task manager of affairs to be located at different distributed systems not On node, namely: distributed transaction is the affairs for influencing multiple resources.Integration across database distribution thing described herein Business refers to that executing for distributed transaction will can have different affairs simultaneously naturally across multiple and different target data base resources Hair accesses the case where identical target data base resource, in order to ensure the data consistency in entire target data base resource, by force The ACID attribute that integration across database distributed transaction processed meets affairs is necessary.It is also understood that evaluation affairs are It is no to support distributed calling, mainly see whether the ACID principle of affairs in its distributed calling process meets, this is also this Shen Please technical solution core where.
For ease of description, in the present embodiment, the reality of integration across database distributed transaction provided by the present application will be implemented Module, application or the system of existing method, referred to as system adjust layer.
Using the implementation method of integration across database distributed transaction provided by the present application, when operation system is distributed formula affairs When process demand, do not need directly to send each database manipulation for including in its distributed transaction to each target database, But it is requested first to the starting that system adjusts layer to send distributed transaction, the starting request for adjusting layer to receive the distributed transaction of uniting Afterwards, a new Transaction Identifier is created for the affairs, and the Transaction Identifier is returned to the operation system for proposing starting request, from And complete the operation of distribution Transaction Identifier.In addition, system adjusts layer that the number that system adjusts layer maintenance also is written in newly created Transaction Identifier (adjust the explanation of layer data referring to the relevant portion in step 102 about system) in, and in the subsequent execution of the distributed transaction In the process, it is mutually distinguished using the Transaction Identifier and other distributed transactions.Specifically in an implementation, system adjusts layer that can use multi-thread Journey mechanism realizes the management of multiple concurrent transactions, it may be assumed that it is that each distributed transaction creates a new thread that system, which adjusts layer, by the line Journey is responsible for the subsequent relevant treatment of corresponding distributed transaction and operation.
Operation system adjusts the starting application and the subsequent interaction between system tune layer of layer transmission distributed transaction to system, By function call, message mechanism and it can establish the various ways such as connection and realize.In order to guarantee that operation system can be with System adjusts layer to establish interaction channel, user needed for can adjusting layer address information by necessary function interface, system and establish connection The information hardnesses such as name, password can also use more flexible mode, above- mentioned information are written inside the code of operation system In configuration file, each operation system adjusts layer to establish interaction channel by reading the information in configuration file, with system.These interactions Mechanism is not the core of the application, and the application does not limit specifically.
Step 102: receiving the operation requests for database manipulation for being assigned the distributed transaction of Transaction Identifier or behaviour Make request set.
After completing step 101, operation system obtains the mark of the distributed transaction needed to be implemented, so that it may adjust layer to system Send the operation requests that the distributed transaction is directed to database manipulation.It can only include a number in one distributed transaction It is operated according to library, also may include one group of database manipulation that is mutually related.The distributed transaction can include by operation system Database manipulation be disposably sent to system and adjust layer, system adjusts layer to handle received database manipulation one by one, and by operating result Report operation system;Operation system can also only send a database manipulation every time, receive the execution knot that system adjusts layer to return Next database manipulation is issued after fruit again.Both embodiments can realize the technical solution of the application.
Realize that integration across database distributed transaction provided by the present application, system adjust layer to need to learn that each distributed transaction includes The influence of which database manipulation and these database manipulations to database resource, so just when mistake or exception occurs It is able to achieve the rollback function of affairs, guarantees the atomicity of affairs;In addition, in order to realize that each concurrent transaction provides target database The access control in source, system adjust layer also to need to know which data the currently performed database manipulation of each distributed transaction is related to Whether the access of base resource and these database resources the information such as are accessing by other distributed transactions, and according to these Information carries out corresponding access control, can avoid the operation conflict between different affairs, guarantees the consistency and just of data True property.In addition, system adjusts layer also multiple concurrent distributed transactions are distinguished and are managed collectively, therefore unites and layer is adjusted to need The details for the database manipulation for including about distributed transaction and distributed transaction are safeguarded in its memory, this is also to realize The indispensable part of technical scheme.
System adjusts the data of layer maintenance to be divided into three classes, and a kind of global data, one kind is the relevant data of affairs, and there are also one kind to be Data relevant to database manipulation.Global data includes: target database description, transaction list, affairs clearance time etc.;Thing Business related data is used to record the information of each affairs, comprising: database manipulation set that Transaction Identifier, each affairs include, The overtime settings of affairs, execution state of affairs etc.;The relevant data of database manipulation are for recording each database manipulation Details, comprising: target database information, the line identifier of influence, write operation (including updating operation and delete operation) execute Preceding database data content, access control, data base manipulation statement, type of database manipulation etc..
In one specific example of the present embodiment, target database system is the relevant database for supporting SQL operation, industry It is exactly specific SQL statement that business system, which is sent to system and adjusts the database manipulation of layer, and access control is to realize (this by lock mechanism Part explanation refers to the relevant portion in step 103), system adjusts the data of layer maintenance as shown in the table:
Table one: global data
Table two: affairs related data
Table three: database manipulation related data
System adjusts layer to the maintaining method and application method of above-mentioned data, has further instruction in the description below. Data in upper table are only the data in a specific example of the present embodiment, and in other embodiments, system adjusts layer can be with Maintenance is different from the data of upper table, can also increase other data newly, adjusts layer to the pipe of distributed transaction as long as can satisfy system Reason demand can, specifically safeguard the type of which data and data, these changes to embodiment, all without departing from this The core of application, all within the scope of protection of this application.
In this step, after system adjusts layer to receive the distributed transaction database manipulation request or operation requests set, The relevant information write-in system of the database manipulation is adjusted in layer data corresponding with the distributed transaction.In the present embodiment In one specific example, system adjusts layer to be added to received SQL statement in one array element of SQL set.
Step 103: being directed to each operation requests, obtain the target database information of the database manipulation, and follow ACID principle sends the target database for the database manipulation and executes.
The implementation method of integration across database distributed transaction provided by the present application, target are exactly to realize to meet ACID principle Distributed transaction.Wherein, the atomicity of affairs adjusts the rollback mechanism of layer and log mechanism to realize that persistence passes through target by system The functions such as the redundancy backup of Database Systems are realized, and the operation in this step mainly passes through the access control to concurrent transaction System, and realize the isolation in multiple concurrent transaction implementation procedures, to guarantee the consistency of data.This step is the application The core of technical solution.In order to make it easy to understand, making letter to main problem existing for concurrent transaction and isolation level first below The explanation wanted.
Concurrent transaction may manipulate the identical data in the same target database simultaneously, therefore it is different data to occur The problem of cause, these problems include: to lose update, dirty reading, non-repeatable read and illusion to read.
A) lose and update: same a line in two or more affairs selection database is then based on initially selected value When updating the row, it may occur that lose replacement problem.Each affairs do not know the presence of other affairs.Last update will be rewritten The update done by other offices, this will lead to loss of data.
B) dirty reading: just referring to that working as an affairs is accessing data, and be modified to data, and this modification is also It is not submitted in database, at this moment, another affairs also accesses this data, has then used this data.Because this A data be not yet submit data, then this data that another affairs is read be process data (also referred to as are as follows: dirty number According to), the operation done according to the process data may be incorrect.
C) non-repeatable read: in same affairs, needing the same data of twi-read, and between twi-read, it may There are other affairs to change data, the content for causing first affairs twi-read to obtain is different.
D) unreal reading: in same affairs, being read twice with same operation, and between twi-read, there may be other things Business performs insertion operation, and the record number for causing first affairs to be inquired twice is not identical.
In order to solve the above problem existing for concurrent transaction, on the one hand, it is required that concurrent transaction must be to the write operation of data (that is: updating operation, newly-increased operation or delete operation) access control, it may be assumed that whenever only allows an affairs to identical Data execute write operation, before affairs submission, prevent other affairs from modifying identical data resource, this point is to simultaneously The basic demand for sending out transactions access control is likely to avoid the occurrence of the phenomenon that loss updates in this way.On the other hand, by using not Same access control policy and increase can solve other above-mentioned three sides to the access control of read operation to varying degrees The problem of face, that is to say, that realize the different isolation levels between concurrent transaction.
So-called isolation level refers to, the degree that the data change that an affairs must be carried out with other affairs be isolated.It is logical Isolation level between normal concurrent transaction has following four:
A) read not submit (read uncommitted): this is minimum isolation level, under this isolation level, is owned Affairs are it can be seen that and read the data that other affairs are not yet submitted.In the isolation level, it is possible that dirty read, can not weigh Re-reading and unreal reading etc., therefore this isolation level is rarely used in practical application.
B) read to submit (read committed): this is the isolated by default rank of most of Database Systems.It is realized Such a isolation: an affairs can only see the change that submitted office makes, it may be assumed that data that affairs view or It is state before another affairs modify it or is that another affairs modify state after it, affairs will not views centre The data of state.But when an affairs execute read operation, what other affairs may be related to the transactions read operations Resource is updated and submits, therefore this isolation level is it is possible that the problem of non-repeatable read and unreal reading, that is to say, that Same inquiry operation may return to Different Results.
C) repeatable read (read repeatable): the rank ensures that data are being read in multiple operations in same affairs When, it can be appreciated that same data line.The rank solves the problems, such as non-repeatable read, but since other affairs can be in ability The problem of business executes newly-increased operation during reading data, this affairs is caused to be likely to occur unreal reading.
D) serializability (serializable, also referred to as serializability): this is highest isolation level, it passes through pressure Transaction orderings make it impossible to conflict with each other, to solve the problems, such as unreal reading.When affairs serializability, can be held parallel from one group The result that capable affairs obtain is identical as by continuous operation each affairs result obtained.
The ability of transaction concurrency data can be enhanced in lower isolation level, but also increases each affairs and may meet Concurrent side effect (such as dirty reading) possibility arrived, that is to say, that may be decreased the integrality and correctness of data.On the contrary, higher Type of the isolation level due to reducing the concurrent side effect that affairs are likely encountered, can better ensure that the complete of data Whole property and correctness, but need to carry out relative complex access control, while also increasing Transaction Blocking other affairs A possibility that (other affairs, which have to wait for the affairs, to be terminated), influence the concurrency performance of affairs.
Although serializability ensures that correctness of the data in database in institute's having time is quite important for affairs, so And many affairs are not always to require completely to be isolated.Should comprehensively consider requirement of the operation system to data integrity with each every Expense from rank selects corresponding isolation level on this basis.Isolation level is reduced to exchange bigger handling capacity for, is very The conventional thinking of multiservice system.Due to often being set as reading to submit by isolation in actual application process, at this In embodiment, provides a kind of realize and read that the preferred embodiment of the distributed transaction of isolation level is submitted (to refer to this step Subsequent description).
It should be noted that Transaction service is selected to have no effect on the access control (institute here executed for write operation The access control stated in the specific implementation process, is usually realized using lock mechanism), each affairs are always in times of its modification Lock is obtained in what data and holds the lock before affairs completion, regardless of which type of isolation level be provided with for the affairs.It can To be understood that, isolation level is mainly that read operation defines different protection levels, to prevent the reading an of affairs from grasping Work is altered by other offices to be influenced.
The isolation level of affairs can be specified by operation system, such as: operation system can send every time affairs starting When request, the parameter of specified isolation level is carried, system performs corresponding processing after adjusting layer to receive according to the requirement of operation system;? Layer can be adjusted to be handled using fixed isolation level (such as: reading to submit rank) by system.The selection and adjustment of isolation level, The specific change for belonging to embodiment, does not affect the core of the application, all within the scope of protection of this application.
Following 9 sub-steps are executed after receiving the database manipulation request of distributed transaction specific to the present embodiment, Realize integration across database distributed transaction provided herein.
1) the target database information of the database manipulation is obtained.
According to the schema information of the database manipulation, the database description set in system tune layer global data is searched, Obtain the access address for executing the database schema of the database manipulation.In general, schema refers to database table Tissue and definition, the level that can also be understood as in a container or database object NameSpace are main to use To solve the problems, such as naming conflict.Conceptually, a Database Systems may include multiple schema, and each schema Include multiple database objects (table, view, field etc.).The requesting party of the distributed transaction requires no knowledge about target database Specific access address, but adjust layer to be responsible for according to the corresponding number of targets of schema acquisition of information of the database manipulation by system According to library address.
2) type of the database manipulation is obtained.
The data base manipulation statement received is read, the type of the database manipulation is therefrom obtained.The database behaviour The type of work includes: update operation, delete operation, newly-increased operation, inquiry operation, wherein updating operation, delete operation and increasing newly Operation belongs to write operation, the read operation that inquiry operation is known as.
3) database manipulation is parsed, the line identifier that the database manipulation influences is obtained.
Line identifier is for unique identification data row, in order to realize method provided by the present application, it is desirable that in entire target Guarantee that the uniqueness of line identifier, this point are also to implement the key point of method provided herein in Database Systems, leads to It crosses using the line identifier, system adjusts layer that can determine unique a line in target database like clockwork, correspondingly, carrying out mesh Newly-increased one special line identifier column, such as rowEid are also required to when the table design of mark database.In order to realize line identifier only One property, the line identifier is unified to adjust layer-management by system.
If the type of the database manipulation is newly-increased operation, explanation will be inserted into a newline into target database, unite It adjusts layer to create a new line identifier for it, and the line identifier information is added in newly-increased operation, such as: the newly-increased behaviour Work is Insert sentence as follows:
INSERT INTO TABLE_NAME (column1, column2) VALUES (values1, values2);
It is that the new line increment creates a line identifier 200, and the line identifier information is added to the Insert sentence that system, which adjusts layer, In, obtain the SQL statement of following newly-increased operation:
INSERT INTO TABLE_NAME (column1, column2, rowEid)
VALUES(values1,values2,‘200');
If the type of the database manipulation is to update operation, delete operation or inquiry operation, need to be implemented down It states step and obtains the line identifier that the database manipulation influences.
A) database manipulation is resolved to the inquiry operation of the acquisition line identifier using the same terms.
Data base manipulation statement does not carry the line identifier information of influence usually, therefore only by the database manipulation Sentence is converted to the query statement of the same terms, and goes in target database to execute, and can return to the line identifier of its influence.? In one specific example of the present embodiment, converted by the way of as follows:
For select*from table where queryCondition;Resolve to select rowEid from table where queryCondition;
For update table set xxxx where queryCondition;Resolve to select rowEid from table where queryCondition;
For delete from table where queryCondition;Resolve to select rowEid from table where queryCondition。
B) inquiry operation target database is sent to execute.
Inquiry operation after conversion is sent to target database to execute.Due to sub-step 1 in front) in obtained The target database address of the database manipulation, therefore connection is directly established according to target database address, and send institute Inquiry operation after stating conversion.It as to how establishing connection, can be realized by ODBC interface, its other party can also be used Formula realizes that specific mode is not the core of the application, and the application is not construed as limiting.
C) line identifier that the target data returns is received, the line identifier of return is influenced as the database manipulation Line identifier.
The response of target database is received, the line identifier that target database returns is exactly the row that the database manipulation influences Mark.Time-out in this step, it is also possible to the unresponsive abnormal conditions of destination server occur, can be according to sub-step 8) Processing mode is handled, and details are not described herein again.
In conclusion obtaining new row by way of unified distribution if the database manipulation is newly-increased operation Mark, if the database manipulation is to update, delete, inquiry operation, by executing one query behaviour to target database Obtain the line identifier that these operations influence.After system adjusts layer to obtain above-mentioned line identifier, above-mentioned line identifier information can be written In the line identifier set that system adjusts the line identifier set of the business-impacting of layer and database manipulation to influence.
4) the current accessed state of the corresponding row of the line identifier is obtained.
Why line identifier that the database manipulation influence is obtained in above-mentioned steps, exactly in order to further obtain The current accessed state of the corresponding row of the line identifier.The access state of the corresponding row of the line identifier, refers to currently whether deposit Access control and the type of access control etc. of the corresponding row of the line identifier are obtained in other affairs.
In implementation process, affairs generally use lock mechanism for the access control of row in database to realize.Lock is several According to a very important concept in library, it is mainly used for guaranteeing data base integrity and consistency under multi-user environment.Institute Lock mechanism is called, exactly data resource (such as: certain a line or a few rows in database) associates with single affairs, and Control the mechanism how other affairs interact with the resource, usually we claim to hold with the affairs of locked resource associations or Possess the lock.Once being locked, just hold the lock before service termination always, release lock when the service termination, other affairs are just The data resource being unlocked can be used, otherwise other affairs necessarily are in wait state.
Lock is the main method for realizing con current control, especially realizes the main method for writing control, is that multiple affairs can The data in the same database are manipulated without the important leverage of the inconsistent phenomenon of data simultaneously.When multiple affairs are right simultaneously When identical data execute write operation (include: update, deletion, create) in database, only allow the affairs of holder lock that can execute The write operation, other affairs have to wait for, and until previous affairs release lock, other affairs just have an opportunity to continue to execute. Lock is also the main method for realizing the isolation of affairs.Most of databases, such as SQL Server and other relationship types Data are all to realize isolation mech isolation test by using locking.
The type of so-called access control refers to the type of lock.In integration across database distributed transaction provided herein In implementation method, two kinds of locks: process lock and exclusive lock are related generally to.So-called process lock refers to, if certain affairs is to its database Operation added process lock, then other affairs is not allowed to modify the row of database manipulation influence, but other affairs is allowed to read The row for taking the database manipulation to influence, that is to say, that process lock is to guarantee that only having a write operation in synchronization influences number According in library certain a line or a few rows.So-called exclusive lock (also known as exclusive lock) refers to, not only other affairs is not allowed to modify the number According to the row that library operation influences, while other affairs not being allowed to read the row that the database manipulation influences yet, that is to say, that current Before affairs discharge the lock of the database manipulation, the row that other affairs influence the database manipulation can neither be modified It cannot read.In specific implement, to the process that database manipulation locks, the row exactly influenced on the database manipulation adds Lock mark process, referring to sub-step 6) in related description.
In a specific example of the present embodiment, the current accessed state of the corresponding row of the line identifier is obtained, is logical It crosses and searches what system adjusted the data of layer maintenance to realize, specifically use following steps: a) first searching system and adjust the affairs of layer maintenance related Data, check that the line identifier whether in the line identifier set of some business-impacting, and records corresponding Transaction Identifier TransId;B) the relevant data of the corresponding database manipulation of the Transaction Identifier then are searched, it is corresponding obtains the line identifier Capable current accessed status information, comprising: accessing the type of the database manipulation of the corresponding row of the line identifier, the row Whether lock, and type of lock etc..
5) according to the type of the current accessed state of the corresponding row of the line identifier and the database manipulation, judge whether The access for waiting the corresponding row of the line identifier is needed to terminate;If so, waiting is executed, until the corresponding row of the line identifier Access terminates, then executes following step;If it is not, continuing to execute following step.
This sub-step be mainly judge the database manipulation whether with the operations of other concurrent transactions there are read/write conflict, If it is present executing waiting, the database manipulation is executed again after waiting other concurrent transactions, to guarantee the one of data Cause property and integrality.
In a kind of preferred embodiment provided by the present application, is locked using process and realize con current control, that is to say, that if Certain affairs added process lock to its database manipulation, then other affairs is not allowed to modify the row of database manipulation influence, but It is that other affairs is allowed to read the row that the database manipulation influences.Therefore, if the type of the database manipulation is newly-increased behaviour Make or inquiry operation, the then access for withouting waiting for the corresponding row of the line identifier terminate (because newly-increased or inquiry operation is all The row of other business-impactings will not be modified), it may be assumed that it withouts waiting for the release of other affairs and is added on the corresponding row of the line identifier Process lock;If the type of the database manipulation is to update operation or delete operation, further determine whether to meet Following conditions:
A) the corresponding row of the line identifier is accessed currently without by other distributed transactions, that is to say, that sub-step 4) in look into See that the line identifier whether in the line identifier set of some business-impacting, does not find the Trans_ for influencing the line identifier Id, although find, the Trans_Id mark affairs not instead of other affairs, currently be ready for executing the number The affairs itself operated according to library;
B) it is accessed before the corresponding trade of the line identifier by other distributed transactions but is locked without adding procedure, that is to say, that Sub-step 4) in check that the line identifier whether in the line identifier set of some business-impacting, has found different from Current transaction Other Transaction Identifiers Trans_Id of mark, that is to say, that there are other affairs to access the corresponding row of the line identifier, but It is that there is no adding procedures to lock.
If meet it is above-mentioned a) or b) in any one condition, without waiting for the visit of the corresponding row of the line identifier Ask end, it may be assumed that without waiting for the process lock that the release of other affairs is added on the corresponding row of the line identifier;Otherwise, it needs The process lock for waiting the release of other affairs to add on the corresponding row of the mark.
The waiting process, the blocking mechanism that can be provided using system are realized, it may be assumed that by all same resources of request The database manipulation of (such as: it is required that same a line in the same target database of access) is ranked up, and is put into a queue, After resource release, it is notified that the request waited in request queue starts to execute.Different lock machines is formed with different algorithms, The inside for the blocking mechanism that homologous ray provides, which is realized, would also vary from, but these details not examining in technical scheme Within worry, a kind of embodiment for being capable of providing above-mentioned blocking mechanism is mainly used, the application does not limit specifically.
In above-mentioned preferred embodiment provided by the present application, if the database manipulation is inquiry operation, it is not required to The process lock for waiting the release of other affairs to add on the corresponding row of the line identifier, can increase the concurrent journey of affairs in this way Degree, but is likely to occur dirty reading, it may be assumed that current inquiry operation may can read process data that other affairs not yet submit (or Person's intermediate data), therefore preferred embodiment provided by the present application uses reconstruct inquiry operation, merges for inquiry operation The processing mode of query result avoids to realize the isolation level of " reading to submit " and the phenomenon that dirty reading occurs, about this portion It defends oneself bright, refers to the explanation in sub-step 7.
In above-mentioned preferred embodiment provided by the present application, concurrent write is controlled using process lock.At it In his embodiment, other access control schemes can also be used.For example, if to realize the isolation level of serializability, It needs using exclusive lock, that is to say, that before the lock that some affairs discharges the database manipulation, other affairs are to the number According to the row that library operation influences, can neither modify can not be read.Therefore under the requirement of this isolation level, regardless of the data Library operation is write operation or read operation, will carry out more stringent judgement, if the rower that the database manipulation influences Know and currently locked by other affairs using exclusive lock, then the database manipulation has to carry out waiting, is likely to realize in this way The isolation level of serializability.
In order to realize the isolation level of serializability, in addition to use exclusive lock, it is also necessary to consider that there may be unreal readings Problem, it may be assumed that in same affairs, read twice with same operation, and between twi-read, there may be other affairs to perform Insertion operation, the record number for causing first affairs to be inquired twice be not identical, that is to say, that other affairs may will be new Mirage phantom row is inserted into some data acquisition system or table, and mirage phantom row includes in the subsequent reading of Current transaction.In order to avoid occurring The case where unreal reading, cannot simply row grade lock as use process lock or exclusive lock, and need using similar range lock Lock mechanism integrally locks data acquisition system or table that the read operation in first affairs may influence, to prevent other Newline is inserted into data set or table by affairs before the completion of this affairs.Correspondingly, in the judgement of this step, if the number Newly-increased operation according to library operation, it is necessary to judge row that the newly-increased operation influences whether be in the range lock locking range it It is interior, if so, having to carry out waiting.Serializability is that maximum rank is limited in four isolation levels, and concurrent rank is lower, is led to The isolation level is often only just used under special application demand.
In preferred embodiment provided by the present application, the concurrent control mechanism locked using Kernel-based methods, in other implementations , can also be using other lock mechanisms, exclusive lock as described above or range lock in mode, this is to belong to specific reality The change of mode is applied, as long as can satisfy the demand of operation system, realizes the con current control between distributed transaction, specifically Using which kind of lock mechanism, the application is not limited explicitly.
6) according to the type of the database manipulation, judge whether to need to obtain the access to the corresponding row of the line identifier Control, if so, adding access control for the corresponding row of the line identifier.
If the database manipulation does not need to execute waiting by deterministic process above, it may be assumed that the data manipulation shadow Loud line identifier is not locked by other affairs;Or the database manipulation is in obstruction wait state, and waits until other Affairs, which are finished, releases the locking of the corresponding row of the line identifier, under both of these case, can all go to the execution of this sub-step, Access control is added for the corresponding row of the line identifier.
It is already described above, in order to solve to update the problems such as losing existing for concurrent transaction, it is desirable that concurrent transaction is necessary To the write operation of data (that is: updating operation, newly-increased operation or delete operation), access control, it may be assumed that whenever only allows One affairs executes write operation to identical data, and this point just may be used in this way to the basic demand of concurrent transaction access control It can guarantee the consistency and integrality of data.It in the specific implementation process, is the corresponding row addition access control of the line identifier System, is usually realized by lock mechanism, it may be assumed that for the corresponding row addition locking mark of the line identifier.
In a specific example of the present embodiment, by the database manipulation related data that system adjusts layer maintenance Specific locking information is written in " lock " data item, realizes the lock of the corresponding row of line identifier influenced on the database manipulation It is fixed, it may be assumed that be added to locking mark for the corresponding row of the line identifier.
In a kind of preferred embodiment provided by the present application, access control is realized to write operation using process lock, it may be assumed that such as The type of database manipulation described in fruit is newly-increased operation, updates operation or delete operation, then is the corresponding row of the line identifier Adding procedure lock;If the type of the database manipulation is inquiry operation, it is not necessarily the corresponding row addition of the line identifier Process lock.
In other embodiments, access control can also be realized using other lock mechanisms, for example, can be Current transaction In newly-increased operation, update operation or delete operation adds exclusive lock, so that other affairs cannot access in this affairs simultaneously The row (write or read regardless of other affairs) that influences of these operations, this affairs can be read to avoid other affairs and not yet submitted Process data (intermediate data), the isolation level for " reading to submit " to realize, that is to say, that improved by reducing concurrency The rank of isolation;Again for example: can be locked for the inquiry operation in Current transaction also adding procedure, so that other affairs be avoided to modify The row that inquiry operation in Current transaction influences guarantees to inquire the front and back mutually gone together twice in Current transaction, query result It is consistent, that is, realizes the isolation level of " repeatable read ".The change of above embodiment, can be based on operation system not It is determined with demand, no matter which kind of mode is taken, as long as demand of the operation system to isolation level is met, all without departing from the application The core of the technical solution, all within the scope of protection of this application.
7) inquiry operation is reconfigured.
If the database manipulation is inquiry operation, and unites and layer is adjusted to carry out con current control using process lock, then such as Fruit directly executes inquiry operation, it is possible to read the process data that other affairs are not yet submitted, it may be assumed that be only able to achieve minimum The isolation level of " reading not submit ";If carrying out con current control using exclusive lock, although the isolation level of " reading to submit " may be implemented Not, but it will affect the concurrent effect of eventful business, therefore this application provides a kind of preferred embodiments, take construction inquiry behaviour Make, the mode of Fusion query result, while carrying out con current control using process lock, realizes the isolation level of " reading to submit " Not.
Therefore preferred embodiment provided by the present application, holds the database manipulation is sent to the target database Before row, if the database manipulation be inquiry operation, and in sub-step 4) in obtain the line identifier access state For other affairs are added to process lock to the row in the line identifier, then needing to be implemented following steps reconstruct inquiry behaviour Make:
A) type of the currently performed database manipulation of locked row is obtained.
In sub-step 4) in, the affairs related data and database manipulation related data of layer maintenance are adjusted by searching for system, Through obtaining the current accessed status information of corresponding row in the line identifier, held before therefrom obtaining the trade for being added to process lock The type of capable database manipulation.In a specific example of the present embodiment, the line identifier that the inquiry operation influences is 100,101,102, the affairs related data of layer is adjusted by searching for system, it is 100 that discovery, which has other affairs T1 accessing line identifier, Row, further search for the corresponding SQL statement set of affairs T1, therefrom have found current accessed line identifier be 100 row SQL Sentence, it can be seen that affairs T1 has been that the row is added to process lock, and can further obtain the class of the SQL statement Type, and carry out following processing.
It, will be described locked if b) type of the currently performed database manipulation of locked row is newly-increased operation Rower be denoted as and be unsatisfactory for querying condition;If the type of the currently performed database manipulation of locked row is to update behaviour Making perhaps delete operation then further judges the locked row before executing current update operation or delete operation Whether the condition of the inquiry operation is met, if so, record meets the row of the condition of the inquiry operation;It otherwise, will be described Locked rower, which is denoted as, is unsatisfactory for querying condition.
Operation herein is primarily to realize the isolation level of " reading to submit ".If other affairs are not completed to described The operation of lock line, it may be assumed that not yet submit, then although accessible this part is locked current inquiry operation by other affairs Row, but in-between data should not be obtained, but the data before other described affairs have not carried out should be obtained.
If the type of the currently performed database manipulation of locked row is newly-increased operation, regardless of what is increased newly Whether row meets the condition of the inquiry operation, should all identify as being unsatisfactory for querying condition, because new line increment is described The intermediate data of other affairs.
If the type of the currently performed database manipulation of locked row is to update operation or delete operation, It further reads system and adjusts original of the locked row of layer storage before executing current update operation or delete operation The content of database row, and judge whether the content meets the condition of the inquiry operation, if so, record original database row, It otherwise, is to be unsatisfactory for querying condition by locked line identifier.Even if full after executing current update operation to locked row The condition of the foot inquiry operation, can not as meet querying condition as a result, because updates operates not It submits, updated row is the intermediate data of other affairs.
In the above-mentioned specific example of the present embodiment, the line identifier that the inquiry operation influences is 100,101,102, wherein Other affairs T1 is accessing and is locking the row that line identifier is 100, and the row that T1 affairs are 100 to the line identifier executes Be to update operation, and the row that the line identifier is 100 executes the content before updating operation and is unsatisfactory for the inquiry and grasps The rower that line identifier is 100 is then denoted as and is unsatisfactory for querying condition by the condition of work.
C) it generates and eliminates the inquiry operation of the line identifier for being unsatisfactory for querying condition.
According to above-mentioned processing result, rejects and be unsatisfactory for the line identifier of querying condition, regenerate inquiry operation sentence.At this In the above-mentioned example of embodiment, the inquiry operation is: select*from table where queryCondition, because Row 100 is identified as to be unsatisfactory for querying condition, therefore the inquiry operation after reconfiguring is: select*from table where queryCondition and rowEid no in(‘100’)。
Implement above-mentioned the step of reconfiguring inquiry operation, is to realize " reading to submit " while using process lock Isolation level does not need the step of executing above-mentioned reconstruct inquiry operation for updating operation, delete operation, increasing behaviour's lock newly.For Other embodiments, it is above-mentioned for inquiry behaviour due to the isolation level that different lock mechanisms may be used different with realization The reconstruct sub-step for making to execute is not required in that.
8) database manipulation target database is sent to execute.
By 7 sub-steps above, has been completed and send institute before target database for the database manipulation The necessary processing operation for needing to carry out, comprising: distribution line identifier executes waitings, adds that access control, to reconstruct inquiry operation etc. pre- Processing, goes to execute then target database can be sent to the inquiry operation of the database manipulation or reconstruct.
In order to adjust the data that layer uniformly safeguards the information of each distributed transaction and each distributed transaction includes in system The specifying information of library operation needs to write information relevant to the database manipulation before executing the database manipulation Enter system to adjust in the data of layer, comprising: if the line identifier set of database manipulation influence, the database manipulation are to write behaviour Make content, the execution state of the database manipulation, the database that also to record the original database row before the operation executes At the beginning of operating and whether add the type of lock and lock, executing the database manipulation etc..In general, directly by the number The database manipulation collection that is added to the distributed transaction is operated according to library as a new member in the distributed transaction In conjunction, if some database manipulation executed before row and the distributed transaction that the database manipulation influences The row of influence is identical, such as: former and later two database manipulations in the distributed transaction are all the same number of targets of modification According to same a line in library, then the database manipulation can not additionally occupy new memory space, but suitable plan is used Slightly update the related data of previous database manipulation.
It not only needs to update system before executing the database manipulation and adjusts layer related data, also should on other opportunitys The corresponding operation for updating system and adjusting layer data is carried out, such as: after system adjusts layer to receive the request of some database manipulation, it should record The sentence of the database manipulation, and its execution state is recorded for " pending ", after the type for obtaining the database manipulation, it should It is recorded accordingly, before the database manipulation is sent to target database execution, updates the database manipulation Execution state is " in execution " and records the time for starting to execute, and after target database return successful respond, then updates the number Execution state according to library operation is " running succeeded " etc..Record the dependency number of currently performed distributed transaction and database manipulation According to being that system adjusts layer that can be managed collectively the bases of multiple distributed transactions, different embodiments may take different data Structure, the opportunity that different more new datas can also be taken, as long as each affairs correctly can be recorded and database manipulation is worked as Preceding state, the details of specific embodiment is not the core of the application, and the application is not especially limited.
Then target database is sent by the inquiry operation of the database manipulation or reconstruct to execute, and wait target The response of database, usual target database are finished the database manipulation, and implementing result will be returned to system and adjust layer, It is contemplated that under the scene of integration across database distributed transaction, system adjust layer and target database usually not it is same physically Point is to be interacted by network connection, therefore be unavoidably likely to occur because of target database faults itself between the two Or response time-out phenomenon caused by the reasons such as temporary interruption of network connection, it may be assumed that system adjusts layer between one preset time Every the interior response for not receiving target database.Preset time interval can be system and adjust a layer system predetermined One value (such as: 100ms), different values can also be arranged according to the different feature of each database manipulation, in the present embodiment In, using the implementation of the latter, it may be assumed that have an item data in the database manipulation related data that system adjusts layer maintenance " actively Verification time is poor ", after the request for receiving the database manipulation, it can be set according to the type of the database manipulation for it The value is set, such as: for the inquiry operation of mass data to be returned, a biggish value can be set, for only modifying one Capable update operation can be set to relatively small value.If system adjusts layer to send to target database and executes the database behaviour After the order of work, system adjusts layer to detect that the difference of the time of current time and " Starting Executing Time " record is greater than " Proactive authentication The value of time difference " setting, system adjust layer to can be determined that the database manipulation is likely to occur failure, and at this moment system adjusts layer can be using master The mode of dynamic inquiry obtains the executive condition of the database manipulation.
9) implementing result of the database manipulation is returned to the requesting party of the distributed transaction.
The implementing result for the database manipulation that target database returns is received, and the result is sent to described point The requesting party of cloth affairs.
For a kind of preferred embodiment provided by the present application, in order to realize the isolation level of " reading to submit ", for inquiry Operation in sub-step 7) in reconfigured inquiry operation, correspondingly, should also be looked into according to what is reconfigured in this sub-step Returning the result for operation is ask, necessary merging treatment is executed, it may be assumed that by the implementing result of the reconstruct inquiry operation, and has been recorded The row of the condition for meeting the inquiry operation merge, and the result after merging is returned to the request of the distributed transaction Side.In a specific example of the present embodiment, if in sub-step 7) in, system adjusts layer in the original database for meeting condition 10 datas (that is: there are 10 rows to meet querying condition) is had recorded in capable set, sends mesh for the inquiry operation reconfigured It marks and returns to 10 when inquiring in database table again, then adjusting layer just to need that the number will be returned to after this 20 data merger in system The requesting party operated according to library.
Under normal conditions, target database can correctly execute the database manipulation, and return to operation successful respond, but It is also to be not excluded for being likely to occur the case where target database executes exception and adjusts layer to return operation failure response to system, this feelings System tune layer guarantees the atomicity, consistency and persistence of distributed transaction using rollback mechanism under condition.
It is an indivisible operating unit since affairs are the relevant database manipulation sequences of one group of logic, for Database manipulation therein or all execute or do not execute all, an affairs can not only carry out half and just stop Only, this is also the basic demand of transaction atomicity.If some point in affairs breaks down, the office do it is all more New capital should be restored to the state before affairs start.
The atomicity for realizing affairs, generallys use rollback (rolling back) mechanism, and so-called rollback refers to, cancels one The database manipulation executed in failed affairs is to modification made by data, that is to say, that if any one number in affairs Failure is executed according to library operation, then the database manipulation to have run succeeded in the affairs must also cancel, makes database positioning The state returning back to before executing affairs.The realization of rollback, usually can be by the way of similar inverse operation, it may be assumed that the newly-increased behaviour of revocation Make, executes corresponding delete operation;Delete operation is cancelled, corresponding newly-increased operation is executed;Revocation updates operation, holds Row restores the update operation of initial data.It can be seen that in order to realize rollback mechanism, it is necessary to before saving write operation execution The content of database data.System adjusts layer in the relevant data of database manipulation of its maintenance, and having an item data, " write operation executes Why preceding database data content ", design the data item, is on the one hand for realizing the reconstruct of " reading to submit " isolation level On the other hand inquiry operation is exactly the rollback mechanism in order to realize affairs.
There is exception in the process of implementation in the distributed transaction, then system adjust layer can the result is returned to it is described After the requesting party of distributed transaction, rolling back action is actively executed, the requesting party of the distributed transaction can also be waited to issue and opened Rollback is executed again after the order of dynamic rolling back action, both modes can guarantee the atomicity of the distributed transaction.System is adjusted Layer executes rolling back action by following step:
A) it updates system and adjusts layer data, the execution state of the distributed transaction is updated to " in rollback ", by the distribution In formula affairs the execution state of the database manipulation of revocation in need be all updated to " to rollback ";
B) for database manipulation each to be cancelled, according to " the database data content before write operation execution " data item Content, construct the database manipulation inverse operation either restore data original contents update operation, be subsequently sent to Target database executes.The state that the database manipulation is updated before execution is " in rollback ", its shape is updated after execution State is " rollback success ";
C) " rollback success " message is reported to the requesting party of the distributed transaction, informs the request of the distributed transaction Side, the distributed transaction have cancelled.Certainly, as a kind of abnormal conditions, rolling back action may also fail, in this case System adjusts layer unautogenous can also take movement, but the situation is reported to the requesting party of the distributed transaction, then by described According to the policy distribution of application layer, the order of the distributed transaction is either removed in rollback to the requesting party of distributed transaction again.
Step 104: being finished to all database manipulations, remove the distributed transaction.
On the one hand, if system adjusts layer to be carried out all database manipulations in the distributed transaction received Finish, including run succeeded and rollback two kinds of situations of success, then system adjusts layer that can remove the distributed transaction;Another party Face, system adjust layer that can also refer to receiving the display terminated about the distributed transaction that the distributed transaction requesting party issues After showing, the distributed transaction is removed.
The distributed transaction is removed, mainly includes that following both sides operates:
1) operation that unlocks is executed to the row of distributed transaction locking.
Since system adjusts layer in the implementation procedure of the distributed transaction, in order to realize the access control and reality of concurrent transaction Now certain isolation level uses lock mechanism, therefore the row that the database manipulation in the distributed transaction is influenced is current It may be also in lock state, that is to say, that holder of possible still one or more lock of the distributed transaction, it is this In the case of, the row that system adjusts layer to need to lock the distributed transaction executes the operation to unlock, that is, described point of release The lock that cloth affairs are held, other, which are blocked in above-mentioned other distributed transactions locked, in this way can terminate wait state, and It is carried out, to guarantee the normal operation of integration across database distributed transaction.
2) the distributed transaction mark and corresponding internal storage data are deleted.
Because the distributed transaction has been finished, system adjusts layer to need to delete in the system tune layer data safeguarded from it Except data relevant to the affairs, comprising: the mark of the distributed transaction, execution state, the distributed transaction include Database manipulation set and other data relevant to the distributed transaction, and from system adjust layer safeguard global transaction The distributed transaction is deleted in list.By clearing up the related data of completed distributed transaction, system adjusts layer can be effective Ground recycles and manages its memory headroom used, avoids the occurrence of the case where consuming memory headroom excessively.
The starting that integration across database distributed transaction is described above, the treatment process for executing and terminating, in actual implementation In the process, it is also contemplated that some abnormal conditions being likely to occur, and necessary processing mode is set for abnormal conditions, to guarantee System adjusts layer that can run well in abnormal cases and guarantee the ACID characteristic of integration across database distributed transaction.System is adjusted Layer can provide the exception handling of two kinds of ranks:
1) exception handling of database manipulation rank.Aforementioned system adjusts layer to issue the database manipulation After target database, it is possible that the situation of target database response time-out, at this moment system adjusts layer that can pass through active inquiry Mode obtains the practical executive condition of the database manipulation.This exception handling belongs to the exception of database manipulation rank Treatment mechanism.
2) the other exception handling of transaction-level.The characteristics of due to integration across database distributed transaction, the distributed transaction Be likely to occur during execution it is various it is difficult to predict the problem of, cause the distributed transaction phenomenon of time-out, needle occur To this problem, system adjusts layer to be handled using following mechanism: system tune layer judges the duration of the distributed transaction, if It was found that the duration is greater than the preset time, (that is: system is adjusted in the data of layer maintenance for each distributed transaction The setting of affairs time-out), then it dishes out overtime abnormal, it, can be according to setting in advance after corresponding exception handler captures the exception Fixed strategy carries out necessary processing, such as: initiate the rolling back action etc. of the distributed transaction.Certainly, above-mentioned affairs time-out It is abnormal, a kind of abnormal conditions being only likely to occur in distributed transaction implementation procedure, in the specific implementation process, for can Other exceptions that can occur can also use similar processing mode, exception handler is transferred to handle.
During the realization of integration across database distributed transaction, in addition to consider the above-mentioned abnormal conditions being likely to occur, also The emergency events such as catastrophic event, such as delay machine may occur for the system of must be taken into consideration, and may cause some distributed transaction and only hold It has gone partial database operation, the data of target database is made to be in inconsistent state.The integration across database perfect as one Distributed transaction, it is necessary to have the ability for handling above-mentioned catastrophic event, it may be assumed that allow for restoring to have not carried out the distribution finished The data of formula affairs.Realize this point, it usually needs use log mechanism, it may be assumed that adjust layer to safeguard a transaction journal text in system Part, the modification made for recording all affairs and each affairs to target database then use once system breaks down The update that transaction journal revocation affairs have done target database, is restored to the consistent shape before executing affairs for target database State.Tune layer of uniting is guaranteed the atomicity of distributed transaction, consistency using previously described rollback mechanism and journaling techniques and held Long property.
It adjusts layer to realize journal function in system, needs to be implemented both sides operation:
1) simultaneously care of transaction journal file is generated.System is adjusted to the related data of the distributed transaction of layer maintenance, and distribution In formula affairs in the related data write-in transaction log file of each database manipulation, in order to guarantee that transaction log file can be just The really execution state of reflection distributed transaction, preferably with the mode of real-time write-in transaction log file, it may be assumed that system adjusts layer every time more It, also simultaneously will be in the content write-in transaction log file of update when the data of its new maintenance.When some distributed transaction has executed Finish, system adjust layer while clear up data relevant to the affairs, should also delete recorded in transaction log file it is related this The data of distributed transaction, and the space of the transaction log file of recycling is used to store the log number of other distributed transactions According to.
2) it when system adjusts layer restarting, loads the Transaction Information in the journal file and carries out necessary rolling back action.
Once the catastrophic events such as delay machine occur, system adjusts layer during restarting, reads first and loads log Data in file restore the execution state that system adjusts the distributed transaction of layer before restart, and are directed to and have had not carried out Distributed transaction execute rolling back action, the update that the distributed transaction has done target database is cancelled, by target database The original state being restored to before executing the distributed transaction, to guarantee the atomicity of affairs.Rolling back action described here with Rolling back action in affairs implementation procedure is similar, and specific steps may refer to the related description in step 103, no longer superfluous herein It states.
In the case where being abnormal, rollback mechanism and log mechanism are on the one hand used, it is ensured that distributed transaction Atomicity, consistency and persistence;On the other hand, system adjusts layer to be also required to consider the Rational Maintenance mechanism of its own data.System is adjusted Layer has recorded data relevant to distributed transaction and data relevant with the database manipulation in distributed transaction, is being distributed In the case where formula affairs normal termination, above-mentioned data can adjust layer to clear up in time by system, in the case where being abnormal, above-mentioned data It may pass into silence, the invalid data that system adjusts layer memory headroom be occupied to become, in order to provide descaling machine to above-mentioned invalid data " affairs clearance time " this data item is written in system, method provided herein in the global data that system adjusts layer, is used for The abnormal affairs to have terminated are cleaned up on specific time point.Specifically, system adjust layer can setting affairs it is clear The execution state that all distributed transactions of its maintenance are scanned on reason time point, if it find that the state of the distributed transaction is always It is not updated, it may be assumed that the distributed transaction is in an inactive state, then unites and adjust layer that can actively initiate to clear up the distributed transaction Operation.
Using the implementation method of integration across database distributed transaction provided by the present application, by making in target database system The access operation of distributed transaction is managed collectively with unique line identifier, and using access control mechanisms, is avoided pair The problem that the asynchronous operation of target database causes data inconsistent, realize lightweight, it is easy to maintain and meet The integration across database distributed transaction of ACID principle.
A kind of preferred embodiment provided by the present application, by distributed transaction write operation (including newly-increased operation, Update operation and delete operation) plus process lock, it may be assumed that allow other distributed transactions read row that the write operation influences but not Write operation can be executed to the row, while additionally use the mode of reconstruct query statement, Fusion query result, avoid reading other The process data that affairs are not yet submitted, thus while " reading to submit " isolation level for realizing integration across database distributed transaction, Also preferable concurrency effect is obtained.
In the above-described embodiment, a kind of implementation method of integration across database distributed transaction is provided, it is corresponding, The application also provides a kind of realization device of integration across database distributed transaction.Fig. 2 is please referred to, is one kind of the application across data The embodiment schematic diagram of the realization device of library distributed transaction.Since Installation practice is substantially similar to embodiment of the method, so Describe fairly simple, the relevent part can refer to the partial explaination of embodiments of method.Installation practice described below is only It is schematical.
The realization device of a kind of integration across database distributed transaction of the present embodiment, comprising: affairs start unit 201 is used for The starting request of distributed transaction is received, and distributes Transaction Identifier for the distributed transaction;Receiving unit 202 is operated, is used for Receive the operation requests or operation requests set for database manipulation for being assigned the distributed transaction of Transaction Identifier;Operation is held Row unit 203 obtains the target database information of the database manipulation, and follow ACID for being directed to each operation requests Principle sends the target database for the database manipulation and executes;Affairs clearing cell 204, for the distribution After affairs are finished, the distributed transaction is removed.
Optionally, the operation execution unit obtains the target database letter of the database manipulation in the following way Breath: the title of the target database and/or table specified according to the database manipulation searches pre-set database description letter Breath therefrom obtains target database information corresponding with the title of the target database and/or table.
Optionally, the operation execution unit includes:
Target data library inquiry subelement, target database and/or table for being specified according to the database manipulation Title searches pre-set database description information, therefrom obtains corresponding with the title of the target database and/or table Target database information;
Action type obtains subelement, for obtaining the type of the database manipulation;
Line identifier obtains subelement, for parsing the database manipulation, obtains the rower that the database manipulation influences Know;
Access state obtains subelement, for obtaining the current accessed state of the corresponding row of the line identifier;
Subelement is waited, for according to the current accessed state of the corresponding row of the line identifier and the database manipulation Type judges whether to need to wait the access of the corresponding row of the line identifier to terminate;If so, executing waiting, the row is waited until The access for identifying corresponding row terminates, then executes following step;If it is not, continuing to execute following step;
Access control subelement judges whether to need to obtain to the row for the type according to the database manipulation The access control of corresponding row is identified, if so, adding access control for the corresponding row of the line identifier;
Operation executes subelement, executes for the database manipulation to be sent to the target database;
As a result subelement is returned to, for returning to the execution knot of the database manipulation to the requesting party of the distributed transaction Fruit.
Optionally, the operation execution unit further include:
Operation overtime handles subelement, and holding for target database return is not received within the preset time for working as When row result, the implementing result of the database manipulation is obtained by way of active access target database.
Optionally, the action type obtains the action type that subelement obtains and includes: newly-increased operation, update operation, delete Except operation or read operation.
Optionally, the line identifier acquisition subelement includes:
Line identifier distributes subelement, for being the newly-increased behaviour when the type of the database manipulation is newly-increased operation Make to distribute the line identifier of the unique identification row, and the line identifier is added in newly-increased operation;
Line identifier inquires subelement, for the database manipulation to be resolved to the acquisition line identifier using the same terms Inquiry operation, and the inquiry operation is sent to the target database and is executed, the rower that the target database is returned Know the line identifier influenced as the database manipulation.
Optionally, the waiting subelement is specifically used for, when the type of the database manipulation is newly-increased operation or is looked into When asking operation, waiting is not executed;When the type of the database manipulation is to update operation or delete operation, if the row Corresponding row is identified currently without by the transactions access except current distributed transaction, though by except current distributed transaction Transactions access but without locked, then do not execute waiting, otherwise execute waiting.
Optionally, the access control subelement is specifically used for, when the type of the database manipulation is newly-increased operates, more When new operation or delete operation, allows to execute inquiry operation for the corresponding row addition of the line identifier but do not allow to execute newly-increased Operation, the process lock for updating operation and delete operation.
Optionally, the operation execution unit further include:
Inquiry operation reconstructs subelement, is inquiry operation and the rower for the type when the database manipulation When there is the row locked by the affairs except current distributed transaction in knowledge, inquiry operation is reconfigured.
The inquiry operation reconstructs subelement
Lock line action type obtains subelement, for obtaining the currently performed database manipulation of locked row Type;
Querying condition verifies subelement, is new for the type when the currently performed database manipulation of locked row When increasing operation, the locked rower is denoted as and is unsatisfactory for querying condition;When the currently performed data of locked row The type of library operation be update operation or delete operation and the locked row execute current update operate or When meeting the condition of the inquiry operation before delete operation, record meets the row of the condition of the inquiry operation, otherwise, by institute It states locked rower and is denoted as and be unsatisfactory for querying condition;
Inquiry operation generates subelement, eliminates the inquiry behaviour of the line identifier for being unsatisfactory for querying condition for generating Make;
Correspondingly, the operation, which executes the inquiry operation that subelement is specifically used for reconfigure, is sent to the number of targets It is executed according to library.
It is specifically used for correspondingly, the result returns to subelement, the implementing result of the inquiry operation and has recorded The row for meeting the condition of the inquiry operation merges, and the result after merging is returned to the requesting party of the distributed transaction.
Optionally, described device further include:
Data write unit, the data for including by the relevant information of the distributed transaction and the distributed transaction The relevant information of library operation is written in internal storage data corresponding with distributed transaction mark.
Optionally, the affairs clearing cell includes:
Unlock subelement, for executing the operation that unlocks to the row that the distributed transaction locks;
Data dump subelement, for deleting the distributed transaction mark and memory relevant to the distributed transaction Data.
Optionally, described device further include:
Rollback unit, for obtaining the implementing result of database manipulation, when some database in the distributed transaction When operation fails to run succeeded, rollback behaviour is executed to other database manipulations of the successful execution in the distributed transaction Make, is restored to the state before the distributed transaction executes.
Optionally, described device further include:
Exception processing unit, for judging the duration of the distributed transaction, if the distributed transaction fails It is completed within the preset time, then triggers exception handler and execute rolling back action.
Optionally, described device further include:
Log management unit, for by the implementation procedure of the distributed transaction and the distributed transaction to number of targets In the modification write-in journal file made according to library.
Optionally, described device further include:
Transaction recovery unit, for reading the journal file, and according to the distributed thing recorded in the journal file The information of business executes rolling back action to the distributed transaction not yet completed.
Although the application is disclosed as above with preferred embodiment, it is not for limiting the application, any this field skill Art personnel are not departing from spirit and scope, can make possible variation and modification, therefore the guarantor of the application Shield range should be subject to the range that the claim of this application defined.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium Example.
1, computer-readable medium can be by any side including permanent and non-permanent, removable and non-removable media Method or technology realize that information stores.Information can be computer readable instructions, data structure, the module of program or other numbers According to.The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory techniques, CD-ROM are read-only Memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or Other magnetic storage devices or any other non-transmission medium, can be used for storage can be accessed by a computing device information.According to Herein defines, and computer-readable medium does not include non-temporary computer readable media (transitory media), such as modulates Data-signal and carrier wave.
2, it will be understood by those skilled in the art that embodiments herein can provide as the production of method, system or computer program Product.Therefore, complete hardware embodiment, complete software embodiment or embodiment combining software and hardware aspects can be used in the application Form.It can be used moreover, the application can be used in the computer that one or more wherein includes computer usable program code The computer program product implemented on storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) Form.

Claims (19)

1. a kind of implementation method of integration across database distributed transaction characterized by comprising
The starting request of distributed transaction is received, and distributes Transaction Identifier for the distributed transaction;
Receive the operation requests or operation requests set for database manipulation for being assigned the distributed transaction of Transaction Identifier;
For each operation requests, the target database information of the database manipulation is obtained, and following ACID principle will be described Database manipulation is sent to the target database and executes;
It is finished to all database manipulations, removes the distributed transaction;
Wherein, it is described follow ACID principle and send the target database for the database manipulation execute, comprising:
According to the current accessed shape for the corresponding row of line identifier that the type of the database manipulation and the database manipulation influence State determines the opportunity that the database manipulation is sent to the target database execution, and according to the database manipulation Type determines whether to add access control, is sent to the target database and executes.
2. the implementation method of integration across database distributed transaction according to claim 1, which is characterized in that described in the acquisition The target database information of database manipulation specifically refers to, the target database and/or table specified according to the database manipulation Title, search pre-set database description information, therefrom obtain it is corresponding with the title of the target database and/or table Target database information.
3. the implementation method of integration across database distributed transaction according to claim 1, which is characterized in that described according to The current accessed state for the corresponding row of line identifier that the type of database manipulation and the database manipulation influence, determination will be described Database manipulation is sent to the opportunity that the target database executes, and determines whether to add according to the type of the database manipulation Add access control, be sent to the target database and execute, comprising:
Obtain the type of the database manipulation;
The database manipulation is parsed, the line identifier that the database manipulation influences is obtained;
Obtain the current accessed state of the corresponding row of the line identifier;
According to the type of the current accessed state of the corresponding row of the line identifier and the database manipulation, judge whether to need To the end of the access of the corresponding row of the line identifier;If so, waiting is executed, until the access knot of the corresponding row of the line identifier Beam, then execute following step;If it is not, continuing to execute following step;
According to the type of the database manipulation, judge whether to need to obtain the access control to the corresponding row of the line identifier, If so, executing following step after adding access control for the corresponding row of the line identifier;If it is not, executing following step;
The database manipulation is sent to the target database to execute;
The implementing result of the database manipulation is returned to the requesting party of the distributed transaction.
4. the implementation method of integration across database distributed transaction according to claim 3, which is characterized in that execute described by institute After stating the step of database manipulation is sent to target database execution, if not receiving mesh within the preset time The implementing result that database returns is marked, then obtains the execution of the database manipulation by way of active access target database As a result.
5. the implementation method of integration across database distributed transaction according to claim 3, which is characterized in that the database behaviour The type of work includes: newly-increased operation, updates operation, delete operation or inquiry operation.
6. the implementation method of integration across database distributed transaction according to claim 5, which is characterized in that described in the parsing Database manipulation obtains the line identifier that the database manipulation influences, comprising:
If the type of the database manipulation is newly-increased operation, the unique identification row is distributed for the newly-increased operation Line identifier, and the line identifier is added in newly-increased operation;
Otherwise, following step is executed:
The database manipulation is resolved to the inquiry operation of the acquisition line identifier using the same terms;
The inquiry operation is sent to the target database to execute;
Receive the line identifier that the target database returns, the rower that the line identifier of return is influenced as the database manipulation Know.
7. the implementation method of integration across database distributed transaction according to claim 5, which is characterized in that described according to The current accessed state of the corresponding row of line identifier and the type of the database manipulation, judge whether to need to wait the line identifier The access of corresponding row terminate, in particular to:
If the type of the database manipulation is newly-increased operation or inquiry operation, it is judged to withouting waiting for the rower The access for knowing corresponding row terminates;
If the type of the database manipulation is to update operation or delete operation, further judge that the line identifier is corresponding The trade before whether not by except current distributed transaction office access, though by except current distributed transaction Transactions access but without locked, if so, the access for being judged to withouting waiting for the corresponding row of the line identifier terminates;It is no Then, it is judged to needing to wait the access of the corresponding row of the line identifier to terminate.
8. according to the implementation method of integration across database distributed transaction described in claim 5-7 any one, which is characterized in that institute The type according to the database manipulation is stated, judges whether to need to obtain the access control to the corresponding row of the line identifier, tool Body refers to:
If the type of the database manipulation is newly-increased operation, updates operation or delete operation, it is judged to needing to obtain To the access control of the corresponding row of the line identifier;
Correspondingly, it is described for the corresponding row of the line identifier add access control, in particular to, be the corresponding row of the line identifier Addition allows to execute inquiry operation but does not allow to execute newly-increased operation, updates operation and the process lock of delete operation.
9. the implementation method of integration across database distributed transaction according to claim 8, which is characterized in that it is described will be described Database manipulation was sent to before the step of target database executes, and executed operations described below: if the database manipulation Type be inquiry operation, and in the line identifier exist by except current distributed transaction affairs lock row, then adopt Inquiry operation is reconfigured with following step:
Obtain the type of the currently performed database manipulation of locked row;
If the type of the currently performed database manipulation of locked row is newly-increased operation, by the locked rower It is denoted as and is unsatisfactory for querying condition;
If the type of the currently performed database manipulation of locked row is to update operation or delete operation, into one Step judges whether the locked row meets the inquiry operation before executing current update operation or delete operation Condition, if so, record meet the inquiry operation condition row;Otherwise, the locked rower is denoted as discontented Sufficient querying condition;
It generates and eliminates the inquiry operation of the line identifier for being unsatisfactory for querying condition;
The database manipulation is sent to target database execution refers to correspondingly, described, the inquiry that will be reconfigured Operation is sent to the target database and executes;
Correspondingly, the implementing result that the requesting party to the distributed transaction returns to the database manipulation refers to, by institute The implementing result for stating inquiry operation merges with the row of the condition for meeting the inquiry operation that has recorded, and by the knot after merging Fruit returns to the requesting party of the distributed transaction.
10. the implementation method of integration across database distributed transaction according to claim 9, which is characterized in that the method is also Include:
The relevant information for the database manipulation for including by the relevant information of the distributed transaction and the distributed transaction is written In internal storage data corresponding with distributed transaction mark.
11. the implementation method of integration across database distributed transaction according to claim 10, which is characterized in that the distribution The relevant information of affairs includes: the Transaction Identifier of the distributed transaction, execution state and time-out setting;
The relevant information for the database manipulation that the distributed transaction includes include: target database information, influence line identifier, The content of row before updating operation or delete operation execution, executes state, Proactive authentication time difference, database manipulation at lock status The type of sentence and database manipulation.
12. the implementation method of integration across database distributed transaction according to claim 11, which is characterized in that the removing institute Stating distributed transaction includes:
The operation that unlocks is executed to the row of distributed transaction locking;
Delete the distributed transaction mark and internal storage data relevant to the distributed transaction.
13. according to claim 1-7, implementation method of any integration across database distributed transaction of 9-12, which is characterized in that The method also includes:
The implementing result of database manipulation is obtained, if any database operation in the distributed transaction fails to run succeeded, Rollback operation then is executed to other database manipulations of the successful execution in the distributed transaction, is restored to the distribution State before the execution of formula affairs.
14. the implementation method of integration across database distributed transaction according to claim 8, which is characterized in that the method is also Include:
The implementing result of database manipulation is obtained, if any database operation in the distributed transaction fails to run succeeded, Rollback operation then is executed to other database manipulations of the successful execution in the distributed transaction, is restored to the distribution State before the execution of formula affairs.
15. according to claim 1-7, implementation method of any integration across database distributed transaction of 9-12, which is characterized in that The method also includes:
Judge the duration of the distributed transaction, if the duration is greater than the preset time, triggers different Normal processing routine is handled.
16. the implementation method of integration across database distributed transaction according to claim 8, which is characterized in that the method is also Include:
Judge the duration of the distributed transaction, if the duration is greater than the preset time, triggers different Normal processing routine is handled.
17. the implementation method of integration across database distributed transaction according to claim 13, which is characterized in that the method is also Include:
Day is written into the modification that the implementation procedure of the distributed transaction and the distributed transaction make target database In will file.
18. the implementation method of integration across database distributed transaction according to claim 17, which is characterized in that the method is also Include:
The journal file is read, and according to the information of the distributed transaction recorded in the journal file, to what is not yet completed The database manipulation of successful execution in distributed transaction executes rollback operation.
19. a kind of realization device of integration across database distributed transaction characterized by comprising
Affairs start unit, the starting for receiving distributed transaction is requested, and distributes Transaction Identifier for the distributed transaction;
Operate receiving unit, the operation requests for database manipulation of the distributed transaction for receiving assigned Transaction Identifier Or operation requests set;
Operation execution unit obtains the target database information of the database manipulation, and abide by for being directed to each operation requests It follows ACID principle and sends the target database execution for the database manipulation;
Affairs clearing cell, for removing the distributed transaction after the distributed transaction is finished;
Transaction recovery unit, for reading journal file, and according to the information of the distributed transaction recorded in the journal file, Rolling back action is executed to the distributed transaction not yet completed;
Wherein, it is described follow ACID principle and send the target database for the database manipulation execute, comprising:
According to the current accessed shape for the corresponding row of line identifier that the type of the database manipulation and the database manipulation influence State determines the opportunity that the database manipulation is sent to the target database execution, and according to the database manipulation Type determines whether to add access control, is sent to the target database and executes.
CN201410025961.8A 2014-01-20 2014-01-20 The implementation method and device of integration across database distributed transaction Active CN104793988B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410025961.8A CN104793988B (en) 2014-01-20 2014-01-20 The implementation method and device of integration across database distributed transaction

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410025961.8A CN104793988B (en) 2014-01-20 2014-01-20 The implementation method and device of integration across database distributed transaction

Publications (2)

Publication Number Publication Date
CN104793988A CN104793988A (en) 2015-07-22
CN104793988B true CN104793988B (en) 2019-01-22

Family

ID=53558803

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410025961.8A Active CN104793988B (en) 2014-01-20 2014-01-20 The implementation method and device of integration across database distributed transaction

Country Status (1)

Country Link
CN (1) CN104793988B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110888929A (en) * 2019-12-06 2020-03-17 秒针信息技术有限公司 Data processing method, data processing device, data node and storage medium

Families Citing this family (50)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11301457B2 (en) 2015-06-29 2022-04-12 Microsoft Technology Licensing, Llc Transactional database layer above a distributed key/value store
CN105159991B (en) * 2015-09-01 2019-08-02 北京皮尔布莱尼软件有限公司 A kind of method, apparatus, system and application server keeping data consistency
CN106547781B (en) * 2015-09-21 2021-06-11 南京中兴新软件有限责任公司 Method and device for realizing distributed transaction and database server
CN106570027B (en) * 2015-10-10 2020-08-25 阿里巴巴集团控股有限公司 Transactional task processing method and device
CN105426234B (en) * 2015-10-30 2019-02-19 小米科技有限责任公司 Database deadlocks detection method and device
CN105512244B (en) * 2015-11-30 2019-03-01 北京京东尚科信息技术有限公司 The method and device of db transaction processing is realized based on message queue
CN106897306B (en) * 2015-12-21 2019-04-30 阿里巴巴集团控股有限公司 Database operation method and device
CN105718572B (en) * 2016-01-21 2017-03-15 成都索贝数码科技股份有限公司 A kind of transaction consistency of isomeric data composite object reaches method and system
US10339127B2 (en) * 2016-01-28 2019-07-02 Oracle International Corporation Guaranteed commit outcome in a distributed transaction processing system
CN105786595B (en) * 2016-02-29 2019-04-23 浪潮通用软件有限公司 A kind of transaction control method that two-part is submitted
CN107203560B (en) * 2016-03-18 2020-07-07 中国移动通信集团宁夏有限公司 Database, multi-database operation transaction consistency ensuring method and system
CN107229628B (en) * 2016-03-23 2022-02-01 金篆信科有限责任公司 Distributed database preprocessing method and device
CN105955804B (en) * 2016-04-22 2018-06-05 星环信息科技(上海)有限公司 A kind of method and apparatus for handling distributed transaction
CN107491975B (en) * 2016-06-13 2021-02-23 阿里巴巴集团控股有限公司 Data slot data processing method and device for server and consumer
CN105892957B (en) * 2016-06-14 2019-04-23 中山大学 A kind of distributed transaction execution method based on Dynamic Program Slicing
CN107644025B (en) * 2016-07-20 2021-03-16 阿里巴巴集团控股有限公司 Method and device for distributing WAL records of distributed database
CN106354747B (en) * 2016-08-15 2019-08-16 成都轻车快马网络科技有限公司 Service providing method for big data
CN107797850B (en) * 2016-08-30 2021-09-21 阿里巴巴集团控股有限公司 Method, device and system for distributed transaction processing
CN109997166B (en) * 2016-09-19 2024-02-06 金融与风险组织有限公司 System and method for intercepting intelligent contracts
CN107870954B (en) * 2016-09-28 2021-09-21 中国移动通信集团广东有限公司 Method and device for expanding distributed database
CN106528754A (en) * 2016-10-28 2017-03-22 努比亚技术有限公司 Processing device and method of recycled data in cloud services
US10565187B2 (en) * 2016-11-17 2020-02-18 Sap Se Management of transactions spanning different database types
CN106682082B (en) * 2016-11-23 2021-03-26 青岛海信移动通信技术股份有限公司 Writing method and device for database
CN108228617A (en) * 2016-12-14 2018-06-29 北京国双科技有限公司 Ensure the method and device of database manipulation atomicity
CN107784055A (en) * 2017-02-17 2018-03-09 平安科技(深圳)有限公司 Transaction methods and device based on non-relational database
CN108572991A (en) * 2017-03-14 2018-09-25 北京京东尚科信息技术有限公司 Data base processing method, device and storage medium
CN107465725B (en) * 2017-07-20 2020-11-06 中国银行股份有限公司 Heterogeneous long transaction processing system and method based on client information control system
CN107272437B (en) * 2017-08-01 2021-06-04 中国联合网络通信集团有限公司 Intelligent device, control method and control platform thereof, and intelligent device system
CN109408201B (en) * 2017-08-18 2022-07-12 中国银联股份有限公司 Transaction management method based on distributed database
CN110019050A (en) * 2017-10-19 2019-07-16 中兴通讯股份有限公司 A kind of data rewind method, system, equipment and computer readable storage medium
CN109783200B (en) * 2017-11-13 2023-09-22 阿里云计算有限公司 Data processing method, device and equipment
CN110019530A (en) * 2017-12-29 2019-07-16 百度在线网络技术(北京)有限公司 Transaction methods and device based on distributed data base
CN108363806B (en) * 2018-03-01 2020-07-31 上海达梦数据库有限公司 Multi-version concurrency control method and device for database, server and storage medium
CN108491252B (en) * 2018-03-13 2022-03-22 万惠投资管理有限公司 Distributed transaction processing method and distributed system
CN108733457B (en) * 2018-04-12 2021-07-20 创新先进技术有限公司 Method and device for realizing distributed transaction
CN109002462B (en) * 2018-06-04 2020-11-27 北京明朝万达科技股份有限公司 Method and system for realizing distributed transaction
CN108829876A (en) * 2018-06-26 2018-11-16 山东汇贸电子口岸有限公司 The solution and device that the pl/sql client request time-out of Oracle does not respond
CN109918178B (en) * 2019-03-06 2021-04-30 恒生电子股份有限公司 Transaction submitting method and related device
CN110765143B (en) * 2019-10-10 2022-08-02 腾讯科技(深圳)有限公司 Data processing method, device, server and storage medium
CN110765178B (en) * 2019-10-18 2021-03-05 京东数字科技控股有限公司 Distributed transaction processing method and device and computer storage medium
CN110807046B (en) * 2019-10-31 2022-06-07 浪潮云信息技术股份公司 Novel distributed NEWSQL database intelligent transaction optimization method
CN111581241B (en) * 2020-04-21 2023-08-18 上海爱数信息技术股份有限公司 Read caching method for lock-free processing
CN111858629B (en) * 2020-07-02 2023-08-22 北京奥星贝斯科技有限公司 Implementation method and device for two-stage submitting distributed transaction update database
CN112182082B (en) * 2020-09-24 2021-07-06 广州巨杉软件开发有限公司 System and method for realizing strong consistency of transactions across different database engines
CN112598520A (en) * 2020-12-28 2021-04-02 中国农业银行股份有限公司 Transaction management method, device, electronic equipment and storage medium
CN113467898B (en) * 2021-09-02 2022-01-18 北京开科唯识技术股份有限公司 Multi-party cooperative service processing method and system
CN114510495B (en) * 2022-04-21 2022-07-08 北京安华金和科技有限公司 Database service data consistency processing method and system
CN115495205B (en) * 2022-11-01 2023-03-14 武汉大数据产业发展有限公司 Method and device for realizing data consistency based on distributed transaction lock
CN115994191B (en) * 2023-03-24 2023-07-07 北京极数云舟科技有限公司 DDL execution data synchronization method and device based on physical replication
CN117763052A (en) * 2024-02-22 2024-03-26 浩鲸云计算科技股份有限公司 data synchronization method and system for charging multi-center memory database

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101196926A (en) * 2007-12-29 2008-06-11 中国建设银行股份有限公司 Database access platform and access method thereof
CN102193986A (en) * 2011-03-25 2011-09-21 北京世纪互联工程技术服务有限公司 Method of implementing online transaction in graphic database
CN102279873A (en) * 2010-06-11 2011-12-14 微软公司 Unified concurrent changes to data, schema, and application
CN102831156A (en) * 2012-06-29 2012-12-19 浙江大学 Distributed transaction processing method on cloud computing platform
CN103473318A (en) * 2013-09-12 2013-12-25 中国科学院软件研究所 Distributed transaction security method for memory data grid

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9009182B2 (en) * 2010-10-05 2015-04-14 Sap Se Distributed transaction management with tokens
US8984170B2 (en) * 2011-09-09 2015-03-17 Oracle International Corporation Idempotence for database transactions

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101196926A (en) * 2007-12-29 2008-06-11 中国建设银行股份有限公司 Database access platform and access method thereof
CN102279873A (en) * 2010-06-11 2011-12-14 微软公司 Unified concurrent changes to data, schema, and application
CN102193986A (en) * 2011-03-25 2011-09-21 北京世纪互联工程技术服务有限公司 Method of implementing online transaction in graphic database
CN102831156A (en) * 2012-06-29 2012-12-19 浙江大学 Distributed transaction processing method on cloud computing platform
CN103473318A (en) * 2013-09-12 2013-12-25 中国科学院软件研究所 Distributed transaction security method for memory data grid

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110888929A (en) * 2019-12-06 2020-03-17 秒针信息技术有限公司 Data processing method, data processing device, data node and storage medium
CN110888929B (en) * 2019-12-06 2022-03-29 秒针信息技术有限公司 Data processing method, data processing device, data node and storage medium

Also Published As

Publication number Publication date
CN104793988A (en) 2015-07-22

Similar Documents

Publication Publication Date Title
CN104793988B (en) The implementation method and device of integration across database distributed transaction
JP4114861B2 (en) Method for managing distributed savepoints across multiple DBMSs in a distributed transaction
CN107077382B (en) System and method for transaction recovery in a multi-tenant application server environment
US11132350B2 (en) Replicable differential store data structure
US7996633B2 (en) Sequencing transactions and operations
US8209696B2 (en) Method and system for load balancing a distributed database
US9009116B2 (en) Systems and methods for synchronizing data in a cache and database
US6012094A (en) Method of stratified transaction processing
US9417977B2 (en) Distributed transactional recovery system and method
US8117153B2 (en) Systems and methods for a distributed cache
US9747356B2 (en) Eager replication of uncommitted transactions
US8892509B2 (en) Systems and methods for a distributed in-memory database
US20180173745A1 (en) Systems and methods to achieve sequential consistency in replicated states without compromising performance in geo-distributed, replicated services
US9348641B2 (en) System and method for performing a transaction in a massively parallel processing database
US6895529B2 (en) Rebuilding “in-doubt” states reliably after multiple system failures in a data processing system performing two-phase transaction processing
US20070239661A1 (en) Systems and methods for a distributed in-memory database and distributed cache
US9922086B1 (en) Consistent query of local indexes
JP2006012153A (en) Concurrent transactions and page synchronization
Dey et al. Scalable distributed transactions across heterogeneous stores
WO2023103340A1 (en) Block data committing method and apparatus
Pankowski Consistency and availability of Data in replicated NoSQL databases
CN112685142A (en) Distributed data processing system
US10459810B2 (en) Technique for higher availability in a multi-node system using replicated lock information to determine a set of data blocks for recovery
Lev-Ari et al. Quick: a queuing system in cloudkit
Srivastava et al. Transaction processing in replicated data in the DDBMS

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
EXSB Decision made by sipo to initiate substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20191209

Address after: P.O. Box 31119, grand exhibition hall, hibiscus street, 802 West Bay Road, Grand Cayman, Cayman Islands

Patentee after: Innovative advanced technology Co., Ltd

Address before: A four-storey 847 mailbox in Grand Cayman Capital Building, British Cayman Islands

Patentee before: Alibaba Group Holding Co., Ltd.

TR01 Transfer of patent right