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

Update release/v3.2011 branch #1634

Merged
merged 36 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8e4085b
fix: Disable CompactL0OnClose by default (#1586)
ajeetdsouza Nov 10, 2020
50f07a6
Add smallstep/certificates to projects using badger (#1589)
Nov 11, 2020
b94b561
Use AllocatorPool in Stream and TableBuilder (#1593)
manishrjain Nov 11, 2020
e002a9d
Bring in Ristretto with allocator fix.
manishrjain Nov 12, 2020
34c6154
fix(readonly): fix the file opening mode (#1592)
NamanJain8 Nov 12, 2020
741de05
Small improvements (#1598)
manishrjain Nov 12, 2020
5a96b2c
fix(skiplist): Remove z.Buffer from skiplist (#1600)
ahsanbarkati Nov 19, 2020
5ff9e1d
Bug Fix: Fix up how we use z.Allocator
manishrjain Nov 23, 2020
340ccfc
Test: Add a test for encryption.
manishrjain Nov 23, 2020
f36daf5
fix(stream): Stop produceKVs on error (#1604)
Nov 25, 2020
925e15b
Fix race condition in L0StallMs variable (#1605)
Nov 25, 2020
feb1f5f
chore(iterators): Do not return error on missing vlog (#1602)
Nov 25, 2020
ab8b5d9
Opt(stream): Use z.Buffer to stream data (#1606)
manishrjain Nov 25, 2020
3d225d7
Bug Fix: Create the right txn based on Badger mode
manishrjain Nov 26, 2020
2d88aea
Remove link from index.md (#1607)
bucanero Nov 30, 2020
6e7f078
Keep the cheaper parts of the index within table struct. (#1608)
manishrjain Dec 3, 2020
70088c6
Fix(OOM): Reuse pb.KVs in Stream (#1609)
manishrjain Dec 3, 2020
74f2e02
Opt(pickTables): Fix an optimization regression
manishrjain Dec 3, 2020
3782d88
chore(cmd/stream): Default to snappy for compression flag. (#1610)
danielmai Dec 4, 2020
0f77c00
chore(cmd/info): Fix printed spacing of summary. (#1559)
danielmai Dec 4, 2020
a75cb55
Fix(OOM): Use z.Allocator for Stream (#1611)
manishrjain Dec 4, 2020
b80c792
Make itr.Alloc public
manishrjain Dec 4, 2020
5e41893
Fix: Do not stop Stream due to KeyToList error.
manishrjain Dec 4, 2020
3a4d8e7
Bring in latest Ristretto
manishrjain Dec 5, 2020
63726a8
Fix(OOM): Avoid too many splits
manishrjain Dec 5, 2020
6142e81
Fix typo in width calculation.
danielmai Dec 5, 2020
f492aa3
fix(compaction): fix table size estimation on compaction (#1613)
NamanJain8 Dec 7, 2020
eaf91a1
docs: Set relativeURL for Netlify. (#1612)
mbj36 Dec 7, 2020
c65ef1d
docs: Fix relative URL settings in config.toml.
danielmai Dec 7, 2020
068c66d
docs: Set relative URLs in config. (#1616)
mbj36 Dec 8, 2020
c4b8179
fix(tableBuilding): reduce scope of valuePointer (#1617)
NamanJain8 Dec 8, 2020
4fea5dc
fix(GC): Set bits correctly for moved keys (#1619)
Dec 10, 2020
bcfae61
Revert mmap in skiplists (#1620)
ajeetdsouza Dec 14, 2020
9a34eed
Merge commit 'bcfae6104545e824b40814e4bc3bc4b1430c3367' into release/…
Jan 5, 2021
54688d8
changing badger module path to v3
aman-bansal Jan 6, 2021
6266a4e
changing metrics to v3 and badgerpb2 to badgerpb3
aman-bansal Jan 15, 2021
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ For more details on our version naming schema please read [Choosing a version](#
To start using Badger, install Go 1.12 or above. Badger v2 needs go modules. Run the following command to retrieve the library.

```sh
$ go get github.com/dgraph-io/badger/v2
$ go get github.com/dgraph-io/badger/v3
```
This will retrieve the library.

##### Note: Badger does not directly use CGO but it relies on https://github.com/DataDog/zstd for compression and it requires gcc/cgo. If you wish to use badger without gcc/cgo, you can run `CGO_ENABLED=0 go get github.com/dgraph-io/badger/v2` which will download badger without the support for ZSTD compression algorithm.
##### Note: Badger does not directly use CGO but it relies on https://github.com/DataDog/zstd for compression and it requires gcc/cgo. If you wish to use badger without gcc/cgo, you can run `CGO_ENABLED=0 go get github.com/dgraph-io/badger/v3` which will download badger without the support for ZSTD compression algorithm.

#### Installing Badger Command Line Tool

Expand Down Expand Up @@ -162,6 +162,7 @@ Below is a list of known projects that use Badger:
* [emitter](https://github.com/emitter-io/emitter) - Scalable, low latency, distributed pub/sub broker with message storage, uses MQTT, gossip and badger.
* [OctoSQL](https://github.com/cube2222/octosql) - Query tool that allows you to join, analyse and transform data from multiple databases using SQL.
* [Dkron](https://dkron.io/) - Distributed, fault tolerant job scheduling system.
* [smallstep/certificates](https://github.com/smallstep/certificates) - Step-ca is an online certificate authority for secure, automated certificate management.
* [Sandglass](https://github.com/celrenheit/sandglass) - distributed, horizontally scalable, persistent, time sorted message queue.
* [TalariaDB](https://github.com/grab/talaria) - Grab's Distributed, low latency time-series database.
* [Sloop](https://github.com/salesforce/sloop) - Salesforce's Kubernetes History Visualization Project.
Expand Down
26 changes: 18 additions & 8 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
"encoding/binary"
"io"

"github.com/dgraph-io/badger/v2/pb"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/badger/v3/pb"
"github.com/dgraph-io/badger/v3/y"
"github.com/dgraph-io/ristretto/z"
"github.com/golang/protobuf/proto"
)

Expand Down Expand Up @@ -61,6 +62,7 @@ func (db *DB) Backup(w io.Writer, since uint64) (uint64, error) {
func (stream *Stream) Backup(w io.Writer, since uint64) (uint64, error) {
stream.KeyToList = func(key []byte, itr *Iterator) (*pb.KVList, error) {
list := &pb.KVList{}
a := itr.Alloc
for ; itr.Valid(); itr.Next() {
item := itr.Item()
if !bytes.Equal(item.Key(), key) {
Expand All @@ -76,7 +78,10 @@ func (stream *Stream) Backup(w io.Writer, since uint64) (uint64, error) {
if !item.IsDeletedOrExpired() {
// No need to copy value, if item is deleted or expired.
var err error
valCopy, err = item.ValueCopy(nil)
err = item.Value(func(val []byte) error {
valCopy = a.Copy(val)
return nil
})
if err != nil {
stream.db.opt.Errorf("Key [%x, %d]. Error while fetching value [%v]\n",
item.Key(), item.Version(), err)
Expand All @@ -86,13 +91,14 @@ func (stream *Stream) Backup(w io.Writer, since uint64) (uint64, error) {

// clear txn bits
meta := item.meta &^ (bitTxn | bitFinTxn)
kv := &pb.KV{
Key: item.KeyCopy(nil),
kv := y.NewKV(a)
*kv = pb.KV{
Key: a.Copy(item.Key()),
Value: valCopy,
UserMeta: []byte{item.UserMeta()},
UserMeta: a.Copy([]byte{item.UserMeta()}),
Version: item.Version(),
ExpiresAt: item.ExpiresAt(),
Meta: []byte{meta},
Meta: a.Copy([]byte{meta}),
}
list.Kv = append(list.Kv, kv)

Expand All @@ -115,7 +121,11 @@ func (stream *Stream) Backup(w io.Writer, since uint64) (uint64, error) {
}

var maxVersion uint64
stream.Send = func(list *pb.KVList) error {
stream.Send = func(buf *z.Buffer) error {
list, err := BufferToKVList(buf)
if err != nil {
return err
}
out := list.Kv[:0]
for _, kv := range list.Kv {
if maxVersion < kv.Version {
Expand Down
2 changes: 1 addition & 1 deletion backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"testing"
"time"

"github.com/dgraph-io/badger/v2/pb"
"github.com/dgraph-io/badger/v3/pb"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion badger/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"math"
"os"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v3"
"github.com/spf13/cobra"
)

Expand Down
21 changes: 12 additions & 9 deletions badger/cmd/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import (
"sync/atomic"
"time"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/pb"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v3/pb"
"github.com/dgraph-io/badger/v3/y"
"github.com/dgraph-io/ristretto/z"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -359,7 +360,7 @@ func runTest(cmd *cobra.Command, args []string) error {
WithNumVersionsToKeep(int(math.MaxInt32)).
WithBlockCacheSize(1 << 30).
WithIndexCacheSize(1 << 30)

if verbose {
opts = opts.WithLoggingLevel(badger.DEBUG)
}
Expand Down Expand Up @@ -498,13 +499,15 @@ func runTest(cmd *cobra.Command, args []string) error {
batch := tmpDb.NewWriteBatch()

stream := db.NewStream()
stream.Send = func(list *pb.KVList) error {
for _, kv := range list.Kv {
if err := batch.Set(kv.Key, kv.Value); err != nil {
stream.Send = func(buf *z.Buffer) error {
err := buf.SliceIterate(func(s []byte) error {
var kv pb.KV
if err := kv.Unmarshal(s); err != nil {
return err
}
}
return nil
return batch.Set(kv.Key, kv.Value)
})
return err
}
y.Check(stream.Orchestrate(context.Background()))
y.Check(batch.Flush())
Expand Down
2 changes: 1 addition & 1 deletion badger/cmd/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"math"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v3"
"github.com/spf13/cobra"
)

Expand Down
10 changes: 6 additions & 4 deletions badger/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

"github.com/pkg/errors"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/table"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v3/table"
"github.com/dgraph-io/badger/v3/y"
humanize "github.com/dustin/go-humanize"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -99,6 +99,8 @@ func handleInfo(cmd *cobra.Command, args []string) error {
db, err := badger.Open(badger.DefaultOptions(sstDir).
WithValueDir(vlogDir).
WithReadOnly(opt.readOnly).
WithBlockCacheSize(100 << 20).
WithIndexCacheSize(200 << 20).
WithEncryptionKey([]byte(opt.encryptionKey)))
if err != nil {
return y.Wrap(err, "failed to open database")
Expand Down Expand Up @@ -434,7 +436,7 @@ func printInfo(dir, valueDir string) error {
totalSSTSize += sz
}

fmt.Printf("Total SST size: %8s\n", hbytes(totalSSTSize))
fmt.Printf("Total SST size: %10s\n", hbytes(totalSSTSize))
fmt.Printf("Value log size: %10s\n", hbytes(valueLogSize))
fmt.Println()
totalExtra := numExtra + numValueDirExtra
Expand Down
28 changes: 19 additions & 9 deletions badger/cmd/read_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
"time"

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

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/pb"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v3/pb"
"github.com/dgraph-io/badger/v3/y"
"github.com/dgraph-io/ristretto/z"
)

Expand Down Expand Up @@ -79,7 +80,7 @@ func init() {

// Scan the whole database using the iterators
func fullScanDB(db *badger.DB) {
txn := db.NewTransaction(false)
txn := db.NewTransactionAt(math.MaxUint64, false)
defer txn.Discard()

startTime = time.Now()
Expand Down Expand Up @@ -111,7 +112,7 @@ func readBench(cmd *cobra.Command, args []string) error {
WithBlockCacheSize(blockCacheSize << 20).
WithIndexCacheSize(indexCacheSize << 20)
fmt.Printf("Opening badger with options = %+v\n", opt)
db, err := badger.Open(opt)
db, err := badger.OpenManaged(opt)
if err != nil {
return y.Wrapf(err, "unable to open DB")
}
Expand Down Expand Up @@ -205,21 +206,30 @@ func getSampleKeys(db *badger.DB) ([][]byte, error) {
return l, nil
}

errStop := errors.Errorf("Stop iterating")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stream.Send = func(l *pb.KVList) error {
stream.Send = func(buf *z.Buffer) error {
if count >= sampleSize {
return nil
}
for _, kv := range l.Kv {
err := buf.SliceIterate(func(s []byte) error {
var kv pb.KV
if err := kv.Unmarshal(s); err != nil {
return err
}
keys = append(keys, kv.Key)
count++
if count >= sampleSize {
cancel()
return nil
return errStop
}
return nil
})
if err == errStop || err == nil {
return nil
}
return nil
return err
}

if err := stream.Orchestrate(ctx); err != nil && err != context.Canceled {
Expand Down
2 changes: 1 addition & 1 deletion badger/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"os"
"path"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v3"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion badger/cmd/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"time"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v3"

"github.com/spf13/cobra"
)
Expand Down
4 changes: 2 additions & 2 deletions badger/cmd/rotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"os"
"testing"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v3/y"
"github.com/stretchr/testify/require"
)

Expand Down
65 changes: 39 additions & 26 deletions badger/cmd/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"math"
"os"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/options"
"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v3/options"
"github.com/dgraph-io/badger/v3/y"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand All @@ -39,40 +39,29 @@ This command streams the contents of this DB into another DB with the given opti
}

var outDir string
var outFile string
var compressionType uint32

func init() {
// TODO: Add more options.
RootCmd.AddCommand(streamCmd)
streamCmd.Flags().StringVarP(&outDir, "out", "o", "",
"Path to output DB. The directory should be empty.")
streamCmd.Flags().StringVarP(&outFile, "", "f", "",
"Run a backup to this file.")
streamCmd.Flags().BoolVarP(&readOnly, "read_only", "", true,
"Option to open input DB in read-only mode")
streamCmd.Flags().IntVarP(&numVersions, "num_versions", "", 0,
"Option to configure the maximum number of versions per key. "+
"Values <= 0 will be considered to have the max number of versions.")
streamCmd.Flags().Uint32VarP(&compressionType, "compression", "", 0,
streamCmd.Flags().Uint32VarP(&compressionType, "compression", "", 1,
"Option to configure the compression type in output DB. "+
"0 to disable, 1 for Snappy, and 2 for ZSTD.")
streamCmd.Flags().StringVarP(&keyPath, "encryption-key-file", "e", "",
"Path of the encryption key file.")
}

func stream(cmd *cobra.Command, args []string) error {
// Check that outDir doesn't exist or is empty.
if _, err := os.Stat(outDir); err == nil {
f, err := os.Open(outDir)
if err != nil {
return err
}
defer f.Close()

_, err = f.Readdirnames(1)
if err != io.EOF {
return errors.Errorf("cannot run stream tool on non-empty output directory %s", outDir)
}
}

// Options for input DB.
if numVersions <= 0 {
numVersions = math.MaxInt32
Expand All @@ -94,20 +83,44 @@ func stream(cmd *cobra.Command, args []string) error {
return errors.Errorf(
"compression value must be one of 0 (disabled), 1 (Snappy), or 2 (ZSTD)")
}
outOpt := inOpt.
WithDir(outDir).
WithValueDir(outDir).
WithNumVersionsToKeep(numVersions).
WithCompression(options.CompressionType(compressionType)).
WithReadOnly(false)

inDB, err := badger.OpenManaged(inOpt)
if err != nil {
return y.Wrapf(err, "cannot open DB at %s", sstDir)
}
defer inDB.Close()

err = inDB.StreamDB(outOpt)
stream := inDB.NewStreamAt(math.MaxUint64)

if len(outDir) > 0 {
if _, err := os.Stat(outDir); err == nil {
f, err := os.Open(outDir)
if err != nil {
return err
}
defer f.Close()

_, err = f.Readdirnames(1)
if err != io.EOF {
return errors.Errorf(
"cannot run stream tool on non-empty output directory %s", outDir)
}
}

stream.LogPrefix = "DB.Stream"
outOpt := inOpt.
WithDir(outDir).
WithValueDir(outDir).
WithNumVersionsToKeep(numVersions).
WithCompression(options.CompressionType(compressionType)).
WithReadOnly(false)
err = inDB.StreamDB(outOpt)

} else if len(outFile) > 0 {
stream.LogPrefix = "DB.Backup"
f, err := os.OpenFile(outFile, os.O_RDWR|os.O_CREATE, 0666)
y.Check(err)
_, err = stream.Backup(f, 0)
}
fmt.Println("Done.")
return err
}
Loading