From 4f9429ed8a90d1affbff9f867511d2d90c23cb45 Mon Sep 17 00:00:00 2001 From: sawka Date: Sun, 19 May 2024 23:48:08 -0700 Subject: [PATCH] checkpoint, bug fixes --- pkg/blockstore/blockstore.go | 16 +++++----------- pkg/blockstore/blockstore_cache.go | 2 +- pkg/blockstore/blockstore_test.go | 1 - 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pkg/blockstore/blockstore.go b/pkg/blockstore/blockstore.go index 7d506bf68..f770b51df 100644 --- a/pkg/blockstore/blockstore.go +++ b/pkg/blockstore/blockstore.go @@ -218,7 +218,7 @@ func (s *BlockStore) WriteAt(ctx context.Context, blockId string, name string, o if err != nil { return err } - entry.writeAt(offset, data, true) + entry.writeAt(offset, data, false) return nil }) } @@ -229,9 +229,10 @@ func (s *BlockStore) AppendData(ctx context.Context, blockId string, name string if err != nil { return err } - lastPartIdx := entry.File.getLastIncompletePartNum() - if lastPartIdx != NoPartIdx { - err = entry.loadDataPartsIntoCache(ctx, []int{lastPartIdx}) + partMap := entry.File.computePartMap(entry.File.Size, int64(len(data))) + incompleteParts := incompletePartsFromMap(partMap) + if len(incompleteParts) > 0 { + err = entry.loadDataPartsIntoCache(ctx, incompleteParts) if err != nil { return err } @@ -290,13 +291,6 @@ func (s *BlockStore) FlushCache(ctx context.Context) error { /////////////////////////////////// -func (f *BlockFile) getLastIncompletePartNum() int { - if f.Size%partDataSize == 0 { - return NoPartIdx - } - return f.partIdxAtOffset(f.Size) -} - func (f *BlockFile) partIdxAtOffset(offset int64) int { partIdx := int(offset / partDataSize) if f.Opts.Circular { diff --git a/pkg/blockstore/blockstore_cache.go b/pkg/blockstore/blockstore_cache.go index e25716136..60f6c27f9 100644 --- a/pkg/blockstore/blockstore_cache.go +++ b/pkg/blockstore/blockstore_cache.go @@ -162,7 +162,7 @@ func (entry *CacheEntry) writeAt(offset int64, data []byte, replace bool) { } if entry.File.Opts.Circular { startCirFileOffset := entry.File.Size - entry.File.Opts.MaxSize - if offset+int64(len(data)) < startCirFileOffset { + if offset+int64(len(data)) <= startCirFileOffset { // write is before the start of the circular file return } diff --git a/pkg/blockstore/blockstore_test.go b/pkg/blockstore/blockstore_test.go index 8fbdfb22d..170f58973 100644 --- a/pkg/blockstore/blockstore_test.go +++ b/pkg/blockstore/blockstore_test.go @@ -401,7 +401,6 @@ func TestCircularWrites(t *testing.T) { t.Fatalf("error writing data: %v", err) } checkFileData(t, ctx, blockId, "c1", "123456789 123456789 123456789 123456789 123456789 ") - err = GBS.AppendData(ctx, blockId, "c1", []byte("apple")) if err != nil { t.Fatalf("error appending data: %v", err)