implemented priority preloading

This commit is contained in:
ston1th 2022-05-03 22:14:47 +02:00
commit eb6272e411
7 changed files with 134 additions and 107 deletions

View file

@ -50,13 +50,14 @@ func (p *preload) Read(data []byte) (n int, err error) {
func (f *File) Preload(ctx context.Context, unlock func()) {
log := f.log
defer f.Close()
defer unlock()
if f.offline {
log.V(2).Error(errors.New("no preload in offline mode"), "error preloading file")
unlock()
return
}
if f.md.FullyCached() {
log.V(2).Info("skipped preload for fully cached file")
unlock()
return
}
@ -65,6 +66,7 @@ func (f *File) Preload(ctx context.Context, unlock func()) {
_, err := io.Copy(Discard, p)
if err == context.Canceled {
log.V(2).Info("preload canceled", "skipped", p.skipped, "written", p.written)
// do not call unlock() to keep preload in list
return
}
if err != nil && err != io.EOF {
@ -75,6 +77,7 @@ func (f *File) Preload(ctx context.Context, unlock func()) {
log.Error(err, "error closing cache file")
}
log.V(2).Info("preload finished", "skipped", p.skipped, "written", p.written)
unlock()
}
func (f *File) Read(p []byte) (n int, err error) {