mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
Remove blob size cache from restic mount
This commit is contained in:
parent
5d8d70542f
commit
07da61baee
@ -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,14 +35,10 @@ 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)
|
||||
size, found := root.repo.LookupBlobSize(id, restic.DataBlob)
|
||||
if !found {
|
||||
return nil, errors.Errorf("id %v not found in repository", id)
|
||||
}
|
||||
}
|
||||
|
||||
bytes += uint64(size)
|
||||
cumsize[i+1] = bytes
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
@ -30,7 +28,6 @@ type Root struct {
|
||||
inode uint64
|
||||
snapshots restic.Snapshots
|
||||
blobCache *blobCache
|
||||
blobSizeCache *BlobSizeCache
|
||||
|
||||
snCount int
|
||||
lastCheck time.Time
|
||||
@ -50,7 +47,7 @@ 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{
|
||||
@ -58,7 +55,6 @@ func NewRoot(ctx context.Context, repo restic.Repository, cfg Config) *Root {
|
||||
inode: rootInode,
|
||||
cfg: cfg,
|
||||
blobCache: newBlobCache(blobCacheSize),
|
||||
blobSizeCache: NewBlobSizeCache(ctx, repo.Index()),
|
||||
}
|
||||
|
||||
if !cfg.OwnerIsRoot {
|
||||
|
Loading…
Reference in New Issue
Block a user