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

Add auto retry mechanism on connection failure #133

Merged
merged 8 commits into from Aug 17, 2014
Merged

Add auto retry mechanism on connection failure #133

merged 8 commits into from Aug 17, 2014

Conversation

alakra
Copy link
Contributor

@alakra alakra commented Jul 15, 2014

In development, I am often restarting my cassandra clusters and find that the cequel gem would not handle reconnecting gracefully without a manual reconnection.

This pull request provides a retry mechanism to auto-reconnect to cassandra a number of times specified by a max-retries config parameter that defaults to 10. It does this by clearing out the disconnected raw_client instance in Cequel::Metal::Keyspace when it detects a connection error.

Thanks ahead of time for looking at this and feedback is appreciated.

Angelo Lakra added 3 commits July 15, 2014 07:18
  NOTE: This will retry 10x before giving up.

  Credit to @pezra also for pairing.
…um retries that will be made to reconnect to cassandra

  * Added spec stubs
  * Modified template for config file (added max-retries)
@pezra
Copy link
Contributor

pezra commented Jul 29, 2014

@outoftime, any chance we could get some feed back on this? It looks good to me but then i helped write it. 😄

@@ -269,6 +288,10 @@ def extract_hosts_and_port(configuration)
def extract_credentials(configuration)
configuration.slice(:username, :password).presence
end

def extract_max_retries(configuration)
configuration[:"max-retries"] || 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like 10 is a pretty big default, no? I would actually say let's have no retries by default, or if it makes sense to have a non-zero default, something in the ballpark of 2 or 3 seems better…

Also configuration.fetch(:"max-retries", 10) would be a bit better I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll make that change.

@outoftime
Copy link
Member

Implementation looks good in general, thanks for this! I left a couple of comments on specifics…

@alakra
Copy link
Contributor Author

alakra commented Jul 30, 2014

@outoftime I updated the max-retries default to 3 and I believe I've made the spec a bit clearer. Let me know what you think. Thanks!

@pezra
Copy link
Contributor

pezra commented Aug 15, 2014

@outoftime, thoughts?

@@ -98,6 +100,8 @@ def initialize(configuration={})
# single Cassandra instance to connect to
# @option configuration [Integer] :port (9042) port on which to connect
# to all specified hosts
# @option configuration [Integer] :max-retries maximum number of retries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean :max_retries not :max-retries

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I guess you do mean :max-retries but :max_retries seems more idiomatic no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters—I can do either it either way. If you feel strongly about it, I have no problem changing it to an underscore.

…ctions!` instead of directly accessing ivar
@alakra
Copy link
Contributor Author

alakra commented Aug 16, 2014

@outoftime Thanks for you feedback. @pezra and I are eager to see this in the main branch and hopefully in a release soon. Do you feel like our work is sufficient for the code base?

@@ -269,6 +288,10 @@ def extract_hosts_and_port(configuration)
def extract_credentials(configuration)
configuration.slice(:username, :password).presence
end

def extract_max_retries(configuration)
configuration.fetch(:"max_retries", 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need the quotation marks around the symbol

@outoftime
Copy link
Member

Couple of tinnnny style comments inline. Knock those out and I'd be happy to merge. I am traveling without a laptop until the middle next week so won't be able to do a gem release until then.

outoftime added a commit that referenced this pull request Aug 17, 2014
…ction_failure

Add auto retry mechanism on connection failure
@outoftime outoftime merged commit 1515149 into cequel:master Aug 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants