Update copy to discard over truncate

Prevents the copy method from calling discard on the
writer when the reader is not seekable. Instead,
the copy method will discard up to the offset.
Truncate is a more expensive operation since any
bytes that are truncated already have their hash calculated
and are stored on disk in the backend. Re-writing bytes
which were truncated requires transfering the data over
GRPC again and re-computing the hash up to the point of
truncation.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2018-01-25 17:15:32 -08:00
parent 02d737f967
commit a12f493bd3
3 changed files with 20 additions and 20 deletions

View File

@@ -42,9 +42,9 @@ func TestCopy(t *testing.T) {
},
{
name: "copy with offset from unseekable source",
source: copySource{reader: bytes.NewBufferString("foo"), size: 3},
writer: fakeWriter{status: Status{Offset: 8}},
expected: "foo",
source: copySource{reader: bytes.NewBufferString("foobar"), size: 6},
writer: fakeWriter{status: Status{Offset: 3}},
expected: "bar",
},
{
name: "commit already exists",