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:
commit
020cab8e08
@ -139,7 +139,7 @@ func mount(opts MountOptions, gopts GlobalOptions, mountpoint string) error {
|
||||
Paths: opts.Paths,
|
||||
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("When finished, quit with Ctrl-c or umount the mountpoint.\n")
|
||||
|
@ -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
|
||||
}
|
@ -24,8 +24,6 @@ type dir struct {
|
||||
inode uint64
|
||||
parentInode uint64
|
||||
node *restic.Node
|
||||
|
||||
blobsize *BlobSizeCache
|
||||
}
|
||||
|
||||
func cleanupNodeName(name string) string {
|
||||
|
@ -35,13 +35,9 @@ func newFile(ctx context.Context, root *Root, inode uint64, node *restic.Node) (
|
||||
var bytes uint64
|
||||
cumsize := make([]uint64, 1+len(node.Content))
|
||||
for i, id := range node.Content {
|
||||
size, ok := root.blobSizeCache.Lookup(id)
|
||||
if !ok {
|
||||
var found bool
|
||||
size, found = root.repo.LookupBlobSize(id, restic.DataBlob)
|
||||
if !found {
|
||||
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)
|
||||
|
@ -156,9 +156,7 @@ func TestFuseFile(t *testing.T) {
|
||||
Size: filesize,
|
||||
Content: content,
|
||||
}
|
||||
root := NewRoot(context.TODO(), repo, Config{})
|
||||
|
||||
t.Logf("blob cache has %d entries", len(root.blobSizeCache.m))
|
||||
root := NewRoot(repo, Config{})
|
||||
|
||||
inode := fs.GenerateDynamicInode(1, "foo")
|
||||
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()
|
||||
|
||||
ctx := context.Background()
|
||||
root := NewRoot(ctx, repo, cfg)
|
||||
root := NewRoot(repo, cfg)
|
||||
|
||||
var attr fuse.Attr
|
||||
err := root.Attr(ctx, &attr)
|
||||
|
@ -9,8 +9,6 @@ import (
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"bazil.org/fuse/fs"
|
||||
)
|
||||
|
||||
@ -25,12 +23,11 @@ type Config struct {
|
||||
|
||||
// Root is the root node of the fuse mount of a repository.
|
||||
type Root struct {
|
||||
repo restic.Repository
|
||||
cfg Config
|
||||
inode uint64
|
||||
snapshots restic.Snapshots
|
||||
blobCache *blobCache
|
||||
blobSizeCache *BlobSizeCache
|
||||
repo restic.Repository
|
||||
cfg Config
|
||||
inode uint64
|
||||
snapshots restic.Snapshots
|
||||
blobCache *blobCache
|
||||
|
||||
snCount int
|
||||
lastCheck time.Time
|
||||
@ -50,15 +47,14 @@ const rootInode = 1
|
||||
const blobCacheSize = 64 << 20
|
||||
|
||||
// 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)
|
||||
|
||||
root := &Root{
|
||||
repo: repo,
|
||||
inode: rootInode,
|
||||
cfg: cfg,
|
||||
blobCache: newBlobCache(blobCacheSize),
|
||||
blobSizeCache: NewBlobSizeCache(ctx, repo.Index()),
|
||||
repo: repo,
|
||||
inode: rootInode,
|
||||
cfg: cfg,
|
||||
blobCache: newBlobCache(blobCacheSize),
|
||||
}
|
||||
|
||||
if !cfg.OwnerIsRoot {
|
||||
|
Loading…
Reference in New Issue
Block a user