当前位置:网站首页>Shardingsphere integrates atomikos support for XA distributed transactions (1)

Shardingsphere integrates atomikos support for XA distributed transactions (1)

2020-11-23 10:21:51 InfoQ

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Apache ShardingSphere Is a set of open source distributed database middleware solutions composed of the ecosystem , It consists of JDBC、Proxy and Sidecar( Planning ) this 3 They are independent of each other , But it can mix deployment and use of product composition . They all provide standardized data fragmentation 、 Distributed transaction and database governance functions , It can be applied to such as Java isomorphism 、 Heterogeneous languages 、 Various application scenarios such as cloud native ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ShardingSphere Has been in 2020 year 4 month 16 Day to day Apache Top projects at the software foundation ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" Distributed systems CAP theory "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/f7\/28\/f79273yya895fae95e745eb6d8fc5a28.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" Uniformity (Consistency)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Consistency means "},{"type":"codeinline","content":[{"type":"text","text":"all nodes see the same data at the same time"}]},{"type":"text","text":", That is, after the update operation succeeds and returns to the client , All nodes have the same data at the same time , There can be no intermediate state ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" About consistency , If the data that users see all the time is consistent , So it's called strong consistency . If an intermediate state is allowed , Only after a period of time , The data is consistent in the end , It's called ultimate consistency . Besides , If some data inconsistencies are allowed , So it's called weak consistency "}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" Usability (Availability)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Availability means that the services provided by the system must always be available , For each operation request of the user, the result can always be returned in a limited time ."},{"type":"codeinline","content":[{"type":"text","text":" Limited time means "}]},{"type":"text","text":": An operation request for the user , The system must be able to return the corresponding processing results within the specified time , If it goes beyond this time frame , Then the system is considered unavailable ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":" Return results "}]},{"type":"text","text":" Another very important indicator of usability , It requires the system to complete the processing of user requests , Return a normal response result , Whether the result is success or failure ."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" Partition tolerance (Partition tolerance )"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" When the distributed system encounters any network partition failure , There is still a need to be able to ensure that external services meet the requirements of consistency and availability , Unless the entire network environment is down ."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"X\/Open DTP Model and XA standard "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"X\/Open, That is, the present open group, It's an independent organization , Mainly responsible for the development of various industry technical standards . Official website address :http:\/\/www.opengroup.org\/.X\/Open The organization is mainly supported by well-known companies or manufacturers , These organizations don't just follow X\/Open Industry technical standards defined by the organization , Also involved in the development of standards . The following figure shows open group At present, the main members ( Website screenshot ):"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/62\/b9\/62c003487d5f82bab2dd509ebb9594b9.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"DTP Model "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/95\/6d\/95c5a2356387700a06855fe96dfa126d.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Applications (Application Program , abbreviation AP): Used to define transaction boundaries ( Define the beginning and end of a transaction ), And operate on resources within the transaction boundaries ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Explorer (Resource Manager, abbreviation RM, Also known as a transaction participant ): Such as a database 、 File system, etc , And provide access to resources ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Transaction manager (Transaction Manager , abbreviation TM, It is also known as the transaction coordinator ): Responsible for assigning transaction unique identifier , Monitor the progress of transactions , And responsible for the submission of affairs 、 Roll back, etc ."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"XA standard "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/a1\/b7\/a1b6edc2726bc94d2f82078259cb50b7.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" There are many interface specifications here , Let's just talk about a few of the most important ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"xa_start"}]},{"type":"text","text":" : stay "},{"type":"codeinline","content":[{"type":"text","text":"RM"}]},{"type":"text","text":" The client calls this interface to open a "},{"type":"codeinline","content":[{"type":"text","text":"XA"}]},{"type":"text","text":" Business , It needs to be connected at the back "},{"type":"codeinline","content":[{"type":"text","text":"XID"}]},{"type":"text","text":" As a parameter ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"xa_end"}]},{"type":"text","text":" : Disassociate the current thread from the transaction , And "},{"type":"codeinline","content":[{"type":"text","text":"xa_start"}]},{"type":"text","text":" It's pairing ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"xa_prepare"}]},{"type":"text","text":" : inquiry "},{"type":"codeinline","content":[{"type":"text","text":"RM"}]},{"type":"text","text":" Whether you are ready to commit the transaction ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"xa_commit"}]},{"type":"text","text":" : notice "},{"type":"codeinline","content":[{"type":"text","text":"RM"}]},{"type":"text","text":" Commit transaction branch ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"xa_rollback"}]},{"type":"text","text":" : notice "},{"type":"codeinline","content":[{"type":"text","text":"RM"}]},{"type":"text","text":" Commit rollback transaction branch ."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"XA Two stage submission "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":" Stage 1 "}]},{"type":"text","text":" :TM Notifications RM Ready to commit their transaction branches . If RM Judge that your work can be submitted , Then persist the work content , Give again TM A positive reply ; If something else happens , Here TM All the answers are negative . After sending a negative reply and rolling back the work already done ,RM You can discard the transaction branch information ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":" Stage two "}]},{"type":"text","text":" :TM According to the stage 1 each RM prepare Result , Decide whether to commit or roll back the transaction . If all RM all prepare success , that TM Inform all RM Submit ; If there is RM prepare Failure words , be TM Inform all RM Roll back your own transaction branch ."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"MySQL Yes XA Protocol support "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"MySQL"}]},{"type":"text","text":" from "},{"type":"codeinline","content":[{"type":"text","text":"5.0.3"}]},{"type":"text","text":" Start supporting XA Distributed transactions , And only "},{"type":"codeinline","content":[{"type":"text","text":"InnoDB"}]},{"type":"text","text":" Storage engine support XA Business ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"MySQL"}]},{"type":"text","text":" stay "},{"type":"codeinline","content":[{"type":"text","text":"DTP"}]},{"type":"text","text":" The model also belongs to the resource manager "},{"type":"codeinline","content":[{"type":"text","text":"RM"}]},{"type":"text","text":"."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"MySQL XA The transaction SQL grammar "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"XA START xid \/\/ Turn on XA Business ,xid It's a unique value , Represents the transaction branch identifier \nXA END xid \/\/ End one XA Business ,\nXA PREPARE xid Prepare to submit \nXA COMMIT xid [ONE PHASE] \/\/ Commit transaction . In the two-stage commit agreement , If only one RM Participate in , Then it can be optimized for one phase commit \nXA ROLLBACK xid \/\/ Roll back \nXA RECOVER [CONVERT XID] \/\/ List all the places in PREPARE Stage XA Business \n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"MySQL xid Detailed explanation "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"mysql Use in xid As an identifier for a transaction branch . adopt C Language description , as follows :"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"\/∗\n∗ Transaction branch identification: XID and NULLXID:\n∗\/\n#define XIDDATASIZE 128 \/∗ size in bytes ∗\/\n#define MAXGTRIDSIZE 64 \/∗ maximum size in bytes of gtrid ∗\/\n#define MAXBQUALSIZE 64 \/∗ maximum size in bytes of bqual ∗\/\nstruct xid_t {\n long formatID; \/* format identifier *\/\n long gtrid_length; \/* value 1-64 *\/\n long bqual_length; \/* value 1-64 *\/\n char data[XIDDATASIZE];\n };\n\/∗\n∗ A value of -1 in formatID means that the XID is null.\n∗\/\ntypedef struct xid_t XID;\n\/∗\n∗ Declarations of routines by which RMs call TMs:\n∗\/\nextern int ax_reg(int, XID ∗, long);\nextern int ax_unreg(int, long);\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"gtrid"}]},{"type":"text","text":" : Global transaction identifier (global transaction identifier), Maximum not exceeding 64 byte ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"bqual"}]},{"type":"text","text":" : Branch qualifier (branch qualifier), Maximum not exceeding 64 byte ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"formatId"}]},{"type":"text","text":": Record gtrid、bqual The format of , Be similar to memcached in flags The role of fields ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"data"}]},{"type":"text","text":" :xid Value , It is gtrid and bqual The content after splicing ."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"MySQL XA State of affairs "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/fd\/4d\/fd0yyc12b7a02c19b5b5c0b03e21744d.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"JTA standard "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢

随机推荐