From 1ee828b768100e5f242bbf0146fe5ba50c496914 Mon Sep 17 00:00:00 2001 From: chrislu Date: Sat, 22 Jan 2022 06:34:29 -0800 Subject: [PATCH] refactor do not expose internal offset --- weed/filesys/page_writer/page_chunk_mem.go | 5 +++-- weed/filesys/page_writer/upload_pipeline.go | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/weed/filesys/page_writer/page_chunk_mem.go b/weed/filesys/page_writer/page_chunk_mem.go index 422240bd8..887993eea 100644 --- a/weed/filesys/page_writer/page_chunk_mem.go +++ b/weed/filesys/page_writer/page_chunk_mem.go @@ -30,8 +30,9 @@ func (mc *MemChunk) FreeResource() { } func (mc *MemChunk) WriteDataAt(src []byte, offset int64) (n int) { - n = copy(mc.buf[offset:], src) - mc.usage.MarkWritten(offset, offset+int64(n)) + innerOffset := offset % mc.chunkSize + n = copy(mc.buf[innerOffset:], src) + mc.usage.MarkWritten(innerOffset, innerOffset+int64(n)) return } diff --git a/weed/filesys/page_writer/upload_pipeline.go b/weed/filesys/page_writer/upload_pipeline.go index c03a17d2c..40722924f 100644 --- a/weed/filesys/page_writer/upload_pipeline.go +++ b/weed/filesys/page_writer/upload_pipeline.go @@ -57,14 +57,13 @@ func (cw *UploadPipeline) SaveDataAt(p []byte, off int64) (n int) { defer cw.writableChunksLock.Unlock() logicChunkIndex := LogicChunkIndex(off / cw.ChunkSize) - offsetRemainder := off % cw.ChunkSize memChunk, found := cw.writableChunks[logicChunkIndex] if !found { memChunk = NewMemChunk(logicChunkIndex, cw.ChunkSize) cw.writableChunks[logicChunkIndex] = memChunk } - n = memChunk.WriteDataAt(p, offsetRemainder) + n = memChunk.WriteDataAt(p, off) cw.maybeMoveToSealed(memChunk, logicChunkIndex) return