Skip to content

Commit 2c141ea

Browse files
committed
Expand backup meta with uncompressed size
1 parent cdd4e0c commit 2c141ea

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

cmd/pbm/backup.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ type bcpDesc struct {
329329
PBMVersion string `json:"pbm_version" yaml:"pbm_version"`
330330
Status defs.Status `json:"status" yaml:"status"`
331331
Size int64 `json:"size" yaml:"-"`
332+
SizeUncompressed int64 `json:"size_uncompressed" yaml:"-"`
332333
HSize string `json:"size_h" yaml:"size_h"`
334+
HSizeUncompressed string `json:"size_uncompressed_h" yaml:"size_uncompressed_h"`
333335
StorageName string `json:"storage_name,omitempty" yaml:"storage_name,omitempty"`
334336
Err *string `json:"error,omitempty" yaml:"error,omitempty"`
335337
Replsets []bcpReplDesc `json:"replsets" yaml:"replsets"`
@@ -341,7 +343,9 @@ type bcpReplDesc struct {
341343
Node string `json:"node" yaml:"node"`
342344
Files []backup.File `json:"files,omitempty" yaml:"-"`
343345
Size int64 `json:"size" yaml:"-"`
346+
SizeUncompressed int64 `json:"size_uncompressed" yaml:"-"`
344347
HSize string `json:"size_h,omitempty" yaml:"size_h,omitempty"`
348+
HSizeUncompressed string `json:"size_uncompressed_h" yaml:"size_uncompressed_h"`
345349
LastWriteTS int64 `json:"last_write_ts" yaml:"-"`
346350
LastTransitionTS int64 `json:"last_transition_ts" yaml:"-"`
347351
LastWriteTime string `json:"last_write_time" yaml:"last_write_time"`
@@ -419,8 +423,13 @@ func describeBackup(
419423
Status: bcp.Status,
420424
Size: bcp.Size,
421425
HSize: byteCountIEC(bcp.Size),
426+
SizeUncompressed: bcp.SizeUncompressed,
427+
HSizeUncompressed: byteCountIEC(bcp.SizeUncompressed),
422428
StorageName: bcp.Store.Name,
423429
}
430+
if bcp.SizeUncompressed > 0 {
431+
rv.HSizeUncompressed = byteCountIEC(bcp.SizeUncompressed)
432+
}
424433
if bcp.Err != "" {
425434
rv.Err = &bcp.Err
426435
}
@@ -445,6 +454,7 @@ func describeBackup(
445454
IsConfigShard: r.IsConfigShard,
446455
Status: r.Status,
447456
Size: r.Size,
457+
SizeUncompressed: r.SizeUncompressed,
448458
LastWriteTS: int64(r.LastWriteTS.T),
449459
LastTransitionTS: r.LastTransitionTS,
450460
LastWriteTime: time.Unix(int64(r.LastWriteTS.T), 0).UTC().Format(time.RFC3339),
@@ -463,6 +473,9 @@ func describeBackup(
463473
if r.Size > 0 {
464474
rv.Replsets[i].HSize = byteCountIEC(r.Size)
465475
}
476+
if r.SizeUncompressed > 0 {
477+
rv.Replsets[i].HSizeUncompressed = byteCountIEC(r.SizeUncompressed)
478+
}
466479

467480
if !b.coll || bcp.Type != defs.LogicalBackup {
468481
continue

pbm/backup/logical.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (b *Backup) doLogical(
236236
}
237237
}
238238

239-
err = IncBackupSize(ctx, b.leadConn, bcp.Name, snapshotSize+oplogSize)
239+
err = IncBackupSize(ctx, b.leadConn, bcp.Name, snapshotSize+oplogSize, nil)
240240
if err != nil {
241241
return errors.Wrap(err, "inc backup size")
242242
}

pbm/backup/physical.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,10 @@ func (b *Backup) uploadPhysical(
515515
filelist = append(filelist, ju...)
516516

517517
size := int64(0)
518+
sizeUncompressed := int64(0)
518519
for _, f := range filelist {
519520
size += f.StgSize
521+
sizeUncompressed += f.Size
520522
}
521523

522524
filelistPath := path.Join(bcp.Name, rsMeta.Name, FilelistName)
@@ -527,11 +529,25 @@ func (b *Backup) uploadPhysical(
527529
l.Info("uploaded: %q %s", filelistPath, storage.PrettySize(flSize))
528530

529531
totalSize := size + flSize
530-
err = IncBackupSize(ctx, b.leadConn, bcp.Name, totalSize)
532+
totalUncompressed := sizeUncompressed + flSize
533+
err = IncBackupSize(
534+
ctx,
535+
b.leadConn,
536+
bcp.Name,
537+
totalSize,
538+
&totalUncompressed,
539+
)
531540
if err != nil {
532541
return errors.Wrap(err, "inc backup size")
533542
}
534-
err = SetBackupSizeForRS(ctx, b.leadConn, bcp.Name, rsMeta.Name, totalSize)
543+
err = SetBackupSizeForRS(
544+
ctx,
545+
b.leadConn,
546+
bcp.Name,
547+
rsMeta.Name,
548+
totalSize,
549+
totalUncompressed,
550+
)
535551
if err != nil {
536552
return errors.Wrap(err, "set RS backup size")
537553
}

pbm/backup/query.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,27 @@ func ChangeRSState(conn connect.Client, bcpName, rsName string, s defs.Status, m
220220
}
221221

222222
// IncBackupSize increments total backup size.
223-
func IncBackupSize(ctx context.Context, conn connect.Client, bcpName string, size int64) error {
223+
func IncBackupSize(
224+
ctx context.Context,
225+
conn connect.Client,
226+
bcpName string,
227+
size int64,
228+
sizeUncompressed *int64,
229+
) error {
230+
update := bson.D{
231+
{"$inc", bson.M{"size": size}},
232+
}
233+
if sizeUncompressed != nil {
234+
update = append(
235+
update,
236+
bson.E{"$inc", bson.M{"size_uncompressed": sizeUncompressed}},
237+
)
238+
}
239+
224240
_, err := conn.BcpCollection().UpdateOne(ctx,
225241
bson.D{{"name", bcpName}},
226-
bson.D{{"$inc", bson.M{"size": size}}})
242+
update,
243+
)
227244

228245
return err
229246
}
@@ -235,12 +252,16 @@ func SetBackupSizeForRS(
235252
bcpName,
236253
rsName string,
237254
size int64,
255+
sizeUncompressed int64,
238256
) error {
239257
_, err := conn.BcpCollection().UpdateOne(
240258
ctx,
241259
bson.D{{"name", bcpName}, {"replsets.name", rsName}},
242-
bson.D{{"$set", bson.M{"replsets.$.size": size}}})
243-
260+
bson.D{
261+
{"$set", bson.M{"replsets.$.size": size}},
262+
{"$set", bson.M{"replsets.$.size_uncompressed": sizeUncompressed}},
263+
},
264+
)
244265
return err
245266
}
246267

pbm/backup/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type BackupMeta struct {
4444
Compression compress.CompressionType `bson:"compression" json:"compression"`
4545
Store Storage `bson:"store" json:"store"`
4646
Size int64 `bson:"size" json:"size"`
47+
SizeUncompressed int64 `bson:"size_uncompressed" json:"size_uncompressed"`
4748
MongoVersion string `bson:"mongodb_version" json:"mongodb_version"`
4849
FCV string `bson:"fcv" json:"fcv"`
4950
StartTS int64 `bson:"start_ts" json:"start_ts"`
@@ -118,6 +119,7 @@ type BackupReplset struct {
118119
StartTS int64 `bson:"start_ts" json:"start_ts"`
119120
Status defs.Status `bson:"status" json:"status"`
120121
Size int64 `bson:"size" json:"size"`
122+
SizeUncompressed int64 `bson:"size_uncompressed" json:"size_uncompressed"`
121123
IsConfigSvr *bool `bson:"iscs,omitempty" json:"iscs,omitempty"`
122124
IsConfigShard *bool `bson:"configshard,omitempty" json:"configshard,omitempty"`
123125
LastTransitionTS int64 `bson:"last_transition_ts" json:"last_transition_ts"`

0 commit comments

Comments
 (0)