Further delay temp file loading in concurrency with ReadAt
The temp file used to serve ReadAt(), the API used by the gcsfuse file
handler, only after it's fully loaded with content. This creates huge
latency at startup in large sequence reads. Now, the temp file is loaded
concurrently with the reads.
@@ -276,10 +276,12 @@ func minInt64(a int64, b int64) int64 {
return b
}
-func (tf *tempFile) ensure(limit int64) (int64, error) {
+func (tf *tempFile) ensure(limit int64) error {
+ switch tf.state {
+ case fileIncomplete:
size, err := tf.f.Seek(0, 2)
if size >= limit {
- return size, nil
+ return nil
}
var n int64
n, err = io.CopyN(tf.f, tf.source, limit-size)
@@ -289,24 +291,20 @@ func (tf *tempFile) ensure(limit int64) (int64, error) {
tf.state = fileComplete
err = nil
}
- return size + n, err
+ return err
+ case fileComplete, fileDirty:
+ // already completed
+ return nil
+ case fileDestroyed:
+ return fmt.Errorf("file destroyed")
+ }
+ return nil
}
-func (tf *tempFile) ensureComplete() (err error) {
- switch tf.state {
- case fileIncomplete:
- _, err = tf.ensure(math.MaxInt64)
+func (tf *tempFile) ensureComplete() error {
+ err := tf.ensure(math.MaxInt64)
if err != nil {
err = fmt.Errorf("load temp file: %v", err)
- return
}
- return
- case fileComplete, fileDirty:
- // already completed
- return
- case fileDestroyed:
- err = fmt.Errorf("file destroyed")
- return
- }
- return
+ return err
}
