{"id":168865,"date":"2020-01-22T10:00:27","date_gmt":"2020-01-22T02:00:27","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=168865"},"modified":"2020-01-14T10:59:19","modified_gmt":"2020-01-14T02:59:19","slug":"distributed-transaction-framework","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/distributed-transaction-framework.html","title":{"rendered":"\u4e00\u4e2a\u901a\u7528\u7684\u5206\u5e03\u5f0f\u4e8b\u52a1\u6846\u67b6\u5982\u4f55\u5b9e\u73b0\uff1f\u770b\u8fd9\u91cc\u5427"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4e00\u4e2aTCC\u4e8b\u52a1\u6846\u67b6\u9700\u8981\u89e3\u51b3\u7684\u5f53\u7136\u662f\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u7ba1\u7406\u3002\u5173\u4e8eTCC\u4e8b\u52a1\u673a\u5236\u7684\u4ecb\u7ecd\uff0c\u53ef\u4ee5\u53c2\u8003TCC\u4e8b\u52a1\u673a\u5236\u7b80\u4ecb\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4e00\u4e2aTCC\u4e8b\u52a1\u6846\u67b6\u9700\u8981\u89e3\u51b3\u7684\u5f53\u7136\u662f\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u7ba1\u7406\u3002\u5173\u4e8eTCC\u4e8b\u52a1\u673a\u5236\u7684\u4ecb\u7ecd\uff0c\u53ef\u4ee5\u53c2\u8003TCC\u4e8b\u52a1\u673a\u5236\u7b80\u4ecb\u3002<\/p>\n

TCC\u4e8b\u52a1\u6a21\u578b\u867d\u7136\u8bf4\u8d77\u6765\u7b80\u5355\uff0c\u7136\u800c\u8981\u57fa\u4e8eTCC\u5b9e\u73b0\u4e00\u4e2a\u901a\u7528\u7684\u5206\u5e03\u5f0f\u4e8b\u52a1\u6846\u67b6\uff0c\u5374\u6bd4\u5b83\u770b\u4e0a\u53bb\u8981\u590d\u6742\u7684\u591a\uff0c\u4e0d\u53ea\u662f\u7b80\u5355\u7684\u8c03\u7528\u4e00\u4e0bConfirm\/Cancel\u4e1a\u52a1\u5c31\u53ef\u4ee5\u4e86\u7684\u3002<\/p>\n

\u672c\u6587\u5c06\u4ee5Spring\u5bb9\u5668\u4e3a\u4f8b\uff0c\u8bd5\u56fe\u5206\u6790\u4e00\u4e0b\uff0c\u5b9e\u73b0\u4e00\u4e2a\u901a\u7528\u7684TCC\u5206\u5e03\u5f0f\u4e8b\u52a1\u6846\u67b6\u9700\u8981\u6ce8\u610f\u7684\u4e00\u4e9b\u95ee\u9898\u3002<\/p>\n

\u4e00\u3001TCC\u5168\u5c40\u4e8b\u52a1\u5fc5\u987b\u57fa\u4e8eRM\u672c\u5730\u4e8b\u52a1\u6765\u5b9e\u73b0<\/strong><\/strong><\/div>\n

TCC\u670d\u52a1\u662f\u7531Try\/Confirm\/Cancel\u4e1a\u52a1\u6784\u6210\u7684\uff0c\u5176Try\/Confirm\/Cancel\u4e1a\u52a1\u5728\u6267\u884c\u65f6\uff0c\u4f1a\u8bbf\u95ee\u8d44\u6e90\u7ba1\u7406\u5668(Resource Manager\uff0c\u4e0b\u6587\u7b80\u79f0RM)\u6765\u5b58\u53d6\u6570\u636e\u3002<\/p>\n

\u8fd9\u4e9b\u5b58\u53d6\u64cd\u4f5c\uff0c\u5fc5\u987b\u8981\u53c2\u4e0eRM\u672c\u5730\u4e8b\u52a1\uff0c\u4ee5\u4f7f\u5176\u66f4\u6539\u7684\u6570\u636e\u8981\u4e48\u90fdcommit\uff0c\u8981\u4e48\u90fdrollback\u3002<\/p>\n

\u8fd9\u4e00\u70b9\u4e0d\u96be\u7406\u89e3\uff0c\u8003\u8651\u4e00\u4e0b\u5982\u4e0b\u573a\u666f\uff1a<\/p>\n

\"\"<\/p>\n

\u5047\u8bbe\u56fe\u4e2d\u7684\u670d\u52a1B\u6ca1\u6709\u57fa\u4e8eRM\u672c\u5730\u4e8b\u52a1(\u4ee5RDBS\u4e3a\u4f8b\uff0c\u53ef\u901a\u8fc7\u8bbe\u7f6eauto-commit\u4e3atrue\u6765\u6a21\u62df)\uff0c\u90a3\u4e48\u4e00\u65e6[B:Try]\u64cd\u4f5c\u4e2d\u9014\u6267\u884c\u5931\u8d25\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u540e\u7eed\u51b3\u5b9a\u56de\u6eda\u5168\u5c40\u4e8b\u52a1\u65f6\uff0c\u8be5[B:Cancel]\u5219\u9700\u8981\u5224\u65ad[B:Try]\u4e2d\u54ea\u4e9b\u64cd\u4f5c\u5df2\u7ecf\u5199\u5230DB\u3001\u54ea\u4e9b\u64cd\u4f5c\u8fd8\u6ca1\u6709\u5199\u5230DB.<\/p>\n

\u5047\u8bbe[B:Try]\u4e1a\u52a1\u67095\u4e2a\u5199\u5e93\u64cd\u4f5c\uff0c[B:Cancel]\u4e1a\u52a1\u5219\u9700\u8981\u9010\u4e2a\u5224\u65ad\u8fd95\u4e2a\u64cd\u4f5c\u662f\u5426\u751f\u6548\uff0c\u5e76\u5c06\u751f\u6548\u7684\u64cd\u4f5c\u6267\u884c\u53cd\u5411\u64cd\u4f5c\u3002<\/p>\n

\u4e0d\u5e78\u7684\u662f\uff0c\u7531\u4e8e[B:Cancel]\u4e1a\u52a1\u4e5f\u6709n(0<=n<=5)\u4e2a\u53cd\u5411\u7684\u5199\u5e93\u64cd\u4f5c\uff0c\u6b64\u65f6\u4e00\u65e6[B:Cancel]\u4e5f\u4e2d\u9014\u51fa\u9519\uff0c\u5219\u540e\u7eed\u7684[B:Cancel]\u6267\u884c\u4efb\u52a1\u66f4\u52a0\u7e41\u91cd\u3002<\/p>\n

\u56e0\u4e3a\u76f8\u6bd4\u7b2c\u4e00\u6b21[B:Cancel]\u64cd\u4f5c\uff0c\u540e\u7eed\u7684[B:Cancel]\u64cd\u4f5c\u8fd8\u9700\u8981\u5224\u65ad\u5148\u524d\u7684[B:Cancel]\u64cd\u4f5c\u7684n(0<=n<=5)\u4e2a\u5199\u5e93\u4e2d\u54ea\u51e0\u4e2a\u5df2\u7ecf\u6267\u884c\u3001\u54ea\u51e0\u4e2a\u8fd8\u6ca1\u6709\u6267\u884c.<\/p>\n

\u8fd9\u5c31\u6d89\u53ca\u5230\u4e86\u5e42\u7b49\u6027\u95ee\u9898\uff0c\u800c\u5bf9\u5e42\u7b49\u6027\u7684\u4fdd\u969c\uff0c\u53c8\u5f88\u53ef\u80fd\u8fd8\u9700\u8981\u6d89\u53ca\u989d\u5916\u7684\u5199\u5e93\u64cd\u4f5c\uff0c\u8be5\u5199\u5e93\u64cd\u4f5c\u53c8\u4f1a\u56e0\u4e3a\u6ca1\u6709RM\u672c\u5730\u4e8b\u52a1\u7684\u652f\u6301\u800c\u5b58\u5728\u7c7b\u4f3c\u95ee\u9898\u3002\u3002\u3002<\/p>\n

\u53ef\u60f3\u800c\u77e5\uff0c\u5982\u679c\u4e0d\u57fa\u4e8eRM\u672c\u5730\u4e8b\u52a1\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u662f\u65e0\u6cd5\u6709\u6548\u7684\u7ba1\u7406TCC\u5168\u5c40\u4e8b\u52a1\u7684\u3002<\/p>\n

\u53cd\u4e4b\uff0c\u57fa\u4e8eRM\u672c\u5730\u4e8b\u52a1\u7684TCC\u4e8b\u52a1\uff0c\u8fd9\u79cd\u60c5\u51b5\u5219\u4f1a\u5f88\u5bb9\u6613\u5904\u7406\u3002<\/p>\n

[B:Try]\u64cd\u4f5c\u4e2d\u9014\u6267\u884c\u5931\u8d25\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u5c06\u5176\u53c2\u4e0eRM\u672c\u5730\u4e8b\u52a1\u76f4\u63a5rollback\u5373\u53ef\u3002\u540e\u7eedTCC\u4e8b\u52a1\u6846\u67b6\u51b3\u5b9a\u56de\u6eda\u5168\u5c40\u4e8b\u52a1\u65f6\uff0c\u5728\u77e5\u9053\u201c[B:Try]\u64cd\u4f5c\u6d89\u53ca\u7684RM\u672c\u5730\u4e8b\u52a1\u5df2\u7ecfrollback\u201d\u7684\u60c5\u51b5\u4e0b\uff0c\u6839\u672c\u65e0\u9700\u6267\u884c[B:Cancel]\u64cd\u4f5c\u3002<\/p>\n

\u6362\u53e5\u8bdd\u8bf4\uff0c\u57fa\u4e8eRM\u672c\u5730\u4e8b\u52a1\u5b9e\u73b0TCC\u4e8b\u52a1\u6846\u67b6\u65f6\uff0c\u4e00\u4e2aTCC\u578b\u670d\u52a1\u7684cancel\u4e1a\u52a1\u8981\u4e48\u6267\u884c\uff0c\u8981\u4e48\u4e0d\u6267\u884c\uff0c\u4e0d\u9700\u8981\u8003\u8651\u90e8\u5206\u6267\u884c\u7684\u60c5\u51b5\u3002<\/p>\n

\u4e8c\u3001TCC\u4e8b\u52a1\u6846\u67b6\u5e94\u8be5\u63a5\u7ba1Spring\u5bb9\u5668\u7684TransactionManager<\/strong><\/strong><\/div>\n

\u57fa\u4e8eRM\u672c\u5730\u4e8b\u52a1\u7684TCC\u4e8b\u52a1\u6846\u67b6\uff0c\u53ef\u4ee5\u5c06\u5404Try\/Confirm\/Cancel\u4e1a\u52a1\u770b\u6210\u4e00\u4e2a\u539f\u5b50\u670d\u52a1\uff1a\u4e00\u4e2aRM\u672c\u5730\u4e8b\u52a1\u63d0\u4ea4\uff0c\u53c2\u4e0e\u8be5RM\u672c\u5730\u4e8b\u52a1\u7684\u6240\u6709Try\/Confirm\/Cancel\u4e1a\u52a1\u64cd\u4f5c\u90fd\u751f\u6548;\u53cd\u4e4b\uff0c\u5219\u90fd\u4e0d\u751f\u6548\u3002<\/p>\n

\u638c\u63e1\u6bcf\u4e2aRM\u672c\u5730\u4e8b\u52a1\u7684\u72b6\u6001\u4ee5\u53ca\u5b83\u4eec\u4e0eTry\/Confirm\/Cancel\u4e1a\u52a1\u65b9\u6cd5\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb\uff0c\u4ee5\u6b64\u4e3a\u57fa\u7840\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u624d\u80fd\u6709\u6548\u7684\u6784\u5efaTCC\u5168\u5c40\u4e8b\u52a1\u3002<\/p>\n

TCC\u670d\u52a1\u7684Try\/Confirm\/Cancel\u4e1a\u52a1\u65b9\u6cd5\u5728RM\u4e0a\u7684\u6570\u636e\u5b58\u53d6\u64cd\u4f5c\uff0c\u5176RM\u672c\u5730\u4e8b\u52a1\u662f\u7531Spring\u5bb9\u5668\u7684PlatformTransactionManager\u6765commit\/rollback\u7684\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u60f3\u8981\u4e86\u89e3RM\u672c\u5730\u4e8b\u52a1\u7684\u72b6\u6001\uff0c\u53ea\u80fd\u901a\u8fc7\u63a5\u7ba1Spring\u7684\u4e8b\u52a1\u7ba1\u7406\u5668\u529f\u80fd\u3002<\/p>\n

2.1. \u4e3a\u4ec0\u4e48TCC\u4e8b\u52a1\u6846\u67b6\u9700\u8981\u638c\u63e1RM\u672c\u5730\u4e8b\u52a1\u7684\u72b6\u6001?<\/strong><\/strong><\/span><\/div>\n

\u9996\u5148\uff0c\u6839\u636eTCC\u673a\u5236\u7684\u5b9a\u4e49\uff0cTCC\u4e8b\u52a1\u662f\u901a\u8fc7\u6267\u884cCancel\u4e1a\u52a1\u6765\u8fbe\u5230\u56de\u6eda\u6548\u679c\u7684\u3002\u4ed4\u7ec6\u5206\u6790\u4e00\u4e0b\uff0c\u8fd9\u91cc\u6697\u542b\u4e00\u4e2a\u4e8b\u5b9e\uff1a\u53ea\u6709\u751f\u6548\u7684Try\u4e1a\u52a1\u64cd\u4f5c\u624d\u9700\u8981\u6267\u884c\u5bf9\u5e94\u7684Cancel\u4e1a\u52a1\u64cd\u4f5c\u3002<\/p>\n

\u6362\u53e5\u8bdd\u8bf4\uff0c\u53ea\u6709Try\u4e1a\u52a1\u64cd\u4f5c\u6240\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u88abcommit\u4e86\uff0c\u540e\u7eedTCC\u5168\u5c40\u4e8b\u52a1\u56de\u6eda\u65f6\u624d\u9700\u8981\u6267\u884c\u5176\u5bf9\u5e94\u7684Cancel\u4e1a\u52a1\u64cd\u4f5c<\/p>\n

\u5426\u5219\uff0c\u5982\u679cTry\u4e1a\u52a1\u64cd\u4f5c\u6240\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u88abrollback\u4e86\uff0c\u540e\u7eedTCC\u5168\u5c40\u4e8b\u52a1\u56de\u6eda\u65f6\u5c31\u4e0d\u80fd\u6267\u884c\u5176Cancel\u4e1a\u52a1\uff0c\u6b64\u65f6\u82e5\u76f2\u76ee\u6267\u884cCancel\u4e1a\u52a1\u53cd\u800c\u4f1a\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n

\u5176\u6b21\uff0cConfirm\/Cancel\u4e1a\u52a1\u64cd\u4f5c\u5fc5\u987b\u4fdd\u8bc1\u751f\u6548\u3002Confirm\/Cancel\u4e1a\u52a1\u64cd\u4f5c\u4e5f\u4f1a\u6d89\u53caRM\u6570\u636e\u5b58\u53d6\u64cd\u4f5c\uff0c\u5176\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u4e5f\u5fc5\u987b\u88abcommit\u3002<\/p>\n

TCC\u4e8b\u52a1\u6846\u67b6\u9700\u8981\u5728\u786e\u5207\u7684\u77e5\u9053\u6240\u6709Confirm\/Cancel\u4e1a\u52a1\u64cd\u4f5c\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u90fd\u88ab\u6210\u529fcommit\u540e\uff0c\u624d\u80fd\u5c06\u6807\u8bb0\u8be5TCC\u5168\u5c40\u4e8b\u52a1\u4e3a\u5b8c\u6210\u3002<\/p>\n

\u5982\u679cTCC\u4e8b\u52a1\u6846\u67b6\u8bef\u5224\u4e86Confirm\/Cancel\u4e1a\u52a1\u53c2\u4e0eRM\u672c\u5730\u4e8b\u52a1\u7684\u72b6\u6001\uff0c\u5c31\u4f1a\u9020\u6210\u5168\u5c40\u4e8b\u52a1\u4e0d\u4e00\u81f4\u3002<\/p>\n

\u6700\u540e\uff0c\u672a\u5b8c\u6210\u7684TCC\u5168\u5c40\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u5fc5\u987b\u91cd\u65b0\u5c1d\u8bd5\u63d0\u4ea4\/\u56de\u6eda\u64cd\u4f5c\u3002\u91cd\u8bd5\u65f6\u4f1a\u518d\u6b21\u8c03\u7528\u5404TCC\u670d\u52a1\u7684Confirm\/Cancel\u4e1a\u52a1\u64cd\u4f5c\u3002<\/p>\n

\u5982\u679c\u67d0\u4e2a\u670d\u52a1\u7684Confirm\/Cancel\u4e1a\u52a1\u4e4b\u524d\u5df2\u7ecf\u751f\u6548(\u5176\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u5df2\u7ecf\u63d0\u4ea4)\uff0c\u91cd\u8bd5\u65f6\u5c31\u4e0d\u5e94\u8be5\u518d\u6b21\u88ab\u8c03\u7528\u3002\u5426\u5219\uff0c\u5176Confirm\/Cancel\u4e1a\u52a1\u88ab\u591a\u6b21\u8c03\u7528\uff0c\u5c31\u4f1a\u6709\u201c\u670d\u52a1\u5e42\u7b49\u6027\u201d\u7684\u95ee\u9898\u3002<\/p>\n

2.2. \u62e6\u622aTCC\u670d\u52a1\u7684Try\/Confirm\/Cancel\u4e1a\u52a1\u65b9\u6cd5\u7684\u6267\u884c\uff0c\u6839\u636e\u5176\u5f02\u5e38\u4fe1\u606f\u53ef\u5426\u77e5\u9053\u5176RM\u672c\u5730\u4e8b\u52a1\u662f\u5426commit\/rollback\u4e86\u5462?<\/strong><\/strong><\/span><\/div>\n

\u57fa\u672c\u4e0a\u5f88\u96be\u505a\u5230\uff0c\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u8bf4?<\/p>\n

\u7b2c\u4e00\uff0c\u4e8b\u52a1\u662f\u53ef\u4ee5\u5728\u591a\u4e2a(\u672c\u5730\/\u8fdc\u7a0b)\u670d\u52a1\u4e4b\u95f4\u4e92\u76f8\u4f20\u64ad\u5176\u4e8b\u52a1\u4e0a\u4e0b\u6587\u7684\uff0c\u4e00\u4e2a\u4e1a\u52a1\u65b9\u6cd5(Try\/Confirm\/Cancel)\u6267\u884c\u5b8c\u6bd5\u5e76\u4e0d\u4e00\u5b9a\u4f1a\u89e6\u53d1\u5f53\u524d\u4e8b\u52a1\u7684commit\/rollback\u64cd\u4f5c\u3002<\/p>\n

\u6bd4\u5982\uff0c\u88ab\u4f20\u64ad\u4e8b\u52a1\u4e0a\u4e0b\u6587\u7684\u4e1a\u52a1\u65b9\u6cd5\uff0c\u5728\u5b83\u5f00\u59cb\u6267\u884c\u65f6\uff0c\u5bb9\u5668\u5e76\u4e0d\u4f1a\u4e3a\u5176\u521b\u5efa\u65b0\u7684\u4e8b\u52a1\uff0c\u800c\u662f\u5b83\u7684\u8c03\u7528\u65b9\u53c2\u4e0e\u7684\u4e8b\u52a1\uff0c\u4f7f\u5f97\u4e8c\u8005\u64cd\u4f5c\u5728\u540c\u4e00\u4e2a\u4e8b\u52a1\u4e2d;\u540c\u6837\uff0c\u5728\u5b83\u6267\u884c\u5b8c\u6bd5\u65f6\uff0c\u5bb9\u5668\u4e5f\u4e0d\u4f1a\u63d0\u4ea4\/\u56de\u6eda\u5b83\u53c2\u4e0e\u7684\u4e8b\u52a1\u7684\u3002<\/p>\n

\u56e0\u6b64\uff0c\u8fd9\u7c7b\u4e1a\u52a1\u65b9\u6cd5\u4e0a\u7684\u5f02\u5e38\u60c5\u51b5\u5e76\u4e0d\u80fd\u53cd\u6620\u4ed6\u4eec\u662f\u5426\u751f\u6548\u3002\u4e0d\u63a5\u7ba1Spring\u7684TransactionManager\uff0c\u5c31\u65e0\u6cd5\u4e86\u89e3\u4e8b\u52a1\u4e8e\u4f55\u65f6\u88ab\u521b\u5efa\uff0c\u4e5f\u65e0\u6cd5\u4e86\u89e3\u5b83\u4e8e\u4f55\u65f6\u88ab\u63d0\u4ea4\/\u56de\u6eda\u3002<\/p>\n

\u7b2c\u4e8c\u3001\u4e00\u4e2a\u4e1a\u52a1\u65b9\u6cd5\u53ef\u80fd\u4f1a\u5305\u542b\u591a\u4e2aRM\u672c\u5730\u4e8b\u52a1\u7684\u60c5\u51b5\u3002<\/p>\n

\u6bd4\u5982\uff1aA(REQUIRED)->B(REQUIRES_NEW)->C(REQUIRED)\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cA\u670d\u52a1\u6240\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u88ab\u63d0\u4ea4\u65f6\uff0cB\u670d\u52a1\u548cC\u670d\u52a1\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u5219\u53ef\u80fd\u4f1a\u88ab\u56de\u6eda\u3002<\/p>\n

\u7b2c\u4e09\u3001\u5e76\u4e0d\u662f\u629b\u51fa\u4e86\u5f02\u5e38\u7684\u4e1a\u52a1\u65b9\u6cd5\uff0c\u5176\u53c2\u4e0e\u7684\u4e8b\u52a1\u5c31\u56de\u6eda\u4e86\u3002<\/p>\n

Spring\u5bb9\u5668\u7684\u58f0\u660e\u5f0f\u4e8b\u52a1\u5b9a\u4e49\u4e86\u4e24\u7c7b\u5f02\u5e38\uff0c\u5176\u4e8b\u52a1\u5b8c\u6210\u65b9\u5411\u90fd\u4e0d\u4e00\u6837\uff1a\u7cfb\u7edf\u5f02\u5e38(\u4e00\u822c\u4e3aUnchecked\u5f02\u5e38\uff0c\u9ed8\u8ba4\u4e8b\u52a1\u5b8c\u6210\u65b9\u5411\u662frollback)\u3001\u5e94\u7528\u5f02\u5e38(\u4e00\u822c\u4e3aChecked\u5f02\u5e38\uff0c\u9ed8\u8ba4\u4e8b\u52a1\u5b8c\u6210\u65b9\u5411\u662fcommit)\u3002<\/p>\n

\u4e8c\u8005\u7684\u4e8b\u52a1\u5b8c\u6210\u65b9\u5411\u53c8\u53ef\u4ee5\u901a\u8fc7@Transactional\u914d\u7f6e\u663e\u5f0f\u7684\u6307\u5b9a\uff0c\u5982rollbackFor\/noRollbackFor\u7b49\u3002<\/p>\n

\u7b2c\u56db\u3001Spring\u5bb9\u5668\u8fd8\u652f\u6301\u4f7f\u7528setRollbackOnly\u7684\u65b9\u5f0f\u663e\u5f0f\u7684\u63a7\u5236\u4e8b\u52a1\u5b8c\u6210\u65b9\u5411;<\/p>\n

\u6700\u540e\uff0c\u81ea\u884c\u62e6\u622a\u4e1a\u52a1\u65b9\u6cd5\u7684\u62e6\u622a\u5668\u548cSpring\u7684\u4e8b\u52a1\u5904\u7406\u7684\u62e6\u622a\u5668\u8fd8\u4f1a\u5b58\u5728\u6267\u884c\u5148\u540e\u3001\u62e6\u622a\u8303\u56f4\u4e0d\u540c\u7b49\u95ee\u9898\u3002<\/p>\n

\u4f8b\u5982\uff0c\u5982\u679c\u81ea\u884c\u62e6\u622a\u5668\u6267\u884c\u5728\u524d\uff0c\u5c31\u4f1a\u51fa\u73b0\u4e1a\u52a1\u65b9\u6cd5\u867d\u7136\u5df2\u7ecf\u6267\u884c\u5b8c\u6bd5\u4f46\u6b64\u65f6\u5176\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u8fd8\u6ca1\u6709commit\/rollback\u3002<\/p>\n

TCC\u4e8b\u52a1\u6846\u67b6\u7684\u5b9a\u4f4d\u5e94\u8be5\u662f\u4e00\u4e2aTransactionManager\uff0c\u5176\u804c\u8d23\u662f\u8d1f\u8d23commit\/rollback\u4e8b\u52a1\u3002<\/p>\n

\u800c\u4e00\u4e2a\u4e8b\u52a1\u5e94\u8be5commit\u3001\u8fd8\u662frollback\uff0c\u5219\u5e94\u8be5\u662f\u7531Spring\u5bb9\u5668\u6765\u51b3\u5b9a\u7684\uff1a<\/p>\n

Spring\u51b3\u5b9a\u63d0\u4ea4\u4e8b\u52a1\u65f6\uff0c\u4f1a\u8c03\u7528TransactionManager\u6765\u5b8c\u6210commit\u64cd\u4f5c;Spring\u51b3\u5b9a\u56de\u6eda\u4e8b\u52a1\u65f6\uff0c\u4f1a\u8c03\u7528TransactionManager\u6765\u5b8c\u6210rollback\u64cd\u4f5c\u3002<\/p>\n

\u63a5\u7ba1Spring\u5bb9\u5668\u7684TransactionManager\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u53ef\u4ee5\u660e\u786e\u7684\u5f97\u5230Spring\u7684\u4e8b\u52a1\u6027\u6307\u4ee4\uff0c\u5e76\u7ba1\u7406Spring\u5bb9\u5668\u4e2d\u5404\u670d\u52a1\u7684RM\u672c\u5730\u4e8b\u52a1\u3002<\/p>\n

\u5426\u5219\uff0c\u5982\u679c\u901a\u8fc7\u81ea\u884c\u62e6\u622a\u7684\u673a\u5236\uff0c\u5219\u4f7f\u5f97\u4e1a\u52a1\u7cfb\u7edf\u5b58\u5728TCC\u4e8b\u52a1\u5904\u7406\u3001RM\u672c\u5730\u4e8b\u52a1\u5904\u7406\u4e24\u5957\u4e8b\u52a1\u5904\u7406\u903b\u8f91\uff0c\u4e8c\u8005\u4e92\u4e0d\u901a\u4fe1\uff0c\u5404\u884c\u5176\u662f\u3002<\/p>\n

\u8fd9\u79cd\u60c5\u51b5\u4e0b\u8981\u534f\u8c03TCC\u5168\u5c40\u4e8b\u52a1\uff0c\u57fa\u672c\u4e0a\u53ef\u4ee5\u8bf4\u662f\u7f18\u6728\u6c42\u9c7c\uff0c\u672c\u5730\u4e8b\u52a1\u5c1a\u4e14\u65e0\u6cd5\u7ba1\u7406\uff0c\u66f4\u4f55\u8c08\u7ba1\u7406\u5206\u5e03\u5f0f\u4e8b\u52a1?<\/p>\n

\u4e09\u3001TCC\u4e8b\u52a1\u6846\u67b6\u5e94\u8be5\u5177\u5907\u6545\u969c\u6062\u590d\u673a\u5236<\/strong><\/strong><\/div>\n

\u4e00\u4e2aTCC\u4e8b\u52a1\u6846\u67b6\uff0c\u82e5\u662f\u6ca1\u6709\u6545\u969c\u6062\u590d\u7684\u4fdd\u969c\uff0c\u662f\u4e0d\u6210\u5176\u4e3a\u5206\u5e03\u5f0f\u4e8b\u52a1\u6846\u67b6\u7684\u3002<\/p>\n

\u5206\u5e03\u5f0f\u4e8b\u52a1\u7ba1\u7406\u6846\u67b6\u7684\u804c\u8d23\uff0c\u4e0d\u662f\u505a\u51fa\u5168\u5c40\u4e8b\u52a1\u63d0\u4ea4\/\u56de\u6eda\u7684\u6307\u4ee4\uff0c\u800c\u662f\u7ba1\u7406\u5168\u5c40\u4e8b\u52a1\u63d0\u4ea4\/\u56de\u6eda\u7684\u8fc7\u7a0b\u3002<\/p>\n

\u5b83\u9700\u8981\u80fd\u591f\u534f\u8c03\u591a\u4e2aRM\u8d44\u6e90\u3001\u591a\u4e2a\u8282\u70b9\u7684\u5206\u652f\u4e8b\u52a1\uff0c\u4fdd\u8bc1\u5b83\u4eec\u6309\u5168\u5c40\u4e8b\u52a1\u7684\u5b8c\u6210\u65b9\u5411\u5404\u81ea\u5b8c\u6210\u81ea\u5df1\u7684\u5206\u652f\u4e8b\u52a1\u3002<\/p>\n

\u8fd9\u4e00\u70b9\uff0c\u662f\u4e0d\u5bb9\u6613\u505a\u5230\u7684\u3002\u56e0\u4e3a\uff0c\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4f1a\u6709\u5404\u79cd\u6545\u969c\u51fa\u73b0\uff0c\u5f88\u591a\u90fd\u4f1a\u9020\u6210\u4e8b\u52a1\u7684\u4e2d\u65ad\uff0c\u4ece\u800c\u4f7f\u5f97\u7edf\u4e00\u63d0\u4ea4\/\u56de\u6eda\u5168\u5c40\u4e8b\u52a1\u7684\u76ee\u6807\u4e0d\u80fd\u8fbe\u5230\uff0c\u751a\u81f3\u51fa\u73b0\u201d\u4e00\u90e8\u5206\u5206\u652f\u4e8b\u52a1\u5df2\u7ecf\u63d0\u4ea4\uff0c\u800c\u53e6\u4e00\u90e8\u5206\u5206\u652f\u4e8b\u52a1\u5219\u5df2\u56de\u6eda\u201d\u7684\u60c5\u51b5\u3002<\/p>\n

\u6bd4\u8f83\u5e38\u89c1\u7684\u6545\u969c\uff0c\u6bd4\u5982\uff1a\u4e1a\u52a1\u7cfb\u7edf\u670d\u52a1\u5668\u5b95\u673a\u3001\u91cd\u542f;\u6570\u636e\u5e93\u670d\u52a1\u5668\u5b95\u673a\u3001\u91cd\u542f;\u7f51\u7edc\u6545\u969c;\u65ad\u7535\u7b49\u3002\u8fd9\u4e9b\u6545\u969c\u53ef\u80fd\u5355\u72ec\u53d1\u751f\uff0c\u4e5f\u53ef\u80fd\u4f1a\u540c\u65f6\u53d1\u751f\u3002<\/p>\n

\u4f5c\u4e3a\u5206\u5e03\u5f0f\u4e8b\u52a1\u6846\u67b6\uff0c\u5e94\u8be5\u5177\u5907\u76f8\u5e94\u7684\u6545\u969c\u6062\u590d\u673a\u5236\uff0c\u65e0\u89c6\u8fd9\u4e9b\u6545\u969c\u7684\u5f71\u54cd\u662f\u4e0d\u8d1f\u8d23\u4efb\u7684\u505a\u6cd5\u3002<\/p>\n

\u4e00\u4e2a\u5b8c\u6574\u7684\u5206\u5e03\u5f0f\u4e8b\u52a1\u6846\u67b6\uff0c\u5e94\u8be5\u4fdd\u969c\u5373\u4f7f\u5728\u6700\u4e25\u82db\u7684\u6761\u4ef6\u4e0b\u4e5f\u80fd\u4fdd\u8bc1\u5168\u5c40\u4e8b\u52a1\u7684\u4e00\u81f4\u6027\uff0c\u800c\u4e0d\u662f\u53ea\u80fd\u5728\u6700\u7406\u60f3\u7684\u73af\u5883\u4e0b\u624d\u80fd\u63d0\u4f9b\u8fd9\u79cd\u4fdd\u969c\u3002\u9000\u4e00\u6b65\u8bf4\uff0c\u5982\u679c\u80fd\u6709\u6240\u8c13\u201c\u7406\u60f3\u7684\u73af\u5883\u201d\uff0c\u90a3\u4e5f\u65e0\u9700\u4f7f\u7528\u5206\u5e03\u5f0f\u4e8b\u52a1\u4e86\u3002<\/p>\n

TCC\u4e8b\u52a1\u6846\u67b6\u8981\u652f\u6301\u6545\u969c\u6062\u590d\uff0c\u5c31\u5fc5\u987b\u8bb0\u5f55\u76f8\u5e94\u7684\u4e8b\u52a1\u65e5\u5fd7\u3002\u4e8b\u52a1\u65e5\u5fd7\u662f\u6545\u969c\u6062\u590d\u7684\u57fa\u7840\u548c\u524d\u63d0\uff0c\u5b83\u8bb0\u5f55\u4e86\u4e8b\u52a1\u7684\u5404\u9879\u6570\u636e\u3002<\/p>\n

TCC\u4e8b\u52a1\u6846\u67b6\u505a\u6545\u969c\u6062\u590d\u65f6\uff0c\u53ef\u4ee5\u6839\u636e\u4e8b\u52a1\u65e5\u5fd7\u7684\u6570\u636e\u5c06\u4e2d\u65ad\u7684\u4e8b\u52a1\u6062\u590d\u81f3\u6b63\u786e\u7684\u72b6\u6001\uff0c\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u7ee7\u7eed\u6267\u884c\u5148\u524d\u672a\u5b8c\u6210\u7684\u63d0\u4ea4\/\u56de\u6eda\u64cd\u4f5c\u3002\u5173\u6ce8\u5fae\u4fe1\u516c\u4f17\u53f7\uff1aJava\u6280\u672f\u6808\uff0c\u5728\u540e\u53f0\u56de\u590d\uff1a\u67b6\u6784\uff0c\u53ef\u4ee5\u83b7\u53d6\u6211\u6574\u7406\u7684 N \u7bc7\u67b6\u6784\u6559\u7a0b\uff0c\u90fd\u662f\u5e72\u8d27\u3002<\/p>\n

\u56db\u3001TCC\u4e8b\u52a1\u6846\u67b6\u5e94\u8be5\u63d0\u4f9bConfirm\/Cancel\u670d\u52a1\u7684\u5e42\u7b49\u6027\u4fdd\u969c<\/strong><\/strong><\/div>\n

\u4e00\u822c\u8ba4\u4e3a\uff0c\u670d\u52a1\u7684\u5e42\u7b49\u6027\uff0c\u662f\u6307\u9488\u5bf9\u540c\u4e00\u4e2a\u670d\u52a1\u7684\u591a\u6b21(n>1)\u8bf7\u6c42\u548c\u5bf9\u5b83\u7684\u5355\u6b21(n=1)\u8bf7\u6c42\uff0c\u4e8c\u8005\u5177\u6709\u76f8\u540c\u7684\u526f\u4f5c\u7528\u3002<\/p>\n

\u5728TCC\u4e8b\u52a1\u6a21\u578b\u4e2d\uff0cConfirm\/Cancel\u4e1a\u52a1\u53ef\u80fd\u4f1a\u88ab\u91cd\u590d\u8c03\u7528\uff0c\u5176\u539f\u56e0\u5f88\u591a\u3002<\/p>\n

\u6bd4\u5982\uff0c\u5168\u5c40\u4e8b\u52a1\u5728\u63d0\u4ea4\/\u56de\u6eda\u65f6\u4f1a\u8c03\u7528\u5404TCC\u670d\u52a1\u7684Confirm\/Cancel\u4e1a\u52a1\u903b\u8f91\u3002\u6267\u884c\u8fd9\u4e9bConfirm\/Cancel\u4e1a\u52a1\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u5982\u7f51\u7edc\u4e2d\u65ad\u7684\u6545\u969c\u800c\u4f7f\u5f97\u5168\u5c40\u4e8b\u52a1\u4e0d\u80fd\u5b8c\u6210\u3002<\/p>\n

\u56e0\u6b64\uff0c\u6545\u969c\u6062\u590d\u673a\u5236\u540e\u7eed\u4ecd\u7136\u4f1a\u91cd\u65b0\u63d0\u4ea4\/\u56de\u6eda\u8fd9\u4e9b\u672a\u5b8c\u6210\u7684\u5168\u5c40\u4e8b\u52a1\uff0c\u8fd9\u6837\u5c31\u4f1a\u518d\u6b21\u8c03\u7528\u53c2\u4e0e\u8be5\u5168\u5c40\u4e8b\u52a1\u7684\u5404TCC\u670d\u52a1\u7684Confirm\/Cancel\u4e1a\u52a1\u903b\u8f91\u3002<\/p>\n

\u65e2\u7136Confirm\/Cancel\u4e1a\u52a1\u53ef\u80fd\u4f1a\u88ab\u591a\u6b21\u8c03\u7528\uff0c\u5c31\u9700\u8981\u4fdd\u969c\u5176\u5e42\u7b49\u6027\u3002<\/p>\n

\u90a3\u4e48\uff0c\u5e94\u8be5\u7531TCC\u4e8b\u52a1\u6846\u67b6\u6765\u63d0\u4f9b\u5e42\u7b49\u6027\u4fdd\u969c?\u8fd8\u662f\u5e94\u8be5\u7531\u4e1a\u52a1\u7cfb\u7edf\u81ea\u884c\u6765\u4fdd\u969c\u5e42\u7b49\u6027\u5462?<\/p>\n

\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u5e94\u8be5\u662f\u7531TCC\u4e8b\u52a1\u6846\u67b6\u6765\u63d0\u4f9b\u5e42\u7b49\u6027\u4fdd\u969c\u3002\u5982\u679c\u4ec5\u4ec5\u53ea\u662f\u6781\u4e2a\u522b\u670d\u52a1\u5b58\u5728\u8fd9\u4e2a\u95ee\u9898\u7684\u8bdd\uff0c\u90a3\u4e48\u7531\u4e1a\u52a1\u7cfb\u7edf\u6765\u8d1f\u8d23\u4e5f\u662f\u53ef\u4ee5\u7684;<\/p>\n

\u7136\u800c\uff0c\u8fd9\u662f\u4e00\u7c7b\u516c\u5171\u95ee\u9898\uff0c\u6beb\u65e0\u7591\u95ee\uff0c\u6240\u6709TCC\u670d\u52a1\u7684Confirm\/Cancel\u4e1a\u52a1\u5b58\u5728\u5e42\u7b49\u6027\u95ee\u9898\u3002TCC\u670d\u52a1\u7684\u516c\u5171\u95ee\u9898\u5e94\u8be5\u7531TCC\u4e8b\u52a1\u6846\u67b6\u6765\u89e3\u51b3;<\/p>\n

\u800c\u4e14\uff0c\u8003\u8651\u4e00\u4e0b\u7531\u4e1a\u52a1\u7cfb\u7edf\u6765\u8d1f\u8d23\u5e42\u7b49\u6027\u9700\u8981\u8003\u8651\u7684\u95ee\u9898\uff0c\u5c31\u4f1a\u53d1\u73b0\uff0c\u8fd9\u65e0\u7591\u589e\u5927\u4e86\u4e1a\u52a1\u7cfb\u7edf\u7684\u590d\u6742\u5ea6\u3002<\/p>\n

\u4e94\u3001TCC\u4e8b\u52a1\u6846\u67b6\u4e0d\u80fd\u76f2\u76ee\u7684\u4f9d\u8d56Cancel\u4e1a\u52a1\u6765\u56de\u6eda\u4e8b\u52a1<\/strong><\/strong><\/div>\n

\u524d\u6587\u4ee5\u53ca\u63d0\u5230\u8fc7\uff0cTCC\u4e8b\u52a1\u901a\u8fc7Cancel\u4e1a\u52a1\u6765\u5bf9Try\u4e1a\u52a1\u8fdb\u884c\u56de\u64a4\u7684\u673a\u5236\u6697\u542b\u4e86\u4e00\u4e2a\u4e8b\u5b9e\uff1aTry\u64cd\u4f5c\u5df2\u7ecf\u751f\u6548\u3002<\/p>\n

\u4e5f\u5c31\u662f\u8bf4\uff0c\u53ea\u6709Try\u64cd\u4f5c\u6240\u53c2\u4e0e\u7684RM\u672c\u5730\u4e8b\u52a1\u5df2\u7ecf\u63d0\u4ea4\u7684\u60c5\u51b5\u4e0b\uff0c\u624d\u9700\u8981\u6267\u884c\u5176Cancel\u64cd\u4f5c\u8fdb\u884c\u56de\u64a4\u3002\u6ca1\u6709\u6267\u884c\u3001\u6216\u8005\u6267\u884c\u4e86\u4f46\u662f\u5176RM\u672c\u5730\u4e8b\u52a1\u88abrollback\u7684Try\u4e1a\u52a1\uff0c\u662f\u4e00\u5b9a\u4e0d\u80fd\u6267\u884c\u5176Cancel\u4e1a\u52a1\u8fdb\u884c\u56de\u64a4\u7684\u3002<\/p>\n

\u56e0\u6b64\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u5728\u5168\u5c40\u4e8b\u52a1\u56de\u6eda\u65f6\uff0c\u5e94\u8be5\u6839\u636eTCC\u670d\u52a1\u7684Try\u4e1a\u52a1\u7684\u6267\u884c\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u5904\u7406\u673a\u5236\u3002\u800c\u4e0d\u80fd\u76f2\u76ee\u7684\u6267\u884cCancel\u4e1a\u52a1\uff0c\u5426\u5219\u5c31\u4f1a\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n

\u4e00\u4e2aTCC\u670d\u52a1\u7684Try\u64cd\u4f5c\u662f\u5426\u751f\u6548\uff0c\u8fd9\u662fTCC\u4e8b\u52a1\u6846\u67b6\u5e94\u8be5\u77e5\u9053\u7684\uff0c\u56e0\u4e3a\u5176Try\u4e1a\u52a1\u6240\u53c2\u4e0e\u7684RM\u4e8b\u52a1\u4e5f\u662f\u7531TCC\u4e8b\u52a1\u6846\u67b6\u6240commit\/rollbac\u7684(\u524d\u63d0\u662fTCC\u4e8b\u52a1\u6846\u67b6\u63a5\u7ba1\u4e86Spring\u7684\u4e8b\u52a1\u7ba1\u7406\u5668)\u3002<\/p>\n

\u6240\u4ee5\uff0cTCC\u4e8b\u52a1\u56de\u6eda\u65f6\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u53ef\u8003\u8651\u5982\u4e0b\u5904\u7406\u7b56\u7565\uff1a<\/p>\n

    \n
  1. \u5982\u679cTCC\u4e8b\u52a1\u6846\u67b6\u53d1\u73b0\u67d0\u4e2a\u670d\u52a1\u7684Try\u64cd\u4f5c\u7684\u672c\u5730\u4e8b\u52a1\u5c1a\u672a\u63d0\u4ea4\uff0c\u5e94\u8be5\u76f4\u63a5\u5c06\u5176\u56de\u6eda\uff0c\u800c\u540e\u5c31\u4e0d\u5fc5\u518d\u6267\u884c\u8be5\u670d\u52a1\u7684cancel\u4e1a\u52a1;<\/li>\n
  2. \u5982\u679cTCC\u4e8b\u52a1\u6846\u67b6\u53d1\u73b0\u67d0\u4e2a\u670d\u52a1\u7684Try\u64cd\u4f5c\u7684\u672c\u5730\u4e8b\u52a1\u5df2\u7ecf\u56de\u6eda\uff0c\u5219\u4e0d\u5fc5\u518d\u6267\u884c\u8be5\u670d\u52a1\u7684cancel\u4e1a\u52a1;<\/li>\n
  3. \u5982\u679cTCC\u4e8b\u52a1\u6846\u67b6\u53d1\u73b0\u67d0\u4e2a\u670d\u52a1\u7684Try\u64cd\u4f5c\u5c1a\u672a\u88ab\u6267\u884c\u8fc7\uff0c\u90a3\u4e48\uff0c\u4e5f\u4e0d\u5fc5\u518d\u6267\u884c\u8be5\u670d\u52a1\u7684cancel\u4e1a\u52a1\u3002<\/li>\n<\/ol>\n

    \u603b\u4e4b\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u5e94\u8be5\u4fdd\u969c\uff1a<\/p>\n

      \n
    1. \u5df2\u751f\u6548\u7684Try\u64cd\u4f5c\u5e94\u8be5\u88ab\u5176Cancel\u64cd\u4f5c\u6240\u56de\u64a4;<\/li>\n
    2. \u5c1a\u672a\u751f\u6548\u7684Try\u64cd\u4f5c\uff0c\u5219\u4e0d\u5e94\u8be5\u6267\u884c\u5176Cancel\u64cd\u4f5c\u3002\u8fd9\u4e00\u70b9\uff0c\u4e0d\u662f\u5e42\u7b49\u6027\u6240\u80fd\u89e3\u51b3\u7684\u95ee\u9898\u3002\u5982\u4e0a\u6587\u6240\u8ff0\uff0c\u5e42\u7b49\u6027\u662f\u6307\u670d\u52a1\u88ab\u6267\u884c\u4e00\u6b21\u548c\u88ab\u6267\u884cn(n>0)\u6b21\u6240\u4ea7\u751f\u7684\u5f71\u54cd\u76f8\u540c\u3002\u4f46\u662f\uff0c\u672a\u88ab\u6267\u884c\u548c\u88ab\u6267\u884c\u8fc7\uff0c\u4e8c\u8005\u6548\u679c\u80af\u5b9a\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u8fd9\u4e0d\u5c5e\u4e8e\u5e42\u7b49\u6027\u7684\u8303\u7574\u3002<\/li>\n<\/ol>\n
      \u516d\u3001Cancel\u4e1a\u52a1\u4e0eTry\u4e1a\u52a1\u5e76\u884c\uff0c\u751a\u81f3\u5148\u4e8eTry\u64cd\u4f5c\u5b8c\u6210<\/strong><\/strong><\/div>\n

      \u8fd9\u5e94\u8be5\u7b97TCC\u4e8b\u52a1\u673a\u5236\u7279\u6709\u7684\u4e00\u4e2a\u4e0d\u53ef\u601d\u8bae\u7684\u9677\u9631\u3002<\/p>\n

      \u4e00\u822c\u6765\u8bf4\uff0c\u4e00\u4e2a\u7279\u5b9a\u7684TCC\u670d\u52a1\uff0c\u5176Try\u64cd\u4f5c\u7684\u6267\u884c\uff0c\u662f\u5e94\u8be5\u5728\u5176Confirm\/Cancel\u64cd\u4f5c\u4e4b\u524d\u7684\u3002<\/p>\n

      Try\u64cd\u4f5c\u6267\u884c\u5b8c\u6bd5\u4e4b\u540e\uff0cSpring\u5bb9\u5668\u518d\u6839\u636eTry\u64cd\u4f5c\u7684\u6267\u884c\u60c5\u51b5\uff0c\u6307\u793aTCC\u4e8b\u52a1\u6846\u67b6\u63d0\u4ea4\/\u56de\u6eda\u5168\u5c40\u4e8b\u52a1\u3002\u7136\u540e\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u518d\u53bb\u9010\u4e2a\u8c03\u7528\u5404TCC\u670d\u52a1\u7684Confirm\/Cancel\u64cd\u4f5c\u3002<\/p>\n

      \u7136\u800c\uff0c\u8d85\u65f6\u3001\u7f51\u7edc\u6545\u969c\u3001\u670d\u52a1\u5668\u7684\u91cd\u542f\u7b49\u6545\u969c\u7684\u5b58\u5728\uff0c\u4f7f\u5f97\u8fd9\u4e2a\u987a\u5e8f\u4f1a\u88ab\u6253\u4e71\u3002\u6bd4\u5982\uff1a<\/p>\n

      \"\"<\/p>\n

      \u4e0a\u56fe\u4e2d\uff0c\u5047\u8bbe[B:Try]\u64cd\u4f5c\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0c\u7f51\u7edc\u95ea\u65ad\uff0c[A:Try]\u4f1a\u6536\u5230\u4e00\u4e2aRPC\u8fdc\u7a0b\u8c03\u7528\u5f02\u5e38\u3002<\/p>\n

      A\u4e0d\u5904\u7406\u8be5\u5f02\u5e38\uff0c\u5bfc\u81f4\u5168\u5c40\u4e8b\u52a1\u51b3\u5b9a\u56de\u6eda\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u5c31\u4f1a\u53bb\u8c03\u7528[B:Cancel]\uff0c\u800c\u6b64\u523bA\u3001B\u4e4b\u95f4\u7f51\u7edc\u521a\u597d\u5df2\u7ecf\u6062\u590d\u3002\u5982\u679c[B:Try]\u64cd\u4f5c\u8017\u65f6\u8f83\u957f(\u7f51\u7edc\u963b\u585e\/\u6570\u636e\u5e93\u64cd\u4f5c\u963b\u585e)\uff0c\u5c31\u4f1a\u51fa\u73b0[B:Try]\u548c[B:Cancel]\u4e8c\u8005\u5e76\u884c\u5904\u7406\u7684\u73b0\u8c61\uff0c\u751a\u81f3[B:Cancel]\u5148\u5b8c\u6210\u7684\u73b0\u8c61\u3002<\/p>\n

      \u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u7531\u4e8e[B:Cancel]\u6267\u884c\u65f6\uff0c[B:Try]\u5c1a\u672a\u751f\u6548(\u5176RM\u672c\u5730\u4e8b\u52a1\u5c1a\u672a\u63d0\u4ea4)\uff0c\u56e0\u6b64\uff0c[B:Cancel]\u662f\u4e0d\u80fd\u6267\u884c\u7684\uff0c\u81f3\u5c11\u662f\u4e0d\u80fd\u751f\u6548(\u6267\u884c\u4e86\u5176RM\u672c\u5730\u4e8b\u52a1\u4e5f\u8981rollback)\u7684\u3002<\/p>\n

      \u7136\u800c\uff0c\u5f53[B:Cancel]\u5904\u7406\u5b8c\u6bd5(\u8df3\u8fc7\u6267\u884c\u3001\u6216\u8005\u6267\u884c\u540erollback\u5176RM\u672c\u5730\u4e8b\u52a1)\u540e\uff0c[B:Try]\u64cd\u4f5c\u5b8c\u6210\u53c8\u751f\u6548\u4e86(\u5176RM\u672c\u5730\u4e8b\u52a1\u6210\u529f\u63d0\u4ea4)\uff0c\u8fd9\u5c31\u4f1a\u4f7f\u5f97[B:Cancel]\u867d\u7136\u63d0\u4f9b\u4e86\uff0c\u4f46\u5374\u6ca1\u6709\u8d77\u5230\u56de\u64a4[B:Try]\u7684\u4f5c\u7528\uff0c\u5bfc\u81f4\u6570\u636e\u7684\u4e0d\u4e00\u81f4\u3002<\/p>\n

      \u6240\u4ee5\uff0cTCC\u6846\u67b6\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\uff1a<\/p>\n

        \n
      1. \u5c06[B:Try]\u7684\u672c\u5730\u4e8b\u52a1\u6807\u6ce8\u4e3arollbackOnly\uff0c\u963b\u6b62\u5176\u540e\u7eed\u751f\u6548;<\/li>\n
      2. \u7981\u6b62\u5176\u518d\u6b21\u5c06\u4e8b\u52a1\u4e0a\u4e0b\u6587\u4f20\u9012\u7ed9\u5176\u4ed6\u8fdc\u7a0b\u5206\u652f\uff0c\u5426\u5219\u8be5\u95ee\u9898\u5c06\u5728\u5176\u4ed6\u5206\u652f\u4e0a\u51fa\u73b0;<\/li>\n
      3. \u76f8\u5e94\u5730\uff0c[B:Cancel]\u4e5f\u4e0d\u5fc5\u6267\u884c\uff0c\u81f3\u5c11\u4e0d\u80fd\u751f\u6548\u3002<\/li>\n<\/ol>\n

        \u5f53\u7136\uff0cTCC\u4e8b\u52a1\u6846\u67b6\u4e5f\u53ef\u4ee5\u7b80\u5355\u7684\u9009\u62e9\u963b\u585e[B:Cancel]\u7684\u5904\u7406\uff0c\u5f85[B:Try]\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u518d\u6839\u636e\u5b83\u7684\u6267\u884c\u60c5\u51b5\u5224\u65ad\u662f\u5426\u9700\u8981\u6267\u884c[B:Cancel]\u3002<\/p>\n

        \u4e0d\u8fc7\uff0c\u8fd9\u79cd\u5904\u7406\u65b9\u5f0f\u56e0\u4e3a\u9700\u8981\u7b49\u5f85\uff0c\u6240\u4ee5\uff0c\u5904\u7406\u6548\u7387\u4e0a\u4f1a\u6709\u6240\u4e0d\u53ca\u3002<\/p>\n

        \u540c\u6837\u7684\u60c5\u51b5\u4e5f\u4f1a\u51fa\u73b0\u5728confirm\u4e1a\u52a1\u4e0a\uff0c\u53ea\u4e0d\u8fc7\uff0c\u53d1\u751f\u5728Confirm\u4e1a\u52a1\u4e0a\u7684\u5904\u7406\u903b\u8f91\u4e0e\u53d1\u751f\u5728Cancel\u4e1a\u52a1\u4e0a\u7684\u5904\u7406\u903b\u8f91\u4f1a\u4e0d\u4e00\u6837\u3002<\/p>\n

        TCC\u6846\u67b6\u5fc5\u987b\u4fdd\u8bc1\uff1a<\/p>\n

          \n
        1. Confirm\u4e1a\u52a1\u5728Try\u4e1a\u52a1\u4e4b\u540e\u6267\u884c\uff0c\u82e5\u53d1\u73b0\u5e76\u884c\uff0c\u5219\u53ea\u80fd\u963b\u585e\u76f8\u5e94\u7684Confirm\u4e1a\u52a1\u64cd\u4f5c;<\/li>\n
        2. \u5728\u8fdb\u5165Confirm\u6267\u884c\u9636\u6bb5\u4e4b\u540e\uff0c\u4e5f\u4e0d\u53ef\u4ee5\u518d\u63d0\u4ea4\u540c\u4e00\u5168\u5c40\u4e8b\u52a1\u5185\u7684\u65b0\u7684Try\u64cd\u4f5c\u7684RM\u672c\u5730\u4e8b\u52a1\u3002<\/li>\n<\/ol>\n
          \u4e03\u3001TCC\u670d\u52a1\u590d\u7528\u6027\u662f\u4e0d\u662f\u76f8\u5bf9\u8f83\u5dee?<\/strong><\/strong><\/div>\n

          TCC\u4e8b\u52a1\u673a\u5236\u7684\u5b9a\u4e49\uff0c\u51b3\u5b9a\u4e86\u4e00\u4e2a\u670d\u52a1\u9700\u8981\u63d0\u4f9b\u4e09\u4e2a\u4e1a\u52a1\u5b9e\u73b0\uff1aTry\u4e1a\u52a1\u3001Confirm\u4e1a\u52a1\u3001Cancel\u4e1a\u52a1\u3002<\/p>\n

          \u53ef\u80fd\u4f1a\u6709\u4eba\u56e0\u6b64\u8ba4\u4e3aTCC\u670d\u52a1\u7684\u590d\u7528\u6027\u8f83\u5dee\u3002\u600e\u4e48\u8bf4\u5462\uff0c\u8981\u662f\u5c06 Try\/Confirm\/Cancel\u4e1a\u52a1\u903b\u8f91\u5355\u72ec\u62ff\u51fa\u6765\u590d\u7528\uff0c\u5176\u590d\u7528\u6027\u5f53\u7136\u662f\u4e0d\u597d\u7684\u3002<\/p>\n

          Try\/Confirm\/Cancel \u903b\u8f91\u4f5c\u4e3aTCC\u578b\u670d\u52a1\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u662f\u4e0d\u80fd\u5355\u72ec\u4f5c\u4e3a\u4e00\u4e2a\u7ec4\u4ef6\u6765\u590d\u7528\u7684\u3002Try\u3001Confirm\u3001Cancel\u4e1a\u52a1\u5171\u540c\u624d\u6784\u6210\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u5982\u679c\u8981\u590d\u7528\uff0c\u5e94\u8be5\u662f\u590d\u7528\u6574\u4e2aTCC\u670d\u52a1\u7ec4\u4ef6\uff0c\u800c\u4e0d\u662f\u5355\u72ec\u7684Try\/Confirm\/Cancel\u4e1a\u52a1\u3002<\/p>\n

          \u516b\u3001TCC\u670d\u52a1\u662f\u5426\u9700\u8981\u5bf9\u5916\u66b4\u9732\u4e09\u4e2a\u670d\u52a1\u63a5\u53e3?<\/strong><\/strong><\/div>\n

          \u4e0d\u9700\u8981\u3002TCC\u670d\u52a1\u4e0e\u666e\u901a\u7684\u670d\u52a1\u4e00\u6837\uff0c\u53ea\u9700\u8981\u66b4\u9732\u4e00\u4e2a\u63a5\u53e3\uff0c\u4e5f\u5c31\u662f\u5b83\u7684Try\u4e1a\u52a1\u3002<\/p>\n

          Confirm\/Cancel\u4e1a\u52a1\u903b\u8f91\uff0c\u53ea\u662f\u56e0\u4e3a\u5168\u5c40\u4e8b\u52a1\u63d0\u4ea4\/\u56de\u6eda\u7684\u9700\u8981\u624d\u63d0\u4f9b\u7684\uff0c\u56e0\u6b64Confirm\/Cancel\u4e1a\u52a1\u53ea\u9700\u8981\u88abTCC\u4e8b\u52a1\u6846\u67b6\u53d1\u73b0\u5373\u53ef\uff0c\u4e0d\u9700\u8981\u88ab\u8c03\u7528\u5b83\u7684\u5176\u4ed6\u4e1a\u52a1\u670d\u52a1\u6240\u611f\u77e5\u3002<\/p>\n

          \u6362\u53e5\u8bdd\u8bf4\uff0c\u4e1a\u52a1\u7cfb\u7edf\u7684\u5176\u4ed6\u670d\u52a1\u5728\u9700\u8981\u8c03\u7528TCC\u670d\u52a1\u65f6\uff0c\u6839\u672c\u4e0d\u9700\u8981\u77e5\u9053\u5b83\u662f\u5426\u4e3aTCC\u578b\u670d\u52a1\u3002<\/p>\n

          \u56e0\u4e3a\uff0cTCC\u670d\u52a1\u80fd\u88ab\u5176\u4ed6\u4e1a\u52a1\u670d\u52a1\u8c03\u7528\u7684\u4e5f\u4ec5\u4ec5\u662f\u5176Try\u4e1a\u52a1\uff0cConfirm\/Cancel\u4e1a\u52a1\u662f\u4e0d\u80fd\u88ab\u5176\u4ed6\u4e1a\u52a1\u670d\u52a1\u76f4\u63a5\u8c03\u7528\u7684\u3002<\/p>\n

          \u4e5d\u3001TCC\u670d\u52a1A\u7684Confirm\/Cancel\u4e1a\u52a1\u4e2d\u80fd\u5426\u8c03\u7528\u5b83\u4f9d\u8d56\u7684TCC\u670d\u52a1B\u7684Confirm\/Cancel\u4e1a\u52a1?<\/strong><\/strong><\/div>\n

          \u6700\u597d\u4e0d\u8981\u8fd9\u6837\u505a\u3002<\/p>\n

          \u9996\u5148\uff0c\u6ca1\u6709\u5fc5\u8981\u3002TCC\u670d\u52a1A\u4f9d\u8d56TCC\u670d\u52a1B\uff0c\u90a3\u4e48[A:Try]\u5df2\u7ecf\u5c06\u4e8b\u52a1\u4e0a\u4e0b\u6587\u4f20\u64ad\u7ed9[B:Try]\u4e86\uff0c\u540e\u7eed\u7531TCC\u4e8b\u52a1\u6846\u67b6\u6765\u8c03\u7528\u5404\u81ea\u7684Confirm\/Cancel\u4e1a\u52a1\u5373\u53ef;<\/p>\n

          \u5176\u6b21\uff0cConfirm\/Cancel\u4e1a\u52a1\u5982\u679c\u88ab\u5141\u8bb8\u8c03\u7528\u5176\u4ed6\u670d\u52a1\uff0c\u90a3\u4e48\u5b83\u5c31\u6709\u53ef\u80fd\u518d\u6b21\u53d1\u8d77\u65b0\u7684TCC\u5168\u5c40\u4e8b\u52a1\u3002\u5982\u6b64\u9012\u5f52\u4e0b\u53bb\uff0c\u5c06\u4f1a\u5bfc\u81f4\u5168\u5c40\u4e8b\u52a1\u5173\u7cfb\u6df7\u4e71\u4e14\u4e0d\u53ef\u63a7\u3002<\/p>\n

          TCC\u5168\u5c40\u4e8b\u52a1\uff0c\u5e94\u8be5\u5c3d\u91cf\u5728Try\u64cd\u4f5c\u9636\u6bb5\u4f20\u64ad\u4e8b\u52a1\u4e0a\u4e0b\u6587\u3002Confirm\/Cancel\u64cd\u4f5c\u9636\u6bb5\u4ec5\u9700\u8981\u5b8c\u6210\u5404\u81eaTry\u4e1a\u52a1\u64cd\u4f5c\u7684\u786e\u8ba4\u64cd\u4f5c\/\u8865\u507f\u64cd\u4f5c\u5373\u53ef\uff0c\u4e0d\u9002\u5408\u518d\u505a\u8fdc\u7a0b\u8c03\u7528\uff0c\u66f4\u4e0d\u80fd\u518d\u5bf9\u5916\u4f20\u64ad\u4e8b\u52a1\u4e0a\u4e0b\u6587\u3002<\/p>\n

          \u7efc\u4e0a\u6240\u8ff0\uff0c\u672c\u6587\u503e\u5411\u4e8e\u8ba4\u4e3a\uff0c\u5b9e\u73b0\u4e00\u4e2a\u901a\u7528\u7684TCC\u5206\u5e03\u5f0f\u4e8b\u52a1\u7ba1\u7406\u6846\u67b6\uff0c\u8fd8\u662f\u76f8\u5bf9\u6bd4\u8f83\u590d\u6742\u7684\u3002\u4e00\u822c\u4e1a\u52a1\u7cfb\u7edf\u5982\u679c\u9700\u8981\u4f7f\u7528TCC\u4e8b\u52a1\u673a\u5236\uff0c\u5e76\u4e0d\u63a8\u8350\u81ea\u884c\u8bbe\u8ba1\u5b9e\u73b0\u3002<\/p>\n

          \u8fd9\u91cc\uff0c\u7ed9\u5927\u5bb6\u63a8\u8350\u4e00\u6b3e\u5f00\u6e90\u7684TCC\u5206\u5e03\u5f0f\u4e8b\u52a1\u7ba1\u7406\u5668ByteTCChttps:\/\/github.com\/liuyangming\/ByteTCC<\/p>\n

          ByteTCC\u57fa\u4e8eTry\/Confirm\/Cancel\u673a\u5236\u5b9e\u73b0\uff0c\u53ef\u4e0eSpring\u5bb9\u5668\u65e0\u7f1d\u96c6\u6210\uff0c\u517c\u5bb9Spring\u7684\u58f0\u660e\u5f0f\u4e8b\u52a1\u7ba1\u7406\u3002\u63d0\u4f9b\u5bf9dubbo\u6846\u67b6\u3001Spring Cloud\u7684\u5f00\u7bb1\u5373\u7528\u7684\u652f\u6301\uff0c\u53ef\u6ee1\u8db3\u591a\u6570\u636e\u6e90\u3001\u8de8\u5e94\u7528\u3001\u8de8\u670d\u52a1\u5668\u7b49\u5404\u79cd\u5206\u5e03\u5f0f\u4e8b\u52a1\u573a\u666f\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

          \u4e00\u4e2aTCC\u4e8b\u52a1\u6846\u67b6\u9700\u8981\u89e3\u51b3\u7684\u5f53\u7136\u662f\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u7ba1\u7406\u3002\u5173\u4e8eTCC\u4e8b\u52a1\u673a\u5236\u7684\u4ecb\u7ecd\uff0c\u53ef\u4ee5\u53c2\u8003TCC\u4e8b\u52a1\u673a\u5236\u7b80\u4ecb\u3002 T […]<\/p>\n","protected":false},"author":1898,"featured_media":168868,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[483],"class_list":["post-168865","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-483"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/168865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=168865"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/168865\/revisions"}],"predecessor-version":[{"id":170357,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/168865\/revisions\/170357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/168868"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=168865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=168865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=168865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}