{"id":848,"date":"2012-11-17T21:44:06","date_gmt":"2012-11-17T13:44:06","guid":{"rendered":"http:\/\/coderbee.net\/?p=848"},"modified":"2014-03-25T22:48:50","modified_gmt":"2014-03-25T14:48:50","slug":"rsync-%e6%a0%b8%e5%bf%83%e7%ae%97%e6%b3%95%e7%9a%84java%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/algorithm\/20121117\/848","title":{"rendered":"rsync \u6838\u5fc3\u7b97\u6cd5\u7684Java\u5b9e\u73b0"},"content":{"rendered":"<h2>rsync \u7b97\u6cd5<\/h2>\n<p>\u573a\u666f\uff1a\u5047\u8bbe\u6709\u4e24\u53f0\u8ba1\u7b97\u673a CA\u548c CB \uff0c CA \u4e0a\u6709\u6587\u4ef6 FA \uff0c CB \u4e0a\u6709\u6587\u4ef6 FB \uff0c FA \u548c FB \u662f\u201c\u76f8\u4f3c\u7684\u201d\u3002 CA \u548c CB \u901a\u8fc7\u4f4e\u901f\u901a\u4fe1\u94fe\u63a5\u8fde\u63a5\uff0c\u73b0\u5728\u8981\u628a FA \u540c\u6b65\u5230 FB \u4e0a\u53bb\uff0c\u5982\u4f55\u624d\u80fd\u9ad8\u6548\u540c\u6b65\u3002<\/p>\n<p>rsync \u7b97\u6cd5\u5305\u542b\u4e0b\u9762\u7684\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>CB\u628a FB \u5206\u5272\u6210\u56fa\u5b9a\u5927\u5c0f S \u5b57\u8282\u7684\u5757\uff0c\u6700\u540e\u4e00\u5757\u53ef\u80fd\u5c11\u4e8e S \u5b57\u8282\uff1b<\/li>\n<li>\u5bf9\u4e8e\u6bcf\u4e2a\u5757\uff0cCB \u8ba1\u7b97\u4e24\u4e2a\u6821\u9a8c\u548c\uff1a\u4e00\u4e2a\u5f31\u7684\u201c\u6eda\u52a8\u201d 32 \u4f4d\u6821\u9a8c\u548c\u548c\u4e00\u4e2a\u5f3a\u7684 128 \u4f4d MD4 \u6821\u9a8c\u548c\u3002<\/li>\n<li>CB\u628a\u8fd9\u4e9b\u6821\u9a8c\u548c\u53d1\u7ed9 CA \u3002<\/li>\n<li>CA\u641c\u7d22 FA \u6765\u67e5\u627e S \u5927\u5c0f\u7684\u5757\uff0c\u8fd9\u4e9b\u5757\u4e0e CB \u7684\u5757\u6709\u76f8\u540c\u7684\u5f31\u548c\u5f3a\u6821\u9a8c\u548c\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4e00\u6b21\u904d\u5386\u6765\u5b8c\u6210\uff0c\u901a\u8fc7\u5229\u7528\u6eda\u52a8\u6821\u9a8c\u548c\u7684\u7279\u6b8a\u5c5e\u6027\u3002<\/li>\n<li>CA\u7ed9 CB \u53d1\u9001\u4e00\u5e8f\u5217\u6307\u4ee4\u6765\u6784\u5efa\u4e00\u4e2a FA \u7684\u62f7\u8d1d\u3002\u6bcf\u4e2a\u6307\u4ee4\u8981\u4e48\u6307\u5411 FB \u7684\u4e00\u4e2a\u5757\uff0c\u8981\u4e48\u662f\u6587\u5b57\u6570\u636e\u3002\u6587\u5b57\u6570\u636e\u53ea\u7528\u4e8e\u53d1\u9001 FA \u7684\u90a3\u4e9b\u4e0d\u5339\u914d FB \u5757\u7684\u533a\u57df\u3002<\/li>\n<\/ol>\n<p>\u6700\u7ec8\u7ed3\u679c\u662f CB\u6709\u4e86 FA \u7684\u62f7\u8d1d\uff0c\u4f46\u53ea\u53d1\u9001\u4e86\u90a3\u4e9b\u5728 FB \u91cc\u627e\u4e0d\u5230\u7684\u6570\u636e\u3002<br \/>\n\u8fd9\u4e2a\u7b97\u6cd5\u53ea\u8981\u6c42\u4e00\u4e2a\u6765\u56de\uff0c\u51cf\u5c11\u4e86\u7f51\u7edc\u5ef6\u8fdf\u3002<\/p>\n<p><strong>\u8fd9\u4e2a\u7b97\u6cd5\u7684\u6700\u91cd\u8981\u7684\u7ec6\u8282\u662f\u6eda\u52a8\u6821\u9a8c\u548c  \u548c associated multi-alternate search mechanism which allows the all-offsets checksum search to proceed very quickly.<\/strong><\/p>\n<p>\u8fd9\u91cc\u8bf4\u5230\u7684\u591a\u9009\u62e9\u641c\u7d22\u673a\u5236\uff0c\u5728\u5b9e\u73b0\u65f6\u7528HashMap + List\u3002<\/p>\n<p><!--more--><\/p>\n<h3>\u7b97\u6cd5\u56fe\u793a<\/h3>\n<p><img decoding=\"async\" src=\"\/\/coderbee.net\/wp-content\/uploads\/2014\/03\/rsync.png\" alt=\"rsync\" \/><\/p>\n<p>\u7ea2\u8272\u7684\u662f\u5339\u914d\u7684\u5757\uff0c\u767d\u8272\u7684\u662f\u5b9e\u9645\u4f20\u8f93\u7684\u5185\u5bb9\u3002<br \/>\n<img decoding=\"async\" src=\"\/\/coderbee.net\/wp-content\/uploads\/2014\/03\/rsync-transfer.png\" alt=\"rsync-transfer\" \/><\/p>\n<h4>\u6eda\u52a8\u6821\u9a8c\u548c<\/h4>\n<p>rsync\u7b97\u6cd5\u4f7f\u7528\u7684\u5f31\u6eda\u52a8\u6821\u9a8c\u548c \u987b\u5177\u6709\u975e\u5e38\u5ec9\u4ef7\u5730\u6839\u636e  X1 .. Xn \u548c\u5b57\u8282\u503c X1 \u548c Xn +1 \u5feb\u901f\u8ba1\u7b97 X2 .. Xn+1 \u7684\u6821\u9a8c\u548c\u7684\u6027\u8d28\u3002<\/p>\n<p>rsync\u7b97\u6cd5\u4f7f\u7528\u5f31\u6821\u9a8c\u548c\u7b97\u6cd5\u662f\u7531 Mark Adler \u53d1\u660e\u7684adler-32 \u6821\u9a8c\u548c\u3002\u6821\u9a8c\u548c\u5b9a\u4e49\u5982\u4e0b\uff1a<br \/>\n<img decoding=\"async\" src=\"\/\/coderbee.net\/wp-content\/uploads\/2014\/03\/rsync-adler32.png\" alt=\"rsync-adler32\" \/><\/p>\n<h2>\u5b9e\u73b0<\/h2>\n<p>\u5728\u5b9e\u73b0\u65f6\uff0cMD5 \u7b97\u6cd5\u5728 Java \u91cc\u662f\u73b0\u6210\u7684\uff0c\u6eda\u52a8\u6821\u9a8c\u548c\u4e5f\u662f\u4e0d\u96be\u5b9e\u73b0\u3002\u7f51\u4e0a\u5176\u4ed6\u7684\u535a\u5ba2\u63d0\u5230\u5728\u8ba1\u7b97\u5757\u7684\u6eda\u52a8\u6821\u9a8c\u548c\u65f6\uff0c a \u7684\u521d\u59cb\u503c\u662f 1 \uff0c\u5728\u6211\u5b9e\u73b0\u65f6\u53d1\u73b0\u90a3\u662f\u9519\u7684\uff0crsync \u7684\u62a5\u544a\u6587\u6863\u6ca1\u8bf4\u8981\u8fd9\u6837\uff0c\u62a5\u544a\u7ed9\u51fa\u7684\u7b97\u6cd5\u516c\u5f0f\u4e5f\u6ca1\u8981\u6c42\uff0c\u8bef\u5bfc\u6211\u8d39\u4e86\u4e0d\u5c11\u65f6\u95f4\u3002<\/p>\n<p>\u5728\u5b9e\u73b0\u8fc7\u7a0b\u4e2d\uff0c\u6211\u89c9\u5f97\u6bd4\u8f83\u96be\u7684\u5728\u4e8e \u6839\u636e checksum \u6d41\u8ba1\u7b97 diffitem \u6d41\uff0c\u4e5f\u662f\u6211\u8981\u5728\u8fd9\u91cc\u60f3\u8bf4\u7684\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u4e24\u4e2a\u56fe\u6240\u8868\u793a\u7684\u662f\u57fa\u4e8e\u907f\u514d\u628a\u6574\u4e2a\u6587\u4ef6\u8bfb\u5165\u5185\u5b58\u5b9e\u73b0\u7684\uff0c\u5982\u679c\u4e0d\u8003\u8651\u5185\u5b58\u5360\u7528\uff0c\u628a\u6574\u4e2a\u6587\u4ef6\u8bfb\u5165\u5185\u5b58\uff0c\u53ea\u9700\u8981\u770b\u7b2c 2 \u5f20\u6d41\u7a0b\u56fe\u3002\u5728\u628a\u6587\u4ef6\u90e8\u5206\u8bfb\u5165\u5185\u5b58\u65f6\uff0c\u7b2c 2 \u5f20\u56fe\u662f\u7b2c 1 \u5f20\u56fe\u7ea2\u8272\u5b57\u4f53\u90e8\u5206\u7684\u903b\u8f91\u3002<\/p>\n<p>\u5728\u5b9e\u73b0\u6709\u4e24\u4e2a\u7f13\u5b58\uff1a<br \/>\nbuffer\uff1a\u7f13\u5b58\uff0c\u5bb9\u91cf\u662f\u5757\u7684N\u500d\uff0c\u76f4\u63a5\u4f7f\u7528\u6570\u7ec4\u3002<br \/>\noutBuffer\uff1a\u65b0\u589e\u6570\u636e\u5757\u7684\u7f13\u5b58\uff0c\u662fByteArrayOutputStream\u7684\u5b9e\u4f8b\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e9bint\u7c7b\u578b\u7684\u5145\u5f53\u6307\u9488\u7684\u53d8\u91cf\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/\/coderbee.net\/wp-content\/uploads\/2014\/03\/rsync-check-flow.png\" alt=\"rsync-check-flow\" \/><\/p>\n<p>\u6d41\u7a0b\u56fe\u8bf4\u660e\uff1a<br \/>\n\u786e\u4fdd\u6eda\u52a8\u67e5\u627e\u6570\u636e\u8db3\u591f\uff1a \u5224\u65ad\u7f13\u5b58\u91cc\u662f\u5426\u8fd8\u6709\u6709\u6548\u7684\u6570\u636e\uff0c\u5e76\u8fd4\u56deboolean \u503c\u8868\u793a\u6d41\u662f\u5426\u7ed3\u675f\u3002\u5982\u679c\u6709\uff0c\u8fd4\u56de false \uff0c\u5982\u679c\u6ca1\u6709\uff0c\u8c03\u7528  \u4e3a\u5757\u5339\u914d\u586b\u5145\u7f13\u5b58\uff0c\u5e76\u8fd4\u56de\u8c03\u7528\u7ed3\u679c\u3002<\/p>\n<p>\u4e3a\u5757\u5339\u914d\u586b\u5145\u7f13\u5b58\uff1a \u6574\u7406\u5e76\u586b\u5145\u7f13\u5b58\uff0c\u8fd4\u56deboolean \u503c\u8868\u793a\u6d41\u662f\u5426\u7ed3\u675f\u3002\u9996\u5148\u628a roll \u8fc7\u7684\u4e0d\u5c5e\u4e8e\u5f53\u524d\u5757\u7684\u6570\u636e\u5199\u5165\u65b0\u589e\u6570\u636e\u7f13\u5b58\uff0c\u7136\u540e\u628a\u5f53\u524d\u5757\u62f7\u8d1d\u5230\u7f13\u5b58\u7684\u9996\u90e8\uff0c\u7136\u540e\u4ece\u6587\u4ef6\u6d41\u8bfb\u53d6\u6570\u636e\u586b\u5145\u5269\u4f59\u7684\u7f13\u5b58\u7a7a\u95f4\uff0c\u5e76\u8fd4\u56de\u8868\u793a\u6d41\u662f\u5426\u7ed3\u675f\u7684 boolean \u503c\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/\/coderbee.net\/wp-content\/uploads\/2014\/03\/rsync-flow.png\" alt=\"rsync-flow\" \/><\/p>\n<p>\u5177\u4f53\u6e90\u4ee3\u7801\u89c1github \uff1a  <a href=\"https:\/\/github.com\/wen866595\/jrsync\">https:\/\/github.com\/wen866595\/jrsync<\/a><\/p>\n<h3>\u53c2\u8003\u8d44\u6599<\/h3>\n<ul>\n<li><a href=\"http:\/\/rsync.samba.org\/tech_report\/tech_report.html\">http:\/\/rsync.samba.org\/tech_report\/tech_report.html<\/a><\/li>\n<li><a href=\"http:\/\/coolshell.cn\/articles\/7425.html\">rsync \u7684\u6838\u5fc3\u7b97\u6cd5  |  \u9177\u58f3  &#8211; CoolShell.cn<\/a><\/li>\n<\/ul>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rsync \u7b97\u6cd5 \u573a\u666f\uff1a\u5047\u8bbe\u6709\u4e24\u53f0\u8ba1\u7b97\u673a CA\u548c CB \uff0c CA \u4e0a\u6709\u6587\u4ef6 FA &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/algorithm\/20121117\/848\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[159],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/848"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=848"}],"version-history":[{"count":4,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/848\/revisions"}],"predecessor-version":[{"id":857,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/848\/revisions\/857"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}