2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

Merge pull request #2787 from greatroar/no-blobsize-cache

Remove blob size cache from restic mount
This commit is contained in:
MichaelEischer 2020-07-25 20:46:35 +02:00 committed by GitHub
commit 020cab8e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 62 deletions

View File

@ -139,7 +139,7 @@ func mount(opts MountOptions, gopts GlobalOptions, mountpoint string) error {
Paths: opts.Paths, Paths: opts.Paths,
SnapshotTemplate: opts.SnapshotTemplate, SnapshotTemplate: opts.SnapshotTemplate,
} }
root := fuse.NewRoot(gopts.ctx, repo, cfg) root := fuse.NewRoot(repo, cfg)
Printf("Now serving the repository at %s\n", mountpoint) Printf("Now serving the repository at %s\n", mountpoint)
Printf("When finished, quit with Ctrl-c or umount the mountpoint.\n") Printf("When finished, quit with Ctrl-c or umount the mountpoint.\n")

View File

@ -1,34 +0,0 @@
// +build darwin freebsd linux
package fuse
import (
"github.com/restic/restic/internal/restic"
"golang.org/x/net/context"
)
// BlobSizeCache caches the size of blobs in the repo.
type BlobSizeCache struct {
m map[restic.ID]uint
}
// NewBlobSizeCache returns a new blob size cache containing all entries from midx.
func NewBlobSizeCache(ctx context.Context, idx restic.Index) *BlobSizeCache {
m := make(map[restic.ID]uint, 1000)
for pb := range idx.Each(ctx) {
m[pb.ID] = uint(restic.PlaintextLength(int(pb.Length)))
}
return &BlobSizeCache{
m: m,
}
}
// Lookup returns the size of the blob id.
func (c *BlobSizeCache) Lookup(id restic.ID) (size uint, found bool) {
if c == nil {
return 0, false
}
size, found = c.m[id]
return size, found
}

View File

@ -24,8 +24,6 @@ type dir struct {
inode uint64 inode uint64
parentInode uint64 parentInode uint64
node *restic.Node node *restic.Node
blobsize *BlobSizeCache
} }
func cleanupNodeName(name string) string { func cleanupNodeName(name string) string {

View File

@ -35,13 +35,9 @@ func newFile(ctx context.Context, root *Root, inode uint64, node *restic.Node) (
var bytes uint64 var bytes uint64
cumsize := make([]uint64, 1+len(node.Content)) cumsize := make([]uint64, 1+len(node.Content))
for i, id := range node.Content { for i, id := range node.Content {
size, ok := root.blobSizeCache.Lookup(id) size, found := root.repo.LookupBlobSize(id, restic.DataBlob)
if !ok { if !found {
var found bool return nil, errors.Errorf("id %v not found in repository", id)
size, found = root.repo.LookupBlobSize(id, restic.DataBlob)
if !found {
return nil, errors.Errorf("id %v not found in repository", id)
}
} }
bytes += uint64(size) bytes += uint64(size)

View File

@ -156,9 +156,7 @@ func TestFuseFile(t *testing.T) {
Size: filesize, Size: filesize,
Content: content, Content: content,
} }
root := NewRoot(context.TODO(), repo, Config{}) root := NewRoot(repo, Config{})
t.Logf("blob cache has %d entries", len(root.blobSizeCache.m))
inode := fs.GenerateDynamicInode(1, "foo") inode := fs.GenerateDynamicInode(1, "foo")
f, err := newFile(context.TODO(), root, inode, node) f, err := newFile(context.TODO(), root, inode, node)
@ -202,7 +200,7 @@ func testTopUidGid(t *testing.T, cfg Config, repo restic.Repository, uid, gid ui
t.Helper() t.Helper()
ctx := context.Background() ctx := context.Background()
root := NewRoot(ctx, repo, cfg) root := NewRoot(repo, cfg)
var attr fuse.Attr var attr fuse.Attr
err := root.Attr(ctx, &attr) err := root.Attr(ctx, &attr)

View File

@ -9,8 +9,6 @@ import (
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
"golang.org/x/net/context"
"bazil.org/fuse/fs" "bazil.org/fuse/fs"
) )
@ -25,12 +23,11 @@ type Config struct {
// Root is the root node of the fuse mount of a repository. // Root is the root node of the fuse mount of a repository.
type Root struct { type Root struct {
repo restic.Repository repo restic.Repository
cfg Config cfg Config
inode uint64 inode uint64
snapshots restic.Snapshots snapshots restic.Snapshots
blobCache *blobCache blobCache *blobCache
blobSizeCache *BlobSizeCache
snCount int snCount int
lastCheck time.Time lastCheck time.Time
@ -50,15 +47,14 @@ const rootInode = 1
const blobCacheSize = 64 << 20 const blobCacheSize = 64 << 20
// NewRoot initializes a new root node from a repository. // NewRoot initializes a new root node from a repository.
func NewRoot(ctx context.Context, repo restic.Repository, cfg Config) *Root { func NewRoot(repo restic.Repository, cfg Config) *Root {
debug.Log("NewRoot(), config %v", cfg) debug.Log("NewRoot(), config %v", cfg)
root := &Root{ root := &Root{
repo: repo, repo: repo,
inode: rootInode, inode: rootInode,
cfg: cfg, cfg: cfg,
blobCache: newBlobCache(blobCacheSize), blobCache: newBlobCache(blobCacheSize),
blobSizeCache: NewBlobSizeCache(ctx, repo.Index()),
} }
if !cfg.OwnerIsRoot { if !cfg.OwnerIsRoot {