Skip to content

Commit a57049a

Browse files
authored
Merge pull request #1118 from percona/PBM-1531-deadlock-physical-restore-file-copy
PBM-1531: Fix deadlock during physical restore file copying
2 parents 97b9c1f + d69b100 commit a57049a

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

pbm/restore/physical.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,10 @@ func (r *PhysRestore) Snapshot(
987987
buf: &bytes.Buffer{},
988988
path: fmt.Sprintf("%s/%s/rs.%s/log/%s", defs.PhysRestoresDir, r.name, r.rsConf.ID, r.nodeInfo.Me),
989989
limit: 1 << 20, // 1Mb
990-
write: func(name string, data io.Reader) error { return r.stg.Save(name, data, -1) },
990+
write: func(name string, data io.Reader) error {
991+
// Logger should be disabled due to: PBM-1531
992+
return r.stg.Save(name, data, -1, storage.UseLogger(false))
993+
},
991994
})
992995
logger.PauseMgo()
993996

pbm/storage/azure/azure.go

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

131-
func (b *Blob) Save(name string, data io.Reader, sizeb int64) error {
131+
func (b *Blob) Save(name string, data io.Reader, sizeb int64, options ...storage.Option) error {
132+
opts := storage.GetDefaultOpts()
133+
for _, opt := range options {
134+
if err := opt(opts); err != nil {
135+
return errors.Wrap(err, "processing options for save")
136+
}
137+
}
138+
132139
bufsz := defaultUploadBuff
133140
if sizeb > 0 {
134141
ps := int(sizeb / maxBlocks * 11 / 10) // add 10% just in case
@@ -142,7 +149,7 @@ func (b *Blob) Save(name string, data io.Reader, sizeb int64) error {
142149
cc = 1
143150
}
144151

145-
if b.log != nil {
152+
if b.log != nil && opts.UseLogger {
146153
b.log.Debug("BufferSize is set to %d (~%dMb) | %d", bufsz, bufsz>>20, sizeb)
147154
}
148155

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) error {
21+
func (*Blackhole) Save(_ string, data io.Reader, _ int64, _ ...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) error {
154+
func (fs *FS) Save(name string, data io.Reader, _ int64, _ ...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) error {
145+
func (g *GCS) Save(name string, data io.Reader, size int64, _ ...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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,13 @@ func (*S3) Type() storage.Type {
314314
return storage.S3
315315
}
316316

317-
func (s *S3) Save(name string, data io.Reader, sizeb int64) error {
317+
func (s *S3) Save(name string, data io.Reader, sizeb int64, options ...storage.Option) error {
318+
opts := storage.GetDefaultOpts()
319+
for _, opt := range options {
320+
if err := opt(opts); err != nil {
321+
return errors.Wrap(err, "processing options for save")
322+
}
323+
}
318324
cc := runtime.NumCPU() / 2
319325
if cc == 0 {
320326
cc = 1
@@ -367,7 +373,7 @@ func (s *S3) Save(name string, data io.Reader, sizeb int64) error {
367373
}
368374
}
369375

370-
if s.log != nil {
376+
if s.log != nil && opts.UseLogger {
371377
s.log.Debug("uploading %q [size hint: %v (%v); part size: %v (%v)]",
372378
name,
373379
sizeb,

pbm/storage/storage.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type FileInfo struct {
3737

3838
type Storage interface {
3939
Type() Type
40-
Save(name string, data io.Reader, size int64) error
40+
Save(name string, data io.Reader, size int64, options ...Option) error
4141
SourceReader(name string) (io.ReadCloser, error)
4242
// FileStat returns file info. It returns error if file is empty or not exists.
4343
FileStat(name string) (FileInfo, error)
@@ -69,6 +69,30 @@ func ParseType(s string) Type {
6969
}
7070
}
7171

72+
// Opts represents storage options
73+
type Opts struct {
74+
UseLogger bool
75+
}
76+
77+
// GetDefaultOpts creates default options.
78+
func GetDefaultOpts() *Opts {
79+
return &Opts{
80+
UseLogger: true,
81+
}
82+
}
83+
84+
// Option is function for setting the storage option
85+
type Option func(*Opts) error
86+
87+
// UseLogger option enables/disables logger when working with storage.
88+
// Logger is enabled by default.
89+
func UseLogger(useLogger bool) Option {
90+
return func(o *Opts) error {
91+
o.UseLogger = useLogger
92+
return nil
93+
}
94+
}
95+
7296
// IsInitialized checks if there is PBM init file on the storage.
7397
func IsInitialized(ctx context.Context, stg Storage) (bool, error) {
7498
_, err := stg.FileStat(defs.StorInitFile)

0 commit comments

Comments
 (0)