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

Crash replays all the value log files #1363

Closed
jarifibrahim opened this issue Jun 11, 2020 · 2 comments · Fixed by #1372
Closed

Crash replays all the value log files #1363

jarifibrahim opened this issue Jun 11, 2020 · 2 comments · Fixed by #1372
Assignees
Labels
area/crash This issue causes a panic or some other of exception that causes a crash. kind/bug Something is broken. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate or work on it.

Comments

@jarifibrahim
Copy link
Contributor

What version of Badger are you using?

14386ac

Does this issue reproduce with the latest master?

Yes

Steps to Reproduce the issue

What Badger options were set?

opt := badger.DefaultOptions(sstDir).    
         WithValueDir(vlogDir).    
         WithTruncate(truncate).    
         WithSyncWrites(false).    
         WithKeepBlocksInCache(true).    
         WithMaxCacheSize(200 << 20).    
         WithKeepBlockIndicesInCache(true).    
         WithCompression(options.ZSTD).    
         WithCompactL0OnClose(force)    

What did you do?

Run benchmark write tool

go run main.go benchmark write -m 400 --dir ~/m2_drive/100m -l 2>&1 | tee 100m-logs.txt

What did you expect to see?

Value log replayed to replay only a few recent files

What did you see instead?

Badger is replaying file with id 0 offset 0, I have 1164 files

ls ~/m2_drive/100m/ | grep .vlog | wc -l
1164
go run main.go benchmark write -m 400 --dir ~/m2_drive/100m -l 2>&1 | tee 100m-logs.txt
Listening for /debug HTTP requests at port: 8080
badger 2020/06/11 17:28:28 INFO: 335 tables out of 1170 opened in 3.002s
badger 2020/06/11 17:28:31 INFO: 669 tables out of 1170 opened in 6.026s
badger 2020/06/11 17:28:34 INFO: 1004 tables out of 1170 opened in 9.015s
badger 2020/06/11 17:28:36 INFO: All 1170 tables opened in 10.797s
badger 2020/06/11 17:28:36 INFO: Replaying file id: 0 at offset: 0
badger 2020/06/11 17:28:37 INFO: Got compaction priority: {level:2 score:1.1463758505880832 dropPrefix:[]}
badger 2020/06/11 17:28:37 INFO: Running for level: 2
badger 2020/06/11 17:28:38 INFO: Got compaction priority: {level:3 score:1.1370206640660763 dropPrefix:[]}
badger 2020/06/11 17:28:38 INFO: Running for level: 3
badger 2020/06/11 17:28:38 INFO: Replay took: 2.271997389s
badger 2020/06/11 17:28:38 INFO: Replaying file id: 1 at offset: 0
@jarifibrahim jarifibrahim added kind/bug Something is broken. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate or work on it. area/crash This issue causes a panic or some other of exception that causes a crash. labels Jun 11, 2020
@jarifibrahim
Copy link
Contributor Author

The issue seems to be happening because we update the head pointer only after replay is successful

badger/value.go

Line 1193 in 14386ac

vlog.db.vhead = valuePointer{Fid: vlog.maxFid, Offset: uint32(lastOffset)}

I think we can update the head pointer as entries are being applied.
I haven't thought this through but the following might fix the issue.

diff --git a/db.go b/db.go
index 79b332d..dacd30f 100644
--- a/db.go
+++ b/db.go
@@ -136,6 +136,7 @@ func (db *DB) replayFunction() func(Entry, valuePointer) error {
 		} else {
 			nv = vp.Encode()
 			meta = meta | bitValuePointer
+			db.vhead = vp
 		}
 
 		v := y.ValueStruct{

@jarifibrahim jarifibrahim self-assigned this Jun 16, 2020
jarifibrahim pushed a commit that referenced this issue Jun 30, 2020
Fixes #1363

The head pointer is not updated when we perform replays. The head
pointer would be updated only when the replay completes. If badger crashes
between the point when replay started and replay finished, we would end up
replaying all the value log files. This PR fixes this issue.
jarifibrahim pushed a commit that referenced this issue Jul 6, 2020
Fixes #1363

The head pointer is not updated when we perform replays. The head
pointer would be updated only when the replay completes. If badger crashes
between the point when replay started and replay finished, we would end up
replaying all the value log files. This PR fixes this issue.

(cherry picked from commit 509de73)
@manishrjain manishrjain reopened this Jul 12, 2020
@github-actions
Copy link

Use Discuss Issues for reporting issues about this repository.

NamanJain8 pushed a commit that referenced this issue Sep 8, 2020
Fixes #1363

The head pointer is not updated when we perform replays. The head
pointer would be updated only when the replay completes. If badger crashes
between the point when replay started and replay finished, we would end up
replaying all the value log files. This PR fixes this issue.

(cherry picked from commit 509de73)
NamanJain8 added a commit that referenced this issue Sep 9, 2020
Fixes #1363

The head pointer is not updated when we perform replays. The head
pointer would be updated only when the replay completes. If badger crashes
between the point when replay started and replay finished, we would end up
replaying all the value log files. This PR fixes this issue.

(cherry picked from commit 509de73)

Co-authored-by: Ibrahim Jarif <[email protected]>
jarifibrahim pushed a commit that referenced this issue Oct 2, 2020
Fixes #1363

The head pointer is not updated when we perform replays. The head
pointer would be updated only when the replay completes. If badger crashes
between the point when replay started and replay finished, we would end up
replaying all the value log files. This PR fixes this issue.
manishrjain pushed a commit to outcaste-io/outserv that referenced this issue Jul 6, 2022
Fixes dgraph-io/badger#1363

The head pointer is not updated when we perform replays. The head
pointer would be updated only when the replay completes. If badger crashes
between the point when replay started and replay finished, we would end up
replaying all the value log files. This PR fixes this issue.
mYmNeo pushed a commit to mYmNeo/badger that referenced this issue Jan 16, 2023
Fixes dgraph-io#1363

The head pointer is not updated when we perform replays. The head
pointer would be updated only when the replay completes. If badger crashes
between the point when replay started and replay finished, we would end up
replaying all the value log files. This PR fixes this issue.

(cherry picked from commit 509de73)

Co-authored-by: Ibrahim Jarif <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/crash This issue causes a panic or some other of exception that causes a crash. kind/bug Something is broken. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate or work on it.
Development

Successfully merging a pull request may close this issue.

2 participants