Skip to content

Commit 128ac55

Browse files
committed
Merge branch 'naman/cp/2103' into release/v3.2103
2 parents 0b4c619 + e1f9dce commit 128ac55

File tree

13 files changed

+81
-85
lines changed

13 files changed

+81
-85
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ $ go get github.com/dgraph-io/badger/v3
5858
```
5959
This will retrieve the library.
6060

61-
##### 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.
62-
6361
#### Installing Badger Command Line Tool
6462

6563
Download and extract the latest Badger DB release from https://github.com/dgraph-io/badger/releases and then run the following commands.

db.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ func checkAndSetOptions(opt *Options) error {
172172
return ErrValueLogSize
173173
}
174174

175-
// Return error if badger is built without cgo and compression is set to ZSTD.
176-
if opt.Compression == options.ZSTD && !y.CgoEnabled {
177-
return y.ErrZstdCgo
178-
}
179-
180175
if opt.ReadOnly {
181176
// Do not perform compaction in read only mode.
182177
opt.CompactL0OnClose = false

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ go 1.12
55
// replace github.com/dgraph-io/ristretto => /home/amanbansal/go/src/github.com/dgraph-io/ristretto
66

77
require (
8-
github.com/DataDog/zstd v1.4.1
98
github.com/cespare/xxhash v1.1.0
10-
github.com/dgraph-io/ristretto v0.0.4-0.20210309073149-3836124cdc5a
9+
github.com/dgraph-io/ristretto v0.1.0
1110
github.com/dustin/go-humanize v1.0.0
1211
github.com/gogo/protobuf v1.3.2
1312
github.com/golang/protobuf v1.3.1
14-
github.com/golang/snappy v0.0.1
13+
github.com/golang/snappy v0.0.3
1514
github.com/google/flatbuffers v1.12.0
1615
github.com/google/go-cmp v0.5.4 // indirect
16+
github.com/klauspost/compress v1.12.3
1717
github.com/kr/pretty v0.1.0 // indirect
1818
github.com/pkg/errors v0.9.1
1919
github.com/spaolacci/murmur3 v1.1.0 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3-
github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM=
4-
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
53
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
64
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
75
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
86
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
97
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
8+
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
9+
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
1010
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1111
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
1212
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
@@ -15,8 +15,8 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
1515
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1616
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1717
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
18-
github.com/dgraph-io/ristretto v0.0.4-0.20210309073149-3836124cdc5a h1:1cMMkx3iegOzbAxVl1ZZQRHk+gaCf33Y5/4I3l0NNSg=
19-
github.com/dgraph-io/ristretto v0.0.4-0.20210309073149-3836124cdc5a/go.mod h1:MIonLggsKgZLUSt414ExgwNtlOL5MuEoAJP514mwGe8=
18+
github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/LuerPI=
19+
github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug=
2020
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
2121
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
2222
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
@@ -32,11 +32,10 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
3232
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3333
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
3434
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
35-
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
36-
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
35+
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
36+
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
3737
github.com/google/flatbuffers v1.12.0 h1:/PtAHvnBY4Kqnx/xCQ3OIV9uYcSFGScBsWI3Oogeh6w=
3838
github.com/google/flatbuffers v1.12.0/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
39-
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
4039
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
4140
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
4241
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -45,6 +44,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
4544
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
4645
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
4746
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
47+
github.com/klauspost/compress v1.12.3 h1:G5AfA94pHPysR56qqrkO2pxEexdDzrpFJ6yt/VqWxVU=
48+
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
4849
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
4950
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
5051
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -111,7 +112,6 @@ golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5h
111112
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
112113
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
113114
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
114-
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
115115
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
116116
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
117117
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

iterator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ func (it *Iterator) parseItem() bool {
638638
// Skip any versions which are beyond the readTs.
639639
version := y.ParseTs(key)
640640
// Ignore everything that is above the readTs and below or at the sinceTs.
641-
if version > it.readTs || version <= it.opt.SinceTs {
641+
if version > it.readTs || (it.opt.SinceTs > 0 && version <= it.opt.SinceTs) {
642642
mi.Next()
643643
return false
644644
}

iterator_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ func TestIterateSinceTs(t *testing.T) {
160160
})
161161
}
162162

163+
func TestIterateSinceTsWithPendingWrites(t *testing.T) {
164+
// The pending entries still have version=0. Even IteratorOptions.SinceTs is 0, the entries
165+
// should be visible.
166+
runBadgerTest(t, nil, func(t *testing.T, db *DB) {
167+
txn := db.NewTransaction(true)
168+
defer txn.Discard()
169+
require.NoError(t, txn.Set([]byte("key1"), []byte("value1")))
170+
require.NoError(t, txn.Set([]byte("key2"), []byte("value2")))
171+
itr := txn.NewIterator(DefaultIteratorOptions)
172+
defer itr.Close()
173+
count := 0
174+
for itr.Rewind(); itr.Valid(); itr.Next() {
175+
count++
176+
}
177+
require.Equal(t, 2, count)
178+
})
179+
}
180+
163181
func TestIteratePrefix(t *testing.T) {
164182
if !*manual {
165183
t.Skip("Skipping test meant to be run manually.")

levels.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,34 +829,29 @@ func (s *levelsController) subcompact(it y.Iterator, kr keyRange, cd compactDef,
829829
continue
830830
}
831831
numBuilds++
832-
fileID := s.reserveFileID()
833832
if err := inflightBuilders.Do(); err != nil {
834833
// Can't return from here, until I decrRef all the tables that I built so far.
835834
break
836835
}
837-
go func(builder *table.Builder) {
836+
go func(builder *table.Builder, fileID uint64) {
838837
var err error
839838
defer inflightBuilders.Done(err)
840839
defer builder.Close()
841840

842-
build := func(fileID uint64) (*table.Table, error) {
843-
fname := table.NewFilename(fileID, s.kv.opt.Dir)
844-
return table.CreateTable(fname, builder)
845-
}
846-
847841
var tbl *table.Table
848842
if s.kv.opt.InMemory {
849843
tbl, err = table.OpenInMemoryTable(builder.Finish(), fileID, &bopts)
850844
} else {
851-
tbl, err = build(fileID)
845+
fname := table.NewFilename(fileID, s.kv.opt.Dir)
846+
tbl, err = table.CreateTable(fname, builder)
852847
}
853848

854849
// If we couldn't build the table, return fast.
855850
if err != nil {
856851
return
857852
}
858853
res <- tbl
859-
}(builder)
854+
}(builder, s.reserveFileID())
860855
}
861856
s.kv.vlog.updateDiscardStats(discardStats)
862857
s.kv.opt.Debugf("Discard stats: %v", discardStats)

options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func DefaultOptions(path string) Options {
159159
// compression is ratio supposed to increase with increasing compression level but since the
160160
// input for compression algorithm is small (4 KB), we don't get significant benefit at
161161
// level 3.
162+
// NOTE: The benchmarks are with DataDog ZSTD that requires CGO. Hence, no longer valid.
162163
// no_compression-16 10 502848865 ns/op 165.46 MB/s -
163164
// zstd_compression/level_1-16 7 739037966 ns/op 112.58 MB/s 2.93
164165
// zstd_compression/level_3-16 7 756950250 ns/op 109.91 MB/s 2.72
@@ -712,6 +713,7 @@ func (opt Options) WithInMemory(b bool) Options {
712713
// algorithm is small (4 KB), we don't get significant benefit at level 3. It is advised to write
713714
// your own benchmarks before choosing a compression algorithm or level.
714715
//
716+
// NOTE: The benchmarks are with DataDog ZSTD that requires CGO. Hence, no longer valid.
715717
// no_compression-16 10 502848865 ns/op 165.46 MB/s -
716718
// zstd_compression/level_1-16 7 739037966 ns/op 112.58 MB/s 2.93
717719
// zstd_compression/level_3-16 7 756950250 ns/op 109.91 MB/s 2.72

txn.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ func (o *oracle) hasConflict(txn *Txn) bool {
160160
return false
161161
}
162162

163-
func (o *oracle) newCommitTs(txn *Txn) uint64 {
163+
func (o *oracle) newCommitTs(txn *Txn) (uint64, bool) {
164164
o.Lock()
165165
defer o.Unlock()
166166

167167
if o.hasConflict(txn) {
168-
return 0
168+
return 0, true
169169
}
170170

171171
var ts uint64
@@ -194,7 +194,7 @@ func (o *oracle) newCommitTs(txn *Txn) uint64 {
194194
})
195195
}
196196

197-
return ts
197+
return ts, false
198198
}
199199

200200
func (o *oracle) doneRead(txn *Txn) {
@@ -537,10 +537,8 @@ func (txn *Txn) commitAndSend() (func() error, error) {
537537
orc.writeChLock.Lock()
538538
defer orc.writeChLock.Unlock()
539539

540-
commitTs := orc.newCommitTs(txn)
541-
// The commitTs can be zero if the transaction is running in managed mode.
542-
// Individual entries might have their own timestamps.
543-
if commitTs == 0 && !txn.db.opt.managedTxns {
540+
commitTs, conflict := orc.newCommitTs(txn)
541+
if conflict {
544542
return nil, ErrConflict
545543
}
546544

txn_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,15 @@ func TestManagedDB(t *testing.T) {
817817
}
818818
}
819819
txn.Discard()
820+
821+
// Write data to same key, causing a conflict
822+
txn = db.NewTransactionAt(10, true)
823+
txnb := db.NewTransactionAt(10, true)
824+
txnb.Get(key(0))
825+
require.NoError(t, txn.SetEntry(NewEntry(key(0), val(0))))
826+
require.NoError(t, txnb.SetEntry(NewEntry(key(0), val(1))))
827+
require.NoError(t, txn.CommitAt(11, nil))
828+
require.Equal(t, ErrConflict, txnb.CommitAt(11, nil))
820829
}
821830
t.Run("disk mode", func(t *testing.T) {
822831
db, err := Open(opt)

0 commit comments

Comments
 (0)