mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
Backend: Expose connections parameter
This commit is contained in:
parent
07a565e6f7
commit
4f97492d28
@ -24,6 +24,7 @@ import (
|
||||
type Backend struct {
|
||||
accountName string
|
||||
container *storage.Container
|
||||
connections uint
|
||||
sem *backend.Semaphore
|
||||
prefix string
|
||||
listMaxItems int
|
||||
@ -55,6 +56,7 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
|
||||
be := &Backend{
|
||||
container: service.GetContainerReference(cfg.Container),
|
||||
accountName: cfg.AccountName,
|
||||
connections: cfg.Connections,
|
||||
sem: sem,
|
||||
prefix: cfg.Prefix,
|
||||
Layout: &backend.DefaultLayout{
|
||||
@ -109,6 +111,10 @@ func (be *Backend) Join(p ...string) string {
|
||||
return path.Join(p...)
|
||||
}
|
||||
|
||||
func (be *Backend) Connections() uint {
|
||||
return be.connections
|
||||
}
|
||||
|
||||
// Location returns this backend's location (the container name).
|
||||
func (be *Backend) Location() string {
|
||||
return be.Join(be.container.Name, be.prefix)
|
||||
|
@ -133,6 +133,10 @@ func (be *b2Backend) SetListMaxItems(i int) {
|
||||
be.listMaxItems = i
|
||||
}
|
||||
|
||||
func (be *b2Backend) Connections() uint {
|
||||
return be.cfg.Connections
|
||||
}
|
||||
|
||||
// Location returns the location for the backend.
|
||||
func (be *b2Backend) Location() string {
|
||||
return be.cfg.Bucket
|
||||
|
@ -45,6 +45,10 @@ func (be *Backend) Remove(ctx context.Context, h restic.Handle) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (be *Backend) Connections() uint {
|
||||
return be.b.Connections()
|
||||
}
|
||||
|
||||
// Location returns the location of the backend.
|
||||
func (be *Backend) Location() string {
|
||||
return "DRY:" + be.b.Location()
|
||||
|
@ -34,6 +34,7 @@ import (
|
||||
type Backend struct {
|
||||
gcsClient *storage.Client
|
||||
projectID string
|
||||
connections uint
|
||||
sem *backend.Semaphore
|
||||
bucketName string
|
||||
bucket *storage.BucketHandle
|
||||
@ -102,12 +103,13 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
|
||||
}
|
||||
|
||||
be := &Backend{
|
||||
gcsClient: gcsClient,
|
||||
projectID: cfg.ProjectID,
|
||||
sem: sem,
|
||||
bucketName: cfg.Bucket,
|
||||
bucket: gcsClient.Bucket(cfg.Bucket),
|
||||
prefix: cfg.Prefix,
|
||||
gcsClient: gcsClient,
|
||||
projectID: cfg.ProjectID,
|
||||
connections: cfg.Connections,
|
||||
sem: sem,
|
||||
bucketName: cfg.Bucket,
|
||||
bucket: gcsClient.Bucket(cfg.Bucket),
|
||||
prefix: cfg.Prefix,
|
||||
Layout: &backend.DefaultLayout{
|
||||
Path: cfg.Prefix,
|
||||
Join: path.Join,
|
||||
@ -185,6 +187,10 @@ func (be *Backend) Join(p ...string) string {
|
||||
return path.Join(p...)
|
||||
}
|
||||
|
||||
func (be *Backend) Connections() uint {
|
||||
return be.connections
|
||||
}
|
||||
|
||||
// Location returns this backend's location (the bucket name).
|
||||
func (be *Backend) Location() string {
|
||||
return be.Join(be.bucketName, be.prefix)
|
||||
|
@ -229,6 +229,10 @@ func (be *MemoryBackend) List(ctx context.Context, t restic.FileType, fn func(re
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
func (be *MemoryBackend) Connections() uint {
|
||||
return 2
|
||||
}
|
||||
|
||||
// Location returns the location of the backend (RAM).
|
||||
func (be *MemoryBackend) Location() string {
|
||||
return "RAM"
|
||||
|
@ -29,9 +29,10 @@ var _ restic.Backend = &Backend{}
|
||||
|
||||
// Backend uses the REST protocol to access data stored on a server.
|
||||
type Backend struct {
|
||||
url *url.URL
|
||||
sem *backend.Semaphore
|
||||
client *http.Client
|
||||
url *url.URL
|
||||
connections uint
|
||||
sem *backend.Semaphore
|
||||
client *http.Client
|
||||
backend.Layout
|
||||
}
|
||||
|
||||
@ -57,10 +58,11 @@ func Open(cfg Config, rt http.RoundTripper) (*Backend, error) {
|
||||
}
|
||||
|
||||
be := &Backend{
|
||||
url: cfg.URL,
|
||||
client: client,
|
||||
Layout: &backend.RESTLayout{URL: url, Join: path.Join},
|
||||
sem: sem,
|
||||
url: cfg.URL,
|
||||
client: client,
|
||||
Layout: &backend.RESTLayout{URL: url, Join: path.Join},
|
||||
connections: cfg.Connections,
|
||||
sem: sem,
|
||||
}
|
||||
|
||||
return be, nil
|
||||
@ -105,6 +107,10 @@ func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (*Backend, er
|
||||
return be, nil
|
||||
}
|
||||
|
||||
func (b *Backend) Connections() uint {
|
||||
return b.connections
|
||||
}
|
||||
|
||||
// Location returns this backend's location (the server's URL).
|
||||
func (b *Backend) Location() string {
|
||||
return b.url.String()
|
||||
|
@ -255,6 +255,10 @@ func (be *Backend) ReadDir(ctx context.Context, dir string) (list []os.FileInfo,
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (be *Backend) Connections() uint {
|
||||
return be.cfg.Connections
|
||||
}
|
||||
|
||||
// Location returns this backend's location (the bucket name).
|
||||
func (be *Backend) Location() string {
|
||||
return be.Join(be.cfg.Bucket, be.cfg.Prefix)
|
||||
|
@ -24,10 +24,11 @@ import (
|
||||
|
||||
// beSwift is a backend which stores the data on a swift endpoint.
|
||||
type beSwift struct {
|
||||
conn *swift.Connection
|
||||
sem *backend.Semaphore
|
||||
container string // Container name
|
||||
prefix string // Prefix of object names in the container
|
||||
conn *swift.Connection
|
||||
connections uint
|
||||
sem *backend.Semaphore
|
||||
container string // Container name
|
||||
prefix string // Prefix of object names in the container
|
||||
backend.Layout
|
||||
}
|
||||
|
||||
@ -68,9 +69,10 @@ func Open(ctx context.Context, cfg Config, rt http.RoundTripper) (restic.Backend
|
||||
|
||||
Transport: rt,
|
||||
},
|
||||
sem: sem,
|
||||
container: cfg.Container,
|
||||
prefix: cfg.Prefix,
|
||||
connections: cfg.Connections,
|
||||
sem: sem,
|
||||
container: cfg.Container,
|
||||
prefix: cfg.Prefix,
|
||||
Layout: &backend.DefaultLayout{
|
||||
Path: cfg.Prefix,
|
||||
Join: path.Join,
|
||||
@ -113,6 +115,10 @@ func (be *beSwift) createContainer(ctx context.Context, policy string) error {
|
||||
return be.conn.ContainerCreate(ctx, be.container, h)
|
||||
}
|
||||
|
||||
func (be *beSwift) Connections() uint {
|
||||
return be.connections
|
||||
}
|
||||
|
||||
// Location returns this backend's location (the container name).
|
||||
func (be *beSwift) Location() string {
|
||||
return be.container
|
||||
|
@ -11,17 +11,18 @@ import (
|
||||
|
||||
// Backend implements a mock backend.
|
||||
type Backend struct {
|
||||
CloseFn func() error
|
||||
IsNotExistFn func(err error) bool
|
||||
SaveFn func(ctx context.Context, h restic.Handle, rd restic.RewindReader) error
|
||||
OpenReaderFn func(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error)
|
||||
StatFn func(ctx context.Context, h restic.Handle) (restic.FileInfo, error)
|
||||
ListFn func(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error
|
||||
RemoveFn func(ctx context.Context, h restic.Handle) error
|
||||
TestFn func(ctx context.Context, h restic.Handle) (bool, error)
|
||||
DeleteFn func(ctx context.Context) error
|
||||
LocationFn func() string
|
||||
HasherFn func() hash.Hash
|
||||
CloseFn func() error
|
||||
IsNotExistFn func(err error) bool
|
||||
SaveFn func(ctx context.Context, h restic.Handle, rd restic.RewindReader) error
|
||||
OpenReaderFn func(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error)
|
||||
StatFn func(ctx context.Context, h restic.Handle) (restic.FileInfo, error)
|
||||
ListFn func(ctx context.Context, t restic.FileType, fn func(restic.FileInfo) error) error
|
||||
RemoveFn func(ctx context.Context, h restic.Handle) error
|
||||
TestFn func(ctx context.Context, h restic.Handle) (bool, error)
|
||||
DeleteFn func(ctx context.Context) error
|
||||
ConnectionsFn func() uint
|
||||
LocationFn func() string
|
||||
HasherFn func() hash.Hash
|
||||
}
|
||||
|
||||
// NewBackend returns new mock Backend instance
|
||||
@ -39,6 +40,14 @@ func (m *Backend) Close() error {
|
||||
return m.CloseFn()
|
||||
}
|
||||
|
||||
func (m *Backend) Connections() uint {
|
||||
if m.ConnectionsFn == nil {
|
||||
return 2
|
||||
}
|
||||
|
||||
return m.ConnectionsFn()
|
||||
}
|
||||
|
||||
// Location returns a location string.
|
||||
func (m *Backend) Location() string {
|
||||
if m.LocationFn == nil {
|
||||
|
@ -18,6 +18,9 @@ type Backend interface {
|
||||
// repository.
|
||||
Location() string
|
||||
|
||||
// Connections returns the maxmimum number of concurrent backend operations.
|
||||
Connections() uint
|
||||
|
||||
// Hasher may return a hash function for calculating a content hash for the backend
|
||||
Hasher() hash.Hash
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user