2

Every time I try to get query using the cassandra python driver, I will receive such an exception:

**File "something.py", line 32, in <module>
    rows = session.execute('some query execution', timeout=None)
  File "C:\Anaconda2\lib\site-packages\cassandra\cluster.py", line 2141, in execute
    return self.execute_async(query, parameters, trace, custom_payload, timeout, execution_profile, paging_state).result()
  File "C:\Anaconda2\lib\site-packages\cassandra\cluster.py", line 4033, in result
    raise self._final_exception
cassandra.ReadTimeout: Error from server: code=1200 [Coordinator node timed out waiting for replica nodes' responses] message="Operation timed out - received only 0 responses." info={'received_responses': 0, 'required_responses': 1, 'consistency': 'LOCAL_ONE'}**

To avoid this exception, I have already tried to set the default timeout to none, like:

cluster.default_timeout = None
session.default_timeout = None
session.execute('some query execution', timeout=None)

However, they never really change the Readtimeout period.

One thing to notice is that this query command doesn't take too long of a time when I execute it in Squrriel, about 1.5 seconds.

Does anyone know how to solve this problem? Thank you!

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
Andy Chang
  • 55
  • 6

1 Answers1

-1

The key message here is Coordinator node timed out waiting for replica nodes' responses - this means that timeout happens inside Cassandra itself. In your case, request doesn't go directly to the node that owns the data, but to one of the nodes that acts as Coordinator, and this node then re-sends request to the node that owns the data, and doesn't get answer from it during allocated time.

I don't remember precisely, but Python driver should use so-called TokenAware load balancing policy that will make driver to send requests directly to nodes that own the data - you need to check that you use this policy.

Also, you need to check logs on the Cassandra nodes to find why they are timeout, and if necessary, tune timeouts on these nodes.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • Thanks! Let me try it out and see. – Andy Chang Jun 01 '18 at 15:15
  • Do you know which child policy I should use? – Andy Chang Jun 01 '18 at 15:33
  • You just need to use default policy - don't change anything, then it will use `TokenAware`: https://github.com/datastax/python-driver/blob/master/cassandra/cluster.py#L187 – Alex Ott Jun 01 '18 at 16:43
  • Thank you but I think it's the problem of my database. It times out pretty frequently and needs to be improved. – Andy Chang Jun 01 '18 at 18:23
  • Could be that as well - if you have very large partitions, then it could be a cause for timeouts... – Alex Ott Jun 01 '18 at 18:25
  • I get the same error querying `system.compaction_history`, even though I confirmed the `load_balancing_policy` to be the default `cassandra.policies.TokenAwarePolicy`. – snooze92 Nov 29 '21 at 10:37
  • Load balancing policy is just one factor - see explanation - it could be big partitions, overloaded nodes, etc. – Alex Ott Nov 29 '21 at 11:16