-
Notifications
You must be signed in to change notification settings - Fork 23
Reset failed state #5175
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
base: master
Are you sure you want to change the base?
Reset failed state #5175
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -792,64 +792,75 @@ def invalidate_db_cache(self, name=None, schema=None, cascade=True, drop=True): | |
log("Resetting state machine.") | ||
current_state, this_thread_is_owner = q_state_machine.reset() | ||
if this_thread_is_owner: | ||
log("Reset state machine.") | ||
con = get_db().engine | ||
try: | ||
log("Getting table reference.") | ||
table_reference_to_this_query = self.get_table() | ||
if table_reference_to_this_query is not self: | ||
log("Invalidating table reference cache.") | ||
table_reference_to_this_query.invalidate_db_cache( | ||
cascade=cascade, drop=drop | ||
) # Remove any Table pointing as this query | ||
except (ValueError, NotImplementedError) as e: | ||
log("Query not stored - no table..") | ||
pass # This cache record isn't actually stored | ||
try: | ||
log = partial(log, table_name=self.fully_qualified_table_name) | ||
except NotImplementedError: | ||
pass # Not a storable by default table | ||
try: | ||
dep_ids = [ | ||
rec[0] | ||
for rec in get_db().fetch( | ||
f"SELECT query_id FROM cache.dependencies WHERE depends_on='{self.query_id}'" | ||
) | ||
] | ||
with con.begin(): | ||
con.execute( | ||
"DELETE FROM cache.cached WHERE query_id=%s", (self.query_id,) | ||
) | ||
log("Deleted cache record.") | ||
if drop: | ||
con.execute( | ||
"DROP TABLE IF EXISTS {}".format( | ||
self.fully_qualified_table_name | ||
) | ||
log("Reset state machine.") | ||
con = get_db().engine | ||
try: | ||
log("Getting table reference.") | ||
table_reference_to_this_query = self.get_table() | ||
if table_reference_to_this_query is not self: | ||
log("Invalidating table reference cache.") | ||
table_reference_to_this_query.invalidate_db_cache( | ||
cascade=cascade, drop=drop | ||
) # Remove any Table pointing as this query | ||
except (ValueError, NotImplementedError) as e: | ||
log("Query not stored - no table..") | ||
pass # This cache record isn't actually stored | ||
try: | ||
log = partial(log, table_name=self.fully_qualified_table_name) | ||
except NotImplementedError: | ||
pass # Not a storable by default table | ||
try: | ||
dep_ids = [ | ||
rec[0] | ||
for rec in get_db().fetch( | ||
f"SELECT query_id FROM cache.dependencies WHERE depends_on='{self.query_id}'" | ||
) | ||
log("Dropped cache table.") | ||
|
||
if cascade: | ||
for dep_id in dep_ids: | ||
dep = get_obj_or_stub(get_db(), dep_id) | ||
log( | ||
"Cascading to dependent.", | ||
dependency=dep.fully_qualified_table_name, | ||
] | ||
with con.begin(): | ||
con.execute( | ||
"DELETE FROM cache.cached WHERE query_id=%s", | ||
(self.query_id,), | ||
) | ||
dep.invalidate_db_cache() | ||
log("Deleted cache record.") | ||
if drop: | ||
con.execute( | ||
"DROP TABLE IF EXISTS {}".format( | ||
self.fully_qualified_table_name | ||
) | ||
) | ||
log("Dropped cache table.") | ||
|
||
if cascade: | ||
for dep_id in dep_ids: | ||
dep = get_obj_or_stub(get_db(), dep_id) | ||
log( | ||
"Cascading to dependent.", | ||
dependency=dep.fully_qualified_table_name, | ||
) | ||
dep.invalidate_db_cache() | ||
else: | ||
log("Not cascading to dependents.") | ||
except NotImplementedError: | ||
logger.info("Table has no standard name.") | ||
# Outside of cache schema table | ||
if schema is not None: | ||
full_name = "{}.{}".format(schema, name) | ||
log("Dropping table outside cache schema.", table_name=full_name) | ||
else: | ||
log("Not cascading to dependents.") | ||
except NotImplementedError: | ||
logger.info("Table has no standard name.") | ||
# Outside of cache schema table | ||
if schema is not None: | ||
full_name = "{}.{}".format(schema, name) | ||
else: | ||
full_name = name | ||
log("Dropping table outside cache schema.", table_name=full_name) | ||
with con.begin(): | ||
con.execute("DROP TABLE IF EXISTS {}".format(full_name)) | ||
q_state_machine.finish_resetting() | ||
full_name = name | ||
with con.begin(): | ||
con.execute("DROP TABLE IF EXISTS {}".format(full_name)) | ||
q_state_machine.finish_resetting() | ||
except Exception as exc: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be a |
||
logger.error( | ||
"Query reset failed.", | ||
query_id=self.query_id, | ||
action="invalidate_db_cache", | ||
exception=exc, | ||
) | ||
q_state_machine.raise_error() | ||
raise exc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a potential for hang here, if a query can reset from elsewhere? This thread throws Exception, some cache service sees it and tries again, this thrown Exception, ect.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, something to be wary of - should have enough information to avoid that because we arrive in an explicit reset failed state. |
||
elif q_state_machine.is_resetting: | ||
log("Query is being reset from elsewhere, waiting for reset to finish.") | ||
while q_state_machine.is_resetting: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a log here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No harm in it for sure