Skip to content

Commit

Permalink
Remove vlog file if bootstrap, syncDir or mmap fails (hypermodeinc#1434
Browse files Browse the repository at this point in the history
…) (hypermodeinc#1515)

The createVlogFile function creates a new vlog file. The function apart
from creating a new file, bootstraps it, syncs it to the disk, and mmaps it.

If any of the three operations fail, we will end up with a file on the
disk but the vlog.maxFid will not be updated.

On the next attempt to create the vlog files, we will get a "File
already exists" error. This commit fixes this issue by removing the file
if createVlogFile encounters any error.

Fixes DGRAPH-1930

(cherry picked from commit dfcca75)
  • Loading branch information
Ibrahim Jarif authored and mYmNeo committed Jan 9, 2023
1 parent 7eec933 commit 2ed011f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,22 @@ func (vlog *valueLog) createVlogFile(fid uint32) (*logFile, error) {
if lf.fd, err = y.CreateSyncedFile(path, vlog.opt.SyncWrites); err != nil {
return nil, errFile(err, lf.path, "Create value log file")
}

removeFile := func() {
// 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 = 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

0 comments on commit 2ed011f

Please sign in to comment.