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

Restrict live migration to single table-list and added guardrails for that around table-list flags #2354

Merged
merged 31 commits into from
Mar 4, 2025

Conversation

priyanshi-yb
Copy link
Contributor

@priyanshi-yb priyanshi-yb commented Feb 24, 2025

Describe the changes in this pull request

  1. During resumption in the command export data from source we are now using the stored table list in MSR TableListExportedFromSource and SourceExportedTableListWithLeafPartitions based on the source type as for PostgreSQL source we allow filtering the leaf partitions as well so storing them in MSR.
  2. In the command export data from target, we use the stored table list in MSR TableListExportedFromSource to populate the leaf partitions from the target for all the partitioned tables. We then store this information in the TargetExportedTableListWithLeafPartitions for further runs to avoid fetching new leaf partitions from the target.
  3. Added guardrails around the table-list and exclude-table-list flags to check for any discrepancy between these on resumption and the initial lists.
    1. If any new tables are passed via these flags, commands error out saying Unknown tables found.
    2. If any table-list changes are found, commands report them on the console output of the commands, like Missing tables ... / Extra tables found ... than the initial list and command error out saying Re-run with the table-list passed in the initial run
  4. For the case of the partition, if any new leaf tables are added during the migration on the partitioned tables that are getting migrated. On resumption, we will give a prompt to the user that some new leaf partitions are found and will not be considered for the migration if they are fine to continue or else restart the migration

Describe if there are any user-facing changes

Yes, as mentioned above there will be user-facing changes for some guardrails around table-list etc.. now user won't be able to change the table-list during the live migration

Behaviour in these scenarios

  • New table is added on database either source/target -

With or without table-list flags: export data from source/target commands will be unaware of newly added tables and won’t consider it either during the run or re-run.
If a newly added table is passed through the table-list/exclude-table-list - commands error out saying unknown table, valid tables names are […].

➜ yb-voyager export data --export-dir ... --export-type snapshot-and-changes  --table-list test_partitions_quences                           
...
Continuing streaming from where we left off...
Unknown table names [test_partitions_quences] in the include list
Valid table names are: [public.foo_bar public.sales_region public.test_seq1 public.try public.sequence_check1 public.london public.sydney public.boston public.test_partitions_sequences_b public.test_partitions_sequences_l public.test_partitions_sequences_s public.sequence_check2 public.se..]
  • New leaf table is added on partitioned table in database either source/target -

With or without table-list flags:
-- During the run, export data from source/target commands will be unaware of newly added leaf tables and won’t consider it.
-- On re-run, export data from source/target commands will report to the user that new leaf tables are detected for partitioned tables with below msg -

Detected new partition tables for the following partitioned tables. These will not be considered during migration:
Root table: public.test_partitions_sequences, new leaf partitions: public.test_partitions_sequences_h
Do you want to continue?? [Y/N]: Y
num tables to export: 1
table list for data export: [test_partitions_sequences (test_partitions_sequences_s)]

If a new leaf partition table is passed through the table-list/exclude-table-list flags - commands error out saying unknown table; valid tables names are […].

➜  yb-voyager export data --export-dir .... --export-type snapshot-and-changes  --table-list test_partitions_sequences_h
....
Continuing streaming from where we left off...
Unknown table names [test_partitions_sequences_h] in the include list
Valid table names are: [public.foo_bar public.sales_region public.test_seq1 public.try public.sequence_check1 public.london public.sydney public.boston public.test_partitions_sequences_b public.test_partitions_sequences_l public.test_partitions_sequences_s public.sequence_check2 publi.....]
  • Table-list changes during resumption via flags

In case some tables are removed from the initial list in resumption - commands will report that there is discrepancy found and error out as mentioned below

  TARGET_DB_PASSWORD=*** yb-voyager export data from target --export-dir ... --table-list public."accounts_list_partitioned",public."empty_partition_table2",public."orders_interval_partition" --exclude-table-list empty_partition_table2
