The Rsync Algorithm

The Rsync Algorithm

TR-CS-96-05 The rsync algorithm Andrew Tridgell and Paul Mackerras June 1996 Joint Computer Science Technical Report Series Department of Computer Science Faculty of Engineering and Information Technology Computer Sciences Laboratory Research School of Information Sciences and Engineering This technical report series is published jointly by the Department of Computer Science, Faculty of Engineering and Information Technology, and the Computer Sciences Laboratory, Research School of Information Sciences and Engineering, The Australian National University. Please direct correspondence regarding this series to: Technical Reports Department of Computer Science Faculty of Engineering and Information Technology The Australian National University Canberra ACT 0200 Australia or send email to: [email protected] A list of technical reports, including some abstracts and copies of some full reports may be found at: http://cs.anu.edu.au/techreports/ Recent reports in this series: TR-CS-96-04 Peter Bailey and David Hawking. A parallel architecture for query processing over a terabyte of text. June 1996. TR-CS-96-03 Brendan D. McKay. autoson – a distributed batch system for unix workstation networks (version 1.3). March 1996. TR-CS-96-02 Richard P. Brent. Factorization of the tenth and eleventh Fermat numbers. February 1996. TR-CS-96-01 Weifa Liang and Richard P. Brent. Constructing the spanners of graphs in parallel. January 1996. TR-CS-95-08 David Hawking. The design and implementation of a parallel document retrieval engine. December 1995. TR-CS-95-07 Raymond H. Chan and Michael K. Ng. Conjugate gradient methods for Toeplitz systems. September 1995. The rsync algorithm Andrew Tridgell Paul Mackerras Departmentof Computer Science Australian National University Canb erra, ACT 0200, Australia June 18, 1996 Abstract This rep ort presents an algorithm for up dating a le on one machine to be identical to a le on another machine. We assume that the two machines are connected bya low-bandwidth high-latency bi-directional communications link. The algorithm identi es parts of the source le which are identical to some part of the destination le, and only sends those parts which cannot b e matched in this way. E ectively, the algo- rithm computes a set of di erences without having b oth les on the same machine. The algorithm works b est when the les are similar, but will also function correctly and reasonably eciently when the les are quite di erent. 1 The problem Imagine you havetwo les, A and B , and you wish to up date B to b e the same as A. The obvious metho d is to copy A onto B . Now imagine that the two les are on machines connected by a slow com- munications link, for example a dial up IP link. If A is large, copying A onto B will b e slow. To make it faster you could compress A b efore sending it, but that will usually only gain a factor of 2 to 4. Now assume that A and B are quite similar, p erhaps b oth derived from the same original le. To really sp eed things up you would need to take advantage of this similarity. A common metho d is to send just the di erences b etween A and B down the link and then use this list of di erences to reconstruct the le. The problem is that the normal metho ds for creating a set of di erences between two les rely on b eing able to read b oth les. Thus they require that b oth les are available b eforehand at one end of the link. If they are not b oth available on the same machine, these algorithms cannot b e used once you had copied the le over, you wouldn't need the di erences. This is the problem that rsync addresses. The rsync algorithm eciently computes which parts of a source le match some part of an existing destination le. These parts need not b e sent across the link; all that is needed is a reference to the part of the destination le. Only parts of the source le which are not matched in this way need to b e sent verbatim. The receiver can then construct a copyof the source le using the references to parts of the existing destination le and the verbatim material. 1 Trivially, the data sent to the receiver can be compressed using any of a range of common compression algorithms, for further sp eed improvements. 2 The rsync algorithm Supp ose we have two general purp ose computers and . Computer has access to a le A and has access to le B , where A and B are \similar". There is a slow communications link b etween and . The rsync algorithm consists of the following steps: 1. splits the le B into a series of non-overlapping xed-sized blo cks of size 1 Sbytes . The last blo ckmay b e shorter than S bytes. 2. For each of these blo cks calculates two checksums: a weak \rolling" 32-bit checksum describ ed b elow and a strong 128-bit MD4 checksum. 3. sends these checksums to . 4. searches through A to nd all blo cks of length S bytes at any o set, not just multiples of S that have the same weak and strong checksum as one of the blo cks of B . This can b e done in a single pass very quickly using a sp ecial prop erty of the rolling checksum describ ed b elow. 5. sends a sequence of instructions for constructing a copyof A. Each instruction is either a reference to a blo ck of B , or literal data. Literal data is sent only for those sections of A which did not matchanyofthe blo cks of B . The end result is that gets a copyofA, but only the pieces of A that are not found in B plus a small amount of data for checksums and blo ck indexes are sentover the link. The algorithm also only requires one round trip, which minimises the impact of the link latency. The most imp ortant details of the algorithm are the rolling checksum and the asso ciated multi-alternate search mechanism which allows the all-o sets checksum search to pro ceed very quickly. These will be discussed in greater detail b elow. 3 Rolling checksum The weak rolling checksum used in the rsync algorithm needs to have the prop- erty that it is very cheap to calculate the checksum of a bu er X ::X given 2 n+1 the checksum of bu er X ::X and the values of the bytes X and X . 1 n 1 n+1 The weak checksum algorithm we used in our implementation was inspired by Mark Adler's adler-32 checksum. Our checksum is de ned by l X ak; l= X modM i i=k 1 Wehave found that values of S b etween 500 and 1000 are quite go o d for most purp oses 2 l X bk; l= l i +1X modM i i=k 16 sk; l=ak; l+2 bk; l where sk; listhe rolling checksum of the bytes X :::X . For simplicity k l 16 and sp eed, we use M =2 . The imp ortant prop erty of this checksum is that successive values can be computed very eciently using the recurrence relations ak +1;l +1= ak; l X + X mod M k l+1 bk +1;l +1= bk; l l k +1X + ak +1;l + 1 mo d M k Thus the checksum can b e calculated for blo cks of length S at all p ossible o sets within a le in a \rolling" fashion, with very little computation at each p oint. Despite its simplicity, this checksum was found to be quite adequate as a rst level check for a matchoftwo le blo cks. Wehave found in practice that the probability of this checksum matching when the blo cks are not equal is quite low. This is imp ortant b ecause the much more exp ensive strong checksum must b e calculated for each blo ck where the weak checksum matches. 4 Checksum searching Once has received the list of checksums of the blo cks of B ,itmust search A for any blo cks at any o set that match the checksum of some blo ckof B . The basic strategy is to compute the 32-bit rolling checksum for a blo ck of length S starting at eachbyte of A in turn, and for eachchecksum, search the list for a match. To do this our implementation uses a simple 3 level searching scheme. 16 The rst level uses a 16-bit hash of the 32-bit rolling checksum and a2 entry hash table. The list of checksum values i.e., the checksums from the blo cks of B is sorted according to the 16-bit hash of the 32-bit rolling checksum. Each entry in the hash table p oints to the rst element of the list for that hash value, or contains a null value if no element of the list has that hash value. At each o set in the le the 32-bit rolling checksum and its 16-bit hash are calculated. If the hash table entry for that hash value is not a null value, the second level checkisinvoked. The second level checkinvolves scanning the sorted checksum list starting with the entry p ointed to by the hash table entry, lo oking for an entry whose 32-bit rolling checksum matches the currentvalue.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us