diff --git a/weed-fs/src/cmd/weed/fix.go b/weed-fs/src/cmd/weed/fix.go index e75bfa2f6..ef717a6b3 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.go index 2333588c1..28dfbbed6 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.go index c606ca811..4ada4e734 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 *NeedleMap replicaType ReplicationType - - version uint8 + version Version accessLock 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 error if 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") }