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 test failure: test_table_migration_job_refreshes_migration_status[regular-migrate-tables] #2625

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 7 additions & 10 deletions src/databricks/labs/ucx/hive_metastore/table_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,16 @@ def __init__(
self._migrate_grants = migrate_grants

def get_remaining_tables(self) -> list[Table]:
self.index_full_refresh()
self.index(force_refresh=True)
table_rows = []
for crawled_table in self._tc.snapshot():
if not self._is_migrated(crawled_table.database, crawled_table.name):
table_rows.append(crawled_table)
logger.warning(f"remained-hive-metastore-table: {crawled_table.key}")
return table_rows

def index(self):
return self._migration_status_refresher.index()

def index_full_refresh(self):
# when we want the latest up-to-date status, e.g. to determine whether views dependencies have been migrated
self._migration_status_refresher.reset()
return self._migration_status_refresher.index()
def index(self, *, force_refresh: bool = False):
return self._migration_status_refresher.index(force_refresh=force_refresh)

def migrate_tables(
self,
Expand Down Expand Up @@ -101,15 +96,17 @@ def _migrate_tables(self, what: What, mounts: list[Mount], hiveserde_in_place_mi
def _migrate_views(self):
tables_to_migrate = self._tm.get_tables_to_migrate(self._tc)
all_tasks = []
sequencer = ViewsMigrationSequencer(tables_to_migrate, migration_index=self.index_full_refresh())
# Every batch of views to migrate needs an up-to-date table migration index
# to determine if the dependencies have been migrated
sequencer = ViewsMigrationSequencer(tables_to_migrate, migration_index=self.index(force_refresh=True))
batches = sequencer.sequence_batches()
for batch in batches:
tasks = []
for view in batch:
tasks.append(partial(self._migrate_view, view))
Threads.strict("migrate views", tasks)
all_tasks.extend(tasks)
self.index_full_refresh()
self.index(force_refresh=True)
return all_tasks

def _migrate_table(self, src_table: TableToMigrate, mounts: list[Mount], hiveserde_in_place_migrate: bool = False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def __init__(self, ws: WorkspaceClient, sbe: SqlBackend, schema, table_crawler:
self._ws = ws
self._table_crawler = table_crawler

def index(self) -> TableMigrationIndex:
return TableMigrationIndex(list(self.snapshot()))
def index(self, *, force_refresh: bool = False) -> TableMigrationIndex:
return TableMigrationIndex(list(self.snapshot(force_refresh=force_refresh)))
JCZuurmond marked this conversation as resolved.
Show resolved Hide resolved

def get_seen_tables(self) -> dict[str, str]:
seen_tables: dict[str, str] = {}
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/hive_metastore/test_workflows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from databricks.labs.ucx.hive_metastore.workflows import (
TableMigration,
MigrateExternalTablesCTAS,
Expand Down Expand Up @@ -63,8 +64,8 @@ def test_migrate_ctas_views(run_workflow):
MigrateTablesInMounts,
],
)
def test_update_migration_status(run_workflow, workflow):
def test_update_migration_status(run_workflow, workflow) -> None:
"""Migration status is refreshed by deleting and showing new tables"""
ctx = run_workflow(getattr(workflow, "update_migration_status"))
assert "TRUNCATE TABLE `hive_metastore`.`ucx`.`migration_status`" in ctx.sql_backend.queries
assert ctx.sql_backend.has_rows_written_for("hive_metastore.ucx.migration_status")
assert "SHOW DATABASES" in ctx.sql_backend.queries