Skip to content

Commit 8481321

Browse files
authored
Merge pull request #1119 from percona/PBM-1531-storage-opts-refactor
PBM-1531: Refactor storage api to use options for file size
2 parents a57049a + 6af63c0 commit 8481321

File tree

13 files changed

+40
-26
lines changed

13 files changed

+40
-26
lines changed

cmd/pbm/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func runFinishRestore(o descrRestoreOpts, node string) (fmt.Stringer, error) {
515515
path := fmt.Sprintf("%s/%s/cluster", defs.PhysRestoresDir, o.restore)
516516
msg := outMsg{"Command sent. Check `pbm describe-restore ...` for the result."}
517517
err = stg.Save(path+"."+string(defs.StatusCopyDone),
518-
strings.NewReader(fmt.Sprintf("%d", time.Now().Unix())), -1)
518+
strings.NewReader(fmt.Sprintf("%d", time.Now().Unix())))
519519
return msg, err
520520
}
521521

pbm/archive/conv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func GenerateV1FromV2(ctx context.Context, stg storage.Storage, bcp, rs string)
5151
}
5252

5353
metaV1Filename := fmt.Sprintf("%s/%s/%s", bcp, rs, MetaFile)
54-
err = stg.Save(metaV1Filename, bytes.NewReader(data), int64(len(data)))
54+
err = stg.Save(metaV1Filename, bytes.NewReader(data), storage.Size(int64(len(data))))
5555
if err != nil {
5656
return errors.Wrapf(err, "save %q", metaV1Filename)
5757
}

pbm/backup/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ func writeMeta(stg storage.Storage, meta *BackupMeta) error {
649649
return errors.Wrap(err, "marshal data")
650650
}
651651

652-
err = stg.Save(meta.Name+defs.MetadataFileSuffix, bytes.NewReader(b), -1)
652+
err = stg.Save(meta.Name+defs.MetadataFileSuffix, bytes.NewReader(b))
653653
return errors.Wrap(err, "write to store")
654654
}
655655

pbm/backup/logical.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (b *Backup) doLogical(
170170
return errors.Wrap(err, "get storage")
171171
}
172172
filepath := path.Join(bcp.Name, rsMeta.Name, ns+ext)
173-
return stg.Save(filepath, r, nssSize[ns])
173+
return stg.Save(filepath, r, storage.Size(nssSize[ns]))
174174
},
175175
bcp.Compression,
176176
bcp.CompressionLevel)

pbm/restore/physical.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ func (r *PhysRestore) Snapshot(
989989
limit: 1 << 20, // 1Mb
990990
write: func(name string, data io.Reader) error {
991991
// Logger should be disabled due to: PBM-1531
992-
return r.stg.Save(name, data, -1, storage.UseLogger(false))
992+
return r.stg.Save(name, data, storage.UseLogger(false))
993993
},
994994
})
995995
logger.PauseMgo()

pbm/storage/azure/azure.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (*Blob) Type() storage.Type {
128128
return storage.Azure
129129
}
130130

131-
func (b *Blob) Save(name string, data io.Reader, sizeb int64, options ...storage.Option) error {
131+
func (b *Blob) Save(name string, data io.Reader, options ...storage.Option) error {
132132
opts := storage.GetDefaultOpts()
133133
for _, opt := range options {
134134
if err := opt(opts); err != nil {
@@ -137,8 +137,8 @@ func (b *Blob) Save(name string, data io.Reader, sizeb int64, options ...storage
137137
}
138138

139139
bufsz := defaultUploadBuff
140-
if sizeb > 0 {
141-
ps := int(sizeb / maxBlocks * 11 / 10) // add 10% just in case
140+
if opts.Size > 0 {
141+
ps := int(opts.Size / maxBlocks * 11 / 10) // add 10% just in case
142142
if ps > bufsz {
143143
bufsz = ps
144144
}
@@ -150,7 +150,7 @@ func (b *Blob) Save(name string, data io.Reader, sizeb int64, options ...storage
150150
}
151151

152152
if b.log != nil && opts.UseLogger {
153-
b.log.Debug("BufferSize is set to %d (~%dMb) | %d", bufsz, bufsz>>20, sizeb)
153+
b.log.Debug("BufferSize is set to %d (~%dMb) | %d", bufsz, bufsz>>20, opts.Size)
154154
}
155155

156156
_, err := b.c.UploadStream(context.TODO(),

pbm/storage/blackhole/blackhole.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (*Blackhole) Type() storage.Type {
1818
return storage.Blackhole
1919
}
2020

21-
func (*Blackhole) Save(_ string, data io.Reader, _ int64, _ ...storage.Option) error {
21+
func (*Blackhole) Save(_ string, data io.Reader, _ ...storage.Option) error {
2222
_, err := io.Copy(io.Discard, data)
2323
return err
2424
}

pbm/storage/fs/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func writeSync(finalpath string, data io.Reader) (err error) {
151151
return nil
152152
}
153153

154-
func (fs *FS) Save(name string, data io.Reader, _ int64, _ ...storage.Option) error {
154+
func (fs *FS) Save(name string, data io.Reader, _ ...storage.Option) error {
155155
return writeSync(path.Join(fs.root, name), data)
156156
}
157157

pbm/storage/gcs/gcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (*GCS) Type() storage.Type {
142142
return storage.GCS
143143
}
144144

145-
func (g *GCS) Save(name string, data io.Reader, size int64, _ ...storage.Option) error {
145+
func (g *GCS) Save(name string, data io.Reader, _ ...storage.Option) error {
146146
ctx := context.Background()
147147

148148
w := g.bucketHandle.Object(path.Join(g.opts.Prefix, name)).NewWriter(ctx)

pbm/storage/s3/s3.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (*S3) Type() storage.Type {
314314
return storage.S3
315315
}
316316

317-
func (s *S3) Save(name string, data io.Reader, sizeb int64, options ...storage.Option) error {
317+
func (s *S3) Save(name string, data io.Reader, options ...storage.Option) error {
318318
opts := storage.GetDefaultOpts()
319319
for _, opt := range options {
320320
if err := opt(opts); err != nil {
@@ -366,8 +366,8 @@ func (s *S3) Save(name string, data io.Reader, sizeb int64, options ...storage.O
366366

367367
partSize = int64(s.opts.UploadPartSize)
368368
}
369-
if sizeb > 0 {
370-
ps := sizeb / int64(s.opts.MaxUploadParts) * 15 / 10 // add 50% just in case
369+
if opts.Size > 0 {
370+
ps := opts.Size / int64(s.opts.MaxUploadParts) * 15 / 10 // add 50% just in case
371371
if ps > partSize {
372372
partSize = ps
373373
}
@@ -376,8 +376,8 @@ func (s *S3) Save(name string, data io.Reader, sizeb int64, options ...storage.O
376376
if s.log != nil && opts.UseLogger {
377377
s.log.Debug("uploading %q [size hint: %v (%v); part size: %v (%v)]",
378378
name,
379-
sizeb,
380-
storage.PrettySize(sizeb),
379+
opts.Size,
380+
storage.PrettySize(opts.Size),
381381
partSize,
382382
storage.PrettySize(partSize))
383383
}

0 commit comments

Comments
 (0)