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

Acquire lock before unmapping vlog files #1050

Merged
merged 2 commits into from
Sep 24, 2019
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
9 changes: 8 additions & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,16 @@ func (lf *logFile) doneWriting(offset uint32) error {
return errors.Wrapf(err, "Unable to sync value log: %q", lf.path)
}

// Before we were acquiring a lock here on lf.lock, because we were invalidating the file
// descriptor due to reopening it as read-only. Now, we don't invalidate the fd, but unmap it,
// truncate it and remap it. That creates a window where we have segfaults because the mmap is
// no longer valid, while someone might be reading it. Therefore, we need a lock here again.
lf.lock.Lock()
defer lf.lock.Unlock()

// Unmap file before we truncate it. Windows cannot truncate a file that is mmapped.
if err := lf.munmap(); err != nil {
return errors.Wrapf(err, "failed to mumap vlog file %s", lf.fd.Name())
return errors.Wrapf(err, "failed to munmap vlog file %s", lf.fd.Name())
}

// TODO: Confirm if we need to run a file sync after truncation.
Expand Down