@@ -41,7 +41,16 @@ type Client struct {
41
41
}
42
42
43
43
func (c * Client ) Close (ctx context.Context ) error {
44
- return c .conn .Disconnect (ctx )
44
+ var firstErr error
45
+ if err := c .conn .Disconnect (ctx ); err != nil {
46
+ firstErr = err
47
+ }
48
+ if c .ccrsConn != c .conn {
49
+ if err := c .ccrsConn .Disconnect (ctx ); err != nil {
50
+ return err
51
+ }
52
+ }
53
+ return firstErr
45
54
}
46
55
47
56
func (c * Client ) CommandInfo (ctx context.Context , id CommandID ) (* Command , error ) {
@@ -50,7 +59,7 @@ func (c *Client) CommandInfo(ctx context.Context, id CommandID) (*Command, error
50
59
return nil , ErrInvalidCommandID
51
60
}
52
61
53
- res := c .conn .CmdStreamCollection ().FindOne (ctx , bson.D {{"_id" , opid .Obj ()}})
62
+ res := c .ccrsConn .CmdStreamCollection ().FindOne (ctx , bson.D {{"_id" , opid .Obj ()}})
54
63
if err := res .Err (); err != nil {
55
64
if errors .Is (err , mongo .ErrNoDocuments ) {
56
65
return nil , ErrNotFound
@@ -68,19 +77,19 @@ func (c *Client) CommandInfo(ctx context.Context, id CommandID) (*Command, error
68
77
}
69
78
70
79
func (c * Client ) GetConfig (ctx context.Context ) (* Config , error ) {
71
- return config .GetConfig (ctx , c .conn )
80
+ return config .GetConfig (ctx , c .ccrsConn )
72
81
}
73
82
74
83
func (c * Client ) SetConfig (ctx context.Context , cfg Config ) (CommandID , error ) {
75
- return NoOpID , config .SetConfig (ctx , c .conn , & cfg )
84
+ return NoOpID , config .SetConfig (ctx , c .ccrsConn , & cfg )
76
85
}
77
86
78
87
func (c * Client ) GetAllConfigProfiles (ctx context.Context ) ([]config.Config , error ) {
79
- return config .ListProfiles (ctx , c .conn )
88
+ return config .ListProfiles (ctx , c .ccrsConn )
80
89
}
81
90
82
91
func (c * Client ) GetConfigProfile (ctx context.Context , name string ) (* config.Config , error ) {
83
- profile , err := config .GetProfile (ctx , c .conn , name )
92
+ profile , err := config .GetProfile (ctx , c .ccrsConn , name )
84
93
if err != nil {
85
94
if errors .Is (err , mongo .ErrNoDocuments ) {
86
95
err = config .ErrMissedConfigProfile
@@ -92,17 +101,17 @@ func (c *Client) GetConfigProfile(ctx context.Context, name string) (*config.Con
92
101
}
93
102
94
103
func (c * Client ) AddConfigProfile (ctx context.Context , name string , cfg * Config ) (CommandID , error ) {
95
- opid , err := ctrl .SendAddConfigProfile (ctx , c .conn , name , cfg .Storage )
104
+ opid , err := ctrl .SendAddConfigProfile (ctx , c .ccrsConn , name , cfg .Storage )
96
105
return CommandID (opid .String ()), err
97
106
}
98
107
99
108
func (c * Client ) RemoveConfigProfile (ctx context.Context , name string ) (CommandID , error ) {
100
- opid , err := ctrl .SendRemoveConfigProfile (ctx , c .conn , name )
109
+ opid , err := ctrl .SendRemoveConfigProfile (ctx , c .ccrsConn , name )
101
110
return CommandID (opid .String ()), err
102
111
}
103
112
104
113
func (c * Client ) GetAllBackups (ctx context.Context ) ([]BackupMetadata , error ) {
105
- return backup .BackupsList (ctx , c .conn , 0 )
114
+ return backup .BackupsList (ctx , c .ccrsConn , 0 )
106
115
}
107
116
108
117
func (c * Client ) GetAllRestores (
@@ -114,15 +123,15 @@ func (c *Client) GetAllRestores(
114
123
if limit < 0 {
115
124
limit = 0
116
125
}
117
- return restore .RestoreList (ctx , c .conn , limit )
126
+ return restore .RestoreList (ctx , c .ccrsConn , limit )
118
127
}
119
128
120
129
func (c * Client ) GetBackupByName (
121
130
ctx context.Context ,
122
131
name string ,
123
132
options GetBackupByNameOptions ,
124
133
) (* BackupMetadata , error ) {
125
- bcp , err := backup .NewDBManager (c .conn ).GetBackupByName (ctx , name )
134
+ bcp , err := backup .NewDBManager (c .ccrsConn ).GetBackupByName (ctx , name )
126
135
if err != nil {
127
136
return nil , errors .Wrap (err , "get backup meta" )
128
137
}
@@ -135,7 +144,7 @@ func (c *Client) GetBackupByOpID(
135
144
opid string ,
136
145
options GetBackupByNameOptions ,
137
146
) (* BackupMetadata , error ) {
138
- bcp , err := backup .NewDBManager (c .conn ).GetBackupByOpID (ctx , opid )
147
+ bcp , err := backup .NewDBManager (c .ccrsConn ).GetBackupByOpID (ctx , opid )
139
148
if err != nil {
140
149
return nil , errors .Wrap (err , "get backup meta" )
141
150
}
@@ -153,7 +162,7 @@ func (c *Client) getBackupHelper(
153
162
return nil , ErrNotBaseIncrement
154
163
}
155
164
156
- increments , err := backup .FetchAllIncrements (ctx , c .conn , bcp )
165
+ increments , err := backup .FetchAllIncrements (ctx , c .ccrsConn , bcp )
157
166
if err != nil {
158
167
return nil , errors .New ("get increments" )
159
168
}
@@ -256,11 +265,11 @@ func (c *Client) getStorageForRead(ctx context.Context, bcp *backup.BackupMeta)
256
265
}
257
266
258
267
func (c * Client ) GetRestoreByName (ctx context.Context , name string ) (* RestoreMetadata , error ) {
259
- return restore .GetRestoreMeta (ctx , c .conn , name )
268
+ return restore .GetRestoreMeta (ctx , c .ccrsConn , name )
260
269
}
261
270
262
271
func (c * Client ) GetRestoreByOpID (ctx context.Context , opid string ) (* RestoreMetadata , error ) {
263
- return restore .GetRestoreMetaByOPID (ctx , c .conn , opid )
272
+ return restore .GetRestoreMetaByOPID (ctx , c .ccrsConn , opid )
264
273
}
265
274
266
275
func (c * Client ) SyncFromStorage (ctx context.Context , includeRestores bool ) (CommandID , error ) {
@@ -277,12 +286,12 @@ func (c *Client) SyncFromExternalStorage(ctx context.Context, name string) (Comm
277
286
return NoOpID , errors .New ("name is not provided" )
278
287
}
279
288
280
- opid , err := ctrl .SendResync (ctx , c .conn , & ctrl.ResyncCmd {Name : name })
289
+ opid , err := ctrl .SendResync (ctx , c .ccrsConn , & ctrl.ResyncCmd {Name : name })
281
290
return CommandID (opid .String ()), err
282
291
}
283
292
284
293
func (c * Client ) SyncFromAllExternalStorages (ctx context.Context ) (CommandID , error ) {
285
- opid , err := ctrl .SendResync (ctx , c .conn , & ctrl.ResyncCmd {All : true })
294
+ opid , err := ctrl .SendResync (ctx , c .ccrsConn , & ctrl.ResyncCmd {All : true })
286
295
return CommandID (opid .String ()), err
287
296
}
288
297
@@ -291,12 +300,12 @@ func (c *Client) ClearSyncFromExternalStorage(ctx context.Context, name string)
291
300
return NoOpID , errors .New ("name is not provided" )
292
301
}
293
302
294
- opid , err := ctrl .SendResync (ctx , c .conn , & ctrl.ResyncCmd {Name : name , Clear : true })
303
+ opid , err := ctrl .SendResync (ctx , c .ccrsConn , & ctrl.ResyncCmd {Name : name , Clear : true })
295
304
return CommandID (opid .String ()), err
296
305
}
297
306
298
307
func (c * Client ) ClearSyncFromAllExternalStorages (ctx context.Context ) (CommandID , error ) {
299
- opid , err := ctrl .SendResync (ctx , c .conn , & ctrl.ResyncCmd {All : true , Clear : true })
308
+ opid , err := ctrl .SendResync (ctx , c .ccrsConn , & ctrl.ResyncCmd {All : true , Clear : true })
300
309
return CommandID (opid .String ()), err
301
310
}
302
311
@@ -315,7 +324,7 @@ func (c *Client) DeleteBackupByName(ctx context.Context, name string) (CommandID
315
324
return NoOpID , err
316
325
}
317
326
318
- opid , err := ctrl .SendDeleteBackupByName (ctx , c .conn , name )
327
+ opid , err := ctrl .SendDeleteBackupByName (ctx , c .ccrsConn , name )
319
328
return CommandID (opid .String ()), err
320
329
}
321
330
@@ -324,12 +333,12 @@ func (c *Client) DeleteBackupBefore(
324
333
beforeTS Timestamp ,
325
334
options DeleteBackupBeforeOptions ,
326
335
) (CommandID , error ) {
327
- opid , err := ctrl .SendDeleteBackupBefore (ctx , c .conn , beforeTS , options .Type )
336
+ opid , err := ctrl .SendDeleteBackupBefore (ctx , c .ccrsConn , beforeTS , options .Type )
328
337
return CommandID (opid .String ()), err
329
338
}
330
339
331
340
func (c * Client ) DeleteOplogRange (ctx context.Context , until Timestamp ) (CommandID , error ) {
332
- opid , err := ctrl .SendDeleteOplogRangeBefore (ctx , c .conn , until )
341
+ opid , err := ctrl .SendDeleteOplogRangeBefore (ctx , c .ccrsConn , until )
333
342
return CommandID (opid .String ()), err
334
343
}
335
344
@@ -338,12 +347,12 @@ func (c *Client) CleanupReport(ctx context.Context, beforeTS Timestamp) (Cleanup
338
347
}
339
348
340
349
func (c * Client ) RunCleanup (ctx context.Context , beforeTS Timestamp ) (CommandID , error ) {
341
- opid , err := ctrl .SendCleanup (ctx , c .conn , beforeTS )
350
+ opid , err := ctrl .SendCleanup (ctx , c .ccrsConn , beforeTS )
342
351
return CommandID (opid .String ()), err
343
352
}
344
353
345
354
func (c * Client ) CancelBackup (ctx context.Context ) (CommandID , error ) {
346
- opid , err := ctrl .SendCancelBackup (ctx , c .conn )
355
+ opid , err := ctrl .SendCancelBackup (ctx , c .ccrsConn )
347
356
return CommandID (opid .String ()), err
348
357
}
349
358
0 commit comments