Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

drop PutMany now that batching exist #4

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// BoltDatastore implements ds.Datastore
// TODO: use buckets to represent the heirarchy of the ds.Keys
// TODO: use buckets to represent the hierarchy of the ds.Keys
type BoltDatastore struct {
db *bolt.DB
bucketName []byte
Expand Down Expand Up @@ -105,23 +105,6 @@ func (bd *BoltDatastore) Put(key ds.Key, val []byte) error {
})
}

func (bd *BoltDatastore) PutMany(data map[ds.Key]interface{}) error {
return bd.db.Update(func(tx *bolt.Tx) error {
buck := tx.Bucket(bd.bucketName)
for k, v := range data {
bval, ok := v.([]byte)
if !ok {
return ds.ErrInvalidType
}
err := buck.Put(k.Bytes(), bval)
if err != nil {
return err
}
}
return nil
})
}

func (bd *BoltDatastore) Query(q query.Query) (query.Results, error) {
// Special case order by key.
orders := q.Orders
Expand Down
32 changes: 0 additions & 32 deletions datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,3 @@ func BenchmarkPut(b *testing.B) {
}
b.StopTimer()
}

func BenchmarkPutMany(b *testing.B) {
b.StopTimer()
path, err := ioutil.TempDir("/tmp", "boltdbtest")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(path)
db, err := NewBoltDatastore(path, "test", false)
if err != nil {
b.Fatal(err)
}
defer db.Close()

values := make(map[string][]byte)
for i := 0; i < b.N; i++ {
values[fmt.Sprint(i)] = []byte(fmt.Sprintf("value number %d", i))
}

b.StartTimer()

data := make(map[ds.Key]interface{})
for k, v := range values {
dsk := ds.NewKey(k)
data[dsk] = v
}
err = db.PutMany(data)
if err != nil {
b.Fatal(err)
}
b.StopTimer()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/ipfs/go-ds-bolt

require (
github.com/boltdb/bolt v1.3.1
github.com/ipfs/go-datastore v0.1.0
github.com/ipfs/go-datastore v0.1.1
github.com/jbenet/goprocess v0.1.3
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/ipfs/go-datastore v0.1.0 h1:TOxI04l8CmO4zGtesENhzm4PwkFwJXY3rKiYaaMf9fI=
github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-datastore v0.1.1 h1:F4k0TkTAZGLFzBOrVKDAvch6JZtuN4NHkfdcEZL50aI=
github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw=
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5fcGNuQzp6IGzYQSenLEgH3s6jkXrWw=
Expand Down