Skip to content

Commit

Permalink
backup: reduce memory usage
Browse files Browse the repository at this point in the history
Signed-off-by: huanghaoyuanhhy <[email protected]>
  • Loading branch information
huanghaoyuanhhy committed Dec 27, 2024
1 parent c998e64 commit b5df220
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 5 additions & 6 deletions core/backup_impl_create_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,18 +750,17 @@ func (b *BackupContext) executeCreateBackup(ctx context.Context, request *backup
}

func (b *BackupContext) writeBackupInfoMeta(ctx context.Context, id string) error {
log.Info("Start write backup meta", zap.String("backupName", id))
b.meta.CleanBinlogInfo(id)
log.Info("Clean binlog info done", zap.String("backupName", id))
backupInfo := b.meta.GetFullMeta(id)
log.Debug("Final backupInfo", zap.String("backupInfo", backupInfo.String()))
output, _ := serialize(backupInfo)
log.Debug("backup meta", zap.String("value", string(output.BackupMetaBytes)))
log.Debug("collection meta", zap.String("value", string(output.CollectionMetaBytes)))
log.Debug("partition meta", zap.String("value", string(output.PartitionMetaBytes)))
log.Debug("segment meta", zap.String("value", string(output.SegmentMetaBytes)))

collectionBackups := backupInfo.GetCollectionBackups()
collectionPositions := make(map[string][]*backuppb.ChannelPosition, 0)
collectionPositions := make(map[string][]*backuppb.ChannelPosition, len(collectionBackups))
for _, collectionBackup := range collectionBackups {
collectionCPs := make([]*backuppb.ChannelPosition, 0)
collectionCPs := make([]*backuppb.ChannelPosition, 0, len(collectionBackup.GetChannelCheckpoints()))
for vCh, position := range collectionBackup.GetChannelCheckpoints() {
pCh := strings.Split(vCh, "_")[0] + "_" + strings.Split(vCh, "_")[1]
collectionCPs = append(collectionCPs, &backuppb.ChannelPosition{
Expand Down
15 changes: 15 additions & 0 deletions core/backup_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ func treeToLevel(backup *backuppb.BackupInfo) (LeveledBackupInfo, error) {
}, nil
}

func (meta *MetaManager) CleanBinlogInfo(id string) {
meta.mu.Lock()
defer meta.mu.Unlock()
collections := meta.collections[id]
for _, collection := range collections {
for _, partition := range meta.partitions[collection.GetCollectionId()] {
for _, segment := range meta.segments[partition.GetPartitionId()] {
segment.Binlogs = nil
segment.Statslogs = nil
segment.Deltalogs = nil
}
}
}
}

func serialize(backup *backuppb.BackupInfo) (*BackupMetaBytes, error) {
level, err := treeToLevel(backup)
if err != nil {
Expand Down

0 comments on commit b5df220

Please sign in to comment.