mirror of
https://github.com/restic/restic.git
synced 2025-10-09 13:31:26 +00:00
Replace mount's per-file cache by a global LRU cache
This commit is contained in:

committed by
Michael Eischer

parent
d42c169458
commit
58719e1f47
@@ -20,6 +20,48 @@ import (
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
var id1, id2, id3 restic.ID
|
||||
id1[0] = 1
|
||||
id2[0] = 2
|
||||
id3[0] = 3
|
||||
|
||||
const (
|
||||
kiB = 1 << 10
|
||||
cacheSize = 64*kiB + 3*cacheOverhead
|
||||
)
|
||||
|
||||
c := newBlobCache(cacheSize)
|
||||
|
||||
addAndCheck := func(id restic.ID, exp []byte) {
|
||||
c.add(id, exp)
|
||||
blob, ok := c.get(id)
|
||||
rtest.Assert(t, ok, "blob %v added but not found in cache", id)
|
||||
rtest.Equals(t, &exp[0], &blob[0])
|
||||
rtest.Equals(t, exp, blob)
|
||||
}
|
||||
|
||||
addAndCheck(id1, make([]byte, 32*kiB))
|
||||
addAndCheck(id2, make([]byte, 30*kiB))
|
||||
addAndCheck(id3, make([]byte, 10*kiB))
|
||||
|
||||
_, ok := c.get(id2)
|
||||
rtest.Assert(t, ok, "blob %v not present", id2)
|
||||
_, ok = c.get(id1)
|
||||
rtest.Assert(t, !ok, "blob %v present, but should have been evicted", id1)
|
||||
|
||||
c.add(id1, make([]byte, 1+c.size))
|
||||
_, ok = c.get(id1)
|
||||
rtest.Assert(t, !ok, "blob %v too large but still added to cache")
|
||||
|
||||
c.c.Remove(id1)
|
||||
c.c.Remove(id3)
|
||||
c.c.Remove(id2)
|
||||
|
||||
rtest.Equals(t, cacheSize, c.size)
|
||||
rtest.Equals(t, cacheSize, c.free)
|
||||
}
|
||||
|
||||
func testRead(t testing.TB, f *file, offset, length int, data []byte) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -114,10 +156,7 @@ func TestFuseFile(t *testing.T) {
|
||||
Size: filesize,
|
||||
Content: content,
|
||||
}
|
||||
root := &Root{
|
||||
blobSizeCache: NewBlobSizeCache(context.TODO(), repo.Index()),
|
||||
repo: repo,
|
||||
}
|
||||
root := NewRoot(context.TODO(), repo, Config{})
|
||||
|
||||
t.Logf("blob cache has %d entries", len(root.blobSizeCache.m))
|
||||
|
||||
@@ -163,11 +202,10 @@ func testTopUidGid(t *testing.T, cfg Config, repo restic.Repository, uid, gid ui
|
||||
t.Helper()
|
||||
|
||||
ctx := context.Background()
|
||||
root, err := NewRoot(ctx, repo, cfg)
|
||||
rtest.OK(t, err)
|
||||
root := NewRoot(ctx, repo, cfg)
|
||||
|
||||
var attr fuse.Attr
|
||||
err = root.Attr(ctx, &attr)
|
||||
err := root.Attr(ctx, &attr)
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, uid, attr.Uid)
|
||||
rtest.Equals(t, gid, attr.Gid)
|
||||
|
Reference in New Issue
Block a user