aboutsummaryrefslogtreecommitdiff
path: root/go/storage/needle_map_boltdb.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/storage/needle_map_boltdb.go')
-rw-r--r--go/storage/needle_map_boltdb.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/go/storage/needle_map_boltdb.go b/go/storage/needle_map_boltdb.go
index e95c016bb..a17e6ccf6 100644
--- a/go/storage/needle_map_boltdb.go
+++ b/go/storage/needle_map_boltdb.go
@@ -1,13 +1,12 @@
package storage
import (
+ "encoding/binary"
"fmt"
"os"
"github.com/boltdb/bolt"
-
"github.com/chrislusf/seaweedfs/go/glog"
- "github.com/chrislusf/seaweedfs/go/util"
)
type BoltDbNeedleMap struct {
@@ -75,7 +74,7 @@ func generateBoltDbFile(dbFileName string, indexFile *os.File) error {
func (m *BoltDbNeedleMap) Get(key uint64) (element *NeedleValue, ok bool) {
bytes := make([]byte, 8)
var data []byte
- util.Uint64toBytes(bytes, key)
+ binary.BigEndian.PutUint64(bytes, key)
err := m.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket(boltdbBucket)
if bucket == nil {
@@ -89,8 +88,8 @@ func (m *BoltDbNeedleMap) Get(key uint64) (element *NeedleValue, ok bool) {
if err != nil || len(data) != 8 {
return nil, false
}
- offset := util.BytesToUint32(data[0:4])
- size := util.BytesToUint32(data[4:8])
+ offset := binary.BigEndian.Uint32(data[0:4])
+ size := binary.BigEndian.Uint32(data[4:8])
return &NeedleValue{Key: Key(key), Offset: offset, Size: size}, true
}
@@ -110,9 +109,9 @@ func (m *BoltDbNeedleMap) Put(key uint64, offset uint32, size uint32) error {
func boltDbWrite(db *bolt.DB,
key uint64, offset uint32, size uint32) error {
bytes := make([]byte, 16)
- util.Uint64toBytes(bytes[0:8], key)
- util.Uint32toBytes(bytes[8:12], offset)
- util.Uint32toBytes(bytes[12:16], size)
+ binary.BigEndian.PutUint64(bytes[0:8], key)
+ binary.BigEndian.PutUint32(bytes[8:12], offset)
+ binary.BigEndian.PutUint32(bytes[12:16], size)
return db.Update(func(tx *bolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(boltdbBucket)
if err != nil {
@@ -128,7 +127,7 @@ func boltDbWrite(db *bolt.DB,
}
func boltDbDelete(db *bolt.DB, key uint64) error {
bytes := make([]byte, 8)
- util.Uint64toBytes(bytes, key)
+ binary.BigEndian.PutUint64(bytes, key)
return db.Update(func(tx *bolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(boltdbBucket)
if err != nil {