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: Metastore sync tables with a single transaction #1482

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
12 changes: 9 additions & 3 deletions querybook/server/lib/metastore/base_metastore_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ def _create_table_table(
)

delete_column_not_in_metastore(
table_id, set(map(lambda c: c.name, columns)), session=session
table_id,
set(map(lambda c: c.name, columns)),
commit=False,
session=session,
)

for column in columns:
Expand Down Expand Up @@ -630,11 +633,14 @@ def delete_table_not_in_metastore(schema_id, table_names, session=None):


@with_session
def delete_column_not_in_metastore(table_id, column_names, session=None):
def delete_column_not_in_metastore(table_id, column_names, commit=True, session=None):
db_columns = get_column_by_table_id(table_id, session=session)

for column in db_columns:
if column.name not in column_names:
delete_column(id=column.id, commit=False, session=session)
LOG.info("deleted column %d" % column.id)
session.commit()
if commit:
session.commit()
else:
session.flush()
4 changes: 3 additions & 1 deletion querybook/server/logic/metastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ def create_table_warnings(
"message": message,
"severity": severity,
"table_id": table_id,
}
},
commit=False,
session=session,
)
if commit:
session.commit()
Expand Down
6 changes: 4 additions & 2 deletions querybook/server/logic/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ def create_table_tags(

# update or create a new tag if not exist
create_or_update_tag(
tag_name=tag.name, meta=meta, commit=commit, session=session
tag_name=tag.name, meta=meta, commit=False, session=session
)

# add a new tag_item to associate with the table
TagItem.create(
{"tag_name": tag.name, "table_id": table_id, "uid": None},
commit=False,
session=session,
)

Expand Down Expand Up @@ -176,12 +177,13 @@ def create_column_tags(

# update or create a new tag if not exist
create_or_update_tag(
tag_name=tag.name, meta=meta, commit=commit, session=session
tag_name=tag.name, meta=meta, commit=False, session=session
)

# add a new tag_item to associate with the table
TagItem.create(
{"tag_name": tag.name, "column_id": column_id, "uid": None},
commit=False,
session=session,
)

Expand Down
Loading