{"id":1052,"date":"2023-02-23T10:43:40","date_gmt":"2023-02-23T02:43:40","guid":{"rendered":"https:\/\/blog.frost-s.com\/?p=1052"},"modified":"2023-02-23T11:25:37","modified_gmt":"2023-02-23T03:25:37","slug":"flink%e4%ba%8c%e9%98%b6%e6%ae%b5%e6%8f%90%e4%ba%a4","status":"publish","type":"post","link":"https:\/\/blog.frost-s.com\/index.php\/2023\/02\/23\/flink%e4%ba%8c%e9%98%b6%e6%ae%b5%e6%8f%90%e4%ba%a4\/","title":{"rendered":"Flink 2PC \u4e00\u81f4\u6027\u8bed\u4e49"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"outline_1\"><a><\/a><a><\/a>\u4e00\u3001\u5f15\u7533\uff08\u4ec0\u4e48\u662fXA\u4e8b\u52a1\uff09<\/h1>\n\n\n\n<p>XA\uff08eXtended Architecture\uff09\u662f\u6307\u7531X\/Open \u7ec4\u7ec7\u63d0\u51fa\u7684\u5206\u5e03\u5f0f\u4ea4\u6613\u5904\u7406\u7684\u89c4\u8303\u3002XA \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u4e8b\u52a1\u534f\u8bae\uff0c\u7531Tuxedo \u63d0\u51fa\uff0c\u6240\u4ee5\u5206\u5e03\u5f0f\u4e8b\u52a1\u4e5f\u79f0\u4e3aXA \u4e8b\u52a1\u3002XA \u534f\u8bae\u4e3b\u8981\u5b9a\u4e49\u4e86\u4e8b\u52a1\u7ba1\u7406\u5668TM\uff08Transaction Manager\uff0c\u534f\u8c03\u8005\uff09\u548c\u8d44\u6e90\u7ba1\u7406\u5668RM\uff08Resource Manager\uff0c\u53c2\u4e0e\u8005\uff09\u4e4b\u95f4\u7684\u63a5\u53e3\u3002\u5176\u4e2d\uff0c\u8d44\u6e90\u7ba1\u7406\u5668\u5f80\u5f80\u7531\u6570\u636e\u5e93\u5b9e\u73b0\uff0c\u5982Oracle\u3001DB2\u3001MySQL\uff0c\u8fd9\u4e9b\u5546\u4e1a\u6570\u636e\u5e93\u90fd\u5b9e\u73b0\u4e86XA \u63a5\u53e3\uff0c\u800c\u4e8b\u52a1\u7ba1\u7406\u5668\u4f5c\u4e3a\u5168\u5c40\u7684\u8c03\u5ea6\u8005\uff0c\u8d1f\u8d23\u5404\u4e2a\u672c\u5730\u8d44\u6e90\u7684\u63d0\u4ea4\u548c\u56de\u6eda\u3002XA \u4e8b\u52a1\u662f\u57fa\u4e8e\u4e24\u9636\u6bb5\u63d0\u4ea4\uff08Two-phaseCommit\uff0c2PC\uff09\u534f\u8bae\u5b9e\u73b0\u7684\uff0c\u53ef\u4ee5\u4fdd\u8bc1\u6570\u636e\u7684\u5f3a\u4e00\u81f4\u6027\uff0c\u8bb8\u591a\u5206\u5e03\u5f0f\u5173\u7cfb\u578b\u6570\u636e\u7ba1\u7406\u7cfb\u7edf\u90fd\u91c7\u7528\u6b64\u534f\u8bae\u6765\u5b8c\u6210\u5206\u5e03\u5f0f\u3002\u9636\u6bb5\u4e00\u4e3a\u51c6\u5907\u9636\u6bb5\uff0c\u5373\u6240\u6709\u7684\u53c2\u4e0e\u8005\u51c6\u5907\u6267\u884c\u4e8b\u52a1\u5e76\u9501\u4f4f\u9700\u8981\u7684\u8d44\u6e90\u3002\u5f53\u53c2\u4e0e\u8005Ready\u65f6\uff0c\u5411TM \u6c47\u62a5\u81ea\u5df1\u5df2\u7ecf\u51c6\u5907\u597d\u3002\u9636\u6bb5\u4e8c\u4e3a\u63d0\u4ea4\u9636\u6bb5\u3002\u5f53TM \u786e\u8ba4\u6240\u6709\u53c2\u4e0e\u8005\u90fdReady \u540e\uff0c\u5411\u6240\u6709\u53c2\u4e0e\u8005\u53d1\u9001COMMIT \u547d\u4ee4\u3002<\/p>\n\n\n\n<p>XA \u4e8b\u52a1\u5141\u8bb8\u4e0d\u540c\u6570\u636e\u5e93\u7684\u5206\u5e03\u5f0f\u4e8b\u52a1\uff0c\u53ea\u8981\u53c2\u4e0e\u5728\u5168\u5c40\u4e8b\u52a1\u4e2d\u7684\u6bcf\u4e2a\u7ed3\u70b9\u90fd\u652f\u6301XA \u4e8b\u52a1\u3002Oracle\u3001MySQL \u548cSQL Server \u90fd\u652f\u6301XA \u4e8b\u52a1\u3002<\/p>\n\n\n\n<p>XA \u4e8b\u52a1\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u8d44\u6e90\u7ba1\u7406\u5668\uff08RM\uff09\u3001\u4e00\u4e2a\u4e8b\u52a1\u7ba1\u7406\u5668\uff08TM\uff09\u548c\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff08ApplicationProgram\uff09\u7ec4\u6210\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ul>\n<li>\u8d44\u6e90\u7ba1\u7406\u5668\uff1a\u63d0\u4f9b\u8bbf\u95ee\u4e8b\u52a1\u8d44\u6e90\u7684\u65b9\u6cd5\u3002\u901a\u5e38\u4e00\u4e2a\u6570\u636e\u5e93\u5c31\u662f\u4e00\u4e2a\u8d44\u6e90\u7ba1\u7406\u5668\u3002<\/li>\n\n\n\n<li>\u4e8b\u52a1\u7ba1\u7406\u5668\uff1a\u534f\u8c03\u53c2\u4e0e\u5168\u5c40\u4e8b\u52a1\u4e2d\u7684\u5404\u4e2a\u4e8b\u52a1\u3002\u9700\u8981\u548c\u53c2\u4e0e\u5168\u5c40\u4e8b\u52a1\u7684\u6240\u6709\u8d44\u6e90\u7ba1\u7406\u5668\u8fdb\u884c\u901a\u4fe1\u3002<\/li>\n\n\n\n<li>\u5e94\u7528\u7a0b\u5e8f\uff1a\u5b9a\u4e49\u4e8b\u52a1\u7684\u8fb9\u754c\u3002<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<p>XA \u4e8b\u52a1\u7684\u7f3a\u70b9\u662f\u6027\u80fd\u4e0d\u597d\uff0c\u4e14\u65e0\u6cd5\u6ee1\u8db3\u9ad8\u5e76\u53d1\u573a\u666f\u3002\u4e00\u4e2a\u6570\u636e\u5e93\u7684\u4e8b\u52a1\u548c\u591a\u4e2a\u6570\u636e\u5e93\u95f4\u7684XA \u4e8b\u52a1\u6027\u80fd\u4f1a\u76f8\u5dee\u5f88\u591a\u3002\u56e0\u6b64\uff0c\u8981\u5c3d\u91cf\u907f\u514dXA \u4e8b\u52a1\uff0c\u5982\u53ef\u4ee5\u5c06\u6570\u636e\u5199\u5165\u672c\u5730\uff0c\u7528\u9ad8\u6027\u80fd\u7684\u6d88\u606f\u7cfb\u7edf\u5206\u53d1\u6570\u636e\uff0c\u6216\u4f7f\u7528\u6570\u636e\u5e93\u590d\u5236\u7b49\u6280\u672f\u3002\u53ea\u6709\u5728\u5176\u4ed6\u529e\u6cd5\u90fd\u65e0\u6cd5\u5b9e\u73b0\u4e1a\u52a1\u9700\u6c42\uff0c\u4e14\u6027\u80fd\u4e0d\u662f\u74f6\u9888\u65f6\u624d\u4f7f\u7528XA\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"outline_2\"><a><\/a><a><\/a>\u4e8c\u3001Flink\u4e8c\u9636\u6bb5\u63d0\u4ea4<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"outline_3\"><a><\/a><a><\/a>2.1 \u5f15\u5165 EXACTLY_ONCE \u8bed\u4e49<\/h2>\n\n\n\n<p>EXACTLY_ONCE\u8bed\u4e49\u7b80\u79f0EOS\uff0c\u6307\u7684\u662f\u6bcf\u6761\u8f93\u5165\u6d88\u606f\u53ea\u4f1a\u5f71\u54cd\u6700\u7ec8\u7ed3\u679c\u4e00\u6b21\uff0c\u6ce8\u610f\u8fd9\u91cc\u662f\u5f71\u54cd\u4e00\u6b21\uff0c\u800c\u975e\u5904\u7406\u4e00\u6b21\uff0cFlink\u4e00\u76f4\u5ba3\u79f0\u81ea\u5df1\u652f\u6301EOS\uff0c\u5b9e\u9645\u4e0a\u4e3b\u8981\u662f\u5bf9\u4e8eFlink\u5e94\u7528\u5185\u90e8\u6765\u8bf4\u7684\uff0c\u5bf9\u4e8e\u5916\u90e8\u7cfb\u7edf(\u7aef\u5230\u7aef)\u5219\u6709\u6bd4\u8f83\u5f3a\u7684\u9650\u5236<\/p>\n\n\n\n<p>\u5916\u90e8\u7cfb\u7edf\u5199\u5165\u652f\u6301<a href=\"https:\/\/so.csdn.net\/so\/search?q=%E5%B9%82%E7%AD%89%E6%80%A7&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">\u5e42\u7b49\u6027<\/a><\/p>\n\n\n\n<p>\u5916\u90e8\u7cfb\u7edf\u652f\u6301\u4ee5\u4e8b\u52a1\u7684\u65b9\u5f0f\u5199\u5165<\/p>\n\n\n\n<p>Flink\u57281.4.0\u7248\u672c\u5f15\u5165\u4e86TwoPhaseCommitSinkFunction\u63a5\u53e3\uff0c\u5e76\u5728<a href=\"https:\/\/so.csdn.net\/so\/search?q=Kafka&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">Kafka<\/a>&nbsp;Producer\u7684connector\u4e2d\u5b9e\u73b0\u4e86\u5b83\uff0c\u652f\u6301\u4e86\u5bf9\u5916\u90e8Kafka Sink\u7684EXACTLY_ONCE\u8bed\u4e49\u3002<\/p>\n\n\n\n<p>\u8be6\u89c1\uff1a<a href=\"https:\/\/flink.apache.org\/features\/2018\/03\/01\/end-to-end-exactly-once-apache-flink.html\">End-to-End Exactly-Once Processing in Apache Flink<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"outline_4\"><a><\/a><a><\/a>2.2 Kafka\u5e42\u7b49\u6027\u548c\u4e8b\u52a1\u6027<\/h2>\n\n\n\n<p>\u5728kafka 0.11\u7248\u672c\u4e2d\u5df2\u7ecf\u63d0\u51fa\uff0ckafka \u5c06\u5bf9\u4e8b\u52a1\u548c\u5e42\u7b49\u6027\u7684\u652f\u6301\uff0c\u4f7f\u5f97kafka \u7aef\u5230\u7aefexactly once\u8bed\u4e49\u6210\u4e3a\u53ef\u80fd\u3002\u5e42\u7b49\u6027\u4e0e\u4e8b\u52a1\u6027\u90fd\u662fKafka\u53d1\u5c55\u8fc7\u7a0b\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n\n\n\n<p>\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0cproduce\u5411Broker\u6295\u9012\u6d88\u606f\uff0cbroker\u5c06\u6d88\u606f\u8ffd\u52a0\u5199\u5230\u5bf9\u5e94\u7684\u6d41\uff08\u5373\u67d0\u4e00\u4e2atopic\u7684\u67d0\u4e00partition\uff09\u4e2d\uff0c\u5e76\u5411Producer\u8fd4\u56deACK\u4fe1\u53f7\uff0c\u8868\u793a\u786e\u8ba4\u6536\u5230\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>1\u3001\u5e42\u7b49\u6027\u7684\u5b9e\u73b0<\/p>\n\n\n\n<p>kafka \u4e3a\u4e86\u5b9e\u60f3\u5e42\u7b49\u6027\uff0c\u4ed6\u5728\u5e95\u5c42\u7684\u8bbe\u8ba1\u67b6\u6784\u4e2d\u5f15\u5165\u4e86Producer\u548cSequenceNumber\u3002<\/p>\n\n\n\n<p>\uff081\uff09\u3001ProducerID\uff1a\u5728\u6bcf\u4e00\u4e2a\u65b0\u7684Producer\u521d\u59cb\u5316\u65f6\uff0c\u6216\u88ab\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684ProducerID\uff0c\u8fd9\u4e2aProducerID\u5bf9\u5ba2\u6237\u7aef\u4f7f\u7528\u8005\u662f\u4e0d\u53ef\u89c1\u7684\u3002<\/p>\n\n\n\n<p>\uff082\uff09\u3001sequenceNumber:\u5bf9\u4e8e\u6bcf\u4e2aproducerID,Producer\u53d1\u9001\u6570\u636e\u7684\u6bcf\u4e2aTopic\u548cPartition\u90fd\u5bf9\u996e\u4e00\u4e2a\u4ece0\u5f00\u59cb\u9012\u589e\u7684SequenceNumber\u503c\u3002<\/p>\n\n\n\n<p>2\u3001\u5f53\u5f15\u5165\u5e42\u7b49\u6027\u540e\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u540c\u6837\u7684\u6570\u636e\u53d1\u9001\u5230kafka\u4e2d\u4f1a\u5bf9\u6570\u636e\u589e\u52a0Pid \u548csequenceId<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>2\u3001\u4e8b\u52a1<\/p>\n<\/blockquote>\n\n\n\n<p>\u5728\u6570\u636e\u7aef\u5bf9\u7aef\u6570\u636e\u4fdd\u8bc1\u4e2d\uff0c\u53e6\u4e2a\u4e00\u4e2a\u6211\u4eec\u7279\u522b\u5173\u6ce8\u7684\u95ee\u9898\u5c31\u662f\u4e8b\u52a1\u3002\u5373\u539f\u5b50\u6027\u64cd\u4f5c\u3002\u5bf9\u5e94\u7684\u7ed3\u679c\u662f\u540c\u65f6\u6210\u529f\u6216\u8005\u540c\u65f6\u5931\u8d25\uff0ckafka\u7684\u4e8b\u52a1\u6ce8\u91cd\u7684\u751f\u4ea7\u548c\u6d88\u8d39\u7684\u7684\u539f\u5b50\u6027\u64cd\u4f5c\u3002\u5178\u578b\u7684\u4f8b\u5b50\u4e3a\u3002<br>\u4e00\u7cfb\u5217\u7684Producer\u751f\u4ea7\u6d88\u606f\u548c\u6d88\u8d39\u6d88\u606f\u63d0\u4ea4Offsets\u7684\u64cd\u4f5c\u5728\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\u4ea7\u751f\u7684\u573a\u666f\u5305\u62ec\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>(1)\u3001producer\u591a\u6b21\u53d1\u9001\u6d88\u606f\u5c01\u88c5\u5728\u4e00\u4e2a\u539f\u5b50\u6027\u64cd\u4f5c\uff0c\u5373\u8981\u6c42\u540c\u65f6\u6210\u529f\uff0c\u6216\u8005\u540c\u65f6\u5931\u8d25\u3002<\/p>\n\n\n\n<p>(2)\u3001\u5728\u6d88\u8d39\u8005&amp;\u751f\u4ea7\u8005\u7684\u6a21\u5f0f\u4e0b\uff0c\u56e0\u4e3aconsumer\u5728 commit offsets\u51fa\u73b0\u95ee\u9898\u65f6\uff0c\u5bfc\u81f4\u91cd\u590d\u6d88\u8d39\u6d88\u606f\u65f6\uff0c\u9700\u8981\u5c06\u8fd9\u4e2a\u6a21\u5f0f\u4e0b\u7684Consumer\u548cCommit offsets\u64cd\u4f5c\u548cProducer\u4e00\u7cfb\u5217\u751f\u4ea7\u6d88\u606f\u7684\u64cd\u4f5c\u5c01\u88c5\u6210\u4e00\u4e2a\u539f\u5b50\u6027\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>(3\uff09\u3001kafka\u7684\u4e8b\u52a1\u603b\u4f53\u53ef\u4ee5\u5206\u4e3a\u4e09\u65b9\u9762\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n<ul>\n<li>1\uff09\u3001\u53ea\u6709Producer\u751f\u4ea7\u6d88\u606f\uff0c\u8fd9\u79cd\u573a\u666f\u9700\u8981\u4e8b\u52a1\u7684\u4ecb\u5165\uff1b<\/li>\n\n\n\n<li>2\uff09\u3001\u6d88\u8d39\u6d88\u606f\u548c\u751f\u4ea7\u6d88\u606f\u5e76\u5b58\uff0c\u6bd4\u5982Consumer&amp;Producer\u6a21\u5f0f\uff0c\u8fd9\u79cd\u573a\u666f\u662f\u4e00\u822cKafka\u9879\u76ee\u4e2d\u6bd4\u8f83\u5e38\u89c1\u7684\u6a21\u5f0f\uff0c\u9700\u8981\u4e8b\u52a1\u4ecb\u5165\uff1b<\/li>\n\n\n\n<li>3\uff09\u3001\u4f46\u662f\u53ea\u6709Consumer\u6d88\u8d39\u6d88\u606f\uff0c\u8fd9\u79cd\u64cd\u4f5c\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u610f\u4e49\u4e0d\u5927\uff0c\u548c\u624b\u52a8Commit Offsets\u7684\u7ed3\u679c\u4e00\u6837\uff0c\u800c\u4e14\u8fd9\u79cd\u573a\u666f\u4e0d\u662f\u4e8b\u52a1\u7684\u5f15\u5165\u76ee\u7684\u3002<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<p>\u4e8b\u52a1\u63d0\u4f9b\u76845\u79cdAPI\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>org.apache.kafka.clients.producer.Producer&lt;K,V>\u63a5\u53e3\u4e2d:\n\n\n\n\/\/ 1. \u521d\u59cb\u5316\u4e8b\u52a1\uff0c\u9700\u8981\u6ce8\u610f\u786e\u4fddtransation.id\u5c5e\u6027\u88ab\u5206\u914d\n<strong>void<\/strong> <strong>initTransactions<\/strong>();\n\n\/\/ 2. \u5f00\u542f\u4e8b\u52a1\n<strong>void<\/strong> <strong>beginTransaction<\/strong>() throws ProducerFencedException;\n\n\/\/ 3. \u4e3aConsumer\u63d0\u4f9b\u7684\u5728\u4e8b\u52a1\u5185Commit Offsets\u7684\u64cd\u4f5c\n<strong>void<\/strong> <strong>sendOffsetsToTransaction<\/strong>(Map&lt;TopicPartition, OffsetAndMetadata> offsets,\n                              String consumerGroupId) throws ProducerFencedException;\n\n\/\/ 4. \u63d0\u4ea4\u4e8b\u52a1\n<strong>void<\/strong> <strong>commitTransaction<\/strong>() throws ProducerFencedException;\n\n\/\/ 5. \u653e\u5f03\u4e8b\u52a1\uff0c\u7c7b\u4f3c\u4e8e\u56de\u6eda\u4e8b\u52a1\u7684\u64cd\u4f5c\n<strong>void<\/strong> <strong>abortTransaction<\/strong>() throws ProducerFencedException;\n<\/code><\/pre>\n\n\n\n<p>\u8be6\u89c1\uff1a<a href=\"https:\/\/blog.csdn.net\/weixin_40809627\/article\/details\/106918385\">kafka\u7684\u5e42\u7b49\u6027\u548c\u4e8b\u52a1\u6027<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"outline_5\"><a><\/a><a><\/a>2.3 Flink\u4e8c\u9636\u6bb5\u63d0\u4ea4<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u573a\u666f\u63cf\u8ff0<\/p>\n<\/blockquote>\n\n\n\n<p>\u4e24\u9636\u6bb5\u63d0\u4ea4\uff08two-phase commit, 2PC\uff09\u662f\u6700\u57fa\u7840\u7684\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u534f\u8bae\uff0c\u5e94\u7528\u5e7f\u6cdb\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>2PC\u4ecb\u7ecd\uff1a<\/p>\n<\/blockquote>\n\n\n\n<p>2PC \u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\uff0c\u4e3a\u4e86\u8ba9\u6bcf\u4e2a\u8282\u70b9\u80fd\u591f\u611f\u77e5\u5176\u4ed6\u6240\u6709\u8282\u70b9\u7684\u4e8b\u52a1\u6267\u884c\u60c5\u51b5\uff0c\u9700\u8981\u6211\u4eec\u5f15\u5165\u4e00\u4e2a\u4e2d\u5fc3\u8282\u70b9\u6765\u7edf\u4e00\u6240\u6709\u8282\u70b9\u7684\u6267\u884c\u903b\u8f91\u548c\u8fdb\u5ea6\uff0c\u8fd9\u4e2a\u4e2d\u5fc3\u8282\u70b9\u53eb\u505a<code>\u534f\u8c03\u8005\uff08Coordinator\uff09<\/code>\uff0c\u800c\u5176\u4e2d\u5411\u4e2d\u5fc3\u8282\u70b9\u6c47\u62a5\u6216\u8005\u88ab\u4e2d\u5fc3\u8282\u70b9\u8c03\u5ea6\u7684\u5176\u4ed6\u8282\u70b9\u53eb\u505a<code>\u53c2\u4e0e\u8005\uff08Participant\uff09<\/code>\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>2PC\u539f\u7406<\/p>\n<\/blockquote>\n\n\n\n<p><strong>\u2460\u3001\u8bf7\u6c42\u9636\u6bb5<\/strong><\/p>\n\n\n\n<ul>\n<li>1\u3001\u534f\u8c03\u8005\u5411\u6240\u6709\u53c2\u4e0e\u8005\u53d1\u9001\u51c6\u5907\u8bf7\u6c42\u4e0e\u4e8b\u52a1\u5185\u5bb9\uff0c\u8be2\u95ee\u662f\u5426\u53ef\u4ee5\u51c6\u5907\u4e8b\u52a1\u63d0\u4ea4\uff0c\u5e76\u7b49\u5f85\u53c2\u4e0e\u8005\u7684\u54cd\u5e94\u3002<\/li>\n\n\n\n<li>2\u3001\u53c2\u4e0e\u8005\u6267\u884c\u4e8b\u52a1\u4e2d\u7684\u5305\u542b\u64cd\u4f5c\uff0c\u5e76\u8bb0\u5f55undo\u65e5\u5fd7\uff08\u7528\u4e8e\u56de\u6eda\uff09\u548credo\u65e5\u5fd7\uff08\u7528\u4e8e\u91cd\u653e\uff09\uff0c\u4f46\u662f\u4e0d\u771f\u6b63\u63d0\u4ea4\u3002<\/li>\n\n\n\n<li>3\u3001\u53c2\u4e0e\u8005\u5411\u534f\u8c03\u8005\u8fd4\u56de\u4e8b\u52a1\u624d\u505a\u7684\u6267\u884c\u7ed3\u679c\uff0c\u6267\u884c\u9648\u5de5\u8fd4\u56deyes,\u5426\u5219\u8fd4\u56deno.<\/li>\n<\/ul>\n\n\n\n<p><strong>\u2461\u3001\u63d0\u4ea4\u9636\u6bb5<\/strong>\uff08\u5206\u6210<strong>\u6210\u529f<\/strong>\u548c<strong>\u5931\u8d25<\/strong>\u4e24\u79cd\u60c5\u51b5\uff09<\/p>\n\n\n\n<p><em>\u60c5\u51b51\uff1a \u82e5\u6240\u6709\u7684\u53c2\u4e0e\u8005\u90fd\u8fd4\u56deyes,\u8bf4\u660e\u4e8b\u52a1\u53ef\u4ee5\u63d0\u4ea4\u3002<\/em><\/p>\n\n\n\n<ul>\n<li>1\u3001\u534f\u8c03\u8005\u5411\u6240\u6709\u53c2\u4e0e\u8005\u53d1\u9001commit\u8bf7\u6c42\u3002<\/li>\n\n\n\n<li>2\u3001\u53c2\u4e0e\u8005\u6536\u5230commit \u8bf7\u6c42\u540e\uff0c\u5c06\u4e8b\u52a1\u771f\u6b63\u7684\u63d0\u4ea4\u4e0a\u53bb\uff0c\u5e76\u91ca\u653e\u5360\u7528\u7684\u4e8b\u52a1\u8d44\u6e90\uff0c\u5e76\u5411\u534f\u8c03\u8005\u8fd4\u56deack\u3002<\/li>\n\n\n\n<li>3\u3001\u534f\u8c03\u8005\u6536\u5230\u6240\u6709\u53c2\u4e0e\u8005ack\u6d88\u606f\uff0c\u4e8b\u52a1\u6210\u529f\u5b8c\u6210\u3002<\/li>\n<\/ul>\n\n\n\n<p><em>\u60c5\u51b52\uff1a\u82e5\u6709\u53c2\u4e0e\u8005\u8fd4\u56deno\u6216\u8005\u8d85\u65f6\u672a\u8fd4\u56de\uff0c\u8bf4\u660e\u4e8b\u52a1\u7ec8\u7aef\uff0c\u9700\u8981\u56de\u6eda\u3002<\/em><\/p>\n\n\n\n<ul>\n<li>1\u3001\u534f\u8c03\u8005\u5411\u6240\u6709\u53c2\u4e0e\u8005\u53d1\u9001rollback\u8bf7\u6c42\u3002<\/li>\n\n\n\n<li>2\u3001\u53c2\u4e0e\u8005\u6536\u5230rollback\u8bf7\u6c42\u540e\uff0c\u6839\u636eundo\u65e5\u5fd7\u56de\u6eda\u5230\u4e8b\u52a1\u6267\u884c\u524d\u7684\u72b6\u6001\uff0c\u91ca\u653e\u5360\u7528\u7684\u4e8b\u52a1\u8d44\u6e90\uff0c\u5e76\u5411\u534f\u8c03\u8005\u8fd4\u56deack\u3002<\/li>\n\n\n\n<li>3\u3001\u534f\u8c03\u8005\u6536\u5230\u6240\u6709\u53c2\u4e0e\u8005\u7684ack\u6d88\u606f\uff0c\u4e8b\u52a1\u56de\u6eda\u5b8c\u6210\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img-blog.csdnimg.cn\/c3894fcb334246e3891cb9c6afead331.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img-blog.csdnimg.cn\/c3894fcb334246e3891cb9c6afead331.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/div><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>2pc \u7684\u4f18\u7f3a\u70b9<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>2PC\u7684\u4f18\u70b9\u5728\u4e8e\u539f\u7406\u975e\u5e38\u7b80\u5355\uff0c\u5bb9\u6613\u7406\u89e3\u53ca\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u7f3a\u70b9\u4e3b\u8981\u67093\u4e2a\uff0c\u5217\u4e3e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\uff081\uff09\u534f\u8c03\u8005\u5b58\u5728\u5355\u70b9\u95ee\u9898\u3002\u5982\u679c\u534f\u8c03\u8005\u6302\u4e86\uff0c\u6574\u4e2a2PC\u903b\u8f91\u5c31\u5f7b\u5e95\u4e0d\u80fd\u8fd0\u884c\u3002<\/p>\n\n\n\n<p>\uff082\uff09\u3001\u6267\u884c\u8fc7\u7a0b\u662f\u5b8c\u5168\u540c\u6b65\u7684\u3002\u5404\u53c2\u4e0e\u8005\u5728\u7b49\u5f85\u5176\u4ed6\u53c2\u4e0e\u8005\u54cd\u5e94\u7684\u8fc7\u7a0b\u4e2d\u90fd\u5904\u4e8e\u963b\u585e\u72b6\u6001\uff0c\u5927\u5e76\u53d1\u4e0b\u6709\u6027\u80fd\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\uff083\uff09\u3001\u4ecd\u7136\u5b58\u5728\u4e0d\u4e00\u81f4\u98ce\u9669\u3002\u5982\u679c\u7531\u4e8e\u7f51\u7edc\u5f02\u5e38\u7b49\u610f\u5916\u5bfc\u81f4\u53ea\u6709\u90e8\u5206\u53c2\u4e0e\u8005\u6536\u5230\u4e86commit\u8bf7\u6c42\uff0c\u5c31\u4f1a\u9020\u6210\u90e8\u5206\u53c2\u4e0e\u8005\u63d0\u4ea4\u4e86\u4e8b\u52a1\u800c\u5176\u4ed6\u53c2\u4e0e\u8005\u672a\u63d0\u4ea4\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u4e0d\u8fc7\uff0c\u73b0\u5728\u4eba\u4eec\u5728\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u9886\u57df\u505a\u4e86\u5f88\u591a\u5de5\u4f5c\uff0c\u4ee5ZooKeeper\u4e3a\u4ee3\u8868\u7684\u5206\u5e03\u5f0f\u534f\u8c03\u6846\u67b6\u4e5f\u6570\u4e0d\u80dc\u6570\uff0c2PC\u6709\u4e86\u8fd9\u4e9b\u7684\u52a0\u6301\uff0c\u53ef\u9760\u6027\u5927\u5927\u63d0\u5347\u4e86\uff0c\u4e5f\u5c31\u80fd\u591f\u771f\u6b63\u7528\u5728\u8981\u6c42\u9ad8\u7684\u751f\u4ea7\u73af\u5883\u4e2d\u4e86\u3002<\/p>\n<\/blockquote>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Flink\u57fa\u4e8e2PC\u7684\u5b9e\u73b0<\/p>\n<\/blockquote>\n\n\n\n<p>2PC \u7684\u6700\u5e38\u89c1\u5e94\u7528\u573a\u666f\u5176\u5b9e\u662f\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u6bd4\u5982mysql InnoDB \u5b58\u50a8\u5f15\u64ce\u7684XA\u4e8b\u52a1\u7cfb\u7edf\u3002<br>Flink\u4f5c\u4e3a\u6d41\u5f0f\u5904\u7406\u5f15\u64ce\uff0c\u81ea\u7136\u4e5f\u63d0\u4f9b\u4e86\u5bf9exactly once\u8bed\u4e49\u7684\u4fdd\u8bc1\u3002flink\u7684\u5185\u90e8\u610f\u56fe\u68c0\u67e5\u70b9\u673a\u5236\u548c\u8f7b\u91cf\u7ea7\u5206\u5e03\u5f0f\u5feb\u7167\u7b97\u6cd5ABS \u4fdd\u8bc1exactly once .\u3002\u4e8c\u6211\u4eec\u8981\u5b9e\u73b0\u7aef\u5230\u7aef\u7684\u7cbe\u786e\u4e00\u6b21\u7684\u8f93\u51fa\u903b\u8f91\uff0c\u5219\u9700\u8981\u65bd\u52a0\u4ee5\u4e0b\u4e24\u79cd\u9650\u5236\u4e4b\u4e00\uff1a\u5e42\u7b49\u6027\u5199\u5165\uff08idempotent write\uff09\u3001\u4e8b\u52a1\u6027\u5199\u5165\uff08transactional write\uff09\u3002<\/p>\n\n\n\n<p>\u5728Spark Streaming\u4e2d\uff0c\u8981\u5b9e\u73b0\u4e8b\u52a1\u6027\u5199\u5165\u5b8c\u5168\u9760\u7528\u6237\u81ea\u5df1\uff0c\u6846\u67b6\u672c\u8eab\u5e76\u6ca1\u6709\u63d0\u4f9b\u4efb\u4f55\u5b9e\u73b0\u3002\u4f46\u662f\u5728Flink\u4e2d\u63d0\u4f9b\u4e86\u57fa\u4e8e2PC\u7684SinkFunction\uff0c\u540d\u4e3aTwoPhaseCommitSinkFunction\uff0c\u5e2e\u52a9\u6211\u4eec\u505a\u4e86\u4e00\u4e9b\u57fa\u7840\u7684\u5de5\u4f5c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img-blog.csdnimg.cn\/56992a7bd54b4612baf725784009fc15.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img-blog.csdnimg.cn\/56992a7bd54b4612baf725784009fc15.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/div><\/figure>\n\n\n\n<p>flink \u5b98\u65b9\u63a8\u8350\u6240\u6709\u9700\u8981\u4fdd\u8bc1exactly once \u7684sink \u903b\u8f91\u90fd\u7ee7\u627f\u8be5\u62bd\u8c61\u7c7b\u3002\u5b83\u5177\u4f53\u5b9a\u4e49\u5982\u4e0b\u56db\u4e2a\u62bd\u8c61\u65b9\u6cd5\u3002\u9700\u8981\u6211\u4eec\u53bb\u5728\u5b50\u7c7b\u4e2d\u5b9e\u73b0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5f00\u59cb\u4e00\u4e2a\u4e8b\u52a1\uff0c\u8fd4\u56de\u4e8b\u52a1\u4fe1\u606f\u7684\u53e5\u67c4\n    <strong>protected<\/strong> <strong>abstract<\/strong> TXN <strong>beginTransaction<\/strong>() <strong>throws<\/strong> Exception;\n\n\/\/ \u9884\u63d0\u4ea4\uff08\u5373\u63d0\u4ea4\u8bf7\u6c42\uff09\u9636\u6bb5\u7684\u903b\u8f91\n    <strong>protected<\/strong> <strong>abstract<\/strong> <strong>void<\/strong> <strong>preCommit<\/strong>(TXN transaction) <strong>throws<\/strong> Exception;\n \n\/\/ \u6b63\u5f0f\u63d0\u4ea4\u9636\u6bb5\u7684\u903b\u8f91\n   <strong>protected<\/strong> <strong>abstract<\/strong> <strong>void<\/strong> <strong>commit<\/strong>(TXN transaction);\n\n\/\/ \u53d6\u6d88\u4e8b\u52a1\n   <strong>protected<\/strong> <strong>abstract<\/strong> <strong>void<\/strong> <strong>abort<\/strong>(TXN transaction);\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>class<\/strong> <strong>FlinkKafkaProducer<\/strong>&lt;<strong>IN<\/strong>>\n        <strong>extends<\/strong> <strong>TwoPhaseCommitSinkFunction<\/strong>&lt;\n                <strong>IN<\/strong>,\n                <strong>FlinkKafkaProducer<\/strong>.<strong>KafkaTransactionState<\/strong>,\n                <strong>FlinkKafkaProducer<\/strong>.<strong>KafkaTransactionContext<\/strong>> {\n\n    \/**\n     * Semantics that can be chosen.\n     * &lt;li>{<strong>@link<\/strong> #EXACTLY_ONCE}\n     * &lt;li>{<strong>@link<\/strong> #AT_LEAST_ONCE}\n     * &lt;li>{<strong>@link<\/strong> #NONE}\n     *\/\n    <strong>public<\/strong> <strong>enum<\/strong> <strong>Semantic<\/strong> {\n\n        \/**\n         * Semantic.EXACTLY_ONCE the Flink producer will write all messages in a Kafka transaction\n         * that will be committed to Kafka on a checkpoint.\n         *\n         * &lt;p>In this mode {<strong>@link<\/strong> FlinkKafkaProducer} sets up a pool of {<strong>@link<\/strong>\n         * FlinkKafkaInternalProducer}. Between each checkpoint a Kafka transaction is created,\n         * which is committed on {<strong>@link<\/strong> \n\nFlinkKafkaProducer#notifyCheckpointComplete(long)}\n\n\n. If\n         * checkpoint complete notifications are running late, {<strong>@link<\/strong> FlinkKafkaProducer} can run\n         * out of {<strong>@link<\/strong> FlinkKafkaInternalProducer}s in the pool. In that case any subsequent\n         * {<strong>@link<\/strong> FlinkKafkaProducer#snapshotState(FunctionSnapshotContext)} requests will fail and\n         * {<strong>@link<\/strong> FlinkKafkaProducer} will keep using the {<strong>@link<\/strong> FlinkKafkaInternalProducer} from\n         * the previous checkpoint. To decrease the chance of failing checkpoints there are four\n         * options:\n         * &lt;li>decrease number of max concurrent checkpoints\n         * &lt;li>make checkpoints more reliable (so that they complete faster)\n         * &lt;li>increase the delay between checkpoints\n         * &lt;li>increase the size of {<strong>@link<\/strong> FlinkKafkaInternalProducer}s pool\n         *\/\n        EXACTLY_ONCE,\n\n        \/**\n         * Semantic.AT_LEAST_ONCE the Flink producer will wait for all outstanding messages in the\n         * Kafka buffers to be acknowledged by the Kafka producer on a checkpoint.\n         *\/\n        AT_LEAST_ONCE,\n\n        \/**\n         * Semantic.NONE means that nothing will be guaranteed. Messages can be lost and\/or\n         * duplicated in case of failure.\n         *\/\n        NONE\n    }\n<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u4ee5Flink\u4e0eKafka\u7684\u96c6\u6210\u6765\u8bf4\u660e2PC\u7684\u5177\u4f53\u6d41\u7a0b\u3002\u6ce8\u610f\u8fd9\u91cc\u7684Kafka\u7248\u672c\u5fc5\u987b\u662f0.11\u53ca\u4ee5\u4e0a\uff0c\u56e0\u4e3a\u53ea\u67090.11+\u7684\u7248\u672c\u624d\u652f\u6301\u5e42\u7b49producer\u4ee5\u53ca\u4e8b\u52a1\u6027\uff0c\u4ece\u800c2PC\u624d\u6709\u5b58\u5728\u7684\u610f\u4e49\u3002Kafka\u5185\u90e8\u4e8b\u52a1\u6027\u7684\u673a\u5236\u5982\u4e0b\u6846\u56fe\u6240\u793a\u3002<\/p>\n\n\n\n<p>flink \u5b9e\u73b0\u4e24\u9636\u6bb5\u63d0\u4ea4\u5177\u4f53\u5b9e\u73b0\u4e3a\uff1a<br>FlinkKafkaProducer.commit()\u65b9\u6cd5\u5b9e\u9645\u4e0a\u662f\u4ee3\u7406\u4e86KafkaProducer.commitTransaction()\u65b9\u6cd5\uff0c\u6b63\u5f0f\u5411Kafka\u63d0\u4ea4\u4e8b\u52a1\u3002<\/p>\n\n\n\n<p>Flink\u7248\u672c\uff1a1.13.6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t@Override\n    <strong>protected<\/strong> void <strong>commit<\/strong>(FlinkKafkaProducer.KafkaTransactionState transaction) {\n        <strong>if<\/strong> (transaction.<strong>isTransactional<\/strong>()) {\n            <strong>try<\/strong> {\n                transaction.producer.<strong>commitTransaction<\/strong>();\n            } <strong>finally<\/strong> {\n                <strong>recycleTransactionalProducer<\/strong>(transaction.producer);\n            }\n        }\n    }\n<\/code><\/pre>\n\n\n\n<p>\u8be5\u65b9\u6cd5\u7684\u8c03\u7528\u70b9\u4f4d\u4e8e TwoPhaseCommitSinkFunction.notifyCheckpointComplete()\u65b9\u6cd5\u4e2d\uff0c\u987e\u540d\u601d\u4e49\uff0c\u5f53\u6240\u6709\u7684\u68c0\u67e5\u70b9\u90fd\u6210\u529f\u540e\uff0c\u4f1a\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t@Override\n    <strong>public<\/strong> <strong>final<\/strong> <strong>void<\/strong> notifyCheckpointComplete(<strong>long<\/strong> checkpointId) <strong>throws<\/strong> Exception {\n        \/\/ the following scenarios are possible here\n        \/\/\n        \/\/  (1) there is exactly one transaction from the latest checkpoint that\n        \/\/      was triggered and completed. That should be the common case.\n        \/\/      Simply commit that transaction in that case.\n        \/\/\n        \/\/  (2) there are multiple pending transactions because one previous\n        \/\/      checkpoint was skipped. That is a rare case, but can happen\n        \/\/      for example when:\n        \/\/\n        \/\/        - the master cannot persist the metadata of the last\n        \/\/          checkpoint (temporary outage in the storage system) but\n        \/\/          could persist a successive checkpoint (the one notified here)\n        \/\/\n        \/\/        - other tasks could not persist their status during\n        \/\/          the previous checkpoint, but did not trigger a failure because they\n        \/\/          could hold onto their state and could successfully persist it in\n        \/\/          a successive checkpoint (the one notified here)\n        \/\/\n        \/\/      In both cases, the prior checkpoint never reach a committed state, but\n        \/\/      this checkpoint is always expected to subsume the prior one and cover all\n        \/\/      changes since the last successful one. As a consequence, we need to commit\n        \/\/      all pending transactions.\n        \/\/\n        \/\/  (3) Multiple transactions are pending, but the checkpoint complete notification\n        \/\/      relates not to the latest. That is possible, because notification messages\n        \/\/      can be delayed (in an extreme case till arrive after a succeeding checkpoint\n        \/\/      was triggered) and because there can be concurrent overlapping checkpoints\n        \/\/      (a new one is started before the previous fully finished).\n        \/\/\n        \/\/ ==&gt; There should never be a case where we have no pending transaction here\n        \/\/\n\n        Iterator&lt;Map.Entry&lt;<strong>Long<\/strong>, TransactionHolder&lt;TXN&gt;&gt;&gt; pendingTransactionIterator =\n                pendingCommitTransactions.entrySet().iterator();\n        Throwable firstError = <strong>null<\/strong>;\n\n        <strong>while<\/strong> (pendingTransactionIterator.hasNext()) {\n            Map.Entry&lt;<strong>Long<\/strong>, TransactionHolder&lt;TXN&gt;&gt; entry = pendingTransactionIterator.<strong>next<\/strong>();\n            <strong>Long<\/strong> pendingTransactionCheckpointId = entry.getKey();\n            TransactionHolder&lt;TXN&gt; pendingTransaction = entry.getValue();\n            <strong>if<\/strong> (pendingTransactionCheckpointId &gt; checkpointId) {\n                <strong>continue<\/strong>;\n            }\n\n            LOG.info(\n                    \"{} - checkpoint {} complete, committing transaction {} from checkpoint {}\",\n                    name(),\n                    checkpointId,\n                    pendingTransaction,\n                    pendingTransactionCheckpointId);\n\n            logWarningIfTimeoutAlmostReached(pendingTransaction);\n            <strong>try<\/strong> {\n                commit(pendingTransaction.handle);\n            } <strong>catch<\/strong> (Throwable t) {\n                <strong>if<\/strong> (firstError == <strong>null<\/strong>) {\n                    firstError = t;\n                }\n            }\n\n            LOG.debug(\"{} - committed checkpoint transaction {}\", name(), pendingTransaction);\n\n            pendingTransactionIterator.remove();\n        }\n\n        <strong>if<\/strong> (firstError != <strong>null<\/strong>) {\n            <strong>throw<\/strong> <strong>new<\/strong> FlinkRuntimeException(\n                    \"Committing one of transactions failed, logging first encountered failure\",\n                    firstError);\n        }\n    }\n<\/code><\/pre>\n\n\n\n<p>\u4ece\u4ee3\u7801\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u8be5\u65b9\u6cd5\u6bcf\u6b21\u4ece\u8d48\u707e\u7b49\u5f85\u63d0\u4ea4\u7684\u4e8b\u52a1\u53e5\u67c4\u4e2d\u53d6\u51fa\u4e00\u4e2a\uff0c\u68c0\u67e5\u4ed6\u7684\u68c0\u67e5\u70b9ID,\u5e76\u8c03\u7528commit()\u65b9\u6cd5\u63d0\u4ea4\uff0c\u8fd9\u4e2a\u9636\u6bb5\u6d41\u7a0b\u56fe\u4e3a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img-blog.csdnimg.cn\/08069aacadb84a96886cc37164580024.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img-blog.csdnimg.cn\/08069aacadb84a96886cc37164580024.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/div><\/figure>\n\n\n\n<p>\u53ef\u89c1\uff0c\u53ea\u6709\u5728\u6240\u6709\u7684\u68c0\u67e5\u70b9\u90fd\u6210\u529f\u7684\u8fd9\u4e2a\u524d\u63d0\u4e0b\uff0c\u5199\u5165\u624d\u4f1a\u6210\u529f\u3002\u8fd9\u7b26\u5408\u524d\u6587\u63cf\u8ff02PC\u7684\u6d41\u7a0b\u3002\u5176\u4e2djobmanager\u4e3a\u534f\u8c03\u8005\uff0c\u5404\u4e2a\u7b97\u5b50\u4e3a\u53c2\u4e0e\u8005\uff0c\u5e76\u4e14\u4e2d\u6709sink\u4e00\u4e2a\u53c2\u4e0e\u8005\u4f1a\u6267\u884c\u63d0\u4ea4\u3002\u4e00\u65e6\u6709\u4e86\u68c0\u67e5\u70b9\u5931\u8d25\uff0cnotifyCheckpointComplete()\u65b9\u6cd5\u4e0d\u4f1a\u6267\u884c\uff0c\u5982\u679c\u91cd\u8bd5\u4e0d\u6210\u529f\uff0c\u5219\u6700\u540e\u4f1a\u8c03\u7528abort()\u65b9\u6cd5\u56de\u6eda\u4e8b\u52a1\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t@Override\n    protected void <strong>abort<\/strong>(FlinkKafkaProducer.KafkaTransactionState <strong>transaction<\/strong>) {\n        <strong>if<\/strong> (<strong>transaction<\/strong>.isTransactional()) {\n            <strong>transaction<\/strong>.producer.abortTransaction();\n            recycleTransactionalProducer(<strong>transaction<\/strong>.producer);\n        }\n    }\n<\/code><\/pre>\n\n\n\n<p>\u53c2\u8003list\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul>\n<li><a href=\"https:\/\/flink.apache.org\/features\/2018\/03\/01\/end-to-end-exactly-once-apache-flink.html\">End-to-End Exactly-Once Processing in Apache Flink<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/blog.csdn.net\/weixin_40809627\/article\/details\/106918385\">kafka\u7684\u5e42\u7b49\u6027\u548c\u4e8b\u52a1\u6027<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5f15\u7533\uff08\u4ec0\u4e48\u662fXA\u4e8b\u52a1\uff09 XA\uff08eXtended Architecture\uff09\u662f\u6307\u7531X\/Open \u7ec4\u7ec7\u63d0\u51fa\u7684\u5206 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":695,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,8],"tags":[56],"_links":{"self":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/1052"}],"collection":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/comments?post=1052"}],"version-history":[{"count":3,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/1052\/revisions"}],"predecessor-version":[{"id":1058,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/1052\/revisions\/1058"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/media\/695"}],"wp:attachment":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/media?parent=1052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/categories?post=1052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/tags?post=1052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}