From 267201ff44d58d339ad2c9006ffe1d6d65e569b3 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 10 Sep 2018 02:39:41 -0700 Subject: [PATCH] handle non continuous writes fix #728 --- weed/filesys/dirty_page.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/weed/filesys/dirty_page.go b/weed/filesys/dirty_page.go index 1dd7d3fde..145d89138 100644 --- a/weed/filesys/dirty_page.go +++ b/weed/filesys/dirty_page.go @@ -66,10 +66,18 @@ func (pages *ContinuousDirtyPages) AddPage(ctx context.Context, offset int64, da if offset != pages.Offset+pages.Size { // when this happens, debug shows the data overlapping with existing data is empty // the data is not just append - return pages.flushAndSave(ctx, offset, data) + if offset == pages.Offset { + copy(pages.Data[pages.Size:], data[pages.Size:]) + } else { + if pages.Size != 0 { + glog.V(0).Infof("possible error: pages [%d, %d) write [%d, %d)", pages.Offset, pages.Offset+pages.Size, offset, offset+int64(len(data))) + } + return pages.flushAndSave(ctx, offset, data) + } + } else { + copy(pages.Data[offset-pages.Offset:], data) } - copy(pages.Data[offset-pages.Offset:], data) pages.Size = max(pages.Size, offset+int64(len(data))-pages.Offset) return