Skip to content

Commit 1e9489c

Browse files
committed
update sdk
1 parent d00a75e commit 1e9489c

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

cmd/pbm/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func getStorageStat(
580580
// which the `confsrv` param in `bcpMatchCluster` is all about
581581
bcpsMatchCluster(bcps, ver.VersionString, fcv, shards, inf.SetName, rsMap)
582582

583-
stg, err := util.GetStorage(ctx, conn, inf.Me,
583+
stg, err := util.GetStorage(ctx, ccrsConn, inf.Me,
584584
log.FromContext(ctx).NewEvent("", "", "", primitive.Timestamp{}))
585585
if err != nil {
586586
return s, errors.Wrap(err, "get storage")

sdk/impl.go

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ type Client struct {
4141
}
4242

4343
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
4554
}
4655

4756
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
5059
return nil, ErrInvalidCommandID
5160
}
5261

53-
res := c.conn.CmdStreamCollection().FindOne(ctx, bson.D{{"_id", opid.Obj()}})
62+
res := c.ccrsConn.CmdStreamCollection().FindOne(ctx, bson.D{{"_id", opid.Obj()}})
5463
if err := res.Err(); err != nil {
5564
if errors.Is(err, mongo.ErrNoDocuments) {
5665
return nil, ErrNotFound
@@ -68,19 +77,19 @@ func (c *Client) CommandInfo(ctx context.Context, id CommandID) (*Command, error
6877
}
6978

7079
func (c *Client) GetConfig(ctx context.Context) (*Config, error) {
71-
return config.GetConfig(ctx, c.conn)
80+
return config.GetConfig(ctx, c.ccrsConn)
7281
}
7382

7483
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)
7685
}
7786

7887
func (c *Client) GetAllConfigProfiles(ctx context.Context) ([]config.Config, error) {
79-
return config.ListProfiles(ctx, c.conn)
88+
return config.ListProfiles(ctx, c.ccrsConn)
8089
}
8190

8291
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)
8493
if err != nil {
8594
if errors.Is(err, mongo.ErrNoDocuments) {
8695
err = config.ErrMissedConfigProfile
@@ -92,17 +101,17 @@ func (c *Client) GetConfigProfile(ctx context.Context, name string) (*config.Con
92101
}
93102

94103
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)
96105
return CommandID(opid.String()), err
97106
}
98107

99108
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)
101110
return CommandID(opid.String()), err
102111
}
103112

104113
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)
106115
}
107116

108117
func (c *Client) GetAllRestores(
@@ -114,15 +123,15 @@ func (c *Client) GetAllRestores(
114123
if limit < 0 {
115124
limit = 0
116125
}
117-
return restore.RestoreList(ctx, c.conn, limit)
126+
return restore.RestoreList(ctx, c.ccrsConn, limit)
118127
}
119128

120129
func (c *Client) GetBackupByName(
121130
ctx context.Context,
122131
name string,
123132
options GetBackupByNameOptions,
124133
) (*BackupMetadata, error) {
125-
bcp, err := backup.NewDBManager(c.conn).GetBackupByName(ctx, name)
134+
bcp, err := backup.NewDBManager(c.ccrsConn).GetBackupByName(ctx, name)
126135
if err != nil {
127136
return nil, errors.Wrap(err, "get backup meta")
128137
}
@@ -135,7 +144,7 @@ func (c *Client) GetBackupByOpID(
135144
opid string,
136145
options GetBackupByNameOptions,
137146
) (*BackupMetadata, error) {
138-
bcp, err := backup.NewDBManager(c.conn).GetBackupByOpID(ctx, opid)
147+
bcp, err := backup.NewDBManager(c.ccrsConn).GetBackupByOpID(ctx, opid)
139148
if err != nil {
140149
return nil, errors.Wrap(err, "get backup meta")
141150
}
@@ -153,7 +162,7 @@ func (c *Client) getBackupHelper(
153162
return nil, ErrNotBaseIncrement
154163
}
155164

156-
increments, err := backup.FetchAllIncrements(ctx, c.conn, bcp)
165+
increments, err := backup.FetchAllIncrements(ctx, c.ccrsConn, bcp)
157166
if err != nil {
158167
return nil, errors.New("get increments")
159168
}
@@ -256,11 +265,11 @@ func (c *Client) getStorageForRead(ctx context.Context, bcp *backup.BackupMeta)
256265
}
257266

258267
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)
260269
}
261270

262271
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)
264273
}
265274

266275
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
277286
return NoOpID, errors.New("name is not provided")
278287
}
279288

280-
opid, err := ctrl.SendResync(ctx, c.conn, &ctrl.ResyncCmd{Name: name})
289+
opid, err := ctrl.SendResync(ctx, c.ccrsConn, &ctrl.ResyncCmd{Name: name})
281290
return CommandID(opid.String()), err
282291
}
283292

284293
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})
286295
return CommandID(opid.String()), err
287296
}
288297

@@ -291,12 +300,12 @@ func (c *Client) ClearSyncFromExternalStorage(ctx context.Context, name string)
291300
return NoOpID, errors.New("name is not provided")
292301
}
293302

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})
295304
return CommandID(opid.String()), err
296305
}
297306

298307
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})
300309
return CommandID(opid.String()), err
301310
}
302311

@@ -315,7 +324,7 @@ func (c *Client) DeleteBackupByName(ctx context.Context, name string) (CommandID
315324
return NoOpID, err
316325
}
317326

318-
opid, err := ctrl.SendDeleteBackupByName(ctx, c.conn, name)
327+
opid, err := ctrl.SendDeleteBackupByName(ctx, c.ccrsConn, name)
319328
return CommandID(opid.String()), err
320329
}
321330

@@ -324,12 +333,12 @@ func (c *Client) DeleteBackupBefore(
324333
beforeTS Timestamp,
325334
options DeleteBackupBeforeOptions,
326335
) (CommandID, error) {
327-
opid, err := ctrl.SendDeleteBackupBefore(ctx, c.conn, beforeTS, options.Type)
336+
opid, err := ctrl.SendDeleteBackupBefore(ctx, c.ccrsConn, beforeTS, options.Type)
328337
return CommandID(opid.String()), err
329338
}
330339

331340
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)
333342
return CommandID(opid.String()), err
334343
}
335344

@@ -338,12 +347,12 @@ func (c *Client) CleanupReport(ctx context.Context, beforeTS Timestamp) (Cleanup
338347
}
339348

340349
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)
342351
return CommandID(opid.String()), err
343352
}
344353

345354
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)
347356
return CommandID(opid.String()), err
348357
}
349358

sdk/sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func WaitForDeleteOplogRange(ctx context.Context, client *Client) error {
201201
}
202202

203203
func WaitForErrorLog(ctx context.Context, client *Client, cmd *Command) (string, error) {
204-
return lastLogErr(ctx, client.conn, cmd.Cmd, cmd.TS)
204+
return lastLogErr(ctx, client.ccrsConn, cmd.Cmd, cmd.TS)
205205
}
206206

207207
func CanDeleteBackup(ctx context.Context, client *Client, bcp *BackupMetadata) error {

sdk/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func WaitForResync(ctx context.Context, c *Client, cid CommandID) error {
7373
},
7474
}
7575

76-
outC, errC := log.Follow(ctx, c.conn, r, false)
76+
outC, errC := log.Follow(ctx, c.ccrsConn, r, false)
7777

7878
for {
7979
select {

0 commit comments

Comments
 (0)