I have pulled these changes into the git repo.<br><br>Thanks,<br>Toby<br><br><div class="gmail_quote">2009/3/30 Rusty Russell <span dir="ltr"><<a href="mailto:rusty@rustcorp.com.au">rusty@rustcorp.com.au</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Monday 30 March 2009 07:31:38 Alex Wulms wrote:<br>
</div><div class="im">> I have also investigated why the cache-server stops finding block matches<br>
> after the first difference. I think it is because at this moment, the cache<br>
> server does not read ahead enough in the data-stream. Basically, the<br>
> crc_read_block function of Rusty must be fed with as much data as possible,<br>
<br>
</div>Bug fixed. Grab latest from ccan, or just apply this patch.<br>
<br>
Thanks for this: I added tests for feeding 1 byte at a time, and it showed the<br>
issue immediately.<br>
<br>
Cheers,<br>
Rusty.<br>
<br>
=== modified file 'ccan/crcsync/crcsync.c'<br>
--- ccan/crcsync/crcsync.c 2009-02-17 09:16:33 +0000<br>
+++ ccan/crcsync/crcsync.c 2009-03-30 00:07:04 +0000<br>
@@ -138,6 +138,7 @@<br>
goto have_match;<br>
}<br>
<br>
+ /* old is the trailing edge of the checksum window. */<br>
if (buffer_size(ctx) >= ctx->block_size)<br>
old = ctx->buffer + ctx->buffer_start;<br>
else<br>
@@ -153,6 +154,7 @@<br>
*old, *p,<br>
ctx->uncrc_tab);<br>
old++;<br>
+ /* End of stored buffer? Start on data they gave us. */<br>
if (old == ctx->buffer + ctx->buffer_end)<br>
old = buf;<br>
} else {<br>
@@ -167,11 +169,6 @@<br>
p++;<br>
}<br>
<br>
- /* Make sure we have a copy of the last block_size bytes.<br>
- * First, copy down the old data. */<br>
- if (buffer_size(ctx)) {<br>
- }<br>
-<br>
if (crcmatch >= 0) {<br>
/* We have a match! */<br>
if (ctx->literal_bytes > ctx->block_size) {<br>
@@ -187,12 +184,15 @@<br>
assert(ctx->literal_bytes == 0);<br>
ctx->have_match = -1;<br>
ctx->running_crc = 0;<br>
+ /* Nothing more in the buffer. */<br>
+ ctx->buffer_start = ctx->buffer_end = 0;<br>
}<br>
} else {<br>
/* Output literal if it's more than 1 block ago. */<br>
if (ctx->literal_bytes > ctx->block_size) {<br>
*result = ctx->literal_bytes - ctx->block_size;<br>
- ctx->literal_bytes = ctx->block_size;<br>
+ ctx->literal_bytes -= *result;<br>
+ ctx->buffer_start += *result;<br>
} else<br>
*result = 0;<br>
<br>
@@ -243,29 +243,34 @@<br>
long crc_read_flush(struct crc_context *ctx)<br>
{<br>
long ret;<br>
+ size_t final;<br>
<br>
- /* In case we ended on a whole block match. */<br>
- if (ctx->have_match == -1) {<br>
- size_t final;<br>
-<br>
- final = final_block_match(ctx);<br>
- if (!final) {<br>
- /* This is how many bytes we're about to consume. */<br>
- ret = buffer_size(ctx);<br>
- ctx->buffer_start += ret;<br>
- ctx->literal_bytes -= ret;<br>
-<br>
- return ret;<br>
- }<br>
- ctx->buffer_start += final;<br>
- ctx->literal_bytes -= final;<br>
- ctx->have_match = ctx->num_crcs-1;<br>
- }<br>
-<br>
- /* It might be a partial block match, so no assert */<br>
- ctx->literal_bytes = 0;<br>
- ret = -ctx->have_match-1;<br>
- ctx->have_match = -1;<br>
+ /* We might have ended right on a matched block. */<br>
+ if (ctx->have_match != -1) {<br>
+ ctx->literal_bytes -= ctx->block_size;<br>
+ assert(ctx->literal_bytes == 0);<br>
+ ret = -ctx->have_match-1;<br>
+ ctx->have_match = -1;<br>
+ ctx->running_crc = 0;<br>
+ /* Nothing more in the buffer. */<br>
+ ctx->buffer_start = ctx->buffer_end;<br>
+ return ret;<br>
+ }<br>
+<br>
+ /* Look for truncated final block. */<br>
+ final = final_block_match(ctx);<br>
+ if (!final) {<br>
+ /* Nope? Just a literal. */<br>
+ ret = buffer_size(ctx);<br>
+ ctx->buffer_start += ret;<br>
+ ctx->literal_bytes -= ret;<br>
+ return ret;<br>
+ }<br>
+<br>
+ /* We matched (some of) what's left. */<br>
+ ret = -(ctx->num_crcs-1)-1;<br>
+ ctx->buffer_start += final;<br>
+ ctx->literal_bytes -= final;<br>
return ret;<br>
}<br>
<br>
<br>
<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>This email is intended for the addressee only and may contain privileged and/or confidential information<br>