Skip to content

Commit

Permalink
Add VirtualApply(ApplyOpenReadFrozen)
Browse files Browse the repository at this point in the history
Right now the only way to read the contents of a pool backed file is to
upload it into an REv2 CAS. Let's expose the ability to open files for
reading through VirtualApply(), so that it's possible to use this logic
outside the context of REv2.
  • Loading branch information
EdSchouten committed Dec 6, 2024
1 parent 9c51bb0 commit 0e0c240
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/filesystem/virtual/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,21 @@ type ApplyAppendOutputPathPersistencyDirectoryNode struct {
Directory *outputpathpersistency.Directory
Name path.Component
}

// ApplyOpenReadFrozen is an operation for VirtualApply that opens a
// regular file for reading. The file's contents are guaranteed to be
// immutable as long as the file is kept open.
//
// If the file is still opened for writing through the virtual file
// system, implementations should wait for the file to be closed to
// ensure that all data is flushed from the page cache. The
// WritableFileDelay channel can be used to place a bound on the maximum
// amount of time to wait.
type ApplyOpenReadFrozen struct {
// Inputs.
WritableFileDelay <-chan struct{}

// Outputs.
Reader filesystem.FileReader
Err error
}
6 changes: 6 additions & 0 deletions pkg/filesystem/virtual/pool_backed_file_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ func (f *fileBackedFile) VirtualApply(data any) bool {
IsExecutable: f.isExecutable,
})
}
case *ApplyOpenReadFrozen:
if frozenFile, success := f.waitAndOpenReadFrozen(p.WritableFileDelay); success {
p.Reader = frozenFile
} else {
p.Err = status.Error(codes.NotFound, "File was unlinked before file could be opened")
}
default:
return false
}
Expand Down

0 comments on commit 0e0c240

Please sign in to comment.