diff --git a/unmaintained/change_superblock/change_superblock.go b/unmaintained/change_superblock/change_superblock.go index afe651c4e..56342a0cb 100644 --- a/unmaintained/change_superblock/change_superblock.go +++ b/unmaintained/change_superblock/change_superblock.go @@ -92,7 +92,7 @@ func main() { header := superBlock.Bytes() - if n, e := datFile.WriteAt(header, 0); n == 0 || e != nil { + if n, e := datBackend.WriteAt(header, 0); n == 0 || e != nil { glog.Fatalf("cannot write super block: %v", e) } diff --git a/weed/storage/backend/disk_file.go b/weed/storage/backend/disk_file.go index 161f4ca83..498963c31 100644 --- a/weed/storage/backend/disk_file.go +++ b/weed/storage/backend/disk_file.go @@ -2,6 +2,7 @@ package backend import ( "github.com/chrislusf/seaweedfs/weed/glog" + . "github.com/chrislusf/seaweedfs/weed/storage/types" "os" "time" ) @@ -22,11 +23,15 @@ func NewDiskFile(f *os.File) *DiskFile { if err != nil { glog.Fatalf("stat file %s: %v", f.Name(), err) } + offset := stat.Size() + if offset%NeedlePaddingSize != 0 { + offset = offset + (NeedlePaddingSize - offset%NeedlePaddingSize) + } return &DiskFile{ fullFilePath: f.Name(), File: f, - fileSize: stat.Size(), + fileSize: offset, modTime: stat.ModTime(), } } @@ -47,6 +52,10 @@ func (df *DiskFile) WriteAt(p []byte, off int64) (n int, err error) { return } +func (df *DiskFile) Append(p []byte) (n int, err error) { + return df.WriteAt(p, df.fileSize) +} + func (df *DiskFile) Truncate(off int64) error { err := df.File.Truncate(off) if err == nil { diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go index c17c9c937..0ee1e61c6 100644 --- a/weed/storage/volume_vacuum.go +++ b/weed/storage/volume_vacuum.go @@ -286,7 +286,7 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI if err != nil { return fmt.Errorf("ReadNeedleBlob %s key %d offset %d size %d failed: %v", oldDatFile.Name(), key, increIdxEntry.offset.ToActualOffset(), increIdxEntry.size, err) } - dst.Write(needleBytes) + dstDatBackend.Append(needleBytes) util.Uint32toBytes(idxEntryBytes[8:12], uint32(offset/NeedlePaddingSize)) } else { //deleted needle //fakeDelNeedle 's default Data field is nil