forked from TrueCloudLab/restic
repository: remove Packer and SavePacker from public interface
This commit is contained in:
parent
550d1eeac3
commit
04ad9f0c0c
3 changed files with 18 additions and 18 deletions
|
@ -21,8 +21,8 @@ import (
|
||||||
"github.com/minio/sha256-simd"
|
"github.com/minio/sha256-simd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Packer holds a pack.Packer together with a hash writer.
|
// packer holds a pack.packer together with a hash writer.
|
||||||
type Packer struct {
|
type packer struct {
|
||||||
*pack.Packer
|
*pack.Packer
|
||||||
tmpfile *os.File
|
tmpfile *os.File
|
||||||
bufWr *bufio.Writer
|
bufWr *bufio.Writer
|
||||||
|
@ -32,16 +32,16 @@ type Packer struct {
|
||||||
type packerManager struct {
|
type packerManager struct {
|
||||||
tpe restic.BlobType
|
tpe restic.BlobType
|
||||||
key *crypto.Key
|
key *crypto.Key
|
||||||
queueFn func(ctx context.Context, t restic.BlobType, p *Packer) error
|
queueFn func(ctx context.Context, t restic.BlobType, p *packer) error
|
||||||
|
|
||||||
pm sync.Mutex
|
pm sync.Mutex
|
||||||
packer *Packer
|
packer *packer
|
||||||
packSize uint
|
packSize uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// newPackerManager returns a new packer manager which writes temporary files
|
// newPackerManager returns a new packer manager which writes temporary files
|
||||||
// to a temporary directory
|
// to a temporary directory
|
||||||
func newPackerManager(key *crypto.Key, tpe restic.BlobType, packSize uint, queueFn func(ctx context.Context, t restic.BlobType, p *Packer) error) *packerManager {
|
func newPackerManager(key *crypto.Key, tpe restic.BlobType, packSize uint, queueFn func(ctx context.Context, t restic.BlobType, p *packer) error) *packerManager {
|
||||||
return &packerManager{
|
return &packerManager{
|
||||||
tpe: tpe,
|
tpe: tpe,
|
||||||
key: key,
|
key: key,
|
||||||
|
@ -114,7 +114,7 @@ func (r *packerManager) SaveBlob(ctx context.Context, t restic.BlobType, id rest
|
||||||
|
|
||||||
// findPacker returns a packer for a new blob of size bytes. Either a new one is
|
// findPacker returns a packer for a new blob of size bytes. Either a new one is
|
||||||
// created or one is returned that already has some blobs.
|
// created or one is returned that already has some blobs.
|
||||||
func (r *packerManager) newPacker() (packer *Packer, err error) {
|
func (r *packerManager) newPacker() (pck *packer, err error) {
|
||||||
debug.Log("create new pack")
|
debug.Log("create new pack")
|
||||||
tmpfile, err := fs.TempFile("", "restic-temp-pack-")
|
tmpfile, err := fs.TempFile("", "restic-temp-pack-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -123,17 +123,17 @@ func (r *packerManager) newPacker() (packer *Packer, err error) {
|
||||||
|
|
||||||
bufWr := bufio.NewWriter(tmpfile)
|
bufWr := bufio.NewWriter(tmpfile)
|
||||||
p := pack.NewPacker(r.key, bufWr)
|
p := pack.NewPacker(r.key, bufWr)
|
||||||
packer = &Packer{
|
pck = &packer{
|
||||||
Packer: p,
|
Packer: p,
|
||||||
tmpfile: tmpfile,
|
tmpfile: tmpfile,
|
||||||
bufWr: bufWr,
|
bufWr: bufWr,
|
||||||
}
|
}
|
||||||
|
|
||||||
return packer, nil
|
return pck, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// savePacker stores p in the backend.
|
// savePacker stores p in the backend.
|
||||||
func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packer) error {
|
func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *packer) error {
|
||||||
debug.Log("save packer for %v with %d blobs (%d bytes)\n", t, p.Packer.Count(), p.Packer.Size())
|
debug.Log("save packer for %v with %d blobs (%d bytes)\n", t, p.Packer.Count(), p.Packer.Size())
|
||||||
err := p.Packer.Finalize()
|
err := p.Packer.Finalize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -70,7 +70,7 @@ func testPackerManager(t testing.TB) int64 {
|
||||||
rnd := rand.New(rand.NewSource(randomSeed))
|
rnd := rand.New(rand.NewSource(randomSeed))
|
||||||
|
|
||||||
savedBytes := int(0)
|
savedBytes := int(0)
|
||||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, tp restic.BlobType, p *Packer) error {
|
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, tp restic.BlobType, p *packer) error {
|
||||||
err := p.Finalize()
|
err := p.Finalize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -92,7 +92,7 @@ func testPackerManager(t testing.TB) int64 {
|
||||||
func TestPackerManagerWithOversizeBlob(t *testing.T) {
|
func TestPackerManagerWithOversizeBlob(t *testing.T) {
|
||||||
packFiles := int(0)
|
packFiles := int(0)
|
||||||
sizeLimit := uint(512 * 1024)
|
sizeLimit := uint(512 * 1024)
|
||||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, sizeLimit, func(ctx context.Context, tp restic.BlobType, p *Packer) error {
|
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, sizeLimit, func(ctx context.Context, tp restic.BlobType, p *packer) error {
|
||||||
packFiles++
|
packFiles++
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -122,7 +122,7 @@ func BenchmarkPackerManager(t *testing.B) {
|
||||||
|
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
rnd.Seed(randomSeed)
|
rnd.Seed(randomSeed)
|
||||||
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, t restic.BlobType, p *Packer) error {
|
pm := newPackerManager(crypto.NewRandomKey(), restic.DataBlob, DefaultPackSize, func(ctx context.Context, t restic.BlobType, p *packer) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
fillPacks(t, rnd, pm, blobBuf)
|
fillPacks(t, rnd, pm, blobBuf)
|
||||||
|
|
|
@ -7,13 +7,13 @@ import (
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SavePacker implements saving a pack in the repository.
|
// savePacker implements saving a pack in the repository.
|
||||||
type SavePacker interface {
|
type savePacker interface {
|
||||||
savePacker(ctx context.Context, t restic.BlobType, p *Packer) error
|
savePacker(ctx context.Context, t restic.BlobType, p *packer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type uploadTask struct {
|
type uploadTask struct {
|
||||||
packer *Packer
|
packer *packer
|
||||||
tpe restic.BlobType
|
tpe restic.BlobType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ type packerUploader struct {
|
||||||
uploadQueue chan uploadTask
|
uploadQueue chan uploadTask
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPackerUploader(ctx context.Context, wg *errgroup.Group, repo SavePacker, connections uint) *packerUploader {
|
func newPackerUploader(ctx context.Context, wg *errgroup.Group, repo savePacker, connections uint) *packerUploader {
|
||||||
pu := &packerUploader{
|
pu := &packerUploader{
|
||||||
uploadQueue: make(chan uploadTask),
|
uploadQueue: make(chan uploadTask),
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func newPackerUploader(ctx context.Context, wg *errgroup.Group, repo SavePacker,
|
||||||
return pu
|
return pu
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pu *packerUploader) QueuePacker(ctx context.Context, t restic.BlobType, p *Packer) (err error) {
|
func (pu *packerUploader) QueuePacker(ctx context.Context, t restic.BlobType, p *packer) (err error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
|
Loading…
Reference in a new issue