Skip to content

Commit

Permalink
improve on_request_error for read errors
Browse files Browse the repository at this point in the history
  • Loading branch information
soad003 committed Dec 20, 2023
1 parent d0593cd commit f7694b9
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/graphsenselib/db/cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,32 @@ def __init__(self, max_retries=5):

def on_read_timeout(self, *args, **kwargs):
if kwargs["retry_num"] < self.max_retries:
logger.debug(
logger.warning(
"Retrying read after timeout. Attempt #" + str(kwargs["retry_num"])
)
return (self.RETRY, None)
else:
return (self.RETHROW, None)

def on_write_timeout(self, *args, **kwargs):
logger.debug("write timeout; propagate error to application")
logger.warning("write timeout; propagate error to application")
return (self.RETHROW, None)

def on_request_error(self, *args, **kwargs):
logger.debug("Error while executing request; propagate error to application")
def on_request_error(self, query, consistency, error, retry_num):
if (
query.query_string.upper().startswith("SELECT ")
and retry_num < self.max_retries
):
logger.warning(
f"Error while executing request; was read; retry on next host: {error}"
)
return (self.RETRY_NEXT_HOST, None)
else:
logger.warning(
"Error while executing request; "
f"propagate error to application: {error}"
)

return (self.RETHROW, None)

# def on_unavailable(self, *args, **kwargs):
Expand Down

0 comments on commit f7694b9

Please sign in to comment.