TWI687875B - Distributed transaction processing method and device - Google Patents

Distributed transaction processing method and device Download PDF

Info

Publication number
TWI687875B
TWI687875B TW107145886A TW107145886A TWI687875B TW I687875 B TWI687875 B TW I687875B TW 107145886 A TW107145886 A TW 107145886A TW 107145886 A TW107145886 A TW 107145886A TW I687875 B TWI687875 B TW I687875B
Authority
TW
Taiwan
Prior art keywords
branch
transaction
processing
transactions
resource
Prior art date
Application number
TW107145886A
Other languages
Chinese (zh)
Other versions
TW201935332A (en
Inventor
羅自文
Original Assignee
香港商阿里巴巴集團服務有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 香港商阿里巴巴集團服務有限公司 filed Critical 香港商阿里巴巴集團服務有限公司
Publication of TW201935332A publication Critical patent/TW201935332A/en
Application granted granted Critical
Publication of TWI687875B publication Critical patent/TWI687875B/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/08Payment architectures
    • G06Q20/10Payment architectures specially adapted for electronic funds transfer [EFT] systems; specially adapted for home banking systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/405Establishing or using transaction specific rules

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Finance (AREA)
  • Strategic Management (AREA)
  • General Business, Economics & Management (AREA)
  • Economics (AREA)
  • Development Economics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer And Data Communications (AREA)
  • Multi Processors (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本說明書實施例提供一種分布式事務處理方法及裝置,在分布式事務處理方法中,事務管理器獲取分布式事務的多個分支事務。對多個分支事務進行分析,以確定多個分支事務各自的處理對象以及對處理對象對應的資源的處理方式。根據處理對象和處理方式,確定多個分支事務之間的依賴關係。根據該依賴關係,並行及/或串行處理多個分支事務。Embodiments of this specification provide a distributed transaction processing method and device. In the distributed transaction processing method, a transaction manager obtains multiple branch transactions of a distributed transaction. Analyze multiple branch transactions to determine the respective processing objects of the multiple branch transactions and the processing methods of the resources corresponding to the processing objects. According to the processing object and processing method, determine the dependency relationship between multiple branch transactions. According to this dependency, multiple branch transactions are processed in parallel and/or serially.

Description

分布式事務處理方法及裝置Distributed transaction processing method and device

本發明係有關電腦技術領域,尤其是一種用分布式事務處理方法及裝置。The invention relates to the field of computer technology, in particular to a distributed transaction processing method and device.

傳統技術中,在處理分布式事務的過程中,為了保證各個參與者的一致性,事務處理器(Transaction Manager,TM)通常通過串行的方式來調用各個參與者處理相應的分支事務。如圖1所示,TM在處理分布式事務的過程中,會經過兩個階段:預處理階段和提交(commit)或者轉返(rollback)階段。在預處理階段,TM會嘗試鎖定資源管理器(Resource Manager,RM)1(分布式環境下的一個獨立參與者)中的資源,若能夠成功則嘗試去諮詢和鎖定RM2(分布式環境下的另一個獨立參與者)中的資源,若也能夠成功,則進入提交階段。在提交階段,TM會發起事務提交操作,在RM1中解除在預處理階段鎖定的資源並進行資源的消耗處理,成功後繼續進行RM2的資源釋放及實際消耗。在上述提交的過程中,若有任何異常,則TM會不斷進行重試提交,直到成功為止。可以理解的是,如果在預處理階段有失敗,則發起轉返,TM只有在得到RM1及RM2的轉返成功應答後才會最終進行事務完結處理,否則會不斷重試轉返,直到成功。 因此,需要提供一種更高效地處理分布式事務的方案。In the traditional technology, in the process of processing distributed transactions, in order to ensure the consistency of each participant, the transaction processor (Transaction Manager, TM) usually calls each participant to process the corresponding branch transaction in a serial manner. As shown in Figure 1, in the process of processing distributed transactions, TM will go through two stages: pre-processing stage and commit or rollback stage. In the pre-processing stage, TM will try to lock the resources in Resource Manager (Resource Manager, RM) 1 (an independent participant in a distributed environment). If it can succeed, it will try to consult and lock RM2 (a distributed environment). If the resource in another independent participant can also succeed, it will enter the submission phase. In the submission phase, TM will initiate a transaction submission operation, release the resources locked in the pre-processing phase and perform resource consumption processing in RM1, and continue to release the RM2 resources and actual consumption after success. During the above submission process, if there is any abnormality, TM will continue to retry the submission until it succeeds. It is understandable that if there is a failure in the pre-processing stage, a rollback is initiated, and the TM will only finally complete the transaction completion process after receiving the RM1 and RM2 return successful responses, otherwise it will continue to retry the rollback until it succeeds. Therefore, there is a need to provide a solution to more efficiently handle distributed transactions.

本說明書一個或多個實施例描述了一種分布式事務處理方法及裝置,可以提高分布式事務的處理效率。 第一方面,提供了一種分布式事務處理方法,包括: 事務管理器獲取分布式事務對應的多個分支事務; 對所述多個分支事務進行解析,以確定所述多個分支事務各自的處理對象以及對所述處理對象對應的資源的處理方式; 根據所述處理對象和所述處理方式,確定所述多個分支事務之間的依賴關係; 根據所述依賴關係,並行及/或串行處理所述多個分支事務。 第二方面,提供了一種分布式事務處理裝置,包括: 獲取單元,用於獲取分布式事務對應的多個分支事務; 解析單元,用於對所述獲取單元獲取的所述多個分支事務進行解析,以確定所述多個分支事務各自的處理對象以及對所述處理對象對應的資源的處理方式; 確定單元,用於根據所述解析單元解析得到的所述處理對象和所述處理方式,確定所述多個分支事務之間的依賴關係; 處理單元,用於根據所述確定單元確定的所述依賴關係,並行及/或串行處理所述多個分支事務。 本說明書一個或多個實施例提供的分布式事務處理方法及裝置,事務管理器獲取分布式事務的多個分支事務。對多個分支事務進行分析,以確定多個分支事務各自的處理對象以及對處理對象對應的資源的處理方式。根據處理對象和處理方式,確定多個分支事務之間的依賴關係。根據該依賴關係,並行及/或串行處理多個分支事務。由此,可以提高分布式事務的處理效率。One or more embodiments of this specification describe a distributed transaction processing method and device, which can improve the efficiency of distributed transaction processing. In the first aspect, a distributed transaction processing method is provided, including: The transaction manager obtains multiple branch transactions corresponding to distributed transactions; Parse the multiple branch transactions to determine the respective processing objects of the multiple branch transactions and the processing method of the resources corresponding to the processing objects; Determine the dependency relationship between the multiple branch transactions according to the processing object and the processing method; According to the dependency relationship, the plurality of branch transactions are processed in parallel and/or serially. In a second aspect, a distributed transaction processing device is provided, including: Acquisition unit, used to acquire multiple branch transactions corresponding to distributed transactions; The parsing unit is configured to parse the multiple branch transactions acquired by the acquiring unit to determine the respective processing objects of the multiple branch transactions and the processing method of the resources corresponding to the processing objects; A determining unit, configured to determine the dependency relationship between the plurality of branch transactions according to the processing object and the processing mode parsed by the parsing unit; The processing unit is configured to process the plurality of branch transactions in parallel and/or serially according to the dependency relationship determined by the determining unit. In the distributed transaction processing method and device provided in one or more embodiments of this specification, the transaction manager obtains multiple branch transactions of the distributed transaction. Analyze multiple branch transactions to determine the respective processing objects of the multiple branch transactions and the processing methods of the resources corresponding to the processing objects. According to the processing object and processing method, determine the dependency relationship between multiple branch transactions. According to this dependency, multiple branch transactions are processed in parallel and/or serially. Thus, the processing efficiency of distributed transactions can be improved.

在詳細介紹本說明書提供的方案之前,先結合傳統技術給出如下優化思路: 圖1所示的分布式事務處理方法的資訊交互圖可以如圖2所示。從圖2可以看出,在預處理階段,事務管理器對各個參與者的調用本質上沒有必然的依賴關係。此外,無論是在提交階段還是在轉返階段,上述調用過程也沒有必然的依賴關係。因此,在分布式環境中,事務管理器對各個參與者之間的調用是可以採用併發的方式進行的。也即各個分支事務是可以並行處理的。通過上述並行的方式,在參與者越多的情況下,分布式事務處理的時間並不會線性增加。舉例來說,若一次服務交互時間是T,則有N個參與者的情況下,若採用傳統的分布式事務處理的方式,兩個階段的處理開銷都是NT。而採用並行的方式,能夠基本保證處理時間為T。 下面結合上述優化思路,對本說明書提供的方案進行詳細描述。 本說明書一個實施例提供的分布式事務處理方法可以應用於如圖3所示的場景中,圖3中,業務系統用於根據業務請求,將分布式事務劃分為多個分支事務。此處的分支事務可以是指分布式事務的一次行為。以業務需求為:“從帳戶A轉帳100元給帳戶B”為例來說,則可以將分布式事務劃分為兩個分支事務,該兩個分支事務分別用於作如下處理:“A-100”和“B+100”。之後,業務系統可以將劃分的多個分支事務發送給事務管理器。事務管理器在接收到上述多個分支事務之後,可以對該多個分支事務進行解析,以確定各自的處理對象(如,帳戶等)以及對處理對象對應的資源(如,帳戶餘額、黃金等)的處理方式。之後,可以根據處理對象和處理方式,確定多個分支事務之間的依賴關係。並根據該依賴關係,並行及/或串行處理多個分支事務。最後,事務管理器將多個分支事務的處理結果資訊返回給業務系統。 需要說明的是,圖3中,事務管理器具體是通過調用參與者來處理分支事務的,其中,參與者可以是指事務管理器在處理分支事務時所調用的服務。如前述例子,一個參與者可以認為是財務庫A,而另一個參與者可以認為是財務庫B。具體地,在上述兩個分支事務的處理過程中,事務管理器可以調用財務庫A從帳戶A中轉出100元,可以調用財務庫B給帳戶B轉入100元。由此,就保了帳戶A扣款和帳戶B加款的一致性。在上述分支事務的處理過程中,若有任何異常,則失敗轉返,並反饋轉帳失敗。 圖4為本說明書一個實施例提供的分布式事務處理方法流程圖。所述方法的執行主體可以為圖3中的事務管理器。如圖4所示,所述方法具體可以包括: 步驟410,事務管理器獲取分布式事務對應的多個分支事務。 在一種實現方式中,業務系統可以根據業務需求,將分布式事務劃分為多個分支事務。以業務需求為:“從帳戶A轉帳100元給帳戶B,從帳戶B分潤5元給帳戶C”為例來說,則可以將分布式事務劃分為四個分支事務,該四個分支事務分別用於作如下處理:“A-100”、“B+100”、“B-5”和“C+5”。之後,業務系統可以將劃分的多個分支事務發送給事務管理器。 步驟420,對多個分支事務進行解析,以確定多個分支事務各自的處理對象以及對處理對象對應的資源的處理方式。 此處的處理對象可以包括使用者的帳戶等。處理對象對應的資源可以包括但不限於帳戶餘額(也稱資金)以及黃金等。而對處理對象對應的資源的處理方式可以包括資源增加和資源消耗等。以處理對象為帳戶,處理對象對應的資源為帳戶餘額為例來說,可以根據對帳戶的帳戶餘額的增減情況,確定對資源的處理方式。具體地,當增加帳戶中的帳戶餘額時,對資源的處理方式可以為資源增加;而當減少帳戶中的帳戶餘額時,對資源的處理方式可以為資源消耗。 如前述例子,四個分支事務各自的處理對象分別為:“帳戶A”、“帳戶B”、“帳戶B”和“帳戶C”。此外,由於第一個分支事務用於從帳戶A的帳戶餘額中扣除100元,也即第一個分支事務用於減少帳戶A中的帳戶餘額,所以其對資源的處理方式為:“資源消耗”。同理可以確定出其它三個分支事務對資源的處理方式分別為:“資源增加”、“資源消耗”和“資源增加”。 步驟430,根據處理對象和處理方式,確定多個分支事務之間的依賴關係。 在一種實現方式中,可以根據處理方式,對多個分支事務進行分類。在對分支事務進行分類後,根據處理對象,確定不同類別的分支事務之間的依賴關係。具體地,對多個分支事務中的每個分支事務,判斷該分支事務對處理對象對應的資源的處理方式是否為資源增加。若是,則確定該分支事務的類別為資源增加類。若否,則確定該分支事務的類別為資源消耗類。對資源增加類的分支事務,可以直接將該類別的分支事務確定為不存在依賴關係的分支事務。對資源消耗類的分支事務,判斷該資源消耗類的分支事務的處理對象是否與資源增加類的分支事務的處理對象相同。若是,則確定該資源消耗類的分支事務為存在依賴關係的分支事務。若否,則確定該資源消耗類的分支事務為不存在依賴關係的分支事務。 如前述例子,由於第二個分支事務(對應於“B+100”的分支事務)和第四個分支事務(對應於“C+5”的分支事務)對處理對象對應的資源的處理方式均為“資源增加”,所以可以確定該兩個分支事務的類別為資源增加類。由於第一個分支事務(對應於“A-100”的分支事務)和第三個分支事務(對應於“B-5”的分支事務)對處理對象對應的資源的處理方式均為“資源消耗”,所以可以確定該兩個分支事務的類別為資源消耗類。 對於資源增加類的兩個分支事務,可以確定該兩個分支事務為不存在依賴關係的分支事務。對資源消耗類的兩個分支事務,由於第三個分支事務與第二個分支事務的處理對象(帳戶B)相同,所以可以確定第三個分支事務為存在依賴關係的分支事務。而第一個分支事務與資源增加類的兩個分支事務的處理對象均不同,所以確定第一個分支事務為不存在依賴關係的分支事務。 步驟440,根據依賴關係,並行及/或串行處理多個分支事務。 在一種實現方式中,可以將不存在依賴關係的分支事務劃分到第一分組,將存在依賴關係的分支事務劃分到第二組。並行處理第一分組中的分支事務。在第一分組中的分支事務處理結束後,並行處理第二分組中的分支事務。 如前述例子,可以將第二個分支事務、第四個分支事務以及第一個分支事務劃分到第一分組。將第三個分支事務劃分到第二分組。之後,並行處理第二個分支事務、第四個分支事務以及第一個分支事務。在該三個分支事務處理結束後,處理第三個分支事務。此處,也可以理解為,第三個分支事務是串行處理的。 通過本說明書上述實施例提供的分布式事務處理方法,可以既提高分布式事務的處理效率,又能保證其處理的正確性。如前述例子,在對應於“A-100”、“B+100”和“C+5”的分支事務先並行處理,之後在串行處理對應於“B-5”分支事務的情況下,可以避免當對應於“B-5”分支事務先處理時,如果帳戶B的帳戶餘額為0,則會處理失敗的問題。也即,本說明書實施例中,當分支事務的處理對象相同時,可以通過設定處理順序的方式,來保證其處理的正確性。 可以理解的是,在本說明書上述實施例提供的事務處理方法中,假設事務管理器調用一次服務(或者參與者)的時間為T,且假設分布式事務被劃分為N個分支事務。那麼在N個分支事務之間不存在依賴關係的情況下,分布式事務的處理時間開銷為T。而在N個分支事務之間存在依賴關係的情況下,分布式事務的處理時間開銷為2T。由此,可以看出,在分布式事務不存在依賴關係的情況下,本說明書提供的方案可以將分布式事務處理時間控制在單分支事務處理時間範圍內,不會因為參與者增加而使得整個分布式事務處理時間增加。即便自分支事務之間存在依賴的情況下,處理時長依然可控,且不隨著參與者規模擴大而導致處理時間增長。 與上述分布式事務處理方法對應地,本說明書一個實施例還提供的一種分布式事務處理裝置,如圖5所示,該裝置包括: 獲取單元501,用於獲取分布式事務對應的多個分支事務。 解析單元502,用於對獲取單元501獲取的多個分支事務進行解析,以確定多個分支事務各自的處理對象以及對處理對象對應的資源的處理方式。 此處,處理對象可以為使用者的帳戶等。處理對象對應的資源可以為帳戶餘額等。 確定單元503,用於根據解析單元502解析得到的處理對象和處理方式,確定多個分支事務之間的依賴關係。 可選地,確定單元503具體可以用於: 根據處理方式,對多個分支事務進行分類; 根據處理對象,確定不同類別的分支事務之間的依賴關係。 可選地,確定單元503還具體可以用於: 對多個分支事務中的每個分支事務,判斷分支事務對處理對象對應的資源的處理方式是否為資源增加。 若是,則確定分支事務的類別為資源增加類。 若否,則確定分支事務的類別為資源消耗類。 將資源增加類的分支事務確定為不存在依賴關係的分支事務。 對資源消耗類的分支事務,判斷資源消耗類的分支事務的處理對象是否與資源增加類的分支事務的處理對象相同。 若是,則確定資源消耗類的分支事務為存在依賴關係的分支事務。 若否,則確定資源消耗類的分支事務為不存在依賴關係的分支事務。 處理單元504,用於根據確定單元503確定的依賴關係,並行及/或串行處理多個分支事務。 可選地,處理單元504具體可以用於: 將不存在依賴關係的分支事務劃分到第一分組,將存在依賴關係的分支事務劃分到第二組。 並行處理第一分組中的分支事務。 在第一分組中的分支事務處理結束後,並行處理第二分組中的分支事務。 本說明書上述實施例裝置的各功能模組的功能,可以通過上述方法實施例的各步驟來實現,因此,本說明書一個實施例提供的裝置的具體工作過程,在此不復贅述。 本說明書一個實施例提供的分布式事務處理裝置,獲取單元501獲取分布式事務對應的多個分支事務。解析單元502對多個分支事務進行解析,以確定多個分支事務各自的處理對象以及對處理對象對應的資源的處理方式。確定單元503根據處理對象和處理方式,確定多個分支事務之間的依賴關係。處理單元504根據依賴關係,並行及/或串行處理多個分支事務。由此,可以提高分布式事務的處理效率。 本領域技術人員應該可以意識到,在上述一個或多個示例中,本說明書所描述的功能可以用硬體、軟體、韌體或它們的任意組合來實現。當使用軟體實現時,可以將這些功能儲存在電腦可讀媒介中或者作為電腦可讀媒介上的一個或多個指令或代碼進行傳輸。 以上所述的具體實施方式,對本說明書的目的、技術方案和有益效果進行了進一步詳細說明,所應理解的是,以上所述僅為本說明書的具體實施方式而已,並不用於限定本說明書的保護範圍,凡在本說明書的技術方案的基礎之上,所做的任何修改、等同替換、改進等,均應包括在本說明書的保護範圍之內。Before introducing the solutions provided in this manual in detail, the following optimization ideas are given in combination with traditional technologies: The information interaction diagram of the distributed transaction processing method shown in FIG. 1 can be shown in FIG. 2. As can be seen from Figure 2, in the pre-processing stage, the transaction manager's call to each participant has essentially no necessary dependency. In addition, no matter whether it is in the submission phase or in the reversion phase, the above-mentioned calling process also has no inevitable dependency relationship. Therefore, in a distributed environment, the transaction manager can call each participant in a concurrent manner. That is, each branch transaction can be processed in parallel. Through the above parallel method, in the case of more participants, the time of distributed transaction processing does not increase linearly. For example, if the service interaction time is T, and there are N participants, if the traditional distributed transaction processing method is adopted, the processing cost of both stages is NT. In parallel, the processing time can be basically guaranteed to be T. The solution provided in this specification will be described in detail in conjunction with the above optimization ideas. The distributed transaction processing method provided by an embodiment of this specification can be applied to the scenario shown in FIG. 3. In FIG. 3, the business system is used to divide the distributed transaction into multiple branch transactions according to the business request. The branch transaction here may refer to a behavior of the distributed transaction. Taking the business requirement as: "transfer 100 yuan from account A to account B", for example, the distributed transaction can be divided into two branch transactions, and the two branch transactions are used for the following processing: "A-100 "And "B+100". After that, the business system can send the divided branch transactions to the transaction manager. After receiving the multiple branch transactions, the transaction manager can parse the multiple branch transactions to determine the respective processing objects (such as accounts, etc.) and the resources corresponding to the processing objects (such as account balance, gold, etc.) ). Afterwards, the dependency relationship between multiple branch transactions can be determined according to the processing object and processing method. According to the dependency, multiple branch transactions are processed in parallel and/or serially. Finally, the transaction manager returns the processing result information of multiple branch transactions to the business system. It should be noted that, in FIG. 3, the transaction manager specifically handles branch transactions by invoking participants, where participants may refer to services that the transaction manager calls when processing branch transactions. As in the previous example, one participant can be regarded as financial bank A, while another participant can be regarded as financial bank B. Specifically, during the processing of the above two branch transactions, the transaction manager can call financial bank A to transfer out 100 yuan from account A, and can call financial bank B to transfer 100 yuan to account B. As a result, the consistency of account A deduction and account B increase is guaranteed. In the process of the above branch transaction, if there is any abnormality, it will fail back, and feedback transfer failure. 4 is a flowchart of a distributed transaction processing method provided by an embodiment of the present specification. The execution subject of the method may be the transaction manager in FIG. 3. As shown in FIG. 4, the method may specifically include: Step 410: The transaction manager obtains multiple branch transactions corresponding to the distributed transaction. In one implementation, the business system can divide the distributed transaction into multiple branch transactions according to business requirements. Taking the business requirement as follows: "Transfer 100 yuan from account A to account B, and divide 5 yuan from account B to account C." For example, the distributed transaction can be divided into four branch transactions, and the four branch transactions Used for the following processing: "A-100", "B+100", "B-5" and "C+5". After that, the business system can send the divided branch transactions to the transaction manager. Step 420: Analyze the multiple branch transactions to determine the respective processing objects of the multiple branch transactions and the processing method of the resources corresponding to the processing objects. The processing object here may include the user's account and so on. The resources corresponding to the processing object may include but are not limited to account balance (also called funds) and gold. The processing method of the resource corresponding to the processing object may include resource increase and resource consumption. Taking the processing object as the account and the resource corresponding to the processing object as the account balance as an example, the processing method of the resource can be determined according to the increase and decrease of the account balance of the account. Specifically, when the account balance in the account is increased, the processing method for the resource may be increased for the resource; and when the account balance in the account is decreased, the processing method for the resource may be for resource consumption. As in the previous example, the processing objects of the four branch transactions are: "Account A", "Account B", "Account B" and "Account C". In addition, because the first branch transaction is used to deduct 100 yuan from the account balance of account A, that is, the first branch transaction is used to reduce the account balance in account A, so its treatment of resources is: "resource consumption ". Similarly, it can be determined that the other three branch transactions deal with resources as follows: "resource increase", "resource consumption" and "resource increase". Step 430, according to the processing object and the processing method, determine the dependency relationship between the multiple branch transactions. In one implementation, multiple branch transactions can be classified according to processing methods. After classifying branch transactions, according to the processing object, determine the dependency relationship between different types of branch transactions. Specifically, for each branch transaction among the plurality of branch transactions, it is determined whether the processing manner of the branch transaction on the resource corresponding to the processing object is a resource increase. If yes, the category of the branch transaction is determined to be a resource increase category. If not, the category of the branch transaction is determined to be the resource consumption category. For the branch transaction of the resource addition category, the branch transaction of this category can be directly determined as a branch transaction that does not have a dependency relationship. For the branch transaction of the resource consumption class, it is determined whether the processing object of the branch transaction of the resource consumption class is the same as the processing object of the branch transaction of the resource increase class. If yes, it is determined that the branch transaction of the resource consumption class is a branch transaction with a dependency relationship. If not, it is determined that the branch transaction of the resource consumption class is a branch transaction that does not have a dependency relationship. As in the previous example, the second branch transaction (corresponding to the "B+100" branch transaction) and the fourth branch transaction (corresponding to the "C+5" branch transaction) both deal with the resources corresponding to the processing object. It is "resource increase", so the category of the two branch transactions can be determined as the resource increase category. Because the first branch transaction (corresponding to the "A-100" branch transaction) and the third branch transaction (corresponding to the "B-5" branch transaction) deal with the resources corresponding to the processing object are "resource consumption ", so the category of the two branch transactions can be determined as the resource consumption category. For the two branch transactions of the resource increase category, it can be determined that the two branch transactions are branch transactions that do not have a dependency relationship. For the two branch transactions of the resource consumption class, since the third branch transaction and the second branch transaction have the same processing object (account B), it can be determined that the third branch transaction is a branch transaction with a dependency relationship. The first branch transaction and the two branch transactions of the resource increase class have different processing objects, so it is determined that the first branch transaction is a branch transaction that does not have a dependency relationship. Step 440: Process multiple branch transactions in parallel and/or serially according to the dependency relationship. In an implementation manner, branch transactions that do not have a dependency relationship may be divided into a first group, and branch transactions that have a dependency relationship may be divided into a second group. The branch transactions in the first group are processed in parallel. After the branch transaction processing in the first packet ends, the branch transaction in the second packet is processed in parallel. As in the previous example, the second branch transaction, the fourth branch transaction, and the first branch transaction can be divided into the first group. The third branch transaction is divided into the second group. After that, the second branch transaction, the fourth branch transaction, and the first branch transaction are processed in parallel. After the three branch transaction processing ends, the third branch transaction is processed. Here, it can also be understood that the third branch transaction is processed serially. Through the distributed transaction processing method provided by the above embodiments of the present specification, the processing efficiency of the distributed transaction can be improved while the correctness of its processing can be ensured. As in the previous example, in the case where the branch transactions corresponding to "A-100", "B+100", and "C+5" are processed in parallel first, and then in the case of serial processing corresponding to the "B-5" branch transaction, To avoid the problem of processing failure if the account balance of account B is 0 when the branch transaction corresponding to "B-5" is processed first. That is, in the embodiments of the present specification, when the processing objects of the branch transactions are the same, the processing order can be set to ensure the correctness of the processing. It can be understood that, in the transaction processing method provided in the above embodiment of the present specification, it is assumed that the time for the transaction manager to call a service (or participant) is T, and it is assumed that the distributed transaction is divided into N branch transactions. Then, when there is no dependency relationship between N branch transactions, the processing time overhead of the distributed transaction is T. When there are dependencies between N branch transactions, the processing time overhead of distributed transactions is 2T. From this, it can be seen that in the case where distributed transactions do not have dependencies, the solution provided in this specification can control the distributed transaction processing time within the single branch transaction processing time range, and will not cause the entire increase due to the increase in participants. Distributed transaction processing time increased. Even if there is a dependency between self-branch transactions, the processing time is still controllable, and the processing time does not increase as the size of the participants expands. Corresponding to the foregoing distributed transaction processing method, an embodiment of this specification further provides a distributed transaction processing apparatus. As shown in FIG. 5, the apparatus includes: The obtaining unit 501 is used to obtain multiple branch transactions corresponding to the distributed transaction. The parsing unit 502 is configured to parse the multiple branch transactions acquired by the obtaining unit 501 to determine the respective processing objects of the multiple branch transactions and the processing manner of the resources corresponding to the processing objects. Here, the processing object may be the user's account or the like. The resource corresponding to the processing object may be an account balance, etc. The determining unit 503 is configured to determine the dependency relationship between multiple branch transactions according to the processing object and processing mode obtained by the parsing unit 502. Optionally, the determining unit 503 may be specifically used for: According to the processing method, classify multiple branch transactions; According to the processing object, determine the dependency relationship between different types of branch transactions. Optionally, the determining unit 503 may also be specifically used for: For each branch transaction among multiple branch transactions, it is determined whether the branch transaction processes the resource corresponding to the processing object as a resource increase. If it is, the category of the branch transaction is determined to be the resource increase category. If not, the category of the branch transaction is determined to be the resource consumption category. Determine the branch transaction of the resource increase class as a branch transaction that does not have a dependency relationship. For the branch transaction of the resource consumption class, it is determined whether the processing object of the branch transaction of the resource consumption class is the same as the processing object of the branch transaction of the resource increase class. If yes, it is determined that the branch transaction of the resource consumption class is a branch transaction with a dependency relationship. If not, it is determined that the branch transaction of the resource consumption class is a branch transaction that does not have a dependency relationship. The processing unit 504 is configured to process multiple branch transactions in parallel and/or serially according to the dependency relationship determined by the determining unit 503. Optionally, the processing unit 504 may be specifically used to: The branch transactions that do not have a dependency relationship are divided into the first group, and the branch transactions that have a dependency relationship are divided into the second group. The branch transactions in the first group are processed in parallel. After the branch transaction processing in the first packet ends, the branch transaction in the second packet is processed in parallel. The functions of the functional modules of the device in the above embodiments of the present specification can be implemented by the steps of the above method embodiments. Therefore, the specific working process of the device provided by an embodiment of the present specification will not be repeated here. In the distributed transaction processing apparatus provided in an embodiment of this specification, the obtaining unit 501 obtains multiple branch transactions corresponding to the distributed transaction. The parsing unit 502 analyzes the multiple branch transactions to determine the respective processing objects of the multiple branch transactions and the processing manner of the resources corresponding to the processing objects. The determining unit 503 determines the dependency relationship between multiple branch transactions according to the processing object and the processing method. The processing unit 504 processes multiple branch transactions in parallel and/or serially according to the dependency relationship. Thus, the processing efficiency of distributed transactions can be improved. Those skilled in the art should be aware that in the above one or more examples, the functions described in this specification can be implemented by hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on the computer-readable medium. The specific embodiments described above further describe the purpose, technical solutions, and beneficial effects of this specification in detail. It should be understood that the above are only specific implementations of this specification and are not intended to limit the scope of this specification. The scope of protection, any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solutions of this specification, shall be included in the scope of protection of this specification.

TM‧‧‧事務管理器 RM1‧‧‧資源管理器 RM2‧‧‧資源管理器 RMN‧‧‧資源管理器 410‧‧‧步驟 420‧‧‧步驟 430‧‧‧步驟 440‧‧‧步驟 501‧‧‧獲取單元 502‧‧‧解析單元 503‧‧‧確定單元 504‧‧‧處理單元TM‧‧‧ Transaction Manager RM1‧‧‧ Explorer RM2‧‧‧Explorer RMN‧‧‧Resource Manager 410‧‧‧Step 420‧‧‧Step 430‧‧‧Step 440‧‧‧Step 501‧‧‧ acquisition unit 502‧‧‧Analysis unit 503‧‧‧ Confirmation unit 504‧‧‧ processing unit

為了更清楚地說明本說明書實施例的技術方案,下面將對實施例描述中所需要使用的圖式作簡單地介紹,顯而易見地,下面描述中的圖式僅僅是本說明書的一些實施例,對於本領域普通技術人員來講,在不付出進步性勞動的前提下,還可以根據這些圖式獲得其它的圖式。 圖1為傳統的分布式事務處理方法示意圖; 圖2為分布式事務處理方法的資訊交互圖; 圖3為本說明書一個實施例提供的分布式事務處理方法的應用場景示意圖; 圖4為本說明書一個實施例提供的分布式事務處理方法流程圖; 圖5為本說明書一個實施例提供的分布式事務處理裝置示意圖。In order to more clearly explain the technical solutions of the embodiments of the present specification, the following will briefly introduce the drawings used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present description. For those of ordinary skill in the art, on the premise of not paying progressive labor, other drawings can also be obtained according to these drawings. Figure 1 is a schematic diagram of a traditional distributed transaction processing method; Figure 2 is an information interaction diagram of a distributed transaction processing method; 3 is a schematic diagram of an application scenario of a distributed transaction processing method provided by an embodiment of this specification; 4 is a flowchart of a distributed transaction processing method provided by an embodiment of this specification; FIG. 5 is a schematic diagram of a distributed transaction processing apparatus provided by an embodiment of the present specification.

Claims (8)

一種分布式事務處理方法,其特徵在於,包括:事務管理器獲取分布式事務對應的多個分支事務;對所述多個分支事務進行解析,以確定所述多個分支事務各自的處理對象以及對所述處理對象對應的資源的處理方式;根據所述處理對象和所述處理方式,確定所述多個分支事務之間的依賴關係;根據所述依賴關係,並行及/或串行處理所述多個分支事務,其中,所述根據所述處理對象和所述處理方式,確定所述多個分支事務之間的依賴關係,包括:根據所述分支事務對處理對象對應的資源的處理方式是否為資源增加,對所述多個分支事務進行分類;根據所述處理對象和所述分類,確定分支事務之間的依賴關係。 A distributed transaction processing method, comprising: a transaction manager acquiring multiple branch transactions corresponding to a distributed transaction; parsing the multiple branch transactions to determine respective processing objects of the multiple branch transactions and Processing methods for resources corresponding to the processing object; determining the dependency relationship between the plurality of branch transactions according to the processing object and the processing method; according to the dependency relationship, parallel and/or serial processing stations The plurality of branch transactions, wherein the determining the dependency relationship between the plurality of branch transactions according to the processing object and the processing mode includes: processing the resource corresponding to the processing object according to the branch transaction Whether the resource is increased, classify the plurality of branch transactions; determine the dependency relationship between the branch transactions according to the processing object and the classification. 根據請求項1所述的方法,其中,所述根據所述處理方式,對所述多個分支事務進行分類,包括:對所述多個分支事務中的每個分支事務,判斷所述分支事務對處理對象對應的資源的處理方式是否為資源增加;若是,則確定所述分支事務的類別為資源增加類; 若否,則確定所述分支事務的類別為資源消耗類;所述根據所述處理對象和所述分類,確定分支事務之間的依賴關係,包括:將資源增加類的分支事務確定為不存在依賴關係的分支事務;對資源消耗類的分支事務,判斷所述資源消耗類的分支事務的處理對象是否與資源增加類的分支事務的處理對象相同;若是,則確定所述資源消耗類的分支事務為存在依賴關係的分支事務;若否,則確定所述資源消耗類的分支事務為不存在依賴關係的分支事務。 The method according to claim 1, wherein the classifying the plurality of branch transactions according to the processing method includes: determining the branch transaction for each branch transaction in the plurality of branch transactions Whether the processing method of the resource corresponding to the processing object is resource increase; if so, it is determined that the category of the branch transaction is the resource increase class; If not, it is determined that the category of the branch transaction is a resource consumption class; the determining the dependency relationship between the branch transactions according to the processing object and the classification includes: determining that the branch transaction of the resource increase class does not exist Dependent relationship branch transactions; for resource consumption class branch transactions, determine whether the resource consumption class branch transaction processing object is the same as the resource increase class branch transaction processing object; if so, determine the resource consumption class branch transaction The transaction is a branch transaction with a dependency relationship; if not, it is determined that the branch transaction of the resource consumption class is a branch transaction without a dependency relationship. 根據請求項2所述的方法,其中,所述根據所述依賴關係,並行及/或串行處理所述多個分支事務,包括:將所述不存在依賴關係的分支事務劃分到第一分組,將所述存在依賴關係的分支事務劃分到第二組;並行處理第一分組中的分支事務;在所述第一分組中的分支事務處理結束後,並行處理所述第二分組中的分支事務。 The method according to claim 2, wherein the parallel and/or serial processing of the plurality of branch transactions according to the dependency relationship includes: dividing the branch transactions that do not have a dependency relationship into a first group , Divide the branch transactions with the dependency relationship into a second group; process branch transactions in the first group in parallel; after the branch transaction processing in the first group ends, process the branches in the second group in parallel Affairs. 根據請求項1至3中任一項所述的方法,其中,所述處理對象為使用者的帳戶,所述處理對象對應的資源為帳戶餘額。 The method according to any one of claims 1 to 3, wherein the processing object is a user's account, and the resource corresponding to the processing object is an account balance. 一種分布式事務處理裝置,其特徵在於,包括:獲取單元,用於獲取分布式事務對應的多個分支事務;解析單元,用於對所述獲取單元獲取的所述多個分支事務進行解析,以確定所述多個分支事務各自的處理對象以及對所述處理對象對應的資源的處理方式;確定單元,用於根據所述解析單元解析得到的所述處理對象和所述處理方式,確定所述多個分支事務之間的依賴關係;處理單元,用於根據所述確定單元確定的所述依賴關係,並行及/或串行處理所述多個分支事務,其中,所述確定單元具體用於:根據所述分支事務對處理對象對應的資源的處理方式是否為資源增加,對所述多個分支事務進行分類;根據所述處理對象和所述分類,確定分支事務之間的依賴關係。 A distributed transaction processing device, characterized by comprising: an acquisition unit for acquiring a plurality of branch transactions corresponding to a distributed transaction; a parsing unit for parsing the plurality of branch transactions acquired by the acquisition unit, To determine the respective processing objects of the plurality of branch transactions and the processing methods of the resources corresponding to the processing objects; a determining unit, configured to determine the processing objects and the processing methods according to the analysis objects obtained by the parsing unit A dependency relationship between the plurality of branch transactions; a processing unit, configured to process the plurality of branch transactions in parallel and/or serially according to the dependency relationship determined by the determination unit, wherein the determination unit specifically uses Yu: classify the plurality of branch transactions according to whether the branch transaction processes the resource corresponding to the processing object as a resource increase; and determine the dependency relationship between the branch transactions according to the processing object and the classification. 根據請求項5所述的裝置,其中,所述確定單元還具體用於:對所述多個分支事務中的每個分支事務,判斷所述分支事務對處理對象對應的資源的處理方式是否為資源增加;若是,則確定所述分支事務的類別為資源增加類; 若否,則確定所述分支事務的類別為資源消耗類;將資源增加類的分支事務確定為不存在依賴關係的分支事務;對資源消耗類的分支事務,判斷所述資源消耗類的分支事務的處理對象是否與資源增加類的分支事務的處理對象相同;若是,則確定所述資源消耗類的分支事務為存在依賴關係的分支事務;若否,則確定所述資源消耗類的分支事務為不存在依賴關係的分支事務。 The device according to claim 5, wherein the determination unit is further specifically configured to: for each branch transaction in the plurality of branch transactions, determine whether the branch transaction processes the resource corresponding to the processing object as Increase in resources; if it is, determine the category of the branch transaction as a resource increase category; If not, it is determined that the category of the branch transaction is a resource consumption class; the branch transaction of the resource increase class is determined as a branch transaction without dependency relationship; for the branch transaction of the resource consumption class, the branch transaction of the resource consumption class is judged Whether the processing object is the same as the processing object of the branch transaction of the resource increase class; if it is, the branch transaction of the resource consumption class is determined to be a branch transaction with a dependency relationship; if not, the branch transaction of the resource consumption class is determined to be There are no branch transactions with dependencies. 根據請求項6所述的裝置,其中,所述處理單元具體用於:將所述不存在依賴關係的分支事務劃分到第一分組,將所述存在依賴關係的分支事務劃分到第二組;並行處理第一分組中的分支事務;在所述第一分組中的分支事務處理結束後,並行處理所述第二分組中的分支事務。 The apparatus according to claim 6, wherein the processing unit is specifically configured to: divide the branch transactions that do not have a dependency relationship into a first group, and divide the branch transactions that have a dependency relationship into a second group; The branch transactions in the first group are processed in parallel; after the branch transactions in the first group are completed, the branch transactions in the second group are processed in parallel. 根據請求項5至7中任一項所述的裝置,其中,所述處理對象為使用者的帳戶,所述處理對象對應的資源為帳戶餘額。 The apparatus according to any one of claims 5 to 7, wherein the processing object is a user's account, and the resource corresponding to the processing object is an account balance.
TW107145886A 2018-02-02 2018-12-19 Distributed transaction processing method and device TWI687875B (en)

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
??201810106140.5 2018-02-02
CN201810106140.5 2018-02-02
CN201810106140.5A CN108415757B (en) 2018-02-02 2018-02-02 Distributed transaction processing method and device

Publications (2)

Publication Number Publication Date
TW201935332A TW201935332A (en) 2019-09-01
TWI687875B true TWI687875B (en) 2020-03-11

Family

ID=63127505

Family Applications (1)

Application Number Title Priority Date Filing Date
TW107145886A TWI687875B (en) 2018-02-02 2018-12-19 Distributed transaction processing method and device

Country Status (3)

Country Link
CN (1) CN108415757B (en)
TW (1) TWI687875B (en)
WO (1) WO2019149032A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108415757B (en) * 2018-02-02 2020-10-30 创新先进技术有限公司 Distributed transaction processing method and device
CN109491768A (en) * 2018-11-21 2019-03-19 四川长虹电器股份有限公司 A kind of distributed transaction method for dynamically processing and system based on subtransaction stream
CN110990182B (en) * 2019-12-03 2021-06-11 腾讯科技(深圳)有限公司 Transaction processing method, device, equipment and storage medium
US11544245B2 (en) 2019-12-03 2023-01-03 Tencent Technology (Shenzhen) Company Limited Transaction processing method, apparatus, and device and computer storage medium
CN113205407A (en) * 2021-05-28 2021-08-03 中国工商银行股份有限公司 Distributed sub-transaction processing method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103856548A (en) * 2012-12-07 2014-06-11 华为技术有限公司 Dynamic resource scheduling method and dynamic resource scheduler
CN106557514A (en) * 2015-09-29 2017-04-05 中兴通讯股份有限公司 A kind of distributed transaction rollback method and device
TW201737078A (en) * 2016-03-31 2017-10-16 Alibaba Group Services Ltd Task-resource scheduling method and device
CN107621973A (en) * 2016-07-13 2018-01-23 阿里巴巴集团控股有限公司 A kind of method for scheduling task and device across cluster

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6438582B1 (en) * 1998-07-21 2002-08-20 International Business Machines Corporation Method and system for efficiently coordinating commit processing in a parallel or distributed database system
CN102346460B (en) * 2011-05-27 2013-11-13 运软网络科技(上海)有限公司 Transaction-based service control system and method
CN102207883A (en) * 2011-06-01 2011-10-05 华中科技大学 Transaction scheduling method of heterogeneous distributed real-time system
US10191932B2 (en) * 2014-03-21 2019-01-29 Oracle International Corporation Dependency-aware transaction batching for data replication
CN105335143A (en) * 2014-07-30 2016-02-17 阿里巴巴集团控股有限公司 Business processing method and apparatus
CN105589748A (en) * 2014-10-22 2016-05-18 阿里巴巴集团控股有限公司 Service request processing method and apparatus
CN106033439B (en) * 2015-03-13 2019-10-22 阿里巴巴集团控股有限公司 A kind of distributed transaction processing method and system
CN108415757B (en) * 2018-02-02 2020-10-30 创新先进技术有限公司 Distributed transaction processing method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103856548A (en) * 2012-12-07 2014-06-11 华为技术有限公司 Dynamic resource scheduling method and dynamic resource scheduler
CN106557514A (en) * 2015-09-29 2017-04-05 中兴通讯股份有限公司 A kind of distributed transaction rollback method and device
TW201737078A (en) * 2016-03-31 2017-10-16 Alibaba Group Services Ltd Task-resource scheduling method and device
CN107621973A (en) * 2016-07-13 2018-01-23 阿里巴巴集团控股有限公司 A kind of method for scheduling task and device across cluster

Also Published As

Publication number Publication date
CN108415757A (en) 2018-08-17
WO2019149032A1 (en) 2019-08-08
CN108415757B (en) 2020-10-30
TW201935332A (en) 2019-09-01

Similar Documents

Publication Publication Date Title
TWI687875B (en) Distributed transaction processing method and device
CN111277639B (en) Method and device for maintaining data consistency
CN111045794B (en) Distributed transaction processing method, device, system, computer equipment and storage medium
CN106503974B (en) Transaction data processing method and device
WO2020024469A1 (en) Service processing method, calling management system and computer device
WO2020000720A1 (en) Server, packet processing method, program, and computer-readable storage medium
EP3869434B1 (en) Blockchain-based data processing method and apparatus, device, and medium
CN106445644A (en) Distributed transaction processing method and device based on improved one-phase commit
CN111858641A (en) Transaction processing method and device, electronic equipment and readable storage medium
CN109582655A (en) Localization method and device, the computer readable storage medium of system log
WO2020258653A1 (en) Cross-node data processing method and apparatus
CN112907344A (en) Accounting data processing method and device, electronic equipment and storage medium
CN107038025B (en) SOA architecture-based system calling method and device
CN114529413A (en) Processing method of block chain transaction, block chain node and electronic equipment
CN112688802B (en) High-performance exchange middleware based on API gateway
WO2019104844A1 (en) Automatic performance testing method, apparatus and device for monetary fund system, and storage medium
CN108924184B (en) Data processing method and server
CN109491768A (en) A kind of distributed transaction method for dynamically processing and system based on subtransaction stream
WO2022206429A1 (en) Distributed transaction implementation method and distributed system
US8214421B2 (en) Conformance testing without reference implementation of an XML standard
CN113468564B (en) Data processing method and device, electronic equipment and storage medium
CN114385320B (en) Distributed transaction processing method and system
CN113360547A (en) Cross-chain query method and device, electronic equipment and readable storage medium
JPWO2017094096A1 (en) Transaction processing system and transaction control method
TWI842427B (en) Software development system and software developing method