mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
skip seek() when index file writes
This commit is contained in:
parent
98c93ca465
commit
1ad3200094
|
@ -161,7 +161,15 @@ func ReadNeedleBlob(r backend.BackendStorageFile, offset int64, size Size, versi
|
||||||
dataSize := GetActualSize(size, version)
|
dataSize := GetActualSize(size, version)
|
||||||
dataSlice = make([]byte, int(dataSize))
|
dataSlice = make([]byte, int(dataSize))
|
||||||
|
|
||||||
_, err = r.ReadAt(dataSlice, offset)
|
var n int
|
||||||
|
n, err = r.ReadAt(dataSlice, offset)
|
||||||
|
if err != nil && int64(n) == dataSize {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fileSize, _, _ := r.GetStat()
|
||||||
|
println("n",n, "dataSize", dataSize, "offset", offset, "fileSize", fileSize)
|
||||||
|
}
|
||||||
return dataSlice, err
|
return dataSlice, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -41,6 +40,7 @@ type baseNeedleMapper struct {
|
||||||
|
|
||||||
indexFile *os.File
|
indexFile *os.File
|
||||||
indexFileAccessLock sync.Mutex
|
indexFileAccessLock sync.Mutex
|
||||||
|
indexFileOffset int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nm *baseNeedleMapper) IndexFileSize() uint64 {
|
func (nm *baseNeedleMapper) IndexFileSize() uint64 {
|
||||||
|
@ -56,11 +56,10 @@ func (nm *baseNeedleMapper) appendToIndexFile(key NeedleId, offset Offset, size
|
||||||
|
|
||||||
nm.indexFileAccessLock.Lock()
|
nm.indexFileAccessLock.Lock()
|
||||||
defer nm.indexFileAccessLock.Unlock()
|
defer nm.indexFileAccessLock.Unlock()
|
||||||
if _, err := nm.indexFile.Seek(0, 2); err != nil {
|
written, err := nm.indexFile.WriteAt(bytes, nm.indexFileOffset)
|
||||||
return fmt.Errorf("cannot seek end of indexfile %s: %v",
|
if err == nil {
|
||||||
nm.indexFile.Name(), err)
|
nm.indexFileOffset += int64(written)
|
||||||
}
|
}
|
||||||
_, err := nm.indexFile.Write(bytes)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,11 @@ func NewLevelDbNeedleMap(dbFileName string, indexFile *os.File, opts *opt.Option
|
||||||
generateLevelDbFile(dbFileName, indexFile)
|
generateLevelDbFile(dbFileName, indexFile)
|
||||||
glog.V(1).Infof("Finished Generating %s from %s", dbFileName, indexFile.Name())
|
glog.V(1).Infof("Finished Generating %s from %s", dbFileName, indexFile.Name())
|
||||||
}
|
}
|
||||||
|
if stat, err := indexFile.Stat(); err != nil {
|
||||||
|
glog.Fatalf("stat file %s: %v", indexFile.Name(), err)
|
||||||
|
} else {
|
||||||
|
m.indexFileOffset = stat.Size()
|
||||||
|
}
|
||||||
glog.V(1).Infof("Opening %s...", dbFileName)
|
glog.V(1).Infof("Opening %s...", dbFileName)
|
||||||
|
|
||||||
if m.db, err = leveldb.OpenFile(dbFileName, opts); err != nil {
|
if m.db, err = leveldb.OpenFile(dbFileName, opts); err != nil {
|
||||||
|
|
|
@ -19,6 +19,11 @@ func NewCompactNeedleMap(file *os.File) *NeedleMap {
|
||||||
m: needle_map.NewCompactMap(),
|
m: needle_map.NewCompactMap(),
|
||||||
}
|
}
|
||||||
nm.indexFile = file
|
nm.indexFile = file
|
||||||
|
stat, err := file.Stat()
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("stat file %s: %v", file.Name(), err)
|
||||||
|
}
|
||||||
|
nm.indexFileOffset = stat.Size()
|
||||||
return nm
|
return nm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue