Skip to content

Remove vlog file if bootstrap, syncDir or mmap fails #1434

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

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,14 +1000,26 @@ func (vlog *valueLog) createVlogFile(fid uint32) (*logFile, error) {
return nil, errFile(err, lf.path, "Create value log file")
}

removeFile := func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to add a test by setting ulimit but this will be difficult for two reasons

  1. ulimit is set per process. If I set the ulimit for a test, it might affect other tests too.
  2. It's hard to set the correct ulimit and the test wouldn't fail even if the limit is off by 1.

// Remove the file so that we don't get an error when createVlogFile is
// called for the same fid, again. This could happen if there is an
// transient error because of which we couldn't create a new file
// and the second attempt to create the file succeeds.
y.Check(os.Remove(lf.fd.Name()))
}

if err = lf.bootstrap(); err != nil {
removeFile()
return nil, err
}

if err = syncDir(vlog.dirPath); err != nil {
removeFile()
return nil, errFile(err, vlog.dirPath, "Sync value log dir")
}

if err = lf.mmap(2 * vlog.opt.ValueLogFileSize); err != nil {
removeFile()
return nil, errFile(err, lf.path, "Mmap value log file")
}

Expand Down