-
Notifications
You must be signed in to change notification settings - Fork 84
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
Catch Redis server errors #1119
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3ddee4f
Catch Redis server errors
mrunge 5353276
Move redis to install dependencies
mrunge 841287a
decorate function and skip other exception
mrunge c27ba76
Remove left over variables in excepts
mrunge 79e2363
Move all exception handling to incoming/redis
mrunge e507e41
Remove empty line added in previous commit
mrunge 7677b1c
Remove s3 and try to enable ceph again
mrunge 8fc147f
Catch exception in another place
mrunge df18070
Turn back testing to s3 and address review feedback
mrunge d6fb9e8
Drop debug output
mrunge c2e6fd0
Add stop condition and fix comment
mrunge 08a1974
Merge branch 'master' into redis_reconnect
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,13 @@ | |
import uuid | ||
|
||
import daiquiri | ||
from redis.exceptions import ConnectionError | ||
import six | ||
import tenacity | ||
|
||
from gnocchi.common import redis | ||
from gnocchi import incoming | ||
from gnocchi import utils | ||
|
||
|
||
LOG = daiquiri.getLogger(__name__) | ||
|
@@ -93,6 +96,10 @@ def add_measures_batch(self, metrics_and_measures): | |
notified_sacks.add(sack_name) | ||
pipe.execute() | ||
|
||
@tenacity.retry( | ||
wait=utils.wait_exponential, | ||
# Never retry except when explicitly asked by raising TryAgain | ||
retry=tenacity.retry_if_exception_type(ConnectionError)) | ||
def _build_report(self, details): | ||
report_vars = {'measures': 0, 'metric_details': {}} | ||
|
||
|
@@ -106,20 +113,23 @@ def update_report(results, m_list): | |
metrics = 0 | ||
m_list = [] | ||
pipe = self._client.pipeline() | ||
for key in self._client.scan_iter(match=match, count=1000): | ||
metrics += 1 | ||
pipe.llen(key) | ||
if details: | ||
m_list.append(key.split(redis.SEP)[1].decode("utf8")) | ||
# group 100 commands/call | ||
if metrics % 100 == 0: | ||
try: | ||
for key in self._client.scan_iter(match=match, count=1000): | ||
metrics += 1 | ||
pipe.llen(key) | ||
if details: | ||
m_list.append(key.split(redis.SEP)[1].decode("utf8")) | ||
# group 100 commands/call | ||
if metrics % 100 == 0: | ||
results = pipe.execute() | ||
update_report(results, m_list) | ||
m_list = [] | ||
pipe = self._client.pipeline() | ||
else: | ||
results = pipe.execute() | ||
update_report(results, m_list) | ||
m_list = [] | ||
pipe = self._client.pipeline() | ||
else: | ||
results = pipe.execute() | ||
update_report(results, m_list) | ||
except ConnectionError: | ||
LOG.debug("Redis Server closed connection. Retrying.") | ||
return (metrics, report_vars['measures'], | ||
report_vars['metric_details'] if details else None) | ||
|
||
|
@@ -176,18 +186,25 @@ def process_measures_for_sack(self, sack): | |
pipe.ltrim(key, item_len + 1, -1) | ||
pipe.execute() | ||
|
||
@tenacity.retry( | ||
wait=utils.wait_exponential, | ||
# Never retry except when explicitly asked by raising TryAgain | ||
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. wrong comment |
||
retry=tenacity.retry_if_exception_type(ConnectionError)) | ||
jd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def iter_on_sacks_to_process(self): | ||
self._client.config_set("notify-keyspace-events", "K$") | ||
p = self._client.pubsub() | ||
db = self._client.connection_pool.connection_kwargs['db'] | ||
keyspace = b"__keyspace@" + str(db).encode() + b"__:" | ||
pattern = keyspace + self._get_sack_name("*").encode() | ||
p.psubscribe(pattern) | ||
for message in p.listen(): | ||
if message['type'] == 'pmessage' and message['pattern'] == pattern: | ||
# FIXME(jd) This is awful, we need a better way to extract this | ||
# Format is defined by _get_sack_name: incoming128-17 | ||
yield self._make_sack(int(message['channel'].split(b"-")[-1])) | ||
try: | ||
for message in p.listen(): | ||
if message['type'] == 'pmessage' and message['pattern'] == pattern: | ||
# FIXME(jd) This is awful, we need a better way to extract this | ||
# Format is defined by _get_sack_name: incoming128-17 | ||
yield self._make_sack(int(message['channel'].split(b"-")[-1])) | ||
except ConnectionError: | ||
LOG.debug("Redis Server closed connection. Retrying.") | ||
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. ditto |
||
|
||
def finish_sack_processing(self, sack): | ||
# Delete the sack key which handles no data but is used to get a SET | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you don't need this anymore (the try/except)