﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-jinfeng_wang-随笔分类-2016-Sharding-JDBC</title><link>http://www.blogjava.net/jinfeng_wang/category/55151.html</link><description>G-G-S,D-D-U!</description><language>zh-cn</language><lastBuildDate>Thu, 29 Dec 2016 16:42:24 GMT</lastBuildDate><pubDate>Thu, 29 Dec 2016 16:42:24 GMT</pubDate><ttl>60</ttl><item><title>Sharding-JDBC 柔性事务</title><link>http://www.blogjava.net/jinfeng_wang/archive/2016/12/29/432214.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Thu, 29 Dec 2016 06:49:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2016/12/29/432214.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/432214.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2016/12/29/432214.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/432214.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/432214.html</trackback:ping><description><![CDATA[<div>跨数据库的事务，只能在业务上保证。<br />不能保证的是，2个SQL能够在同一时间成功。<br />业务上的先期检查、校验、分布式锁的设计，再加上一部分的措施（不停重试、先划一部分蛋糕再恢复）是必须要考虑的问题和方案。<br /><br /><br /><br />http://dangdangdotcom.github.io/sharding-jdbc/post/soft_transaction/<br /><div>http://dangdangdotcom.github.io/sharding-jdbc/post/transaction/</div><br /><h1>最大努力送达型</h1><h2>概念</h2><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;">在分布式数据库的场景下，相信对于该数据库的操作最终一定可以成功，所以通过最大努力反复尝试送达操作。</p><h2>架构图</h2><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;"><img src="http://dangdangdotcom.github.io/sharding-jdbc/img/architecture-soft-transaction-bed.png" alt="最大努力送达型事务" style="box-sizing: border-box; border: 0px; vertical-align: middle;" /></p><h2>适用场景</h2><ul style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; line-height: 1.6em; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; background-color: #f8f8f8;"><li style="box-sizing: border-box;">根据主键删除数据。</li><li style="box-sizing: border-box;">更新记录永久状态，如更新通知送达状态。</li></ul><h2>使用限制</h2><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;">使用最大努力送达型柔性事务的<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">SQL</code>需要满足幂等性。</p><ul style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; line-height: 1.6em; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; background-color: #f8f8f8;"><li style="box-sizing: border-box;">INSERT语句要求必须包含主键，且不能是自增主键。</li><li style="box-sizing: border-box;">UPDATE语句要求幂等，不能是<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">UPDATE xxx SET x=x+1</code></li><li style="box-sizing: border-box;">DELETE语句无要求。</li></ul><h2>开发指南</h2><ul style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; line-height: 1.6em; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; background-color: #f8f8f8;"><li style="box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Sharding-JDBC-transaction</code>完全基于<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">java</code>开发，直接提供<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">jar</code>包，可直接使用maven导入坐标即可使用。</li><li style="box-sizing: border-box;">为了保证事务不丢失，<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Sharding-JDBC-transaction</code>需要提供数据库存储事务日志，配置方法可参见事务管理器配置项。</li><li style="box-sizing: border-box;">由于柔性事务采用异步尝试，需要部署独立的作业和<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Zookeeper</code>。<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Sharding-JDBC-transaction</code>采用<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">elastic-job</code>实现的<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Sharding-JDBC-transaction-async-job</code>，通过简单配置即可启动高可用作业异步送达柔性事务，启动脚本为<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">start.sh</code>。</li><li style="box-sizing: border-box;">为了便于开发，<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Sharding-JDBC-transaction</code>提供了基于内存的事务日志存储器和内嵌异步作业。</li></ul><h2>开发示例</h2><pre language-java"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: 13px; padding: 1em; margin-top: 0.5em; margin-bottom: 0.5em; line-height: 1.5; word-break: normal; word-wrap: normal; border: 1px solid #cccccc; border-radius: 4px; text-shadow: #ffffff 0px 1px; direction: ltr; tab-size: 4; background: #f5f2f0;"><code language-java"="" style="box-sizing: border-box; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: inherit; padding: 0px; border-radius: 0px; text-shadow: #ffffff 0px 1px; direction: ltr; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; background: 0px 0px;">    <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">// 1. 配置SoftTransactionConfiguration</span>     SoftTransactionConfiguration transactionConfig <span operator"="" style="box-sizing: border-box; color: #a67f59; background: rgba(255, 255, 255, 0.498039);">=</span> <span keyword"="" style="box-sizing: border-box; color: #0077aa;">new</span> <span class-name"="" style="box-sizing: border-box;">SoftTransactionConfiguration</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span>dataSource<span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">;</span>     transactionConfig<span punctuation"="" style="box-sizing: border-box; color: #999999;">.</span><span function"="" style="box-sizing: border-box; color: #dd4a68;">setXXX</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">;</span>          <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">// 2. 初始化SoftTransactionManager</span>     SoftTransactionManager transactionManager <span operator"="" style="box-sizing: border-box; color: #a67f59; background: rgba(255, 255, 255, 0.498039);">=</span> <span keyword"="" style="box-sizing: border-box; color: #0077aa;">new</span> <span class-name"="" style="box-sizing: border-box;">SoftTransactionManager</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span>transactionConfig<span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">;</span>     transactionManager<span punctuation"="" style="box-sizing: border-box; color: #999999;">.</span><span function"="" style="box-sizing: border-box; color: #dd4a68;">init</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">;</span>          <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">// 3. 获取BEDSoftTransaction</span>     BEDSoftTransaction transaction <span operator"="" style="box-sizing: border-box; color: #a67f59; background: rgba(255, 255, 255, 0.498039);">=</span> <span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span>BEDSoftTransaction<span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span> transactionManager<span punctuation"="" style="box-sizing: border-box; color: #999999;">.</span><span function"="" style="box-sizing: border-box; color: #dd4a68;">getTransaction</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span>SoftTransactionType<span punctuation"="" style="box-sizing: border-box; color: #999999;">.</span>BestEffortsDelivery<span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">;</span>          <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">// 4. 开启事务</span>     transaction<span punctuation"="" style="box-sizing: border-box; color: #999999;">.</span><span function"="" style="box-sizing: border-box; color: #dd4a68;">begin</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span>connection<span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">;</span>          <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">// 5. 执行JDBC</span>     <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">/*          codes here     */</span>     <span operator"="" style="box-sizing: border-box; color: #a67f59; background: rgba(255, 255, 255, 0.498039);">*</span>      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">// 6.关闭事务</span>     transaction<span punctuation"="" style="box-sizing: border-box; color: #999999;">.</span><span function"="" style="box-sizing: border-box; color: #dd4a68;">end</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">(</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">)</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">;</span> </code></pre><h2>事务管理器配置项</h2><h3><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 21.6px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">SoftTransactionConfiguration</code>配置</h3><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;">用于配置事务管理器。</p><table style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; display: block; width: 872.5px; overflow: auto; word-break: keep-all; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;"><thead style="box-sizing: border-box;"><tr style="box-sizing: border-box;"><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">名称</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">类型</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">必填</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">默认值</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">说明</em></th></tr></thead><tbody style="box-sizing: border-box;"><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">shardingDataSource</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">ShardingDataSource</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">是</code></td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;"></td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">事务管理器管理的数据源</td></tr><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">syncMaxDeliveryTryTimes</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">int</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">3</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">同步的事务送达的最大尝试次数</td></tr><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">storageType</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">enum</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">RDB</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">事务日志存储类型。可选值: RDB,MEMORY。使用RDB类型将自动建表</td></tr><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">transactionLogDataSource</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">DataSource</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">null</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">存储事务日志的数据源，如果storageType为RDB则必填</td></tr><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">bestEffortsDeliveryJobConfiguration</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">NestedBestEffortsDeliveryJobConfiguration</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">null</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">最大努力送达型内嵌异步作业配置对象。如需使用，请参考<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">NestedBestEffortsDeliveryJobConfiguration</code>配置</td></tr></tbody></table><h3><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 21.6px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">NestedBestEffortsDeliveryJobConfiguration</code>配置 (仅开发环境)</h3><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;">用于配置内嵌的异步作业，仅用于开发环境。生产环境应使用独立部署的作业版本。</p><table style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; display: block; width: 872.5px; overflow: auto; word-break: keep-all; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;"><thead style="box-sizing: border-box;"><tr style="box-sizing: border-box;"><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">名称</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">类型</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">必填</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">默认值</em></th><th style="box-sizing: border-box; padding: 0.5rem 1rem; border: 1px solid #e9ebec;"><em style="box-sizing: border-box;">说明</em></th></tr></thead><tbody style="box-sizing: border-box;"><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">zookeeperPort</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">int</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">4181</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">内嵌的注册中心端口号</td></tr><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">zookeeperDataDir</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">String</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">target/test_zk_data/nano/</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">内嵌的注册中心的数据存放目录</td></tr><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">asyncMaxDeliveryTryTimes</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">int</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">3</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">异步的事务送达的最大尝试次数</td></tr><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">asyncMaxDeliveryTryDelayMillis</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">long</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">否</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">60000</td><td style="box-sizing: border-box; padding: 0.5rem 1rem; border-style: solid; border-color: #e9ebec;">执行异步送达事务的延迟毫秒数，早于此间隔时间的入库事务才会被异步作业执行</td></tr></tbody></table><h2>独立部署作业指南</h2><ul style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; line-height: 1.6em; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; background-color: #f8f8f8;"><li style="box-sizing: border-box;">部署用于存储事务日志的数据库。</li><li style="box-sizing: border-box;">部署用于异步作业使用的<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Zookeeper</code>。</li><li style="box-sizing: border-box;">配置<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">yaml</code>文件,参照示例。</li><li style="box-sizing: border-box;">下载并解压文件<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">sharding-jdbc-transaction-async-job-$VERSION.tar</code>，通过<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">start.sh</code>脚本启动异步作业。</li></ul><h2>异步作业yaml文件配置</h2><pre language-yaml"="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: 13px; padding: 1em; margin-top: 0.5em; margin-bottom: 0.5em; line-height: 1.5; word-break: normal; word-wrap: normal; border: 1px solid #cccccc; border-radius: 4px; text-shadow: #ffffff 0px 1px; direction: ltr; tab-size: 4; background: #f5f2f0;"><code language-yaml"="" style="box-sizing: border-box; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: inherit; padding: 0px; border-radius: 0px; text-shadow: #ffffff 0px 1px; direction: ltr; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; background: 0px 0px;"><span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#目标数据库的数据源.</span> <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">targetDataSource</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">ds_0</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span tag"="" style="box-sizing: border-box; color: #990055;">!!org.apache.commons.dbcp.BasicDataSource</span>     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">driverClassName</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> com.mysql.jdbc.Driver     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">url</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> jdbc<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>mysql<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>//localhost<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>3306/ds_0     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">username</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> root     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">password</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">ds_1</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span tag"="" style="box-sizing: border-box; color: #990055;">!!org.apache.commons.dbcp.BasicDataSource</span>     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">driverClassName</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> com.mysql.jdbc.Driver     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">url</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> jdbc<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>mysql<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>//localhost<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>3306/ds_1     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">username</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> root     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">password</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>  <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#事务日志的数据源.</span> <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">transactionLogDataSource</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">ds_trans</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span tag"="" style="box-sizing: border-box; color: #990055;">!!org.apache.commons.dbcp.BasicDataSource</span>     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">driverClassName</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> com.mysql.jdbc.Driver     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">url</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> jdbc<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>mysql<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>//localhost<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>3306/trans_log     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">username</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> root     <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">password</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>  <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#注册中心配置</span> <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">zkConfig</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>   <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#注册中心的连接地址</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">connectionString</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> localhost<span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span><span number"="" style="box-sizing: border-box; color: #990055;">2181</span>      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#作业的命名空间</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">namespace</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> Best<span punctuation"="" style="box-sizing: border-box; color: #999999;">-</span>Efforts<span punctuation"="" style="box-sizing: border-box; color: #999999;">-</span>Delivery<span punctuation"="" style="box-sizing: border-box; color: #999999;">-</span>Job      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#注册中心的等待重试的间隔时间的初始值</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">baseSleepTimeMilliseconds</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span number"="" style="box-sizing: border-box; color: #990055;">1000</span>      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#注册中心的等待重试的间隔时间的最大值</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">maxSleepTimeMilliseconds</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span number"="" style="box-sizing: border-box; color: #990055;">3000</span>      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#注册中心的最大重试次数</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">maxRetries</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span number"="" style="box-sizing: border-box; color: #990055;">3</span>  <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#作业配置</span> <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">jobConfig</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span>   <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#作业名称</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">name</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> bestEffortsDeliveryJob      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#触发作业的cron表达式</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">cron</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> 0/5 * * * * <span punctuation"="" style="box-sizing: border-box; color: #999999;">?</span>      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#每次作业获取的事务日志最大数量</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">transactionLogFetchDataCount</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span number"="" style="box-sizing: border-box; color: #990055;">100</span>      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#事务送达的最大尝试次数.</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">maxDeliveryTryTimes</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span number"="" style="box-sizing: border-box; color: #990055;">3</span>      <span comment"="" spellcheck="true" style="box-sizing: border-box; color: #708090;">#执行送达事务的延迟毫秒数,早于此间隔时间的入库事务才会被作业执行</span>   <span key=""  atrule"="" style="box-sizing: border-box; color: #0077aa;">maxDeliveryTryDelayMillis</span><span punctuation"="" style="box-sizing: border-box; color: #999999;">:</span> <span number"="" style="box-sizing: border-box; color: #990055;">60000</span> </code></pre><div><code language-yaml"="" style="box-sizing: border-box; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: inherit; padding: 0px; border-radius: 0px; text-shadow: #ffffff 0px 1px; direction: ltr; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0px 0px; background-repeat: initial;"><span number"="" style="box-sizing: border-box; color: #990055;"><br /><br /><h1>事务支持说明</h1><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">Sharding-JDBC</code>由于性能方面的考量，决定不支持<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">强一致性</code>分布式事务。我们已明确规划线路图，未来会支持最终一致性的柔性事务。</p><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;">目前<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">最大努力送达型</code>柔性事务已开发完成。</p><p style="box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; line-height: 19.2px; background-color: #f8f8f8;">如果不使用柔性事务，也会自动包含<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px; color: #c7254e; border-radius: 4px; background-color: #f9f2f4;">弱XA</code>事务支持，有以下几点说明：</p><ul style="box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; line-height: 1.6em; color: #333333; font-family: -apple-system-headline, 'Helvetica Neue', Helvetica, sans-serif; font-size: 16px; background-color: #f8f8f8;"><li style="box-sizing: border-box;"><p style="box-sizing: border-box; margin: 0px 0px 10px;">完全支持非跨库事务，例如：仅分表，或分库但是路由的结果在单库中。</p></li><li style="box-sizing: border-box;"><p style="box-sizing: border-box; margin: 0px 0px 10px;">完全支持因逻辑异常导致的跨库事务。例如：同一事务中，跨两个库更新。更新完毕后，抛出空指针，则两个库的内容都能回滚。</p></li><li style="box-sizing: border-box;"><p style="box-sizing: border-box; margin: 0px 0px 10px;">不支持因网络、硬件异常导致的跨库事务。例如：同一事务中，跨两个库更新，更新完毕后、未提交之前，第一个库死机，则只有第二个库数据提交。</p></li></ul></span></code></div></div><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/432214.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2016-12-29 14:49 <a href="http://www.blogjava.net/jinfeng_wang/archive/2016/12/29/432214.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring XML 文件中自定义标签</title><link>http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432208.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Wed, 28 Dec 2016 11:01:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432208.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/432208.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432208.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/432208.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/432208.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 代码：sharding-jdbc-config-spring 目录https://my.oschina.net/nalenwind/blog/599044spring扩展之自定义标签&nbsp;&nbsp; &nbsp; 不知大家在看到那些大牛们在spring里写各种扩展工具，各种方便有没有很羡慕呢？接下来我给大家介绍一下如何通过自定义标签的形式来扩展spring.&nbsp;&nbsp; &nb...&nbsp;&nbsp;<a href='http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432208.html'>阅读全文</a><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/432208.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2016-12-28 19:01 <a href="http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432208.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Sharding-JDBC的分库分表能力</title><link>http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432207.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Wed, 28 Dec 2016 10:57:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432207.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/432207.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432207.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/432207.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/432207.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 代码：sharding-jdbc-config-common 目录面临的问题： select * from a, b where a.user_id =b.user_id &nbsp;在分库分表的情况下，如何决定一个正确的JDBC DataSource，一个正确的Table Namehttp://dangdangdotcom.github.io/sharding-jdbc/post/user_gu...&nbsp;&nbsp;<a href='http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432207.html'>阅读全文</a><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/432207.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2016-12-28 18:57 <a href="http://www.blogjava.net/jinfeng_wang/archive/2016/12/28/432207.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>