From 9af9f36b8934ecb62215e24888d72902769de3fe Mon Sep 17 00:00:00 2001 From: xushuxun Date: Wed, 21 Aug 2019 11:26:01 +0800 Subject: [PATCH 1/2] volume: read dat files' last modified time no matter dat files are catWrite or readonly --- weed/storage/volume_loading.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index ed1cfe124..0b6021ca8 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -31,12 +31,12 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind } if canWrite { v.dataFile, e = os.OpenFile(fileName+".dat", os.O_RDWR|os.O_CREATE, 0644) - v.lastModifiedTsSeconds = uint64(modifiedTime.Unix()) } else { glog.V(0).Infoln("opening " + fileName + ".dat in READONLY mode") v.dataFile, e = os.Open(fileName + ".dat") v.readOnly = true } + v.lastModifiedTsSeconds = uint64(modifiedTime.Unix()) if fileSize >= _SuperBlockSize { alreadyHasSuperBlock = true } From 35d471a8183f0e6ce9502bdcbec94b040463f002 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 23 Aug 2019 07:59:09 -0700 Subject: [PATCH 2/2] Revert "use std encoding lib" --- go.mod | 1 - weed/util/bytes.go | 33 ++++------------------ weed/util/bytes_test.go | 62 ----------------------------------------- 3 files changed, 6 insertions(+), 90 deletions(-) delete mode 100644 weed/util/bytes_test.go diff --git a/go.mod b/go.mod index d12efece7..684db68cc 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/disintegration/imaging v1.6.0 github.com/dustin/go-humanize v1.0.0 github.com/gabriel-vasile/mimetype v0.3.15 - github.com/go-logfmt/logfmt v0.4.0 // indirect github.com/go-redis/redis v6.15.2+incompatible github.com/go-sql-driver/mysql v1.4.1 github.com/gocql/gocql v0.0.0-20190717234527-2ba2dd7440dc diff --git a/weed/util/bytes.go b/weed/util/bytes.go index 68279cefc..dfa4ae665 100644 --- a/weed/util/bytes.go +++ b/weed/util/bytes.go @@ -1,10 +1,8 @@ package util -import "encoding/binary" - // big endian -func BytesToUint64Old(b []byte) (v uint64) { +func BytesToUint64(b []byte) (v uint64) { length := uint(len(b)) for i := uint(0); i < length-1; i++ { v += uint64(b[i]) @@ -13,7 +11,7 @@ func BytesToUint64Old(b []byte) (v uint64) { v += uint64(b[length-1]) return } -func BytesToUint32Old(b []byte) (v uint32) { +func BytesToUint32(b []byte) (v uint32) { length := uint(len(b)) for i := uint(0); i < length-1; i++ { v += uint32(b[i]) @@ -22,45 +20,26 @@ func BytesToUint32Old(b []byte) (v uint32) { v += uint32(b[length-1]) return } -func BytesToUint16Old(b []byte) (v uint16) { +func BytesToUint16(b []byte) (v uint16) { v += uint16(b[0]) v <<= 8 v += uint16(b[1]) return } -func Uint64toBytesOld(b []byte, v uint64) { +func Uint64toBytes(b []byte, v uint64) { for i := uint(0); i < 8; i++ { b[7-i] = byte(v >> (i * 8)) } } -func Uint32toBytesOld(b []byte, v uint32) { +func Uint32toBytes(b []byte, v uint32) { for i := uint(0); i < 4; i++ { b[3-i] = byte(v >> (i * 8)) } } -func Uint16toBytesOld(b []byte, v uint16) { +func Uint16toBytes(b []byte, v uint16) { b[0] = byte(v >> 8) b[1] = byte(v) } - -func BytesToUint64(b []byte) (v uint64) { - return binary.BigEndian.Uint64(b) -} -func BytesToUint32(b []byte) (v uint32) { - return binary.BigEndian.Uint32(b) -} -func BytesToUint16(b []byte) (v uint16) { - return binary.BigEndian.Uint16(b) -} -func Uint64toBytes(b []byte, v uint64) { - binary.BigEndian.PutUint64(b, v) -} -func Uint32toBytes(b []byte, v uint32) { - binary.BigEndian.PutUint32(b, v) -} -func Uint16toBytes(b []byte, v uint16) { - binary.BigEndian.PutUint16(b, v) -} func Uint8toBytes(b []byte, v uint8) { b[0] = byte(v) } diff --git a/weed/util/bytes_test.go b/weed/util/bytes_test.go deleted file mode 100644 index 4e6b3f294..000000000 --- a/weed/util/bytes_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package util - -import ( - "reflect" - "testing" -) - -// go test github.com/chrislusf/seaweedfs/weed/util -run '^(TestAll)$' -v - -func TestAll(t *testing.T) { - for i := 0; i <= 0xff; i += 7 { - assertU16(t, uint16(i)) - } - for i := 0; i <= 0xffff; i += 211 { - assertU32(t, uint32(i)) - } - for i := 0; i <= 0xffffffff; i += 1000000007 { - assertU64(t, uint64(i)) - } -} - -func assertU16(t *testing.T, i uint16) { - var buf1, buf2 [2]byte - Uint16toBytesOld(buf1[:], i) - Uint16toBytes(buf2[:], i) - if !reflect.DeepEqual(buf1, buf2) { - t.Errorf("i: %d, buf1: %v, buf2: %v\n", i, buf1, buf2) - } - v1 := BytesToUint16Old(buf1[:]) - v2 := BytesToUint16(buf2[:]) - if v1 != v2 { - t.Errorf("buf1: %v, v1: %d, buf2: %v, v2: %d\n", buf1, v1, buf2, v2) - } -} - -func assertU32(t *testing.T, i uint32) { - var buf1, buf2 [4]byte - Uint32toBytesOld(buf1[:], i) - Uint32toBytes(buf2[:], i) - if !reflect.DeepEqual(buf1, buf2) { - t.Errorf("i: %d, buf1: %v, buf2: %v\n", i, buf1, buf2) - } - v1 := BytesToUint32Old(buf1[:]) - v2 := BytesToUint32(buf2[:]) - if v1 != v2 { - t.Errorf("buf1: %v, v1: %d, buf2: %v, v2: %d\n", buf1, v1, buf2, v2) - } -} - -func assertU64(t *testing.T, i uint64) { - var buf1, buf2 [8]byte - Uint64toBytesOld(buf1[:], i) - Uint64toBytes(buf2[:], i) - if !reflect.DeepEqual(buf1, buf2) { - t.Errorf("i: %d, buf1: %v, buf2: %v\n", i, buf1, buf2) - } - v1 := BytesToUint64Old(buf1[:]) - v2 := BytesToUint64(buf2[:]) - if v1 != v2 { - t.Errorf("buf1: %v, v1: %d, buf2: %v, v2: %d\n", buf1, v1, buf2, v2) - } -}