SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
skip seek() when index file writes
Chris Lu1ad3200094bc
diff --git a/weed/storage/needle/needle_read_write.go b/weed/storage/needle/needle_read_write.goindex e758a6fee1..0f72bc0bb2 100644--- a/weed/storage/needle/needle_read_write.go+++ b/weed/storage/needle/needle_read_write.go@@ -161,7 +161,15 @@ func ReadNeedleBlob(r backend.BackendStorageFile, offset int64, size Size, versidataSize := GetActualSize(size, version)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}diff --git a/weed/storage/needle_map.go b/weed/storage/needle_map.goindex 5b41286ea8..d35391f66d 100644--- a/weed/storage/needle_map.go+++ b/weed/storage/needle_map.go@@ -1,7 +1,6 @@package storageimport (- "fmt""io""os""sync"@@ -41,6 +40,7 @@ type baseNeedleMapper struct {indexFile *os.FileindexFileAccessLock sync.Mutex+ indexFileOffset int64}func (nm *baseNeedleMapper) IndexFileSize() uint64 {@@ -56,11 +56,10 @@ func (nm *baseNeedleMapper) appendToIndexFile(key NeedleId, offset Offset, sizenm.indexFileAccessLock.Lock()defer nm.indexFileAccessLock.Unlock()- if _, err := nm.indexFile.Seek(0, 2); err != nil {- return fmt.Errorf("cannot seek end of indexfile %s: %v",- nm.indexFile.Name(), err)+ written, err := nm.indexFile.WriteAt(bytes, nm.indexFileOffset)+ if err == nil {+ nm.indexFileOffset += int64(written)}- _, err := nm.indexFile.Write(bytes)return err}diff --git a/weed/storage/needle_map_leveldb.go b/weed/storage/needle_map_leveldb.goindex 415cd14dd0..9716e97290 100644--- a/weed/storage/needle_map_leveldb.go+++ b/weed/storage/needle_map_leveldb.go@@ -31,6 +31,11 @@ func NewLevelDbNeedleMap(dbFileName string, indexFile *os.File, opts *opt.OptiongenerateLevelDbFile(dbFileName, indexFile)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)if m.db, err = leveldb.OpenFile(dbFileName, opts); err != nil {diff --git a/weed/storage/needle_map_memory.go b/weed/storage/needle_map_memory.goindex d0891dc98d..1b58708c61 100644--- a/weed/storage/needle_map_memory.go+++ b/weed/storage/needle_map_memory.go@@ -19,6 +19,11 @@ func NewCompactNeedleMap(file *os.File) *NeedleMap {m: needle_map.NewCompactMap(),}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}