Revert "Cache file descriptors" (fixes #1096)

This reverts commit 992ad97ad5.

Causes issues on Windows which uses file locking.
Meaning we cannot archive or modify the file while it's open.
This commit is contained in:
Audrius Butkevicius
2014-12-08 11:54:22 +00:00
parent 4d9aa10532
commit a9339d0627
14 changed files with 295 additions and 546 deletions

View File

@@ -26,6 +26,8 @@ import (
"sync"
"time"
"github.com/AudriusButkevicius/lfu-go"
"github.com/syncthing/syncthing/internal/config"
"github.com/syncthing/syncthing/internal/events"
"github.com/syncthing/syncthing/internal/osutil"
@@ -600,6 +602,19 @@ nextFile:
p.progressEmitter.Register(state.sharedPullerState)
}
evictionChan := make(chan lfu.Eviction)
fdCache := lfu.New()
fdCache.UpperBound = 50
fdCache.LowerBound = 20
fdCache.EvictionChannel = evictionChan
go func() {
for item := range evictionChan {
item.Value.(*os.File).Close()
}
}()
folderRoots := make(map[string]string)
p.model.fmut.RLock()
for folder, cfg := range p.model.folderCfgs {
@@ -613,11 +628,18 @@ nextFile:
found := p.model.finder.Iterate(block.Hash, func(folder, file string, index uint32) bool {
path := filepath.Join(folderRoots[folder], file)
fd, err := p.model.cache.Open(path)
if err != nil {
return false
var fd *os.File
fdi := fdCache.Get(path)
if fdi != nil {
fd = fdi.(*os.File)
} else {
fd, err = os.Open(path)
if err != nil {
return false
}
fdCache.Set(path, fd)
}
defer fd.Close()
_, err = fd.ReadAt(buf, protocol.BlockSize*int64(index))
if err != nil {
@@ -666,6 +688,8 @@ nextFile:
state.copyDone()
}
}
fdCache.Evict(fdCache.Len())
close(evictionChan)
out <- state.sharedPullerState
}
}