Skip to content

Commit 8fd5740

Browse files
Ibrahim Jarifparalinlgalatindamzmartinmr
authored
Add missing commits to release/v2.0 branch (#1245)
* Cast sz to uint32 to fix compilation on 32 bit (#1175) `env GOOS=linux GOARCH=arm GOARM=7 go build` no longer fails with overflow. Similar to commit fb0cdb8. Signed-off-by: Christian Stewart <[email protected]> (cherry picked from commit 465f28a) * Fix commit sha for WithInMemory in CHANGELOG. (#1172) (cherry picked from commit 03af216) * Fix windows build (#1177) Fix windows build and some deepsource warnings (cherry picked from commit 0f2e629) * Fix checkOverlap in compaction (#1166) The overlap check in compaction would keep additional keys in case the levels under compaction had overlap amongst themselves. This commit fixes it. This commit also fixes the `numVersionsToKeep` check. Without this commit, we would end up keeping `2` versions of a key even when the number of versions to keep was set to `1`. See `level 0 to level 1 with lower overlap` test. Fixes #1053 The following test fails on master but works with this commit ```go func TestCompaction(t *testing.T) { t.Run("level 0 to level 1", func(t *testing.T) { dir, err := ioutil.TempDir("", "badger-test") require.NoError(t, err) defer removeDir(dir) // Disable compactions and keep single version of each key. opt := DefaultOptions(dir).WithNumCompactors(0).WithNumVersionsToKeep(1) db, err := OpenManaged(opt) require.NoError(t, err) l0 := []keyValVersion{{"foo", "bar", 3}, {"fooz", "baz", 1}} l01 := []keyValVersion{{"foo", "bar", 2}} l1 := []keyValVersion{{"foo", "bar", 1}} // Level 0 has table l0 and l01. createAndOpen(db, l0, 0) createAndOpen(db, l01, 0) // Level 1 has table l1. createAndOpen(db, l1, 1) // Set a high discard timestamp so that all the keys are below the discard timestamp. db.SetDiscardTs(10) getAllAndCheck(t, db, []keyValVersion{ {"foo", "bar", 3}, {"foo", "bar", 2}, {"foo", "bar", 1}, {"fooz", "baz", 1}, }) cdef := compactDef{ thisLevel: db.lc.levels[0], nextLevel: db.lc.levels[1], top: db.lc.levels[0].tables, bot: db.lc.levels[1].tables, } require.NoError(t, db.lc.runCompactDef(0, cdef)) // foo version 2 should be dropped after compaction. getAllAndCheck(t, db, []keyValVersion{{"foo", "bar", 3}, {"fooz", "baz", 1}}) }) } ``` (cherry picked from commit 0a06173) * Remove the 'this entry should've caught' log from value.go (#1170) Fixes - #1031 (There wasn't a bug to fix. The log statement shouldn't have been there) This PR removes the warning message `WARNING: This entry should have been caught.`. The warning message assumed that we will always find the **newest key if two keys have the same version** This assumption is valid in case of a normal key but it's **NOT TRUE** in case of **move keys**. Here's how we can end up fetching the older version of a move key if two move keys have the same version. ``` It might be possible that the entry read from LSM Tree points to an older vlog file. This can happen in the following situation. Assume DB is opened with numberOfVersionsToKeep=1 Now, if we have ONLY one key in the system "FOO" which has been updated 3 times and the same key has been garbage collected 3 times, we'll have 3 versions of the movekey for the same key "FOO". NOTE: moveKeyi is the moveKey with version i Assume we have 3 move keys in L0. - moveKey1 (points to vlog file 10), - moveKey2 (points to vlog file 14) and - moveKey3 (points to vlog file 15). Also, assume there is another move key "moveKey1" (points to vlog file 6) (this is also a move Key for key "FOO" ) on upper levels (let's say level 3). The move key "moveKey1" on level 0 was inserted because vlog file 6 was GCed. Here's what the arrangement looks like L0 => (moveKey1 => vlog10), (moveKey2 => vlog14), (moveKey3 => vlog15) L1 => .... L2 => .... L3 => (moveKey1 => vlog6) When L0 compaction runs, it keeps only moveKey3 because the number of versions to keep is set to 1. (we've dropped moveKey1's latest version) The new arrangement of keys is L0 => .... L1 => (moveKey3 => vlog15) L2 => .... L3 => (moveKey1 => vlog6) Now if we try to GC vlog file 10, the entry read from vlog file will point to vlog10 but the entry read from LSM Tree will point to vlog6. The move key read from LSM tree will point to vlog6 because we've asked for version 1 of the move key. This might seem like an issue but it's not really an issue because the user has set the number of versions to keep to 1 and the latest version of moveKey points to the correct vlog file and offset. The stale move key on L3 will be eventually dropped by compaction because there is a newer version in the upper levels. ``` (cherry picked from commit 2a90c66) * Avoid sync in inmemory mode (#1190) This makes db.Sync() no-op when badger is running in in-memory mode. The previous code would unnecessarily load up an atomic and acquire locks. (cherry picked from commit 2698bfc) * Use fastRand instead of locked-rand in skiplist (#1173) The math/rand package (https://golang.org/src/math/rand/rand.go) uses a global lock to allow concurrent access to the rand object. The PR replaces `math.Rand` with `ristretto/z.FastRand()`. `FastRand` is much faster than `math.Rand` and `rand.New(..)` generators. The change improves concurrent writes to skiplist by ~30% ```go func BenchmarkWrite(b *testing.B) { value := newValue(123) l := NewSkiplist(int64((b.N + 1) * MaxNodeSize)) defer l.DecrRef() b.ResetTimer() b.RunParallel(func(pb *testing.PB) { rng := rand.New(rand.NewSource(time.Now().UnixNano())) for pb.Next() { l.Put(randomKey(rng), y.ValueStruct{Value: value, Meta: 0, UserMeta: 0}) } }) } ``` ``` name old time/op new time/op delta Write-16 657ns ± 3% 441ns ± 1% -32.94% (p=0.000 n=9+10) ``` (cherry picked from commit 9d6512b) * Add Jaegar to list of projects (#1192) (cherry picked from commit 01a00cb) * Run all tests on CI (#1189) This could possibly be a bug in `go test` command golang/go#36527 . The `go test` command would skip tests in sub-packages if the top-level package has a `custom flag` defined and the sub-packages don't define it. Issue golang/go#36527 (comment) has an example of this. This PR also removes the code from the test that would unnecessary start a web server. I see two problems here 1. An unnecessary web server running. 2. We cannot run multiple tests are the same time since the second run of the test would try to start a web server and crash saying `port already in use`. (cherry picked from commit 5870b7b) * Improve write stalling on level 0 and 1 We don't need to stall writes if Level 1 does not have enough space. Level 1 is stored on the disk and it should be okay to have more number of tables (more size) on Level 1 than the `max level 1 size`. These tables will eventually be compacted to lower levels. This commit changes the following - We no longer stall writes if L1 doesn't have enough space. - We stall writes on level 0 only if `KeepL0InMemory` is true. - Upper levels (L0, L1, etc) get priority in compaction (previously, level with higher priority score would get preference) (cherry picked from commit 3747be5) * Update ristretto to version 8f368f2 (#1195) This commit pulls following changes from ristretto ``` git log c1f00be0418e...8f368f2 --oneline ``` ``` 8f368f2 (HEAD -> master) Fix DeepSource warnings adb35f0 delete item immediately fce5e91 Support nil *Cache values in Clear and Close 4e224f9 Add .travis.yml 8350826 Fix the way metrics are handled for deletions 99d1bbb (tag: v0.0.1) default to 128bit hashing for collision checks 1eea1b1 atomic Get-Delete operation for eviction 8d6a8a7 add cache test for identifying MaxCost overflows ae09250 use the custom KeyToHash function if one is set 1dd5a4d #19 Fixes memory leak due to Oct 1st regression in processItems ``` (cherry picked from commit 82381ac) * Support disabling the cache completely. (#1183) (#1185) The cache can be disabled by setting `opt.MaxCacheSize=0` (cherry picked from commit 7e5a956) * Fix L0/L1 stall test (#1201) The test `TestL0Stall` and `TestL1Stall` would never fail because of errors in the manifest file. This commit fixes it. (cherry picked from commit 0acb3f6) * Disable compression and set ZSTD Compression Level to 1 (#1191) This PR - Disables compression. By default, badger does not use any compression. - Set default ZSTD compression level to 1 Level 15 is very slow for any practical use of badger. ``` no_compression-16 10 502848865 ns/op 165.46 MB/s zstd_compression/level_1-16 7 739037966 ns/op 112.58 MB/s zstd_compression/level_3-16 7 756950250 ns/op 109.91 MB/s zstd_compression/level_15-16 1 11135686219 ns/op 7.47 MB/s ``` (cherry picked from commit c3333a5) * Add support for caching bloomfilters (#1204) This PR adds support for caching bloom filters in ristretto. The bloom filters and blocks are removed from the cache when the table is deleted. (cherry picked from commit 4676ca9) * Rework concurrency semantics of valueLog.maxFid (#1184) (#1187) Move all access to `valueLog.maxFid` under `valueLog.filesLock`, while all mutations happen either with writes stopped or sequentially under valueLog.write. Fixes a concurrency issue in `valueLog.Read` where the maxFid variable and the `writableLogOffset` variable could point to two different log files. (cherry picked from commit 3e25d77) * Change else-if statements to idiomatic switch statements. (#1207) (cherry picked from commit eee1602) * Fix flaky TestPageBufferReader2 test (#1210) Fixes #1197 The `TestPageBufferReader2` test would fail often because of an `off-by-1` issue. The problem can be reproduced by setting `randOffset` to the biggest number that randInt31n may return statically like: ``` //randOffset := int(rand.Int31n(int32(b.length))) randOffset := int(int32(b.length-1)) ``` This makes the problem reliably reproducible as the offset is now pointing at EOF. Thus changing the line to this should hopefully solve the problem: `randOffset := int(rand.Int31n(int32(b.length-1 (cherry picked from commit c51748e) * Replace t.Fatal with require.NoError in tests (#1213) We are using the following pattern in tests that can be replaced with `require.NoError(t, err)`. ```go if err != nil { t.Fatal(err) } ``` (cherry picked from commit 78d405a) * Add missing package to README for badger.NewEntry (#1223) (cherry picked from commit 8734e3a) * Remove ExampleDB_Subscribe Test (#1214) The test ExampleDB_Subscribe doesn't run reliably on appveyor. This commit removes it. (cherry picked from commit e029e93) * Fix int overflow for 32bit (#1216) - Fix tests for 32 bit systems - Enable 32-bit builds on Travis (cherry picked from commit bce069c) * Update CHANGELOG for Badger 2.0.2 release. (#1230) Co-authored-by: Ibrahim Jarif <[email protected]> (cherry picked from commit e908818) * Fix changelog for v2.0.2 (cherry picked from commit b81faa5) Co-authored-by: Christian Stewart <[email protected]> Co-authored-by: Leyla Galatin <[email protected]> Co-authored-by: Damien Tournoud <[email protected]> Co-authored-by: Martin Martinez Rivera <[email protected]> Co-authored-by: Dieter Plaetinck <[email protected]> Co-authored-by: Apoorv Vardhan <[email protected]>
1 parent bd8da72 commit 8fd5740

25 files changed

+1143
-383
lines changed

.travis.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
language: go
22

33
go:
4-
- "1.11"
5-
- "1.12"
6-
- "1.13"
7-
- tip
4+
- "1.11"
5+
- "1.12"
6+
- "1.13"
7+
- tip
88
os:
9-
- osx
10-
9+
- osx
10+
env:
11+
jobs:
12+
- GOARCH=386
13+
- GOARCH=amd64
14+
global:
15+
- secure: CRkV2+/jlO0gXzzS50XGxfMS117FNwiVjxNY/LeWq06RKD+dDCPxTJl3JCNe3l0cYEPAglV2uMMYukDiTqJ7e+HI4nh4N4mv6lwx39N8dAvJe1x5ITS2T4qk4kTjuQb1Q1vw/ZOxoQqmvNKj2uRmBdJ/HHmysbRJ1OzCWML3OXdUwJf0AYlJzTjpMfkOKr7sTtE4rwyyQtd4tKH1fGdurgI9ZuFd9qvYxK2qcJhsQ6CNqMXt+7FkVkN1rIPmofjjBTNryzUr4COFXuWH95aDAif19DeBW4lbNgo1+FpDsrgmqtuhl6NAuptI8q/imow2KXBYJ8JPXsxW8DVFj0IIp0RCd3GjaEnwBEbxAyiIHLfW7AudyTS/dJOvZffPqXnuJ8xj3OPIdNe4xY0hWl8Ju2HhKfLOAHq7VadHZWd3IHLil70EiL4/JLD1rNbMImUZisFaA8pyrcIvYYebjOnk4TscwKFLedClRSX1XsMjWWd0oykQtrdkHM2IxknnBpaLu7mFnfE07f6dkG0nlpyu4SCLey7hr5FdcEmljA0nIxTSYDg6035fQkBEAbe7hlESOekkVNT9IZPwG+lmt3vU4ofi6NqNbJecOuSB+h36IiZ9s4YQtxYNnLgW14zjuFGGyT5smc3IjBT7qngDjKIgyrSVoRkY/8udy9qbUgvBeW8=
16+
17+
1118
jobs:
1219
allow_failures:
1320
- go: tip
21+
exclude:
22+
# Exclude builds for 386 architecture on go 1.11, 1.12 and tip
23+
# Since we don't want it to run for 32 bit
24+
- go: "1.11"
25+
env: GOARCH=386
26+
- go: "1.12"
27+
env: GOARCH=386
28+
- go: tip
29+
env: GOARCH=386
1430

1531
notifications:
1632
email: false
1733
slack:
1834
secure: X7uBLWYbuUhf8QFE16CoS5z7WvFR8EN9j6cEectMW6mKZ3vwXGwVXRIPsgUq/606DsQdCCx34MR8MRWYGlu6TBolbSe9y0EP0i46yipPz22YtuT7umcVUbGEyx8MZKgG0v1u/zA0O4aCsOBpGAA3gxz8h3JlEHDt+hv6U8xRsSllVLzLSNb5lwxDtcfEDxVVqP47GMEgjLPM28Pyt5qwjk7o5a4YSVzkfdxBXxd3gWzFUWzJ5E3cTacli50dK4GVfiLcQY2aQYoYO7AAvDnvP+TPfjDkBlUEE4MUz5CDIN51Xb+WW33sX7g+r3Bj7V5IRcF973RiYkpEh+3eoiPnyWyxhDZBYilty3b+Hysp6d4Ov/3I3ll7Bcny5+cYjakjkMH3l9w3gs6Y82GlpSLSJshKWS8vPRsxFe0Pstj6QSJXTd9EBaFr+l1ScXjJv/Sya9j8N9FfTuOTESWuaL1auX4Y7zEEVHlA8SCNOO8K0eTfxGZnC/YcIHsR8rePEAcFxfOYQppkyLF/XvAtnb/LMUuu0g4y2qNdme6Oelvyar1tFEMRtbl4mRCdu/krXBFtkrsfUaVY6WTPdvXAGotsFJ0wuA53zGVhlcd3+xAlSlR3c1QX95HIMeivJKb5L4nTjP+xnrmQNtnVk+tG4LSH2ltuwcZSSczModtcBmRefrk=
1935

20-
env:
21-
global:
22-
- secure: CRkV2+/jlO0gXzzS50XGxfMS117FNwiVjxNY/LeWq06RKD+dDCPxTJl3JCNe3l0cYEPAglV2uMMYukDiTqJ7e+HI4nh4N4mv6lwx39N8dAvJe1x5ITS2T4qk4kTjuQb1Q1vw/ZOxoQqmvNKj2uRmBdJ/HHmysbRJ1OzCWML3OXdUwJf0AYlJzTjpMfkOKr7sTtE4rwyyQtd4tKH1fGdurgI9ZuFd9qvYxK2qcJhsQ6CNqMXt+7FkVkN1rIPmofjjBTNryzUr4COFXuWH95aDAif19DeBW4lbNgo1+FpDsrgmqtuhl6NAuptI8q/imow2KXBYJ8JPXsxW8DVFj0IIp0RCd3GjaEnwBEbxAyiIHLfW7AudyTS/dJOvZffPqXnuJ8xj3OPIdNe4xY0hWl8Ju2HhKfLOAHq7VadHZWd3IHLil70EiL4/JLD1rNbMImUZisFaA8pyrcIvYYebjOnk4TscwKFLedClRSX1XsMjWWd0oykQtrdkHM2IxknnBpaLu7mFnfE07f6dkG0nlpyu4SCLey7hr5FdcEmljA0nIxTSYDg6035fQkBEAbe7hlESOekkVNT9IZPwG+lmt3vU4ofi6NqNbJecOuSB+h36IiZ9s4YQtxYNnLgW14zjuFGGyT5smc3IjBT7qngDjKIgyrSVoRkY/8udy9qbUgvBeW8=
23-
2436
before_script:
2537
- go get github.com/mattn/goveralls
2638
script:

CHANGELOG.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,31 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Serialization Versioning](VERSIONING.md).
66

7+
## [2.0.2] - 2020-02-26
8+
9+
### Fixed
10+
11+
- Cast sz to uint32 to fix compilation on 32 bit. (#1175)
12+
- Fix checkOverlap in compaction. (#1166)
13+
- Avoid sync in inmemory mode. (#1190)
14+
- Support disabling the cache completely. (#1185)
15+
- Add support for caching bloomfilters. (#1204)
16+
- Fix int overflow for 32bit. (#1216)
17+
- Remove the 'this entry should've caught' log from value.go. (#1170)
18+
- Rework concurrency semantics of valueLog.maxFid. (#1187)
19+
20+
### Performance
21+
22+
- Use fastRand instead of locked-rand in skiplist. (#1173)
23+
- Improve write stalling on level 0 and 1. (#1186)
24+
- Disable compression and set ZSTD Compression Level to 1. (#1191)
25+
726
## [2.0.1] - 2020-01-02
827

928
### New APIs
1029

1130
- badger.Options
12-
- WithInMemory (5b6321)
31+
- WithInMemory (f5b6321)
1332
- WithZSTDCompressionLevel (3eb4e72)
1433

1534
- Badger.TableInfo
@@ -274,7 +293,7 @@ Bug fix:
274293
## [1.0.1] - 2017-11-06
275294
* Fix an uint16 overflow when resizing key slice
276295

277-
[Unreleased]: https://github.com/dgraph-io/badger/compare/v2.0.1...HEAD
296+
[2.0.2]: https://github.com/dgraph-io/badger/compare/v2.0.1...v2.0.2
278297
[2.0.1]: https://github.com/dgraph-io/badger/compare/v2.0.0...v2.0.1
279298
[2.0.0]: https://github.com/dgraph-io/badger/compare/v1.6.0...v2.0.0
280299
[1.6.0]: https://github.com/dgraph-io/badger/compare/v1.5.5...v1.6.0

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ on it.
252252

253253
```go
254254
err := db.Update(func(txn *badger.Txn) error {
255-
e := NewEntry([]byte("answer"), []byte("42"))
255+
e := badger.NewEntry([]byte("answer"), []byte("42"))
256256
err := txn.SetEntry(e)
257257
return err
258258
})
@@ -401,7 +401,7 @@ and `Txn.SetEntry()` API methods.
401401

402402
```go
403403
err := db.Update(func(txn *badger.Txn) error {
404-
e := NewEntry([]byte("answer"), []byte("42")).WithTTL(time.Hour)
404+
e := badger.NewEntry([]byte("answer"), []byte("42")).WithTTL(time.Hour)
405405
err := txn.SetEntry(e)
406406
return err
407407
})
@@ -414,7 +414,7 @@ metadata can be set using `Entry.WithMeta()` and `Txn.SetEntry()` API methods.
414414

415415
```go
416416
err := db.Update(func(txn *badger.Txn) error {
417-
e := NewEntry([]byte("answer"), []byte("42")).WithMeta(byte(1))
417+
e := badger.NewEntry([]byte("answer"), []byte("42")).WithMeta(byte(1))
418418
err := txn.SetEntry(e)
419419
return err
420420
})
@@ -425,7 +425,7 @@ then can be set using `Txn.SetEntry()`.
425425

426426
```go
427427
err := db.Update(func(txn *badger.Txn) error {
428-
e := NewEntry([]byte("answer"), []byte("42")).WithMeta(byte(1)).WithTTL(time.Hour)
428+
e := badger.NewEntry([]byte("answer"), []byte("42")).WithMeta(byte(1)).WithTTL(time.Hour)
429429
err := txn.SetEntry(e)
430430
return err
431431
})
@@ -748,6 +748,7 @@ Below is a list of known projects that use Badger:
748748

749749
* [0-stor](https://github.com/zero-os/0-stor) - Single device object store.
750750
* [Dgraph](https://github.com/dgraph-io/dgraph) - Distributed graph database.
751+
* [Jaeger](https://github.com/jaegertracing/jaeger) - Distributed tracing platform.
751752
* [TalariaDB](https://github.com/grab/talaria) - Distributed, low latency time-series database.
752753
* [Dispatch Protocol](https://github.com/dispatchlabs/disgo) - Blockchain protocol for distributed application data analytics.
753754
* [Sandglass](https://github.com/celrenheit/sandglass) - distributed, horizontally scalable, persistent, time sorted message queue.

backup_test.go

Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,18 @@ func TestBackupRestore1(t *testing.T) {
116116

117117
func TestBackupRestore2(t *testing.T) {
118118
tmpdir, err := ioutil.TempDir("", "badger-test")
119-
if err != nil {
120-
t.Fatal(err)
121-
}
119+
require.NoError(t, err)
120+
122121
defer removeDir(tmpdir)
123122

124123
s1Path := filepath.Join(tmpdir, "test1")
125124
s2Path := filepath.Join(tmpdir, "test2")
126125
s3Path := filepath.Join(tmpdir, "test3")
127126

128127
db1, err := Open(getTestOptions(s1Path))
129-
if err != nil {
130-
t.Fatal(err)
131-
}
128+
require.NoError(t, err)
129+
130+
defer db1.Close()
132131
key1 := []byte("key1")
133132
key2 := []byte("key2")
134133
rawValue := []byte("NotLongValue")
@@ -139,35 +138,30 @@ func TestBackupRestore2(t *testing.T) {
139138
}
140139
return tx.SetEntry(NewEntry(key2, rawValue))
141140
})
142-
if err != nil {
143-
t.Fatal(err)
144-
}
141+
require.NoError(t, err)
142+
145143
for i := byte(1); i < N; i++ {
146144
err = db1.Update(func(tx *Txn) error {
147145
if err := tx.SetEntry(NewEntry(append(key1, i), rawValue)); err != nil {
148146
return err
149147
}
150148
return tx.SetEntry(NewEntry(append(key2, i), rawValue))
151149
})
152-
if err != nil {
153-
t.Fatal(err)
154-
}
150+
require.NoError(t, err)
151+
155152
}
156153
var backup bytes.Buffer
157154
_, err = db1.Backup(&backup, 0)
158-
if err != nil {
159-
t.Fatal(err)
160-
}
155+
require.NoError(t, err)
156+
161157
fmt.Println("backup1 length:", backup.Len())
162158

163159
db2, err := Open(getTestOptions(s2Path))
164-
if err != nil {
165-
t.Fatal(err)
166-
}
160+
require.NoError(t, err)
161+
162+
defer db2.Close()
167163
err = db2.Load(&backup, 16)
168-
if err != nil {
169-
t.Fatal(err)
170-
}
164+
require.NoError(t, err)
171165

172166
for i := byte(1); i < N; i++ {
173167
err = db2.View(func(tx *Txn) error {
@@ -188,9 +182,8 @@ func TestBackupRestore2(t *testing.T) {
188182
}
189183
return nil
190184
})
191-
if err != nil {
192-
t.Fatal(err)
193-
}
185+
require.NoError(t, err)
186+
194187
}
195188

196189
for i := byte(1); i < N; i++ {
@@ -200,26 +193,22 @@ func TestBackupRestore2(t *testing.T) {
200193
}
201194
return tx.SetEntry(NewEntry(append(key2, i), rawValue))
202195
})
203-
if err != nil {
204-
t.Fatal(err)
205-
}
196+
require.NoError(t, err)
197+
206198
}
207199

208200
backup.Reset()
209201
_, err = db2.Backup(&backup, 0)
210-
if err != nil {
211-
t.Fatal(err)
212-
}
202+
require.NoError(t, err)
203+
213204
fmt.Println("backup2 length:", backup.Len())
214205
db3, err := Open(getTestOptions(s3Path))
215-
if err != nil {
216-
t.Fatal(err)
217-
}
206+
require.NoError(t, err)
207+
208+
defer db3.Close()
218209

219210
err = db3.Load(&backup, 16)
220-
if err != nil {
221-
t.Fatal(err)
222-
}
211+
require.NoError(t, err)
223212

224213
for i := byte(1); i < N; i++ {
225214
err = db3.View(func(tx *Txn) error {
@@ -240,9 +229,8 @@ func TestBackupRestore2(t *testing.T) {
240229
}
241230
return nil
242231
})
243-
if err != nil {
244-
t.Fatal(err)
245-
}
232+
require.NoError(t, err)
233+
246234
}
247235

248236
}
@@ -310,9 +298,8 @@ func TestBackup(t *testing.T) {
310298
}
311299
t.Run("disk mode", func(t *testing.T) {
312300
tmpdir, err := ioutil.TempDir("", "badger-test")
313-
if err != nil {
314-
t.Fatal(err)
315-
}
301+
require.NoError(t, err)
302+
316303
defer removeDir(tmpdir)
317304
opt := DefaultOptions(filepath.Join(tmpdir, "backup0"))
318305
runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
@@ -330,11 +317,9 @@ func TestBackup(t *testing.T) {
330317

331318
func TestBackupRestore3(t *testing.T) {
332319
var bb bytes.Buffer
333-
334320
tmpdir, err := ioutil.TempDir("", "badger-test")
335-
if err != nil {
336-
t.Fatal(err)
337-
}
321+
require.NoError(t, err)
322+
338323
defer removeDir(tmpdir)
339324

340325
N := 1000
@@ -343,10 +328,9 @@ func TestBackupRestore3(t *testing.T) {
343328
// backup
344329
{
345330
db1, err := Open(DefaultOptions(filepath.Join(tmpdir, "backup1")))
346-
if err != nil {
347-
t.Fatal(err)
348-
}
331+
require.NoError(t, err)
349332

333+
defer db1.Close()
350334
require.NoError(t, populateEntries(db1, entries))
351335

352336
_, err = db1.Backup(&bb, 0)
@@ -358,9 +342,9 @@ func TestBackupRestore3(t *testing.T) {
358342

359343
// restore
360344
db2, err := Open(DefaultOptions(filepath.Join(tmpdir, "restore1")))
361-
if err != nil {
362-
t.Fatal(err)
363-
}
345+
require.NoError(t, err)
346+
347+
defer db2.Close()
364348
require.NoError(t, db2.Load(&bb, 16))
365349

366350
// verify
@@ -390,9 +374,8 @@ func TestBackupRestore3(t *testing.T) {
390374

391375
func TestBackupLoadIncremental(t *testing.T) {
392376
tmpdir, err := ioutil.TempDir("", "badger-test")
393-
if err != nil {
394-
t.Fatal(err)
395-
}
377+
require.NoError(t, err)
378+
396379
defer removeDir(tmpdir)
397380

398381
N := 100
@@ -403,9 +386,9 @@ func TestBackupLoadIncremental(t *testing.T) {
403386
// backup
404387
{
405388
db1, err := Open(DefaultOptions(filepath.Join(tmpdir, "backup2")))
406-
if err != nil {
407-
t.Fatal(err)
408-
}
389+
require.NoError(t, err)
390+
391+
defer db1.Close()
409392

410393
require.NoError(t, populateEntries(db1, entries))
411394
since, err := db1.Backup(&bb, 0)
@@ -463,9 +446,10 @@ func TestBackupLoadIncremental(t *testing.T) {
463446

464447
// restore
465448
db2, err := Open(getTestOptions(filepath.Join(tmpdir, "restore2")))
466-
if err != nil {
467-
t.Fatal(err)
468-
}
449+
require.NoError(t, err)
450+
451+
defer db2.Close()
452+
469453
require.NoError(t, db2.Load(&bb, 16))
470454

471455
// verify

0 commit comments

Comments
 (0)