diff --git a/conn/node_test.go b/conn/node_test.go index 35b7944a8f7..1cbac56ad0a 100644 --- a/conn/node_test.go +++ b/conn/node_test.go @@ -65,7 +65,7 @@ func TestProposal(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) store := raftwal.Init(db, 0, 0) defer store.Closer.SignalAndWait() diff --git a/dgraph/cmd/zero/run.go b/dgraph/cmd/zero/run.go index e72d5b0d197..b188553f546 100644 --- a/dgraph/cmd/zero/run.go +++ b/dgraph/cmd/zero/run.go @@ -297,7 +297,7 @@ func run() { } glog.Infof("Opening zero BadgerDB with options: %+v\n", kvOpt) - kv, err := badger.Open(kvOpt) + kv, err := badger.OpenManaged(kvOpt) x.Checkf(err, "Error while opening WAL store") defer kv.Close() diff --git a/go.mod b/go.mod index f8c611c5326..c337400a31a 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/blevesearch/segment v0.0.0-20160915185041-762005e7a34f // indirect github.com/blevesearch/snowballstem v0.0.0-20180110192139-26b06a2c243d // indirect github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd - github.com/dgraph-io/badger/v2 v2.2007.2-0.20200827131741-d5a25b83fbf4 + github.com/dgraph-io/badger/v2 v2.2007.3-0.20200921170002-6a6b506c7386 github.com/dgraph-io/dgo/v200 v200.0.0-20200401175452-e463f9234453 github.com/dgraph-io/graphql-transport-ws v0.0.0-20200916064635-48589439591b github.com/dgraph-io/ristretto v0.0.4-0.20200904131139-4dec2770af66 diff --git a/go.sum b/go.sum index 83bce13e5ff..0b7d60a4835 100644 --- a/go.sum +++ b/go.sum @@ -70,9 +70,7 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U= github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo= @@ -81,8 +79,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger v1.6.0 h1:DshxFxZWXUcO0xX476VJC07Xsr6ZCBVRHKZ93Oh7Evo= github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= -github.com/dgraph-io/badger/v2 v2.2007.2-0.20200827131741-d5a25b83fbf4 h1:DUDFTVgqZysKplH39/ya0aI4+zGm91L9QttXgITT2YE= -github.com/dgraph-io/badger/v2 v2.2007.2-0.20200827131741-d5a25b83fbf4/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= +github.com/dgraph-io/badger/v2 v2.2007.3-0.20200921170002-6a6b506c7386 h1:n8dsIfgnoDeAuTKxi0gr2uhBFl62ukfA7cykc3nqeyE= +github.com/dgraph-io/badger/v2 v2.2007.3-0.20200921170002-6a6b506c7386/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= github.com/dgraph-io/dgo/v200 v200.0.0-20200401175452-e463f9234453 h1:DTgOrw91nMIukDm/WEvdobPLl0LgeDd/JE66+24jBks= github.com/dgraph-io/dgo/v200 v200.0.0-20200401175452-e463f9234453/go.mod h1:Co+FwJrnndSrPORO8Gdn20dR7FPTfmXr0W/su0Ve/Ig= github.com/dgraph-io/graphql-transport-ws v0.0.0-20200916064635-48589439591b h1:PDEhlwHpkEQ5WBfOOKZCNZTXFDGyCEWTYDhxGQbyIpk= @@ -206,7 +204,6 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -260,7 +257,6 @@ github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007 h1:reVOUXwnhsYv/8UqjvhrMOu5CNT9UapHFLbQ2JcXsmg= github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -367,9 +363,7 @@ github.com/prometheus/procfs v0.0.0-20190517135640-51af30a78b0e h1:zK8d1aZ+gw/Ne github.com/prometheus/procfs v0.0.0-20190517135640-51af30a78b0e/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= @@ -378,7 +372,6 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= @@ -428,16 +421,13 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= -github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e h1:+w0Zm/9gaWpEAyDlU1eKOuk5twTjAjuevXqcJJw8hrg= github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U= github.com/vektah/gqlparser v1.3.1 h1:8b0IcD3qZKWJQHSzynbDlrtP3IxVydZ2DZepCGofqfU= github.com/vektah/gqlparser v1.3.1/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74= @@ -543,7 +533,6 @@ golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589 h1:rjUrONFu4kLchcZTfp3/96bR8bW8dIa8uz3cR5n0cgM= golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/raftwal/storage.go b/raftwal/storage.go index be3e399869e..067395c90f9 100644 --- a/raftwal/storage.go +++ b/raftwal/storage.go @@ -19,6 +19,7 @@ package raftwal import ( "bytes" "encoding/binary" + "fmt" "math" "sync" @@ -34,12 +35,16 @@ import ( "golang.org/x/net/trace" ) +// versionKey is hardcoded into the special key used to fetch the maximum version from the DB. +const versionKey = 1 + // DiskStorage handles disk access and writing for the RAFT write-ahead log. type DiskStorage struct { - db *badger.DB - id uint64 - gid uint32 - elog trace.EventLog + db *badger.DB + commitTs uint64 + id uint64 + gid uint32 + elog trace.EventLog cache *sync.Map Closer *z.Closer @@ -60,6 +65,8 @@ func Init(db *badger.DB, id uint64, gid uint32) *DiskStorage { Closer: z.NewCloser(1), indexRangeChan: make(chan indexRange, 16), } + + w.fetchMaxVersion() if prev, err := RaftId(db); err != nil || prev != id { x.Check(w.StoreRaftId(id)) } @@ -88,6 +95,35 @@ func Init(db *badger.DB, id uint64, gid uint32) *DiskStorage { return w } +// fetchMaxVersion fetches the commitTs to be used in the raftwal. The version is +// fetched from the special key "maxVersion-id" or from db.MaxVersion +// API which uses the stream framework. +func (w *DiskStorage) fetchMaxVersion() { + // This is a special key that is used to fetch the latest version. + key := []byte(fmt.Sprintf("maxVersion-%d", versionKey)) + + txn := w.db.NewTransactionAt(math.MaxUint64, true) + defer txn.Discard() + + item, err := txn.Get(key) + if err == nil { + w.commitTs = item.Version() + return + } + if err == badger.ErrKeyNotFound { + // We don't have the special key so get it using the MaxVersion API. + version, err := w.db.MaxVersion() + x.Check(err) + + w.commitTs = version + 1 + // Insert the same key back into badger for reuse. + x.Check(txn.Set(key, nil)) + x.Check(txn.CommitAt(w.commitTs, nil)) + } else { + x.Check(err) + } +} + func (w *DiskStorage) processIndexRange() { defer w.Closer.Done() @@ -95,7 +131,7 @@ func (w *DiskStorage) processIndexRange() { if r.from == r.until { return } - batch := w.db.NewWriteBatch() + batch := w.db.NewWriteBatchAt(w.commitTs) if err := w.deleteRange(batch, r.from, r.until); err != nil { glog.Errorf("deleteRange failed with error: %v, from: %d, until: %d\n", err, r.from, r.until) @@ -192,9 +228,18 @@ func (w *DiskStorage) entryPrefix() []byte { return b } +func (w *DiskStorage) update(cb func(txn *badger.Txn) error) error { + txn := w.db.NewTransactionAt(math.MaxUint64, true) + defer txn.Discard() + if err := cb(txn); err != nil { + return err + } + return txn.CommitAt(w.commitTs, nil) +} + // StoreRaftId stores the given RAFT ID in disk. func (w *DiskStorage) StoreRaftId(id uint64) error { - return w.db.Update(func(txn *badger.Txn) error { + return w.update(func(txn *badger.Txn) error { var b [8]byte binary.BigEndian.PutUint64(b[:], id) return txn.Set(idKey, b[:]) @@ -203,7 +248,7 @@ func (w *DiskStorage) StoreRaftId(id uint64) error { // UpdateCheckpoint writes the given snapshot to disk. func (w *DiskStorage) UpdateCheckpoint(snap *pb.Snapshot) error { - return w.db.Update(func(txn *badger.Txn) error { + return w.update(func(txn *badger.Txn) error { data, err := snap.Marshal() if err != nil { return err @@ -453,7 +498,7 @@ func (w *DiskStorage) reset(es []raftpb.Entry) error { w.cache = new(sync.Map) // reset cache. // Clean out the state. - batch := w.db.NewWriteBatch() + batch := w.db.NewWriteBatchAt(w.commitTs) defer batch.Cancel() if err := w.deleteFrom(batch, 0); err != nil { @@ -679,7 +724,7 @@ func (w *DiskStorage) CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte snap.Metadata.ConfState = *cs snap.Data = data - batch := w.db.NewWriteBatch() + batch := w.db.NewWriteBatchAt(w.commitTs) defer batch.Cancel() if err := w.setSnapshot(batch, &snap); err != nil { return err @@ -701,7 +746,7 @@ func (w *DiskStorage) CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte // writes then all of them can be written together. Note that when writing an Entry with Index i, // any previously-persisted entries with Index >= i must be discarded. func (w *DiskStorage) Save(h *raftpb.HardState, es []raftpb.Entry, snap *raftpb.Snapshot) error { - batch := w.db.NewWriteBatch() + batch := w.db.NewWriteBatchAt(w.commitTs) defer batch.Cancel() if err := w.addEntries(batch, es); err != nil { diff --git a/raftwal/storage_test.go b/raftwal/storage_test.go index 4b5ab23ee83..d923c9fcc21 100644 --- a/raftwal/storage_test.go +++ b/raftwal/storage_test.go @@ -50,7 +50,7 @@ func TestStorageTerm(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := Init(db, 0, 0) defer ds.Closer.SignalAndWait() @@ -101,7 +101,7 @@ func TestStorageEntries(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := Init(db, 0, 0) defer ds.Closer.SignalAndWait() @@ -147,7 +147,7 @@ func TestStorageLastIndex(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := Init(db, 0, 0) defer ds.Closer.SignalAndWait() @@ -178,7 +178,7 @@ func TestStorageFirstIndex(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := Init(db, 0, 0) defer ds.Closer.SignalAndWait() @@ -194,7 +194,7 @@ func TestStorageFirstIndex(t *testing.T) { t.Errorf("first = %d, want %d", first, 4) } - batch := db.NewWriteBatch() + batch := db.NewWriteBatchAt(ds.commitTs) require.NoError(t, ds.deleteRange(batch, 0, 4)) require.NoError(t, batch.Flush()) ds.cache.Store(firstKey, 0) @@ -212,7 +212,7 @@ func TestStorageCompact(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := Init(db, 0, 0) defer ds.Closer.SignalAndWait() @@ -237,7 +237,7 @@ func TestStorageCompact(t *testing.T) { for i, tt := range tests { first, err := ds.FirstIndex() require.NoError(t, err) - batch := db.NewWriteBatch() + batch := db.NewWriteBatchAt(ds.commitTs) err = ds.deleteRange(batch, first-1, tt.i) require.NoError(t, batch.Flush()) if err != tt.werr { @@ -264,7 +264,7 @@ func TestStorageCreateSnapshot(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := Init(db, 0, 0) defer ds.Closer.SignalAndWait() @@ -302,7 +302,7 @@ func TestStorageAppend(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := badger.Open(badger.DefaultOptions(dir)) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := Init(db, 0, 0) defer ds.Closer.SignalAndWait() @@ -351,7 +351,7 @@ func TestStorageAppend(t *testing.T) { for i, tt := range tests { require.NoError(t, ds.reset(ents)) - batch := db.NewWriteBatch() + batch := db.NewWriteBatchAt(ds.commitTs) err := ds.addEntries(batch, tt.entries) if err != tt.werr { t.Errorf("#%d: err = %v, want %v", i, err, tt.werr) diff --git a/worker/draft_test.go b/worker/draft_test.go index e569feb2a91..a26154d2af7 100644 --- a/worker/draft_test.go +++ b/worker/draft_test.go @@ -56,7 +56,7 @@ func TestCalculateSnapshot(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - db, err := openBadger(dir) + db, err := badger.OpenManaged(badger.DefaultOptions(dir)) require.NoError(t, err) ds := raftwal.Init(db, 0, 0) defer ds.Closer.SignalAndWait() diff --git a/worker/server_state.go b/worker/server_state.go index a9b9f5bce0e..e2e5bc45c05 100644 --- a/worker/server_state.go +++ b/worker/server_state.go @@ -159,7 +159,7 @@ func (s *ServerState) initStorage() { glog.Infof("Opening write-ahead log BadgerDB with options: %+v\n", opt) opt.EncryptionKey = key - s.WALstore, err = badger.Open(opt) + s.WALstore, err = badger.OpenManaged(opt) x.Checkf(err, "Error while creating badger KV WAL store") } {