migrationID: 822cd9e3-00bc-4c7f-8d8c-195cdd3e24b7
Note: Live migration is a TECH PREVIEW feature.
export of data for source type as 'yugabytedb'
Continuing streaming from where we left off...
Changing the table list during live-migration is not allowed.
Missing tables in the current run compared to the initial list: empty_partition_table2_p_west,empty_partition_table2_p_east
Table list passed in the initial run of migration - [public.accounts_list_partitioned_p_northwest .... public.orders_interval_partition_interval_partition_less_than_2018 public.orders_interval_partition]. 
Re-run the command with the table list passed in the initial run of migration.

In case some tables are added from the initial list in resumption - commands will report that there is discrepancy found and error out as mentioned below

 TARGET_DB_PASSWORD=*** yb-voyager export data from target --export-dir /home/centos/code/yb-voyager/migtests/tests/oracle/partitions/oracle_partitions_fallb_export-dir --table-list public."accounts_list_partitioned",public."empty_partition_table2",public."orders_interval_partition",empty_partition_table ...
migrationID: 822cd9e3-00bc-4c7f-8d8c-195cdd3e24b7
Note: Live migration is a TECH PREVIEW feature.
export of data for source type as 'yugabytedb'
Continuing streaming from where we left off...
Changing the table list during live-migration is not allowed.
Extra tables in the current run compared to the initial list: empty_partition_table2_p_extra,empty_partition_table_p_west,empty_partition_table_p_east,empty_partition_table
Table list passed in the initial run of migration - [public.accounts_list_partitioned_p_northwest .... public.orders_interval_partition]. 
Re-run the command with the table list passed in the initial run of migration.

How was this pull request tested?

Added unit tests with test container PG source for various cases.

  1. Validating the table-list in the first-run
  2. validating guardrails check prompts in subsequent runs
  3. validating new leaf additions
  4. validating unknown table case in table-list via error exit (any dummy table name or new table added on source)

Does your PR have changes that can cause upgrade issues?

Component Breaking changes?
MetaDB No
Name registry json No
Data File Descriptor Json No
Export Snapshot Status Json No
Import Data State No
Export Status Json No
Data .sql files of tables No
Export and import data queue No
Schema Dump No
AssessmentDB No
Sizing DB o
Migration Assessment Report Json No
Callhome Json No
YugabyteD Tables No
TargetDB Metadata Tables No

@priyanshi-yb priyanshi-yb changed the title Restrict live migration to single table-list from export data from source and guardrail for that around table-list flags Restrict live migration to single table-list and guardrail for that around table-list flags Feb 24, 2025
@priyanshi-yb priyanshi-yb force-pushed the priyanshi/name-reg-table-name branch from 850a85b to ce05787 Compare February 24, 2025 13:03
@priyanshi-yb priyanshi-yb force-pushed the priyanshi/name-reg-table-name branch from bf3e4e0 to f09e16f Compare February 24, 2025 16:35
@priyanshi-yb priyanshi-yb marked this pull request as ready for review February 25, 2025 12:26
@priyanshi-yb priyanshi-yb changed the title Restrict live migration to single table-list and guardrail for that around table-list flags Restrict live migration to single table-list and added guardrails for that around table-list flags Feb 25, 2025
}

