Skip to content

Commit 489486b

Browse files
committed
Expand backup meta with backup's size on RS
1 parent 8d34c16 commit 489486b

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

cmd/pbm/backup.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ type bcpReplDesc struct {
340340
Status defs.Status `json:"status" yaml:"status"`
341341
Node string `json:"node" yaml:"node"`
342342
Files []backup.File `json:"files,omitempty" yaml:"-"`
343+
Size int64 `json:"size" yaml:"-"`
344+
HSize string `json:"size_h" yaml:"size_h"`
343345
LastWriteTS int64 `json:"last_write_ts" yaml:"-"`
344346
LastTransitionTS int64 `json:"last_transition_ts" yaml:"-"`
345347
LastWriteTime string `json:"last_write_time" yaml:"last_write_time"`
@@ -442,6 +444,8 @@ func describeBackup(
442444
IsConfigSvr: r.IsConfigSvr,
443445
IsConfigShard: r.IsConfigShard,
444446
Status: r.Status,
447+
Size: r.Size,
448+
HSize: byteCountIEC(r.Size),
445449
LastWriteTS: int64(r.LastWriteTS.T),
446450
LastTransitionTS: r.LastTransitionTS,
447451
LastWriteTime: time.Unix(int64(r.LastWriteTS.T), 0).UTC().Format(time.RFC3339),

pbm/backup/physical.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,15 @@ func (b *Backup) uploadPhysical(
526526
}
527527
l.Info("uploaded: %q %s", filelistPath, storage.PrettySize(flSize))
528528

529-
err = IncBackupSize(ctx, b.leadConn, bcp.Name, size+flSize)
529+
totalSize := size + flSize
530+
err = IncBackupSize(ctx, b.leadConn, bcp.Name, totalSize)
530531
if err != nil {
531532
return errors.Wrap(err, "inc backup size")
532533
}
534+
err = SetBackupSizeForRS(ctx, b.leadConn, bcp.Name, rsMeta.Name, totalSize)
535+
if err != nil {
536+
return errors.Wrap(err, "set RS backup size")
537+
}
533538

534539
return nil
535540
}

pbm/backup/query.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ func ChangeRSState(conn connect.Client, bcpName, rsName string, s defs.Status, m
219219
return err
220220
}
221221

222+
// IncBackupSize increments total backup size.
222223
func IncBackupSize(ctx context.Context, conn connect.Client, bcpName string, size int64) error {
223224
_, err := conn.BcpCollection().UpdateOne(ctx,
224225
bson.D{{"name", bcpName}},
@@ -227,6 +228,22 @@ func IncBackupSize(ctx context.Context, conn connect.Client, bcpName string, siz
227228
return err
228229
}
229230

231+
// SetBackupSizeForRS sets size of backup for specified RS.
232+
func SetBackupSizeForRS(
233+
ctx context.Context,
234+
conn connect.Client,
235+
bcpName,
236+
rsName string,
237+
size int64,
238+
) error {
239+
_, err := conn.BcpCollection().UpdateOne(
240+
ctx,
241+
bson.D{{"name", bcpName}, {"replsets.name", rsName}},
242+
bson.D{{"$set", bson.M{"replsets.$.size": size}}})
243+
244+
return err
245+
}
246+
230247
func SetRSLastWrite(conn connect.Client, bcpName, rsName string, ts primitive.Timestamp) error {
231248
_, err := conn.BcpCollection().UpdateOne(
232249
context.Background(),

pbm/backup/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type BackupReplset struct {
117117
OplogName string `bson:"oplog_name,omitempty" json:"oplog_name,omitempty"`
118118
StartTS int64 `bson:"start_ts" json:"start_ts"`
119119
Status defs.Status `bson:"status" json:"status"`
120+
Size int64 `bson:"size" json:"size"`
120121
IsConfigSvr *bool `bson:"iscs,omitempty" json:"iscs,omitempty"`
121122
IsConfigShard *bool `bson:"configshard,omitempty" json:"configshard,omitempty"`
122123
LastTransitionTS int64 `bson:"last_transition_ts" json:"last_transition_ts"`

0 commit comments

Comments
 (0)