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:
@@ -41,8 +41,6 @@ import (
|
||||
"github.com/syncthing/syncthing/internal/stats"
|
||||
"github.com/syncthing/syncthing/internal/symlinks"
|
||||
"github.com/syncthing/syncthing/internal/versioner"
|
||||
|
||||
"github.com/AudriusButkevicius/lrufdcache"
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
)
|
||||
|
||||
@@ -88,7 +86,6 @@ type Model struct {
|
||||
db *leveldb.DB
|
||||
finder *files.BlockFinder
|
||||
progressEmitter *ProgressEmitter
|
||||
cache *lrufdcache.FileCache
|
||||
|
||||
deviceName string
|
||||
clientName string
|
||||
@@ -130,7 +127,6 @@ func NewModel(cfg *config.ConfigWrapper, deviceName, clientName, clientVersion s
|
||||
m := &Model{
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
cache: lrufdcache.NewCache(25),
|
||||
deviceName: deviceName,
|
||||
clientName: clientName,
|
||||
clientVersion: clientVersion,
|
||||
@@ -699,11 +695,12 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset
|
||||
}
|
||||
reader = strings.NewReader(target)
|
||||
} else {
|
||||
reader, err = m.cache.Open(fn)
|
||||
reader, err = os.Open(fn) // XXX: Inefficient, should cache fd?
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer reader.(*lrufdcache.CachedFile).Close()
|
||||
|
||||
defer reader.(*os.File).Close()
|
||||
}
|
||||
|
||||
buf := make([]byte, size)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user