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
add version type
Chris Lu5e020196f6d8
diff --git a/weed-fs/src/cmd/weed/fix.go b/weed-fs/src/cmd/weed/fix.goindex e75bfa2f67..ef717a6b3e 100644--- a/weed-fs/src/cmd/weed/fix.go+++ b/weed-fs/src/cmd/weed/fix.go@@ -15,8 +15,8 @@ func init() {var cmdFix = &Command{UsageLine: "fix -dir=/tmp -volumeId=234 -debug=1",- Short: "run weed tool fix on data file if corrupted",- Long: `Fix runs the WeedFS fix command on the .dat volume file.+ Short: "run weed tool fix on index file if corrupted",+ Long: `Fix runs the WeedFS fix command to re-create the index .idx file.`,}diff --git a/weed-fs/src/pkg/storage/needle.go b/weed-fs/src/pkg/storage/needle.goindex 2333588c11..28dfbbed69 100644--- a/weed-fs/src/pkg/storage/needle.go+++ b/weed-fs/src/pkg/storage/needle.go@@ -15,10 +15,15 @@ import ()type Needle struct {- Cookie uint32 "random number to mitigate brute force lookups"- Id uint64 "needle id"- Size uint32 "Data size"- Data []byte "The actual file data"+ Cookie uint32 "random number to mitigate brute force lookups"+ Id uint64 "needle id"+ Size uint32 "sum of DataSize,Data,NameSize,Name,MimeSize,Mime"+ // DataSize uint32 "Data size"+ Data []byte "The actual file data"+ // NameSize uint16+ // Name []byte "maximum 256 characters"+ // MimeSize uint16+ // Mime []byte "maximum 256 characters"Checksum CRC "CRC32 to check integrity"Padding []byte "Aligned to 8 bytes"}@@ -97,7 +102,7 @@ func (n *Needle) Append(w io.Writer) uint32 {w.Write(header[0 : rest+4])return n.Size}-func (n *Needle) Read(r io.Reader, size uint32) (int, error) {+func (n *Needle) Read(r io.Reader, size uint32, version Version) (int, error) {bytes := make([]byte, size+16+4)ret, e := r.Read(bytes)n.Cookie = util.BytesToUint32(bytes[0:4])diff --git a/weed-fs/src/pkg/storage/volume.go b/weed-fs/src/pkg/storage/volume.goindex c606ca811b..4ada4e734a 100644--- a/weed-fs/src/pkg/storage/volume.go+++ b/weed-fs/src/pkg/storage/volume.go@@ -9,9 +9,11 @@ import ("sync")+type Version uint8+const (SuperBlockSize = 8- Version = 1+ CurrentVersion = Version(1))type Volume struct {@@ -21,8 +23,7 @@ type Volume struct {nm *NeedleMapreplicaType ReplicationType-- version uint8+ version VersionaccessLock sync.Mutex}@@ -68,7 +69,7 @@ func (v *Volume) maybeWriteSuperBlock() {stat, _ := v.dataFile.Stat()if stat.Size() == 0 {header := make([]byte, SuperBlockSize)- header[0] = Version+ header[0] = byte(CurrentVersion)header[1] = v.replicaType.Byte()v.dataFile.Write(header)}@@ -79,7 +80,7 @@ func (v *Volume) readSuperBlock() error {if _, e := v.dataFile.Read(header); e != nil {return fmt.Errorf("cannot read superblock: %s", e)}- v.version = header[0]+ v.version = Version(header[0])var err errorif v.replicaType, err = NewReplicationTypeFromByte(header[1]); err != nil {return fmt.Errorf("cannot read replica type: %s", err)@@ -120,7 +121,7 @@ func (v *Volume) read(n *Needle) (int, error) {nv, ok := v.nm.Get(n.Id)if ok && nv.Offset > 0 {v.dataFile.Seek(int64(nv.Offset)*8, 0)- return n.Read(v.dataFile, nv.Size)+ return n.Read(v.dataFile, nv.Size, v.version)}return -1, errors.New("Not Found")}