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

Fix(cleanup): Avoid truncating in value.Open on error #1465

Merged
merged 6 commits into from
Aug 27, 2020

Conversation

jarifibrahim
Copy link
Contributor

@jarifibrahim jarifibrahim commented Aug 18, 2020

The vlog.Open() function can return an error denoting that the open was
unsuccessful but we have db.cleanup which will be called to stop all
the running goroutines in case badger couldn't start. The db.cleanup
function calls vlog.Close() which will truncate the maxFid vlog file
based on the vlog.writableLogOffset. The vlog.writableLogOffset was not
being updated in case open failed. As a result of this, we will end up
truncating the vlog file to length 0 if open fails.

This PR fixes this by using vlog.stopDiscardStatFlush() instead of vlog.close.


This change is Reviewable

The vlog.Open() function can return an error denoting that the open was
unsuccessful but we have `db.cleanup` which will be called to stop all
the running go routines in case badger couldn't start. The db.cleanup
function calls vlog.Close() which will truncate the maxFid vlog file
based on the vlog.writableLogOffset. The vlog.writableLogOffset was not
being updated in case open failed. As a result of this, we will end up
truncating the vlog file to lenght 0 if open fails.

This PR fixes this by setting writableLogOffset to endOffset of the
replay so that we don't truncate the entire file.
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, 1 unresolved discussion (waiting on @ashish-goswami and @manishrjain)


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

	// TODO(ibrahim): Do we really want this? The DB might not open if we end
	// up in this situation.
	y.AssertTruef(endOffset < uint32(sz), "endoffset: %d should be more than sz:%d", endOffset, sz)

I am not sure if we should keep this. An error here would be unrecoverable (unless we manually truncate the file to the given offset which means we create a hole in the file).

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:

Reviewed 1 of 2 files at r2, 1 of 1 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @manishrjain)

@jarifibrahim jarifibrahim merged commit ed3b219 into master Aug 27, 2020
@jarifibrahim jarifibrahim deleted the ibrahim/vlog-woffset branch August 27, 2020 12:00
jarifibrahim pushed a commit that referenced this pull request Aug 27, 2020
* Fix(cleanup): Avoid truncating in value.Open on error

The vlog.Open() function can return an error denoting that the open was
unsuccessful but we have `db.cleanup` which will be called to stop all
the running go routines in case badger couldn't start. The db.cleanup
function calls vlog.Close() which will truncate the maxFid vlog file
based on the vlog.writableLogOffset. The vlog.writableLogOffset was not
being updated in case open failed. As a result of this, we will end up
truncating the vlog file to lenght 0 if open fails.

This PR fixes this by using vlog.stopDiscardStatFlush() instead of vlog.close.

(cherry picked from commit ed3b219)
jarifibrahim pushed a commit that referenced this pull request Aug 27, 2020
The vlog.Open() function can return an error denoting that the open was
unsuccessful but we have `db.cleanup` which will be called to stop all
the running goroutines in case badger couldn't start. The db.cleanup
function calls vlog.Close() which will truncate the maxFid vlog file
based on the vlog.writableLogOffset. The vlog.writableLogOffset was not
being updated in case open failed. As a result of this, we will end up
truncating the vlog file to length 0 if open fails.

This PR fixes this by using vlog.stopDiscardStatFlush() instead of vlog.close.

(cherry picked from commit ed3b219)
jarifibrahim pushed a commit that referenced this pull request Oct 2, 2020
* Fix(cleanup): Avoid truncating in value.Open on error

The vlog.Open() function can return an error denoting that the open was
unsuccessful but we have `db.cleanup` which will be called to stop all
the running go routines in case badger couldn't start. The db.cleanup
function calls vlog.Close() which will truncate the maxFid vlog file
based on the vlog.writableLogOffset. The vlog.writableLogOffset was not
being updated in case open failed. As a result of this, we will end up
truncating the vlog file to lenght 0 if open fails.

This PR fixes this by using vlog.stopDiscardStatFlush() instead of vlog.close.
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.

2 participants