Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use badger v4 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion badger_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"errors"
"time"

"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v4"
"github.com/hashicorp/raft"
)

Expand Down
5 changes: 2 additions & 3 deletions badger_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ package raftbadger

import (
"bytes"
"io/ioutil"
"os"
"reflect"
"testing"

"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v4"
"github.com/hashicorp/raft"
)

func testBadgerStore(t testing.TB) (*BadgerStore, string) {
path, err := ioutil.TempDir("", "raftbadger")
path, err := os.MkdirTemp("", "raftbadger")
if err != nil {
t.Fatalf("err. %s", err)
}
Expand Down
69 changes: 69 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"testing"

"github.com/hashicorp/raft"
raftbench "github.com/hashicorp/raft/bench"
)

Expand Down Expand Up @@ -122,3 +123,71 @@ func BenchmarkBadgerStore_GetUint64(b *testing.B) {

raftbench.GetUint64(b, store)
}

func BenchmarkSet(b *testing.B) {
store, path := testBadgerStore(b)
defer func() {
store.Close()
os.RemoveAll(path)
}()

for n := 0; n < b.N; n++ {
store.Set(uint64ToBytes(uint64(n)), []byte("val"))
}
}

func BenchmarkGet(b *testing.B) {
store, path := testBadgerStore(b)
defer func() {
store.Close()
os.RemoveAll(path)
}()

for n := 0; n < b.N; n++ {
store.Set(uint64ToBytes(uint64(n)), []byte("val"))
}

b.ResetTimer()
for n := 0; n < b.N; n++ {
store.Get(uint64ToBytes(uint64(n)))
}
}

func BenchmarkStoreLogs(b *testing.B) {
store, path := testBadgerStore(b)
defer func() {
store.Close()
os.RemoveAll(path)
}()
for n := 0; n < b.N; n++ {
store.StoreLogs([]*raft.Log{
{
Index: uint64(n),
Term: uint64(n),
},
})
}
}

func BenchmarkGetLog(b *testing.B) {
store, path := testBadgerStore(b)
defer func() {
store.Close()
os.RemoveAll(path)
}()
for n := 0; n < b.N; n++ {
store.StoreLogs([]*raft.Log{
{
Index: uint64(n),
Term: uint64(n),
},
})
}

b.ResetTimer()

ralog := new(raft.Log)
for n := 0; n < b.N; n++ {
store.GetLog(uint64(n), ralog)
}
}
33 changes: 28 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
module github.com/BBVA/raft-badger

go 1.14
go 1.19

require (
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/dgraph-io/badger/v3 v3.2011.1
github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b // indirect
github.com/dgraph-io/badger/v4 v4.1.0
github.com/hashicorp/go-msgpack v0.5.5
github.com/hashicorp/raft v1.1.1
github.com/hashicorp/raft v1.5.0
)

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/pkg/errors v0.9.1 // indirect
go.opencensus.io v0.22.5 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
)
Loading