Skip to content

Commit

Permalink
Vendor badger with the latest changes. (dgraph-io#3606)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr authored and dna2github committed Jul 19, 2019
1 parent 6530be7 commit 7d253e9
Show file tree
Hide file tree
Showing 38 changed files with 628 additions and 344 deletions.
10 changes: 1 addition & 9 deletions conn/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ import (
"golang.org/x/net/context"
)

func openBadger(dir string) (*badger.DB, error) {
opt := badger.DefaultOptions
opt.Dir = dir
opt.ValueDir = dir

return badger.Open(opt)
}

func (n *Node) run(wg *sync.WaitGroup) {
ticker := time.NewTicker(20 * time.Millisecond)
defer ticker.Stop()
Expand Down Expand Up @@ -73,7 +65,7 @@ func TestProposal(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
store := raftwal.Init(db, 0, 0)

Expand Down
10 changes: 3 additions & 7 deletions dgraph/cmd/bulk/reduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ func (r *reducer) run() error {
}

func (r *reducer) createBadger(i int) *badger.DB {
opt := badger.DefaultOptions
opt.SyncWrites = false
opt.TableLoadingMode = bo.MemoryMap
opt.ValueThreshold = 1 << 10 // 1 KB.
opt.Dir = r.opt.shardOutputDirs[i]
opt.ValueDir = opt.Dir
opt.Logger = nil
opt := badger.DefaultOptions(r.opt.shardOutputDirs[i]).WithSyncWrites(false).
WithTableLoadingMode(bo.MemoryMap).WithValueThreshold(1 << 10 /* 1 KB */).
WithLogger(nil)
db, err := badger.OpenManaged(opt)
x.Check(err)
r.dbs = append(r.dbs, db)
Expand Down
8 changes: 3 additions & 5 deletions dgraph/cmd/debug/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,9 @@ func run() {
dir = opt.wdir
isWal = true
}
bopts := badger.DefaultOptions
bopts.Dir = dir
bopts.ValueDir = dir
bopts.TableLoadingMode = options.MemoryMap
bopts.ReadOnly = opt.readOnly
bopts := badger.DefaultOptions(dir).
WithTableLoadingMode(options.MemoryMap).
WithReadOnly(opt.readOnly)

x.AssertTruef(len(bopts.Dir) > 0, "No posting or wal dir specified.")
fmt.Printf("Opening DB: %s\n", bopts.Dir)
Expand Down
9 changes: 3 additions & 6 deletions dgraph/cmd/live/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,11 @@ func setup(opts batchMutationOptions, dc *dgo.Dgraph) *loader {
var db *badger.DB
if len(opt.clientDir) > 0 {
x.Check(os.MkdirAll(opt.clientDir, 0700))
o := badger.DefaultOptions
o.Dir = opt.clientDir
o.ValueDir = opt.clientDir
o.TableLoadingMode = bopt.MemoryMap
o.SyncWrites = false

var err error
db, err = badger.Open(o)
db, err = badger.Open(badger.DefaultOptions(opt.clientDir).
WithTableLoadingMode(bopt.MemoryMap).
WithSyncWrites(false))
x.Checkf(err, "Error while creating badger KV posting store")
}

Expand Down
8 changes: 2 additions & 6 deletions dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,8 @@ func run() {

// Open raft write-ahead log and initialize raft node.
x.Checkf(os.MkdirAll(opts.w, 0700), "Error while creating WAL dir.")
kvOpt := badger.LSMOnlyOptions
kvOpt.SyncWrites = false
kvOpt.Truncate = true
kvOpt.Dir = opts.w
kvOpt.ValueDir = opts.w
kvOpt.ValueLogFileSize = 64 << 20
kvOpt := badger.LSMOnlyOptions(opts.w).WithSyncWrites(false).WithTruncate(true).
WithValueLogFileSize(64 << 20)
kv, err := badger.Open(kvOpt)
x.Checkf(err, "Error while opening WAL store")
defer kv.Close()
Expand Down
19 changes: 7 additions & 12 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,8 @@ func (s *ServerState) runVlogGC(store *badger.DB) {
}
}

func setBadgerOptions(opt badger.Options, dir string) badger.Options {
opt.SyncWrites = false
opt.Truncate = true
opt.Dir = dir
opt.ValueDir = dir
opt.Logger = &x.ToGlog{}
func setBadgerOptions(opt badger.Options) badger.Options {
opt = opt.WithSyncWrites(false).WithTruncate(true).WithLogger(&x.ToGlog{})

glog.Infof("Setting Badger table load option: %s", Config.BadgerTables)
switch Config.BadgerTables {
Expand Down Expand Up @@ -155,8 +151,8 @@ func (s *ServerState) initStorage() {
{
// Write Ahead Log directory
x.Checkf(os.MkdirAll(Config.WALDir, 0700), "Error while creating WAL dir.")
opt := badger.LSMOnlyOptions
opt = setBadgerOptions(opt, Config.WALDir)
opt := badger.LSMOnlyOptions(Config.WALDir)
opt = setBadgerOptions(opt)
opt.ValueLogMaxEntries = 10000 // Allow for easy space reclamation.

// We should always force load LSM tables to memory, disregarding user settings, because
Expand All @@ -175,10 +171,9 @@ func (s *ServerState) initStorage() {
// All the writes to posting store should be synchronous. We use batched writers
// for posting lists, so the cost of sync writes is amortized.
x.Check(os.MkdirAll(Config.PostingDir, 0700))
opt := badger.DefaultOptions
opt.ValueThreshold = 1 << 10 // 1KB
opt.NumVersionsToKeep = math.MaxInt32
opt = setBadgerOptions(opt, Config.PostingDir)
opt := badger.DefaultOptions(Config.PostingDir).WithValueThreshold(1 << 10 /* 1KB */).
WithNumVersionsToKeep(math.MaxInt32)
opt = setBadgerOptions(opt)

glog.Infof("Opening postings BadgerDB with options: %+v\n", opt)
s.Pstore, err = badger.OpenManaged(opt)
Expand Down
20 changes: 8 additions & 12 deletions ee/backup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,22 @@ func runRestoreCmd() error {

// RunRestore calls badger.Load and tries to load data into a new DB.
func RunRestore(pdir, location, backupId string) (uint64, error) {
bo := badger.DefaultOptions
bo.SyncWrites = true
bo.TableLoadingMode = options.MemoryMap
bo.ValueThreshold = 1 << 10
bo.NumVersionsToKeep = math.MaxInt32

// Scan location for backup files and load them. Each file represents a node group,
// and we create a new p dir for each.
return Load(location, backupId, func(r io.Reader, groupId int) error {
bo := bo
bo.Dir = filepath.Join(pdir, fmt.Sprintf("p%d", groupId))
bo.ValueDir = bo.Dir
db, err := badger.OpenManaged(bo)
dir := filepath.Join(pdir, fmt.Sprintf("p%d", groupId))
db, err := badger.OpenManaged(badger.DefaultOptions(dir).
WithSyncWrites(true).
WithTableLoadingMode(options.MemoryMap).
WithValueThreshold(1 << 10).
WithNumVersionsToKeep(math.MaxInt32))
if err != nil {
return err
}
defer db.Close()
fmt.Printf("Restoring groupId: %d\n", groupId)
if !pathExist(bo.Dir) {
fmt.Println("Creating new db:", bo.Dir)
if !pathExist(dir) {
fmt.Println("Creating new db:", dir)
}
gzReader, err := gzip.NewReader(r)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions posting/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,10 +1247,7 @@ func TestMain(m *testing.M) {
dir, err := ioutil.TempDir("", "storetest_")
x.Check(err)

opt := badger.DefaultOptions
opt.Dir = dir
opt.ValueDir = dir
ps, err = badger.OpenManaged(opt)
ps, err = badger.OpenManaged(badger.DefaultOptions(dir))
x.Check(err)
Init(ps)
schema.Init(ps)
Expand Down
22 changes: 7 additions & 15 deletions raftwal/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,12 @@ import (
pb "go.etcd.io/etcd/raft/raftpb"
)

func openBadger(dir string) (*badger.DB, error) {
opt := badger.DefaultOptions
opt.Dir = dir
opt.ValueDir = dir

return badger.Open(opt)
}

func TestStorageTerm(t *testing.T) {
dir, err := ioutil.TempDir("", "badger")
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
ds := Init(db, 0, 0)

Expand Down Expand Up @@ -108,7 +100,7 @@ func TestStorageEntries(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
ds := Init(db, 0, 0)

Expand Down Expand Up @@ -153,7 +145,7 @@ func TestStorageLastIndex(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
ds := Init(db, 0, 0)

Expand Down Expand Up @@ -183,7 +175,7 @@ func TestStorageFirstIndex(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
ds := Init(db, 0, 0)

Expand Down Expand Up @@ -216,7 +208,7 @@ func TestStorageCompact(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
ds := Init(db, 0, 0)

Expand Down Expand Up @@ -265,7 +257,7 @@ func TestStorageCreateSnapshot(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
ds := Init(db, 0, 0)

Expand Down Expand Up @@ -302,7 +294,7 @@ func TestStorageAppend(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

db, err := openBadger(dir)
db, err := badger.Open(badger.DefaultOptions(dir))
require.NoError(t, err)
ds := Init(db, 0, 0)

Expand Down
4 changes: 1 addition & 3 deletions schema/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,7 @@ func TestMain(m *testing.M) {

dir, err := ioutil.TempDir("", "storetest_")
x.Check(err)
kvOpt := badger.DefaultOptions
kvOpt.Dir = dir
kvOpt.ValueDir = dir
kvOpt := badger.DefaultOptions(dir)
ps, err = badger.OpenManaged(kvOpt)
x.Check(err)
Init(ps)
Expand Down
4 changes: 2 additions & 2 deletions vendor/github.com/dgraph-io/badger/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/dgraph-io/badger/appveyor.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions vendor/github.com/dgraph-io/badger/backup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d253e9

Please sign in to comment.