@@ -42,7 +42,8 @@ func (b *BackupContext) RestoreBackup(ctx context.Context, request *backuppb.Res
4242 zap .String ("bucketName" , request .GetBucketName ()),
4343 zap .String ("path" , request .GetPath ()),
4444 zap .String ("databaseCollections" , utils .GetRestoreDBCollections (request )),
45- zap .Bool ("skipDiskQuotaCheck" , request .GetSkipImportDiskQuotaCheck ()))
45+ zap .Bool ("skipDiskQuotaCheck" , request .GetSkipImportDiskQuotaCheck ()),
46+ zap .Int32 ("maxShardNum" , request .GetMaxShardNum ()))
4647
4748 resp := & backuppb.RestoreBackupResponse {
4849 RequestId : request .GetRequestId (),
@@ -311,6 +312,7 @@ func (b *BackupContext) RestoreBackup(ctx context.Context, request *backuppb.Res
311312 DropExistIndex : request .GetDropExistIndex (),
312313 SkipCreateCollection : request .GetSkipCreateCollection (),
313314 SkipDiskQuotaCheck : request .GetSkipImportDiskQuotaCheck (),
315+ MaxShardNum : request .GetMaxShardNum (),
314316 }
315317 restoreCollectionTasks = append (restoreCollectionTasks , restoreCollectionTask )
316318 task .CollectionRestoreTasks = restoreCollectionTasks
@@ -388,7 +390,15 @@ func (b *BackupContext) executeRestoreBackupTask(ctx context.Context, backupBuck
388390 return task , err
389391 }
390392
391- b .meta .UpdateRestoreTask (id , setRestoreStateCode (backuppb .RestoreTaskStateCode_SUCCESS ), setRestoreEndTime (time .Now ().Unix ()))
393+ endTime := time .Now ().Unix ()
394+ task .EndTime = endTime
395+ b .meta .UpdateRestoreTask (id , setRestoreStateCode (backuppb .RestoreTaskStateCode_SUCCESS ), setRestoreEndTime (endTime ))
396+
397+ log .Info ("finish restore all collections" ,
398+ zap .String ("backupName" , backup .GetName ()),
399+ zap .Int ("collections" , len (backup .GetCollectionBackups ())),
400+ zap .String ("taskID" , task .GetId ()),
401+ zap .Int64 ("duration in seconds" , task .GetEndTime ()- task .GetStartTime ()))
392402 return task , nil
393403}
394404
@@ -401,7 +411,8 @@ func (b *BackupContext) executeRestoreCollectionTask(ctx context.Context, backup
401411 zap .String ("backup_collection_name" , task .GetCollBackup ().DbName ),
402412 zap .String ("target_db_name" , targetDBName ),
403413 zap .String ("target_collection_name" , targetCollectionName ),
404- zap .Bool ("skipDiskQuotaCheck" , task .GetSkipDiskQuotaCheck ()))
414+ zap .Bool ("skipDiskQuotaCheck" , task .GetSkipDiskQuotaCheck ()),
415+ zap .Int32 ("maxShardNum" , task .GetMaxShardNum ()))
405416 log .Info ("start restore" ,
406417 zap .String ("backupBucketName" , backupBucketName ),
407418 zap .String ("backupPath" , backupPath ))
@@ -460,21 +471,28 @@ func (b *BackupContext) executeRestoreCollectionTask(ctx context.Context, backup
460471 //so here it is necessary to be compatible with the situation where SkipCreateCollection and DropExistCollection are enabled at the same time.
461472 if ! task .GetSkipCreateCollection () || task .GetDropExistCollection () {
462473 err := retry .Do (ctx , func () error {
474+ // overwrite shardNum by request parameter
475+ shardNum := task .GetCollBackup ().GetShardsNum ()
476+ if shardNum > task .GetMaxShardNum () && task .GetMaxShardNum () != 0 {
477+ shardNum = task .GetMaxShardNum ()
478+ log .Info ("overwrite shardNum by request parameter" , zap .Int32 ("oldShardNum" , task .GetCollBackup ().GetShardsNum ()), zap .Int32 ("newShardNum" , shardNum ))
479+
480+ }
463481 if hasPartitionKey {
464482 partitionNum := len (task .GetCollBackup ().GetPartitionBackups ())
465483 return b .getMilvusClient ().CreateCollection (
466484 ctx ,
467485 targetDBName ,
468486 collectionSchema ,
469- task . GetCollBackup (). GetShardsNum () ,
487+ shardNum ,
470488 gomilvus .WithConsistencyLevel (entity .ConsistencyLevel (task .GetCollBackup ().GetConsistencyLevel ())),
471489 gomilvus .WithPartitionNum (int64 (partitionNum )))
472490 }
473491 return b .getMilvusClient ().CreateCollection (
474492 ctx ,
475493 targetDBName ,
476494 collectionSchema ,
477- task . GetCollBackup (). GetShardsNum () ,
495+ shardNum ,
478496 gomilvus .WithConsistencyLevel (entity .ConsistencyLevel (task .GetCollBackup ().GetConsistencyLevel ())))
479497 }, retry .Attempts (10 ), retry .Sleep (1 * time .Second ))
480498 if err != nil {
0 commit comments