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

Flush vlog buffer if it grows beyond threshold #1067

Merged
merged 4 commits into from
Oct 10, 2019
Merged

Conversation

jarifibrahim
Copy link
Contributor

@jarifibrahim jarifibrahim commented Oct 4, 2019

See #1062 (comment) for more details.

Fixes #1062


This change is Reviewable

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ A review job has been created and sent to the PullRequest network.


@jarifibrahim you can click here to see the review status or cancel the code review job.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the ticket details (#1062 (comment)) to the test and implementation. I added an inline comment regarding readability as well.


Reviewed with ❤️ by PullRequest

@@ -1315,6 +1315,18 @@ func (vlog *valueLog) write(reqs []*request) error {
p.Len = uint32(plen)
b.Ptrs = append(b.Ptrs, p)
written++

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the buffer length be stored since it is retrieved multiple times?

bl := buf.Len()

@coveralls
Copy link

coveralls commented Oct 7, 2019

Coverage Status

Coverage increased (+0.02%) to 77.571% when pulling bd1c2b1 on ibrahim/wb-oom into f50343f on master.

Copy link
Contributor

@ashish-goswami ashish-goswami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @ashish-goswami, @jarifibrahim, and @manishrjain)


value.go, line 1319 at r2 (raw file):

			written++

			if int64(buf.Len()) > vlog.db.opt.ValueLogFileSize {

Please add a comment explaining, why we are doing this change.
Looks like new code written has something common with toDisk method. Can we somehow avoid the repetition?
Also if possible please add a test for this(may be in db2_test.go which can be run manually).

Copy link
Contributor Author

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @ashish-goswami, @manishrjain, and @pullrequest[bot])


value.go, line 1318 at r1 (raw file):

Previously, pullrequest[bot] wrote…

Can the buffer length be stored since it is retrieved multiple times?

bl := buf.Len()

I've changed the code and this comment is no longer valid.


value.go, line 1319 at r2 (raw file):

Previously, ashish-goswami (Ashish Goswami) wrote…

Please add a comment explaining, why we are doing this change.
Looks like new code written has something common with toDisk method. Can we somehow avoid the repetition?
Also if possible please add a test for this(may be in db2_test.go which can be run manually).

Done.

Copy link
Contributor

@ashish-goswami ashish-goswami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @manishrjain and @pullrequest[bot])

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Name changes. Rest is good.

Reviewed 1 of 1 files at r3.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @jarifibrahim and @pullrequest[bot])


value.go, line 1263 at r3 (raw file):

	var buf bytes.Buffer
	toDisk := func() error {

flushBuffer


value.go, line 1279 at r3 (raw file):

		return nil
	}
	flushWrites := func() error {

toDisk

Copy link
Contributor Author

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r4.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @manishrjain and @pullrequest[bot])


value.go, line 1263 at r3 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

flushBuffer

Done.


value.go, line 1279 at r3 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

toDisk

Done.

@jarifibrahim jarifibrahim merged commit bcf8b97 into master Oct 10, 2019
@jarifibrahim jarifibrahim deleted the ibrahim/wb-oom branch October 10, 2019 10:11
jarifibrahim pushed a commit that referenced this pull request Mar 12, 2020
The OOM happens when we trying to flush write batch.
When we insert data into a transaction, we calculate the size
of the transaction by using the following function
https://github.com/dgraph-io/badger/blob/b20e8b6e8b742236f4a88f7c0cead2d64118a416/txn.go#L295-L300
which uses `estimateSize` function
https://github.com/dgraph-io/badger/blob/b20e8b6e8b742236f4a88f7c0cead2d64118a416/structs.go#L134-L139

For a key size of 4 and a value size of 1 MB, the `estimateSize`
function would return 4 + 12 + 2 = 18 byte which is valid in case
of SSTs but not for a vlog file. The entry size for vlog would be
around 1 MB and when all such entries are packed into a single
request for vlog, the bytes.buffer in vlog crashes with OOM error.
This commit fixes it.

(cherry picked from commit bcf8b97)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Write batch crash with OOM error
4 participants