Skip to content

Commit 0e0c240

Browse files
committed
Add VirtualApply(ApplyOpenReadFrozen)
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.
1 parent 9c51bb0 commit 0e0c240

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/filesystem/virtual/node.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,21 @@ type ApplyAppendOutputPathPersistencyDirectoryNode struct {
9393
Directory *outputpathpersistency.Directory
9494
Name path.Component
9595
}
96+
97+
// ApplyOpenReadFrozen is an operation for VirtualApply that opens a
98+
// regular file for reading. The file's contents are guaranteed to be
99+
// immutable as long as the file is kept open.
100+
//
101+
// If the file is still opened for writing through the virtual file
102+
// system, implementations should wait for the file to be closed to
103+
// ensure that all data is flushed from the page cache. The
104+
// WritableFileDelay channel can be used to place a bound on the maximum
105+
// amount of time to wait.
106+
type ApplyOpenReadFrozen struct {
107+
// Inputs.
108+
WritableFileDelay <-chan struct{}
109+
110+
// Outputs.
111+
Reader filesystem.FileReader
112+
Err error
113+
}

pkg/filesystem/virtual/pool_backed_file_allocator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@ func (f *fileBackedFile) VirtualApply(data any) bool {
379379
IsExecutable: f.isExecutable,
380380
})
381381
}
382+
case *ApplyOpenReadFrozen:
383+
if frozenFile, success := f.waitAndOpenReadFrozen(p.WritableFileDelay); success {
384+
p.Reader = frozenFile
385+
} else {
386+
p.Err = status.Error(codes.NotFound, "File was unlinked before file could be opened")
387+
}
382388
default:
383389
return false
384390
}

0 commit comments

Comments
 (0)