@@ -162,54 +162,55 @@ func (r *ReconcilePerconaServerMongoDBRestore) reconcilePhysicalRestore(ctx cont
162
162
return status , errors .Wrapf (err , "resync config stderr: %s stdout: %s" , stderrBuf .String (), stdoutBuf .String ())
163
163
}
164
164
165
- ticker := time .NewTicker (5 * time .Second )
166
- defer ticker .Stop ()
167
-
168
- timeout := time .NewTimer (900 * time .Second )
169
- defer timeout .Stop ()
170
-
171
- outer:
172
- for {
173
- select {
174
- case <- timeout .C :
175
- return status , errors .Errorf ("timeout while waiting PBM operation to finish" )
176
- case <- ticker .C :
177
- err := retry .OnError (retry .DefaultBackoff , func (err error ) bool { return strings .Contains (err .Error (), "No agent available" ) }, func () error {
178
- stdoutBuf .Reset ()
179
- stderrBuf .Reset ()
180
-
181
- command := []string {"/opt/percona/pbm" , "status" , "--out" , "json" }
182
- err := r .clientcmd .Exec (ctx , & pod , "mongod" , command , nil , stdoutBuf , stderrBuf , false )
183
- if err != nil {
184
- log .Error (err , "failed to get PBM status" )
185
- return err
186
- }
187
-
188
- log .V (1 ).Info ("PBM status" , "status" , stdoutBuf .String ())
189
-
190
- return nil
191
- })
165
+ time .Sleep (5 * time .Second ) // wait until pbm will start resync
166
+
167
+ waitErr := errors .New ("waiting for PBM operation to finish" )
168
+ err = retry .OnError (wait.Backoff {
169
+ Duration : 5 * time .Second ,
170
+ Factor : 2.0 ,
171
+ Cap : time .Hour ,
172
+ Steps : 12 ,
173
+ }, func (err error ) bool { return err == waitErr }, func () error {
174
+ err := retry .OnError (retry .DefaultBackoff , func (err error ) bool { return strings .Contains (err .Error (), "No agent available" ) }, func () error {
175
+ stdoutBuf .Reset ()
176
+ stderrBuf .Reset ()
177
+
178
+ command := []string {"/opt/percona/pbm" , "status" , "--out" , "json" }
179
+ err := r .clientcmd .Exec (ctx , & pod , "mongod" , command , nil , stdoutBuf , stderrBuf , false )
192
180
if err != nil {
193
- return status , errors .Wrapf (err , "get PBM status stderr: %s stdout: %s" , stderrBuf .String (), stdoutBuf .String ())
181
+ log .Error (err , "failed to get PBM status" )
182
+ return err
194
183
}
195
184
196
- var pbmStatus struct {
197
- Running struct {
198
- Type string `json:"type,omitempty"`
199
- OpId string `json:"opID,omitempty"`
200
- } `json:"running"`
201
- }
185
+ log .V (1 ).Info ("PBM status" , "status" , stdoutBuf .String ())
202
186
203
- if err := json .Unmarshal (stdoutBuf .Bytes (), & pbmStatus ); err != nil {
204
- return status , errors .Wrap (err , "unmarshal PBM status output" )
205
- }
187
+ return nil
188
+ })
189
+ if err != nil {
190
+ return errors .Wrapf (err , "get PBM status stderr: %s stdout: %s" , stderrBuf .String (), stdoutBuf .String ())
191
+ }
206
192
207
- if len (pbmStatus .Running .OpId ) == 0 {
208
- break outer
209
- }
193
+ var pbmStatus struct {
194
+ Running struct {
195
+ Type string `json:"type,omitempty"`
196
+ OpId string `json:"opID,omitempty"`
197
+ } `json:"running"`
198
+ }
210
199
211
- log .Info ("Waiting for another PBM operation to finish" , "type" , pbmStatus .Running .Type , "opID" , pbmStatus .Running .OpId )
200
+ if err := json .Unmarshal (stdoutBuf .Bytes (), & pbmStatus ); err != nil {
201
+ return errors .Wrap (err , "unmarshal PBM status output" )
212
202
}
203
+
204
+ if len (pbmStatus .Running .OpId ) == 0 {
205
+ return nil
206
+ }
207
+
208
+ log .Info ("Waiting for another PBM operation to finish" , "type" , pbmStatus .Running .Type , "opID" , pbmStatus .Running .OpId )
209
+
210
+ return waitErr
211
+ })
212
+ if err != nil {
213
+ return status , err
213
214
}
214
215
215
216
var restoreCommand []string
0 commit comments