From 4b5ba4927fa4d130d9badbd506195fa0cd7e9168 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 29 Oct 2019 22:37:36 -0700 Subject: [PATCH] adjust NewDiskFile() paramaters --- unmaintained/change_superblock/change_superblock.go | 2 +- unmaintained/fix_dat/fix_dat.go | 2 +- .../remove_duplicate_fids/remove_duplicate_fids.go | 2 +- weed/storage/backend/disk_file.go | 4 ++-- weed/storage/needle/needle_read_write_test.go | 2 +- weed/storage/volume_loading.go | 2 +- weed/storage/volume_super_block.go | 2 +- weed/storage/volume_vacuum.go | 8 ++++---- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/unmaintained/change_superblock/change_superblock.go b/unmaintained/change_superblock/change_superblock.go index 754b0b5e2..04db7cfc1 100644 --- a/unmaintained/change_superblock/change_superblock.go +++ b/unmaintained/change_superblock/change_superblock.go @@ -48,7 +48,7 @@ func main() { if err != nil { glog.Fatalf("Open Volume Data File [ERROR]: %v", err) } - datBackend := backend.NewDiskFile(*fixVolumePath, datFile) + datBackend := backend.NewDiskFile(datFile) defer datBackend.Close() superBlock, err := storage.ReadSuperBlock(datBackend) diff --git a/unmaintained/fix_dat/fix_dat.go b/unmaintained/fix_dat/fix_dat.go index 1ad560a7d..e88a48c96 100644 --- a/unmaintained/fix_dat/fix_dat.go +++ b/unmaintained/fix_dat/fix_dat.go @@ -50,7 +50,7 @@ func main() { if err != nil { glog.Fatalf("Read Volume Data %v", err) } - datBackend := backend.NewDiskFile(datFileName, datFile) + datBackend := backend.NewDiskFile(datFile) defer datBackend.Close() newDatFile, err := os.Create(path.Join(*fixVolumePath, fileName+".dat_fixed")) diff --git a/unmaintained/remove_duplicate_fids/remove_duplicate_fids.go b/unmaintained/remove_duplicate_fids/remove_duplicate_fids.go index 5eeb7e1c8..d44bc5354 100644 --- a/unmaintained/remove_duplicate_fids/remove_duplicate_fids.go +++ b/unmaintained/remove_duplicate_fids/remove_duplicate_fids.go @@ -50,7 +50,7 @@ func (scanner *VolumeFileScanner4SeeDat) VisitNeedle(n *needle.Needle, offset in if err != nil { glog.Fatalf("Write New Volume Data %v", err) } - scanner.datBackend = backend.NewDiskFile(newFileName, newDatFile) + scanner.datBackend = backend.NewDiskFile(newDatFile) scanner.datBackend.WriteAt(scanner.block.Bytes(), 0) } diff --git a/weed/storage/backend/disk_file.go b/weed/storage/backend/disk_file.go index 7c8616cf6..7f2b39d15 100644 --- a/weed/storage/backend/disk_file.go +++ b/weed/storage/backend/disk_file.go @@ -14,9 +14,9 @@ type DiskFile struct { fullFilePath string } -func NewDiskFile(fullFilePath string, f *os.File) *DiskFile { +func NewDiskFile(f *os.File) *DiskFile { return &DiskFile{ - fullFilePath: fullFilePath, + fullFilePath: f.Name(), File: f, } } diff --git a/weed/storage/needle/needle_read_write_test.go b/weed/storage/needle/needle_read_write_test.go index 7b05d5d10..47582dd26 100644 --- a/weed/storage/needle/needle_read_write_test.go +++ b/weed/storage/needle/needle_read_write_test.go @@ -55,7 +55,7 @@ func TestAppend(t *testing.T) { os.Remove(tempFile.Name()) }() - datBackend := backend.NewDiskFile(tempFile.Name(), tempFile) + datBackend := backend.NewDiskFile(tempFile) defer datBackend.Close() offset, _, _, _ := n.Append(datBackend, CurrentVersion) diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index 41cd017cb..e769321c4 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -50,7 +50,7 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind return fmt.Errorf("Volume Data file %s.dat does not exist.", fileName) } } - v.DataBackend = backend.NewDiskFile(fileName+".dat", dataFile) + v.DataBackend = backend.NewDiskFile(dataFile) if e != nil { if !os.IsPermission(e) { diff --git a/weed/storage/volume_super_block.go b/weed/storage/volume_super_block.go index fe357a988..6faf34ef3 100644 --- a/weed/storage/volume_super_block.go +++ b/weed/storage/volume_super_block.go @@ -98,7 +98,7 @@ func (v *Volume) maybeWriteSuperBlock() error { //read-only, but zero length - recreate it! var dataFile *os.File if dataFile, e = os.Create(v.DataBackend.String()); e == nil { - v.DataBackend = backend.NewDiskFile(v.DataBackend.String(), dataFile) + v.DataBackend = backend.NewDiskFile(dataFile) if _, e = v.DataBackend.WriteAt(v.SuperBlock.Bytes(), 0); e == nil { v.readOnly = false } diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go index bf83c4372..9619c9fa3 100644 --- a/weed/storage/volume_vacuum.go +++ b/weed/storage/volume_vacuum.go @@ -147,7 +147,7 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI defer oldIdxFile.Close() oldDatFile, err := os.Open(oldDatFileName) - oldDatBackend := backend.NewDiskFile(oldDatFileName, oldDatFile) + oldDatBackend := backend.NewDiskFile(oldDatFile) defer oldDatBackend.Close() if indexSize, err = verifyIndexFileIntegrity(oldIdxFile); err != nil { @@ -198,7 +198,7 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI if dst, err = os.OpenFile(newDatFileName, os.O_RDWR, 0644); err != nil { return fmt.Errorf("open dat file %s failed: %v", newDatFileName, err) } - dstDatBackend := backend.NewDiskFile(newDatFileName, dst) + dstDatBackend := backend.NewDiskFile(dst) defer dstDatBackend.Close() if idx, err = os.OpenFile(newIdxFileName, os.O_RDWR, 0644); err != nil { @@ -328,7 +328,7 @@ func (v *Volume) copyDataAndGenerateIndexFile(dstName, idxName string, prealloca v: v, now: uint64(time.Now().Unix()), nm: NewBtreeNeedleMap(idx), - dstBackend: backend.NewDiskFile(dstName, dst), + dstBackend: backend.NewDiskFile(dst), writeThrottler: util.NewWriteThrottler(compactionBytePerSecond), } err = ScanVolumeFile(v.dir, v.Collection, v.Id, v.needleMapKind, scanner) @@ -342,7 +342,7 @@ func (v *Volume) copyDataBasedOnIndexFile(dstName, idxName string) (err error) { if dst, err = os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil { return } - dstDatBackend := backend.NewDiskFile(dstName, dst) + dstDatBackend := backend.NewDiskFile(dst) defer dstDatBackend.Close() if idx, err = os.OpenFile(idxName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {