You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
automatically retry reads/writes when they fail due to availability #4331
With the new raft code making failovers automatic it is now more likely that an availability problem like a primary going down will correct itself quickly. So rather than sending back an availability error immediately we could retry it one or more times automatically to see if the problem clears itself up. Ultimately there needs to be a timeout, and it would be nice if the user had an option to set this.
One solution would be to add this as an opt-arg to run, for example retry_timeout. It would have a default value (e.g. 2 seconds), and a value of 0 would cause it to work as it does now. It might also make sense to allow Connection objects to have a value for this, as well as the default connection object used through repl.
As a first step, we could implement this only for read queries.
Implementation-wise, I think this would look somewhat like this:
Attempt to run the query
If it fails because of an availability issue, run a wait({waitFor: "ready_for_reads"}) on the unavailable table
3, Go back to step 1 until it succeeds, or the retry timeout is reached
Note that for step 2 we need to extend the unavailability error to include the UUID of the unavailable table. This might also be useful for #5057 .
Ah yeah, I forgot to mention that but we obviously should.
I think using wait instead of just retrying the query might have better efficiency. An expensive query can cause a lot of server load even when it fails.
Consider a query like r.table("largeTable").sum("val"). If all but one shards are available, all available shards are going to run this query on every attempt, which could take minutes in extreme cases.
Activity
danielmewes commentedon Dec 16, 2015
As a first step, we could implement this only for read queries.
Implementation-wise, I think this would look somewhat like this:
wait({waitFor: "ready_for_reads"})on the unavailable table3, Go back to step 1 until it succeeds, or the retry timeout is reached
Note that for step 2 we need to extend the unavailability error to include the UUID of the unavailable table. This might also be useful for #5057 .
mlucy commentedon Dec 16, 2015
We should probably time out the
waittoo so that reads don't hang indefinitely ifready_for_readsnever occurs for whatever reason.(Alternatively, a way simpler implementation would be to just try to read again and again with exponential backoff until the timeout is up.)
danielmewes commentedon Dec 16, 2015
Ah yeah, I forgot to mention that but we obviously should.
I think using
waitinstead of just retrying the query might have better efficiency. An expensive query can cause a lot of server load even when it fails.Consider a query like
r.table("largeTable").sum("val"). If all but one shards are available, all available shards are going to run this query on every attempt, which could take minutes in extreme cases.danielmewes commentedon Dec 16, 2015
(Or I might be wrong and we fail early if we notice that one shard isn't ready. Not quite sure)