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

[BREAKING]: Change how Badger handles WAL #1555

Merged
merged 90 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
ff6d61a
Initial logic written
manishrjain Oct 1, 2020
13e9b19
More changes
manishrjain Oct 1, 2020
91cf8da
Remove head pointer
manishrjain Oct 2, 2020
f73f11e
Use mmap to store discard stats. Move to a new discard.go file.
manishrjain Oct 2, 2020
6fa80d6
Remove discard stats key
manishrjain Oct 2, 2020
e50eb08
add open wal and open skiplist
NamanJain8 Oct 2, 2020
4596dd6
Fix skl test
Oct 2, 2020
bd756be
Add test for skiplist open
Oct 2, 2020
628c31c
Refactor openskiplist
Oct 2, 2020
460501e
Add replay code but it doesn't work
Oct 2, 2020
8c3a319
more fixes to replay and some tests work
NamanJain8 Oct 2, 2020
85f547c
Add some TODOs
manishrjain Oct 2, 2020
b4b627e
add decrref, increref and function to read from logfile
martinmr Oct 2, 2020
f89448f
add open memtable
NamanJain8 Oct 2, 2020
fca1e71
More changes. code builds
martinmr Oct 2, 2020
84628a8
write entry go wal.
martinmr Oct 2, 2020
2416ada
Refactor code to split it into a new log.go file
manishrjain Oct 3, 2020
096f237
Rename to memtable
manishrjain Oct 3, 2020
eb68bcc
simplify iterate
manishrjain Oct 3, 2020
125012a
Deal with ref counting and WAL deletion.
manishrjain Oct 3, 2020
03e0fbb
Somewhat working
manishrjain Oct 3, 2020
28ac3c8
Remove value log loading mode
manishrjain Oct 3, 2020
4c39854
Seems to work.
manishrjain Oct 3, 2020
35946a4
Set size correctly during truncation.
manishrjain Oct 3, 2020
b739ff4
Capture Truncate to set logFile.size
manishrjain Oct 3, 2020
5bb2995
Fix in-memory mode and remove some tests
Oct 3, 2020
5dd8125
fix skl_test
NamanJain8 Oct 3, 2020
99d0ad7
Merge branch 'mrjn/wal' of github.com:dgraph-io/badger into mrjn/wal
NamanJain8 Oct 3, 2020
8290e85
Avoid zeroing out the entire discard stats file.
manishrjain Oct 3, 2020
0ea920a
Merge branch 'master' into mrjn/wal
manishrjain Oct 3, 2020
c394424
Copmiles
manishrjain Oct 3, 2020
93b612e
Fix up MaxVersion function
manishrjain Oct 3, 2020
a307270
Remove vlog sampling and trace.
manishrjain Oct 3, 2020
c8de40a
fix some tests
Oct 3, 2020
5c53171
enable TestTxnReadTs test
Oct 3, 2020
f21b48c
Empty builder should return slice
Oct 3, 2020
8db3d11
Add assert to catch failure
Oct 3, 2020
a3e096c
Return 0 as MaxVersion if rcv is nil.
martinmr Oct 3, 2020
a3ea60b
Check rcv is not nil in KeyCount.
martinmr Oct 3, 2020
02afa26
more nil checks.
martinmr Oct 3, 2020
2cda2f9
Add assert that index is not nil.
martinmr Oct 3, 2020
e7d85f5
Regenerate TableIndex.go
manishrjain Oct 3, 2020
7055781
Fix segfault in monitorCache.
martinmr Oct 3, 2020
115242c
Set t.index to point to the mmapped table always, unless encryption i…
manishrjain Oct 3, 2020
08cf171
Remove TableLoadingMode. Defaults to mmap
manishrjain Oct 3, 2020
d03573b
Use z.MmapFile and z.Mmap
manishrjain Oct 3, 2020
249b006
Remove truncate option. Move to y.Wrap and y.Wrapf
manishrjain Oct 4, 2020
443d8ee
Zero out the next entry when writing log file.
manishrjain Oct 4, 2020
adc66b0
Fix more tests
Oct 4, 2020
c7f7a7c
fix more tests
Oct 4, 2020
848a1bb
fix another test
Oct 4, 2020
2c4e672
Remove vloggc command
Oct 4, 2020
7e7f4f4
fix table tests
Oct 4, 2020
9538a36
All tests work
Oct 4, 2020
d80a2cc
Merge remote-tracking branch 'origin/master' into mrjn/wal
martinmr Oct 4, 2020
9dc23c0
Fix uint32 overflow test
Oct 4, 2020
dff5229
Merge branch 'mrjn/wal' of https://github.com/dgraph-io/badger into m…
Oct 4, 2020
5bb651c
Fix discard back
manishrjain Oct 4, 2020
dc6904e
Fix Swap
manishrjain Oct 4, 2020
a859f51
Fix another test
manishrjain Oct 4, 2020
38b264c
Add locks in MaxVersion
Oct 4, 2020
7d8b677
Merge branch 'mrjn/wal' of https://github.com/dgraph-io/badger into m…
Oct 4, 2020
01131cb
Add a CreateTable API, which internally just copies bytes from builde…
manishrjain Oct 4, 2020
ad06fd6
Move Badger Flags to its own type
manishrjain Oct 4, 2020
8b32add
Fix up shit ton of tests
manishrjain Oct 4, 2020
92d5ef0
fix(txn): Allow the first big entry to pass
Oct 4, 2020
be413df
Set sync writes to false
manishrjain Oct 4, 2020
308c5a8
Merge remote-tracking branch 'origin/ibrahim/txn-size' into mrjn/wal
manishrjain Oct 4, 2020
53fe46b
Set sync writes to false by default. Update magic number.v
manishrjain Oct 4, 2020
9fbb7d1
Comment out replace in go.mod
Oct 4, 2020
ec49200
Revert "fix(txn): Allow the first big entry to pass"
Oct 4, 2020
9486089
Fix picksorttable
Oct 4, 2020
6e9b66b
Pull in latest ristretto.
manishrjain Oct 4, 2020
7090cf8
tidy go.sum
manishrjain Oct 4, 2020
4c28427
Fix up a seg fault in levels.go
manishrjain Oct 4, 2020
b9f075a
Add check for nil logFile
Oct 5, 2020
d74698d
Merge branch 'mrjn/wal' of https://github.com/dgraph-io/badger into m…
Oct 5, 2020
76a893f
Revert "Fix(builder): Too many small tables when compression is enabl…
Oct 5, 2020
998f30c
Fix discard stats cleanup
Oct 5, 2020
e9a6ec3
Add a test for discard stats
Oct 5, 2020
9555605
Add license
Oct 5, 2020
8fae622
Do not GC files with discard less than discard ratio
Oct 5, 2020
dd9e5d4
Don't rewrite the vlog file already marked for deletion
Oct 5, 2020
3db8512
Revert "Revert "Fix(builder): Too many small tables when compression …
Oct 5, 2020
1082dbe
Use go mem instead of z.Calloc for builder buffer
Oct 5, 2020
6f3fad6
Self review
manishrjain Oct 11, 2020
a5daea1
Remove KeepL0InMemory option.
manishrjain Oct 11, 2020
ef21567
Set default conflict detection to false in write benchmark
Oct 6, 2020
99f4f92
Self review
manishrjain Oct 12, 2020
ac7688c
Self review
manishrjain Oct 12, 2020
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
3 changes: 2 additions & 1 deletion backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestBackupRestore1(t *testing.T) {
if err != nil {
return err
}
t.Logf("Got entry: %v\n", item.Version())
require.Equal(t, entries[count].key, item.Key())
require.Equal(t, entries[count].val, val)
require.Equal(t, entries[count].version, item.Version())
Expand All @@ -112,7 +113,7 @@ func TestBackupRestore1(t *testing.T) {
return nil
})
require.NoError(t, err)
require.Equal(t, db.orc.nextTs(), uint64(3))
require.Equal(t, 3, int(db.orc.nextTs()))
}

