diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2018-05-22 10:20:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-22 10:20:50 -0700 |
| commit | 147665e9a6890a175dd5b008b6b2a78b0ba20812 (patch) | |
| tree | 4b60efec0ffd2a5ba8088aa59033cdffb7cf6909 | |
| parent | 04c2c5e58d1ea1cd83907e16dbcee979f98371e3 (diff) | |
| parent | 88d608b661b092446b8512c2c8c7c74b191f1c25 (diff) | |
| download | seaweedfs-147665e9a6890a175dd5b008b6b2a78b0ba20812.tar.xz seaweedfs-147665e9a6890a175dd5b008b6b2a78b0ba20812.zip | |
Merge pull request #657 from chrislusf/master
Master
| -rw-r--r-- | weed/storage/needle_map_boltdb.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/weed/storage/needle_map_boltdb.go b/weed/storage/needle_map_boltdb.go index 96c29cab6..cd15607bb 100644 --- a/weed/storage/needle_map_boltdb.go +++ b/weed/storage/needle_map_boltdb.go @@ -75,8 +75,8 @@ func generateBoltDbFile(dbFileName string, indexFile *os.File) error { } func (m *BoltDbNeedleMap) Get(key uint64) (element *needle.NeedleValue, ok bool) { + var offset, size uint32 bytes := make([]byte, 8) - var data []byte util.Uint64toBytes(bytes, key) err := m.db.View(func(tx *bolt.Tx) error { bucket := tx.Bucket(boltdbBucket) @@ -84,15 +84,22 @@ func (m *BoltDbNeedleMap) Get(key uint64) (element *needle.NeedleValue, ok bool) return fmt.Errorf("Bucket %q not found!", boltdbBucket) } - data = bucket.Get(bytes) + data := bucket.Get(bytes) + + if len(data) != 8 { + glog.V(0).Infof("wrong data length: %d", len(data)) + return fmt.Errorf("wrong data length: %d", len(data)) + } + + offset = util.BytesToUint32(data[0:4]) + size = util.BytesToUint32(data[4:8]) + return nil }) - if err != nil || len(data) != 8 { + if err != nil { return nil, false } - offset := util.BytesToUint32(data[0:4]) - size := util.BytesToUint32(data[4:8]) return &needle.NeedleValue{Key: needle.Key(key), Offset: offset, Size: size}, true } |
