mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-18 06:30:07 +08:00
refactor: simplifying to ReadAt() and WriteAt()
This commit is contained in:
parent
46ed2ca902
commit
7a51a9a582
@ -154,7 +154,7 @@ func (n *Needle) Append(w *os.File, version Version) (offset uint64, size uint32
|
||||
if exists {
|
||||
mMap.WriteMemory(offset, uint64(len(bytesToWrite)), bytesToWrite)
|
||||
} else {
|
||||
_, err = w.Write(bytesToWrite)
|
||||
_, err = w.WriteAt(bytesToWrite, int64(offset))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func (v *Volume) maybeWriteSuperBlock() error {
|
||||
}
|
||||
if stat.Size() == 0 {
|
||||
v.SuperBlock.version = needle.CurrentVersion
|
||||
_, e = v.dataFile.Write(v.SuperBlock.Bytes())
|
||||
_, e = v.dataFile.WriteAt(v.SuperBlock.Bytes(), 0)
|
||||
if e != nil && os.IsPermission(e) {
|
||||
//read-only, but zero length - recreate it!
|
||||
if v.dataFile, e = os.Create(v.dataFile.Name()); e == nil {
|
||||
@ -123,11 +123,7 @@ func ReadSuperBlock(dataFile *os.File) (superBlock SuperBlock, err error) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, err = dataFile.Seek(0, 0); err != nil {
|
||||
err = fmt.Errorf("cannot seek to the beginning of %s: %v", dataFile.Name(), err)
|
||||
return
|
||||
}
|
||||
if _, e := dataFile.Read(header); e != nil {
|
||||
if _, e := dataFile.ReadAt(header, 0); e != nil {
|
||||
err = fmt.Errorf("cannot read volume %s super block: %v", dataFile.Name(), e)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user