diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-05-22 10:19:44 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-05-22 10:19:44 -0700 |
| commit | 88d608b661b092446b8512c2c8c7c74b191f1c25 (patch) | |
| tree | 4b60efec0ffd2a5ba8088aa59033cdffb7cf6909 | |
| parent | 03fd66e209a0a8c2c5c854e72ab9ba6182497eef (diff) | |
| download | seaweedfs-88d608b661b092446b8512c2c8c7c74b191f1c25.tar.xz seaweedfs-88d608b661b092446b8512c2c8c7c74b191f1c25.zip | |
avoid using the bytes out side of the transaction
fix https://github.com/chrislusf/seaweedfs/issues/656
| -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 } |
