Skip to content

Commit

Permalink
Bump Badger version to v3.2011.1
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Feb 7, 2021
1 parent a0963fd commit 2247327
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 14 deletions.
35 changes: 23 additions & 12 deletions 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/v2"
"github.com/dgraph-io/badger/v3"
"github.com/hashicorp/raft"
)

Expand Down Expand Up @@ -252,19 +252,30 @@ func (b *BadgerStore) StoreLog(log *raft.Log) error {

// StoreLogs stores a set of raft logs.
func (b *BadgerStore) StoreLogs(logs []*raft.Log) error {
return b.conn.Update(func(txn *badger.Txn) error {
for _, log := range logs {
key := append(prefixLogs, uint64ToBytes(log.Index)...)
val, err := encodeMsgPack(log)
if err != nil {
return err
}
if err := txn.Set(key, val.Bytes()); err != nil {
return err
// we manage the transaction manually in order to avoid ErrTxnTooBig errors
txn := b.conn.NewTransaction(true)
for i, log := range logs {
key := append(prefixLogs, uint64ToBytes(log.Index)...)
val, err := encodeMsgPack(log)
if err != nil {
return err
}
if err := txn.Set(key, val.Bytes()); err != nil {
if err == badger.ErrTxnTooBig {
err = txn.Commit()
if err != nil {
return err
}
return b.StoreLogs(logs[i:])
}
return err
}
return nil
})
}
err := txn.Commit()
if err != nil {
return err
}
return nil
}

// DeleteRange deletes logs within a given range inclusively.
Expand Down
2 changes: 1 addition & 1 deletion badger_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"reflect"
"testing"

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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.14

require (
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/dgraph-io/badger/v2 v2.0.3
github.com/dgraph-io/badger/v3 v3.2011.1
github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b // indirect
github.com/hashicorp/go-msgpack v0.5.5
github.com/hashicorp/raft v1.1.1
Expand Down
Loading

0 comments on commit 2247327

Please sign in to comment.