@@ -44,7 +44,9 @@ import (
44
44
"github.com/yugabyte/yb-voyager/yb-voyager/src/datafile"
45
45
"github.com/yugabyte/yb-voyager/yb-voyager/src/dbzm"
46
46
"github.com/yugabyte/yb-voyager/yb-voyager/src/metadb"
47
+ "github.com/yugabyte/yb-voyager/yb-voyager/src/namereg"
47
48
"github.com/yugabyte/yb-voyager/yb-voyager/src/srcdb"
49
+ "github.com/yugabyte/yb-voyager/yb-voyager/src/tgtdb"
48
50
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
49
51
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils/jsonfile"
50
52
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils/sqlname"
@@ -340,7 +342,7 @@ func displayImportedRowCountSnapshot(state *ImportDataState, tasks []*ImportFile
340
342
} else {
341
343
fmt .Printf ("snapshot import report\n " )
342
344
}
343
- tableList := importFileTasksToTableNames (tasks )
345
+ tableList := importFileTasksToTableNameTuples (tasks )
344
346
err := retrieveMigrationUUID ()
345
347
if err != nil {
346
348
utils .ErrExit ("could not retrieve migration UUID: %w" , err )
@@ -352,15 +354,15 @@ func displayImportedRowCountSnapshot(state *ImportDataState, tasks []*ImportFile
352
354
dbType = "source-replica"
353
355
}
354
356
355
- snapshotRowCount := make ( map [ string ] int64 )
357
+ snapshotRowCount := utils . NewStructMap [sqlname. NameTuple , int64 ]( )
356
358
357
359
if importerRole == IMPORT_FILE_ROLE {
358
360
for _ , tableName := range tableList {
359
361
tableRowCount , err := state .GetImportedSnapshotRowCountForTable (tableName )
360
362
if err != nil {
361
363
utils .ErrExit ("could not fetch snapshot row count for table %q: %w" , tableName , err )
362
364
}
363
- snapshotRowCount [ tableName ] = tableRowCount
365
+ snapshotRowCount . Put ( tableName , tableRowCount )
364
366
}
365
367
} else {
366
368
snapshotRowCount , err = getImportedSnapshotRowsMap (dbType , tableList )
@@ -373,11 +375,10 @@ func displayImportedRowCountSnapshot(state *ImportDataState, tasks []*ImportFile
373
375
if i == 0 {
374
376
addHeader (uitable , "SCHEMA" , "TABLE" , "IMPORTED ROW COUNT" )
375
377
}
376
- table := tableName
377
- if len (strings .Split (tableName , "." )) == 2 {
378
- table = strings .Split (tableName , "." )[1 ]
379
- }
380
- uitable .AddRow (getTargetSchemaName (tableName ), table , snapshotRowCount [tableName ])
378
+ s , t := tableName .ForCatalogQuery ()
379
+
380
+ rowCount , _ := snapshotRowCount .Get (tableName )
381
+ uitable .AddRow (s , t , rowCount )
381
382
}
382
383
if len (tableList ) > 0 {
383
384
fmt .Printf ("\n " )
@@ -452,6 +453,49 @@ func initMetaDB() {
452
453
}
453
454
}
454
455
456
+ func InitNameRegistry (
457
+ exportDir string , role string ,
458
+ sconf * srcdb.Source , sdb srcdb.SourceDB ,
459
+ tconf * tgtdb.TargetConf , tdb tgtdb.TargetDB ) error {
460
+
461
+ var sdbReg namereg.SourceDBInterface
462
+ var ybdb namereg.YBDBInterface
463
+ var sourceDbType , sourceDbSchema , sourceDbName string
464
+ var targetDBSchema string
465
+
466
+ if sconf != nil {
467
+ sourceDbType = sconf .DBType
468
+ sourceDbName = sconf .DBName
469
+ sourceDbSchema = sconf .Schema
470
+ }
471
+ if sdb != nil {
472
+ sdbReg = sdb .(namereg.SourceDBInterface )
473
+ }
474
+
475
+ if tconf != nil {
476
+ targetDBSchema = tconf .Schema
477
+ }
478
+ var ok bool
479
+ if tdb != nil && lo .Contains ([]string {TARGET_DB_IMPORTER_ROLE , IMPORT_FILE_ROLE }, role ) {
480
+ ybdb , ok = tdb .(namereg.YBDBInterface )
481
+ if ! ok {
482
+ return fmt .Errorf ("expected targetDB to adhere to YBDBRegirsty" )
483
+ }
484
+ }
485
+ nameregistryParams := namereg.NameRegistryParams {
486
+ FilePath : fmt .Sprintf ("%s/metainfo/name_registry.json" , exportDir ),
487
+ Role : role ,
488
+ SourceDBType : sourceDbType ,
489
+ SourceDBSchema : sourceDbSchema ,
490
+ SourceDBName : sourceDbName ,
491
+ TargetDBSchema : targetDBSchema ,
492
+ SDB : sdbReg ,
493
+ YBDB : ybdb ,
494
+ }
495
+
496
+ return namereg .InitNameRegistry (nameregistryParams )
497
+ }
498
+
455
499
// sets the global variable migrationUUID after retrieving it from MigrationStatusRecord
456
500
func retrieveMigrationUUID () error {
457
501
if migrationUUID != uuid .Nil {
@@ -588,22 +632,20 @@ func validateMetaDBCreated() {
588
632
}
589
633
}
590
634
591
- func getImportTableList (sourceTableList []string ) [] string {
635
+ func getImportTableList (sourceTableList []string ) ([]sqlname. NameTuple , error ) {
592
636
if importerRole == IMPORT_FILE_ROLE {
593
- return nil
637
+ return nil , nil
594
638
}
595
- var tableList []string
639
+ var tableList []sqlname. NameTuple
596
640
sqlname .SourceDBType = source .DBType
597
641
for _ , qualifiedTableName := range sourceTableList {
598
- // TODO: handle case sensitivity?
599
- tableName := sqlname .NewSourceNameFromQualifiedName (qualifiedTableName )
600
- table := tableName .ObjectName .MinQuoted
601
- if source .DBType == POSTGRESQL && tableName .SchemaName .MinQuoted != "public" {
602
- table = tableName .Qualified .MinQuoted
642
+ table , err := namereg .NameReg .LookupTableName (qualifiedTableName )
643
+ if err != nil {
644
+ return nil , fmt .Errorf ("lookup table %s in name registry : %v" , qualifiedTableName , err )
603
645
}
604
646
tableList = append (tableList , table )
605
647
}
606
- return tableList
648
+ return tableList , nil
607
649
}
608
650
609
651
func hideImportFlagsInFallForwardOrBackCmds (cmd * cobra.Command ) {
@@ -769,25 +811,30 @@ func renameTableIfRequired(table string) (string, bool) {
769
811
return table , false
770
812
}
771
813
772
- func getExportedSnapshotRowsMap (tableList []string , exportSnapshotStatus * ExportSnapshotStatus ) (map [string ]int64 , map [string ][]string , error ) {
773
- snapshotRowsMap := make (map [string ]int64 )
774
- snapshotStatusMap := make (map [string ][]string )
775
- for _ , table := range tableList {
776
- tableStatus := exportSnapshotStatus .GetTableStatusByTableName (table )
777
- table = strings .TrimPrefix (table , "public." ) //safely can remove it for now. TODO: fix with NameRegistry all such occurrences
778
- for _ , status := range tableStatus {
779
- if status .FileName == "" {
780
- //in case of root table as well in the tablelist during export an entry with empty file name is there
781
- continue
782
- }
783
- snapshotRowsMap [table ] += status .ExportedRowCountSnapshot
784
- snapshotStatusMap [table ] = append (snapshotStatusMap [table ], status .Status )
814
+ func getExportedSnapshotRowsMap (exportSnapshotStatus * ExportSnapshotStatus ) (* utils.StructMap [sqlname.NameTuple , int64 ], * utils.StructMap [sqlname.NameTuple , []string ], error ) {
815
+ snapshotRowsMap := utils .NewStructMap [sqlname.NameTuple , int64 ]()
816
+ snapshotStatusMap := utils .NewStructMap [sqlname.NameTuple , []string ]()
817
+
818
+ for _ , tableStatus := range exportSnapshotStatus .Tables {
819
+ if tableStatus .FileName == "" {
820
+ //in case of root table as well in the tablelist during export an entry with empty file name is there
821
+ continue
822
+ }
823
+ nt , err := namereg .NameReg .LookupTableName (tableStatus .TableName )
824
+ if err != nil {
825
+ return nil , nil , fmt .Errorf ("lookup table [%s] from name registry: %v" , tableStatus .TableName , err )
785
826
}
827
+ existingSnapshotRows , _ := snapshotRowsMap .Get (nt )
828
+ snapshotRowsMap .Put (nt , existingSnapshotRows + tableStatus .ExportedRowCountSnapshot )
829
+ existingStatuses , _ := snapshotStatusMap .Get (nt )
830
+ existingStatuses = append (existingStatuses , tableStatus .Status )
831
+ snapshotStatusMap .Put (nt , existingStatuses )
786
832
}
833
+
787
834
return snapshotRowsMap , snapshotStatusMap , nil
788
835
}
789
836
790
- func getImportedSnapshotRowsMap (dbType string , tableList []string ) (map [ string ] int64 , error ) {
837
+ func getImportedSnapshotRowsMap (dbType string , tableList []sqlname. NameTuple ) (* utils. StructMap [sqlname. NameTuple , int64 ] , error ) {
791
838
switch dbType {
792
839
case "target" :
793
840
importerRole = TARGET_DB_IMPORTER_ROLE
@@ -802,45 +849,23 @@ func getImportedSnapshotRowsMap(dbType string, tableList []string) (map[string]i
802
849
snapshotDataFileDescriptor = datafile .OpenDescriptor (exportDir )
803
850
}
804
851
805
- msr , err := metaDB .GetMigrationStatusRecord ()
806
- if err != nil {
807
- return nil , fmt .Errorf ("get migration status record: %w" , err )
808
- }
809
- sourceSchemaCount := len (strings .Split (msr .SourceDBConf .Schema , "|" ))
810
-
811
- snapshotRowsMap := make (map [string ]int64 )
812
- for _ , table := range tableList {
813
- parts := strings .Split (table , "." )
814
- schemaName := ""
815
- tableName := parts [0 ]
816
- if len (parts ) > 1 {
817
- schemaName = parts [0 ]
818
- tableName = parts [1 ]
819
- }
820
- if sourceSchemaCount <= 1 && source .DBType != POSTGRESQL { //this check is for Oracle case
821
- schemaName = ""
822
- }
823
- if schemaName == "public" || schemaName == "" {
824
- table = tableName
825
- }
826
- //Now multiple files can be there for a table in case of partitions
827
- dataFiles := snapshotDataFileDescriptor .GetDataFileEntriesByTableName (table )
828
- if len (dataFiles ) == 0 {
829
- dataFile := & datafile.FileEntry {
830
- FilePath : "" ,
831
- TableName : table ,
832
- RowCount : 0 ,
833
- FileSize : 0 ,
834
- }
835
- dataFiles = append (dataFiles , dataFile )
852
+ snapshotRowsMap := utils .NewStructMap [sqlname.NameTuple , int64 ]()
853
+ dataFilePathNtMap := map [string ]sqlname.NameTuple {}
854
+ for _ , fileEntry := range snapshotDataFileDescriptor .DataFileList {
855
+ nt , err := namereg .NameReg .LookupTableName (fileEntry .TableName )
856
+ if err != nil {
857
+ return nil , fmt .Errorf ("lookup table name from data file descriptor %s : %v" , fileEntry .TableName , err )
836
858
}
837
- for _ , dataFile := range dataFiles {
838
- snapshotRowCount , err := state .GetImportedRowCount (dataFile .FilePath , dataFile .TableName )
839
- if err != nil {
840
- return nil , fmt .Errorf ("could not fetch snapshot row count for table %q: %w" , table , err )
841
- }
842
- snapshotRowsMap [table ] += snapshotRowCount
859
+ dataFilePathNtMap [fileEntry .FilePath ] = nt
860
+ }
861
+
862
+ for dataFilePath , nt := range dataFilePathNtMap {
863
+ snapshotRowCount , err := state .GetImportedRowCount (dataFilePath , nt )
864
+ if err != nil {
865
+ return nil , fmt .Errorf ("could not fetch snapshot row count for table %q: %w" , nt , err )
843
866
}
867
+ existingRows , _ := snapshotRowsMap .Get (nt )
868
+ snapshotRowsMap .Put (nt , existingRows + snapshotRowCount )
844
869
}
845
870
return snapshotRowsMap , nil
846
871
}
0 commit comments