Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: retrieving Migration UUID as early as possible in the commands #2162

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions yb-voyager/cmd/analyzeSchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,10 +1126,6 @@ func checkConversions(sqlInfoArr []sqlInfo, filePath string) {
}

func analyzeSchema() {
err := retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}

utils.PrintAndLog("Analyzing schema for target YugabyteDB version %s\n", targetDbVersion)
schemaAnalysisStartedEvent := createSchemaAnalysisStartedEvent()
Expand Down Expand Up @@ -1290,9 +1286,13 @@ var analyzeSchemaCmd = &cobra.Command{
"For more details and examples, visit https://docs.yugabyte.com/preview/yugabyte-voyager/reference/schema-migration/analyze-schema/",
Long: ``,
PreRun: func(cmd *cobra.Command, args []string) {
err := retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
validOutputFormats := []string{"html", "json", "txt", "xml"}
validateReportOutputFormat(validOutputFormats, analyzeSchemaReportFormat)
err := validateAndSetTargetDbVersionFlag()
err = validateAndSetTargetDbVersionFlag()
if err != nil {
utils.ErrExit("%v", err)
}
Expand Down
11 changes: 5 additions & 6 deletions yb-voyager/cmd/assessMigrationBulkCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ var assessMigrationBulkCmd = &cobra.Command{
Long: "Bulk Assessment of multiple schemas across one or more Oracle database instances",

PreRun: func(cmd *cobra.Command, args []string) {
err := validateFleetConfigFile(fleetConfigPath)
err := retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
err = validateFleetConfigFile(fleetConfigPath)
if err != nil {
utils.ErrExit("%s", err.Error())
}
Expand Down Expand Up @@ -156,11 +160,6 @@ func assessMigrationBulk() error {
return fmt.Errorf("failed to parse fleet config file: %w", err)
}

err = retrieveMigrationUUID()
if err != nil {
return fmt.Errorf("failed to get migration UUID: %w", err)
}

for _, dbConfig := range bulkAssessmentDBConfigs {
utils.PrintAndLog("\nAssessing '%s' schema", dbConfig.GetSchemaIdentifier())

Expand Down
14 changes: 6 additions & 8 deletions yb-voyager/cmd/assessMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,18 @@ var assessMigrationCmd = &cobra.Command{
Long: fmt.Sprintf("Assess the migration from source (%s) database to YugabyteDB.", strings.Join(assessMigrationSupportedDBTypes, ", ")),

PreRun: func(cmd *cobra.Command, args []string) {
CreateMigrationProjectIfNotExists(source.DBType, exportDir)
err := retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
validateSourceDBTypeForAssessMigration()
setExportFlagsDefaults()
validateSourceSchema()
validatePortRange()
validateSSLMode()
validateOracleParams()
err := validateAndSetTargetDbVersionFlag()
err = validateAndSetTargetDbVersionFlag()
if err != nil {
utils.ErrExit("%v", err)
}
Expand Down Expand Up @@ -319,13 +324,6 @@ func assessMigration() (err error) {
schemaDir = filepath.Join(assessmentMetadataDir, "schema")

checkStartCleanForAssessMigration(assessmentMetadataDirFlag != "")
CreateMigrationProjectIfNotExists(source.DBType, exportDir)

err = retrieveMigrationUUID()
if err != nil {
return fmt.Errorf("failed to get migration UUID: %w", err)
}

utils.PrintAndLog("Assessing for migration to target YugabyteDB version %s\n", targetDbVersion)

assessmentDir := filepath.Join(exportDir, "assessment")
Expand Down
14 changes: 9 additions & 5 deletions yb-voyager/cmd/endMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ var endMigrationCmd = &cobra.Command{
Long: "End the current migration and cleanup all metadata stored in databases(Target, Source-Replica and Source) and export-dir",

PreRun: func(cmd *cobra.Command, args []string) {
err := validateEndMigrationFlags(cmd)
if utils.IsDirectoryEmpty(exportDir) {
utils.ErrExit("export directory is empty, nothing to end")
}

err := retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
err = validateEndMigrationFlags(cmd)
if err != nil {
utils.ErrExit(err.Error())
}

if utils.IsDirectoryEmpty(exportDir) {
utils.ErrExit("export directory is empty, nothing to end")
}
},

Run: endMigrationCommandFn,
Expand All @@ -76,7 +81,6 @@ func endMigrationCommandFn(cmd *cobra.Command, args []string) {
utils.ErrExit("error while checking streaming mode: %w\n", err)
}

retrieveMigrationUUID()
checkIfEndCommandCanBePerformed(msr)

// backing up the state from the export directory
Expand Down
11 changes: 5 additions & 6 deletions yb-voyager/cmd/importData.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ var importDataCmd = &cobra.Command{
importerRole = TARGET_DB_IMPORTER_ROLE
}
sourceDBType = GetSourceDBTypeFromMSR()
err := validateImportFlags(cmd, importerRole)
err := retrieveMigrationUUID()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this above GetSourceDBTypeFromMSR ? that also ErrExits.

if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
err = validateImportFlags(cmd, importerRole)
if err != nil {
utils.ErrExit("Error: %s", err.Error())
}
Expand Down Expand Up @@ -132,11 +136,6 @@ func importDataCommandFn(cmd *cobra.Command, args []string) {
utils.ErrExit("Failed to get migration status record: %s", err)
}

err = retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}

// Check if target DB has the required permissions
if tconf.RunGuardrailsChecks {
checkImportDataPermissions()
Expand Down
11 changes: 5 additions & 6 deletions yb-voyager/cmd/importDataFileCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ var importDataFileCmd = &cobra.Command{
sourceDBType = POSTGRESQL // dummy value - this command is not affected by it
sqlname.SourceDBType = sourceDBType
CreateMigrationProjectIfNotExists(sourceDBType, exportDir)

err := retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
tconf.Schema = strings.ToLower(tconf.Schema)
tdb = tgtdb.NewTargetDB(&tconf)
err := tdb.Init()
err = tdb.Init()
if err != nil {
utils.ErrExit("Failed to initialize the target DB: %s", err)
}
Expand All @@ -91,10 +94,6 @@ var importDataFileCmd = &cobra.Command{
dataStore = datastore.NewDataStore(dataDir)
importFileTasks := prepareImportFileTasks()
prepareForImportDataCmd(importFileTasks)
err := retrieveMigrationUUID()
if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
importData(importFileTasks)
packAndSendImportDataFilePayload(COMPLETE)

Expand Down
12 changes: 6 additions & 6 deletions yb-voyager/cmd/importSchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ var importSchemaCmd = &cobra.Command{
if tconf.TargetDBType == "" {
tconf.TargetDBType = YUGABYTEDB
}
err := retrieveMigrationUUID()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be slightly unrelated question, but at this point what if export-dir is empty and user runs import-schema? What happens then?
Same question for import-data, analyze-schema as well..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of empty dirs and these commands we already have other checks just before this that checks if export-dir is initiated. And we can't do much in those cases we will still get the 00000... uuid in callhome

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, but i guess now we will get the error message, so that should be helpful.

if err != nil {
utils.ErrExit("failed to get migration UUID: %w", err)
}
sourceDBType = GetSourceDBTypeFromMSR()
err := validateImportFlags(cmd, TARGET_DB_IMPORTER_ROLE)
err = validateImportFlags(cmd, TARGET_DB_IMPORTER_ROLE)
if err != nil {
utils.ErrExit("Error: %s", err.Error())
}
Expand Down Expand Up @@ -79,10 +83,6 @@ var flagRefreshMViews utils.BoolStr
var invalidTargetIndexesCache map[string]bool

func importSchema() error {
err := retrieveMigrationUUID()
if err != nil {
return fmt.Errorf("failed to get migration UUID: %w", err)
}

tconf.Schema = strings.ToLower(tconf.Schema)

Expand All @@ -93,7 +93,7 @@ func importSchema() error {
// available always and this is just for initialisation of tdb and marking it nil again back.
tconf.Schema = "public"
tdb = tgtdb.NewTargetDB(&tconf)
err = tdb.Init()
err := tdb.Init()
if err != nil {
utils.ErrExit("Failed to initialize the target DB: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion yb-voyager/src/callhome/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CREATE TABLE diagnostics (
migration_type TEXT,
time_taken_sec int,
status TEXT,
host_ip character varying 255 -- set by the callhome service
host_ip character varying (255), -- set in callhome service
PRIMARY KEY (migration_uuid, migration_phase, collected_at)

);
Expand Down