mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +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,
|
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")
|
||||||
|
@ -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
|
inode uint64
|
||||||
parentInode uint64
|
parentInode uint64
|
||||||
node *restic.Node
|
node *restic.Node
|
||||||
|
|
||||||
blobsize *BlobSizeCache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupNodeName(name string) string {
|
func cleanupNodeName(name string) string {
|
||||||
|
@ -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)
|
||||||
|
@ -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)
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user