func TestBackupRestore2(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions badger/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

var backupFile string
var truncate bool

// backupCmd represents the backup command
var backupCmd = &cobra.Command{
Expand All @@ -45,16 +44,13 @@ func init() {
RootCmd.AddCommand(backupCmd)
backupCmd.Flags().StringVarP(&backupFile, "backup-file", "f",
"badger.bak", "File to backup to")
backupCmd.Flags().BoolVarP(&truncate, "truncate", "t",
false, "Allow value log truncation if required.")
backupCmd.Flags().IntVarP(&numVersions, "num-versions", "n",
0, "Number of versions to keep. A value <= 0 means keep all versions.")
}

func doBackup(cmd *cobra.Command, args []string) error {
opt := badger.DefaultOptions(sstDir).
WithValueDir(vlogDir).
WithTruncate(truncate).
WithNumVersionsToKeep(math.MaxInt32)

if numVersions > 0 {
Expand Down
5 changes: 2 additions & 3 deletions badger/cmd/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,10 @@ func runTest(cmd *cobra.Command, args []string) error {
WithNumVersionsToKeep(int(math.MaxInt32)).
WithValueThreshold(1). // Make all values go to value log
WithCompression(options.ZSTD).
WithKeepL0InMemory(false).
WithBlockCacheSize(10 << 20)

if mmap {
opts = opts.WithTableLoadingMode(options.MemoryMap)
if verbose {
opts = opts.WithLoggingLevel(badger.DEBUG)
}

if encryptionKey != "" {
Expand Down
1 change: 0 additions & 1 deletion badger/cmd/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func flatten(cmd *cobra.Command, args []string) error {
}
opt := badger.DefaultOptions(sstDir).
WithValueDir(vlogDir).
WithTruncate(truncate).
WithNumVersionsToKeep(numVersions).
WithNumCompactors(0)
fmt.Printf("Opening badger with options = %+v\n", opt)
Expand Down
21 changes: 9 additions & 12 deletions badger/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/pkg/errors"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/options"
"github.com/dgraph-io/badger/v2/table"
"github.com/dgraph-io/badger/v2/y"
humanize "github.com/dustin/go-humanize"
Expand Down Expand Up @@ -93,18 +92,16 @@ to the Dgraph team.

func handleInfo(cmd *cobra.Command, args []string) error {
if err := printInfo(sstDir, vlogDir); err != nil {
return errors.Wrap(err, "failed to print information in MANIFEST file")
return y.Wrap(err, "failed to print information in MANIFEST file")
}

// Open DB
db, err := badger.Open(badger.DefaultOptions(sstDir).
WithValueDir(vlogDir).
WithReadOnly(opt.readOnly).
WithTruncate(opt.truncate).
WithTableLoadingMode(options.MemoryMap).
WithEncryptionKey([]byte(opt.encryptionKey)))
if err != nil {
return errors.Wrap(err, "failed to open database")
return y.Wrap(err, "failed to open database")
}
defer db.Close()

Expand All @@ -114,7 +111,7 @@ func handleInfo(cmd *cobra.Command, args []string) error {

prefix, err := hex.DecodeString(opt.withPrefix)
if err != nil {
return errors.Wrapf(err, "failed to decode hex prefix: %s", opt.withPrefix)
return y.Wrapf(err, "failed to decode hex prefix: %s", opt.withPrefix)
}
if opt.showHistogram {
db.PrintHistogram(prefix)
Expand All @@ -128,7 +125,7 @@ func handleInfo(cmd *cobra.Command, args []string) error {

if len(opt.keyLookup) > 0 {
if err := lookup(db); err != nil {
return errors.Wrapf(err, "failed to perform lookup for the key: %x", opt.keyLookup)
return y.Wrapf(err, "failed to perform lookup for the key: %x", opt.keyLookup)
}
}
return nil
Expand All @@ -153,7 +150,7 @@ func showKeys(db *badger.DB, prefix []byte) error {
for it.Rewind(); it.Valid(); it.Next() {
item := it.Item()
if err := printKey(item, false); err != nil {
return errors.Wrapf(err, "failed to print information about key: %x(%d)",
return y.Wrapf(err, "failed to print information about key: %x(%d)",
item.Key(), item.Version())
}
totalKeys++
Expand All @@ -170,7 +167,7 @@ func lookup(db *badger.DB) error {

key, err := hex.DecodeString(opt.keyLookup)
if err != nil {
return errors.Wrapf(err, "failed to decode key: %q", opt.keyLookup)
return y.Wrapf(err, "failed to decode key: %q", opt.keyLookup)
}

iopts := badger.DefaultIteratorOptions
Expand All @@ -186,7 +183,7 @@ func lookup(db *badger.DB) error {
fmt.Println()
item := itr.Item()
if err := printKey(item, true); err != nil {
return errors.Wrapf(err, "failed to print information about key: %x(%d)",
return y.Wrapf(err, "failed to print information about key: %x(%d)",
item.Key(), item.Version())
}

Expand All @@ -201,7 +198,7 @@ func lookup(db *badger.DB) error {
break
}
if err := printKey(item, true); err != nil {
return errors.Wrapf(err, "failed to print information about key: %x(%d)",
return y.Wrapf(err, "failed to print information about key: %x(%d)",
item.Key(), item.Version())
}
}
Expand All @@ -223,7 +220,7 @@ func printKey(item *badger.Item, showValue bool) error {
if showValue {
val, err := item.ValueCopy(nil)
if err != nil {
return errors.Wrapf(err,
return y.Wrapf(err,
"failed to copy value of the key: %x(%d)", item.Key(), item.Version())
}
fmt.Fprintf(&buf, "\n\tvalue: %v", val)
Expand Down
20 changes: 0 additions & 20 deletions badger/cmd/read_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import (
"fmt"
"math"
"math/rand"
"strings"
"sync/atomic"
"time"

humanize "github.com/dustin/go-humanize"
"github.com/spf13/cobra"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/options"
"github.com/dgraph-io/badger/v2/pb"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/ristretto/z"
Expand Down Expand Up @@ -107,12 +105,9 @@ func readBench(cmd *cobra.Command, args []string) error {
return y.Wrapf(err, "unable to parse duration")
}
y.AssertTrue(numGoroutines > 0)
mode := getLoadingMode(loadingMode)
opt := badger.DefaultOptions(sstDir).
WithValueDir(vlogDir).
WithReadOnly(readOnly).
WithTableLoadingMode(mode).
WithValueLogLoadingMode(mode).
WithBlockCacheSize(blockCacheSize << 20).
WithIndexCacheSize(indexCacheSize << 20)
fmt.Printf("Opening badger with options = %+v\n", opt)
Expand Down Expand Up @@ -239,18 +234,3 @@ func getSampleKeys(db *badger.DB) ([][]byte, error) {

return keys, nil
}

func getLoadingMode(m string) options.FileLoadingMode {
m = strings.ToLower(m)
var mode options.FileLoadingMode
switch m {
case "fileio":
mode = options.FileIO
case "mmap":
mode = options.MemoryMap
default:
panic("loading mode not supported")
}

return mode
}
5 changes: 5 additions & 0 deletions badger/cmd/rotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ func TestRotate(t *testing.T) {
dir, err := ioutil.TempDir("", "badger-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

// Creating sample key.
key := make([]byte, 32)
_, err = rand.Read(key)
require.NoError(t, err)

fp, err := ioutil.TempFile("", "*.key")
require.NoError(t, err)
_, err = fp.Write(key)
Expand All @@ -44,6 +46,8 @@ func TestRotate(t *testing.T) {
// Opening DB with the encryption key.
opts := badger.DefaultOptions(dir)
opts.EncryptionKey = key
opts.BlockCacheSize = 1 << 20

db, err := badger.Open(opts)
require.NoError(t, err)
// Closing the db.
Expand Down Expand Up @@ -126,6 +130,7 @@ func TestRotatePlainTextToEncrypted(t *testing.T) {
require.Nil(t, doRotate(nil, []string{}))

// Try opening DB without the key.
opts.BlockCacheSize = 1 << 20
_, err = badger.Open(opts)
require.EqualError(t, err, badger.ErrEncryptionKeyMismatch.Error())

Expand Down
5 changes: 2 additions & 3 deletions badger/cmd/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/options"
"github.com/dgraph-io/badger/v2/y"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand All @@ -44,7 +45,6 @@ func init() {
RootCmd.AddCommand(streamCmd)
streamCmd.Flags().StringVarP(&outDir, "out", "o", "",
"Path to output DB. The directory should be empty.")
streamCmd.Flags().BoolVarP(&truncate, "truncate", "", false, "Option to truncate the DBs")
streamCmd.Flags().BoolVarP(&readOnly, "read_only", "", true,
"Option to open input DB in read-only mode")
streamCmd.Flags().IntVarP(&numVersions, "num_versions", "", 0,
Expand Down Expand Up @@ -76,7 +76,6 @@ func stream(cmd *cobra.Command, args []string) error {
}
inOpt := badger.DefaultOptions(sstDir).
WithReadOnly(readOnly).
WithTruncate(truncate).
WithValueThreshold(1 << 10 /* 1KB */).
WithNumVersionsToKeep(numVersions)

Expand All @@ -90,7 +89,7 @@ func stream(cmd *cobra.Command, args []string) error {

inDB, err := badger.OpenManaged(inOpt)
if err != nil {
return errors.Wrapf(err, "cannot open DB at %s", sstDir)
return y.Wrapf(err, "cannot open DB at %s", sstDir)
}
defer inDB.Close()
return inDB.StreamDB(outOpt)
Expand Down
84 changes: 0 additions & 84 deletions badger/cmd/vloggc.go

This file was deleted.

Loading