mirror of
https://github.com/restic/restic.git
synced 2024-06-28 08:00:52 +02:00
When looking up a blob in the master index, with several indexes present in the master index, a significant amount of time is spent generating errors for each failed lookup. However, these errors are often used to check if a blob is present, but the contents are not inspected making the overhead of the error not useful. Instead, change Index.Lookup (and Index.LookupSize) to instead return a boolean denoting if the blob was found instead of an error. Also change all the calls to these functions to handle the new function signature. benchmark old ns/op new ns/op delta BenchmarkMasterIndexLookupSingleIndex-6 820 897 +9.39% BenchmarkMasterIndexLookupMultipleIndex-6 12821 2001 -84.39% BenchmarkMasterIndexLookupSingleIndexUnknown-6 5378 492 -90.85% BenchmarkMasterIndexLookupMultipleIndexUnknown-6 17026 1649 -90.31% benchmark old allocs new allocs delta BenchmarkMasterIndexLookupSingleIndex-6 9 9 +0.00% BenchmarkMasterIndexLookupMultipleIndex-6 59 19 -67.80% BenchmarkMasterIndexLookupSingleIndexUnknown-6 22 6 -72.73% BenchmarkMasterIndexLookupMultipleIndexUnknown-6 72 16 -77.78% benchmark old bytes new bytes delta BenchmarkMasterIndexLookupSingleIndex-6 160 160 +0.00% BenchmarkMasterIndexLookupMultipleIndex-6 3200 240 -92.50% BenchmarkMasterIndexLookupSingleIndexUnknown-6 1232 48 -96.10% BenchmarkMasterIndexLookupMultipleIndexUnknown-6 4272 128 -97.00%
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package restic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/restic/restic/internal/crypto"
|
|
)
|
|
|
|
// Repository stores data in a backend. It provides high-level functions and
|
|
// transparently encrypts/decrypts data.
|
|
type Repository interface {
|
|
|
|
// Backend returns the backend used by the repository
|
|
Backend() Backend
|
|
|
|
Key() *crypto.Key
|
|
|
|
SetIndex(Index)
|
|
|
|
Index() Index
|
|
SaveFullIndex(context.Context) error
|
|
SaveIndex(context.Context) error
|
|
LoadIndex(context.Context) error
|
|
|
|
Config() Config
|
|
|
|
LookupBlobSize(ID, BlobType) (uint, bool)
|
|
|
|
List(context.Context, FileType) <-chan ID
|
|
ListPack(context.Context, ID) ([]Blob, int64, error)
|
|
|
|
Flush(context.Context) error
|
|
|
|
SaveUnpacked(context.Context, FileType, []byte) (ID, error)
|
|
SaveJSONUnpacked(context.Context, FileType, interface{}) (ID, error)
|
|
|
|
LoadJSONUnpacked(context.Context, FileType, ID, interface{}) error
|
|
LoadAndDecrypt(context.Context, FileType, ID) ([]byte, error)
|
|
|
|
LoadBlob(context.Context, BlobType, ID, []byte) (int, error)
|
|
SaveBlob(context.Context, BlobType, []byte, ID) (ID, error)
|
|
|
|
LoadTree(context.Context, ID) (*Tree, error)
|
|
SaveTree(context.Context, *Tree) (ID, error)
|
|
}
|
|
|
|
// Lister allows listing files in a backend.
|
|
type Lister interface {
|
|
List(context.Context, FileType) <-chan string
|
|
}
|
|
|
|
// Index keeps track of the blobs are stored within files.
|
|
type Index interface {
|
|
Has(ID, BlobType) bool
|
|
Lookup(ID, BlobType) ([]PackedBlob, bool)
|
|
Count(BlobType) uint
|
|
|
|
// Each returns a channel that yields all blobs known to the index. When
|
|
// the context is cancelled, the background goroutine terminates. This
|
|
// blocks any modification of the index.
|
|
Each(ctx context.Context) <-chan PackedBlob
|
|
}
|