if len(lo.Keys(newLeafTables)) > 0 {
utils.PrintAndLog("Detected new partition tables for the following partitioned tables. These will not be considered during migration:")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we prompt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if a prompt is required, I think there is nothing we want users to do here right? so this might just FYI?

Copy link
Collaborator

@makalaaneesh makalaaneesh left a comment

Choose a reason for hiding this comment

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

Went over it at a high level, looks good!
Will give it a more detailed look soon along with the tests.


// getInitialTableList for subsequent run with start-clean false and basic without table-list flags so no guardrails
startClean = false
getInitialTableistAndAssertExpectedResult(t, expectedTableList, expectedPartitionsToRootMap)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you added a new partition leaf above. This should error out no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not errorring out in this case just reporting to the user that new leafs found for these root tables and these will not be considered during migration,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ticket for having a guardrail check during the ongoing live migration for new leaf tables #2356

…ls and new leafs addition. Added tests for subsequent run validating the guardrails of missing and extra tables and new leaf tables addition
@priyanshi-yb priyanshi-yb force-pushed the priyanshi/name-reg-table-name branch from 3ed77c3 to b034db2 Compare March 3, 2025 07:05
} else {
tableList = fullTableList
//this is only for filtering the non-leaf and non-root tables - the mid level partitioned table from fullTableList
Copy link
Collaborator

Choose a reason for hiding this comment

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

To remove non-leaf and non-root, you're still calling addLeafPartitionsInTableList? That sounds a bit weird. Does that function ignore all leafs, and then re-add them?

Copy link
Contributor Author

@priyanshi-yb priyanshi-yb Mar 3, 2025

Choose a reason for hiding this comment

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

addLeafPartitionsInTableList has a boolean parameter addAllLeafPartitions in case this is false, that function will consider that the table-list passed is already exhaustive with all the tables (root, middle partition, leaf partitions, so on..) and it will just do the filtering to remove the middle level partitions and just the keep the leaf and root tables in the list.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: write a separate specific function to remove the non-leaf/non-root tables.
Add a TODO if defering.

// Tests the unknown table case by over ridding the utils.ErrExit function to assert the error msg
func testUnknownTableCaseForTableListFlags(t *testing.T, expectedUnknownErrorMsg string) {
previousFunction := utils.ErrExit
//changing the error exit function to test the unknown table scenario
Copy link
Collaborator

Choose a reason for hiding this comment

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

oo, this does not seem like the best way to do it. To be fair, it essentially is just like "mocking" a function, so it's okay, but I think the right way would be:
If we write our functions in a way such that they return a list of guardrail failures, then we can just assert that, instead of having to mocking the errExit function.

Is this too much work given our current state?

Copy link
Contributor Author

@priyanshi-yb priyanshi-yb Mar 3, 2025

Choose a reason for hiding this comment

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

It's not a lot of work. I think it's more of a choice between these ways -

  1. Either we directly display the problem/guardrail and error out
  2. Return as an error and then display it on the console eventually with the whole context.

e.g.

➜ yb-voyager export data ... --export-type snapshot-and-changes --table-list asdfa                                                                              
migrationID: a1194e55-3d95-4d37-95e3-d5221eed976d
....
Unknown table names in the include list: [asdfa]
Valid table names are: [...]


➜   yb-voyager export data ... --export-type snapshot-and-changes --table-list asdfa
migrationID: a1194e55-3d95-4d37-95e3-d5221eed976d
...
error getting initial table list: error applying table list flags for current list and remove roots: error in apply table list filter on registered list for the flags in current run: Unknown table names in the include list: [asdfa]
Valid table names are: [...]

I think the first one is better, where we directly display the problem/guardrails because it's not an actual error per say.
Let me know what do you think?

}

//Filtering the new leaf tables if present in filteredListWithoutRootTable as we have reported above
if isNewLeafTable(t) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why/how would the new leaf appear in currentRunTableListFilteredViaFlags?

Copy link
Contributor Author

@priyanshi-yb priyanshi-yb Mar 3, 2025

Choose a reason for hiding this comment

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

While applying include/exclude flags, we also add leaf partitions in case only the root is passed in flags.The addLeafPartitions function goes to db for that case

Copy link
Collaborator

@makalaaneesh makalaaneesh left a comment

Choose a reason for hiding this comment

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

LGTM! pls update the PR description to reflect error vs prompt and if any other changes

@priyanshi-yb priyanshi-yb merged commit 7e0bfa4 into main Mar 4, 2025
66 checks passed
@priyanshi-yb priyanshi-yb deleted the priyanshi/name-reg-table-name branch March 4, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants