checkpoint, bug fixes

This commit is contained in:
sawka 2024-05-19 23:48:08 -07:00
parent 889fcac38d
commit 4f9429ed8a
3 changed files with 6 additions and 13 deletions

View File

@ -218,7 +218,7 @@ func (s *BlockStore) WriteAt(ctx context.Context, blockId string, name string, o
if err != nil { if err != nil {
return err return err
} }
entry.writeAt(offset, data, true) entry.writeAt(offset, data, false)
return nil return nil
}) })
} }
@ -229,9 +229,10 @@ func (s *BlockStore) AppendData(ctx context.Context, blockId string, name string
if err != nil { if err != nil {
return err return err
} }
lastPartIdx := entry.File.getLastIncompletePartNum() partMap := entry.File.computePartMap(entry.File.Size, int64(len(data)))
if lastPartIdx != NoPartIdx { incompleteParts := incompletePartsFromMap(partMap)
err = entry.loadDataPartsIntoCache(ctx, []int{lastPartIdx}) if len(incompleteParts) > 0 {
err = entry.loadDataPartsIntoCache(ctx, incompleteParts)
if err != nil { if err != nil {
return err 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 { func (f *BlockFile) partIdxAtOffset(offset int64) int {
partIdx := int(offset / partDataSize) partIdx := int(offset / partDataSize)
if f.Opts.Circular { if f.Opts.Circular {

View File

@ -162,7 +162,7 @@ func (entry *CacheEntry) writeAt(offset int64, data []byte, replace bool) {
} }
if entry.File.Opts.Circular { if entry.File.Opts.Circular {
startCirFileOffset := entry.File.Size - entry.File.Opts.MaxSize 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 // write is before the start of the circular file
return return
} }

View File

@ -401,7 +401,6 @@ func TestCircularWrites(t *testing.T) {
t.Fatalf("error writing data: %v", err) t.Fatalf("error writing data: %v", err)
} }
checkFileData(t, ctx, blockId, "c1", "123456789 123456789 123456789 123456789 123456789 ") checkFileData(t, ctx, blockId, "c1", "123456789 123456789 123456789 123456789 123456789 ")
err = GBS.AppendData(ctx, blockId, "c1", []byte("apple")) err = GBS.AppendData(ctx, blockId, "c1", []byte("apple"))
if err != nil { if err != nil {
t.Fatalf("error appending data: %v", err) t.Fatalf("error appending data: %v", err)