0

My python application uses twisted, and uses cassandra python driver under the hood. Cassandra python driver can use cassandra.io.twistedreactor.TwistedConnection as a connection class to use twisted as a way to query.

TwistedConnection class uses timer and reactor.callLater to check if a query task has timed out.

The problem is when I use cassandra ORM (cassandra.cqlengine.models.Model) to query.

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model


# ORM for user settings
class UserSettings(Model):
    userid = columns.Text(primary_key=True)
    settings = columns.Text()

# Function registered with autobahn/wamp
def worker():
    userid = "96c5d462-cf7c-11e7-b567-b8e8563d0920"

    def _query():
        # This is a blocking call, internally calling twisted reactor
        # to collect the query result
        setting = model.UserSettings.objects(userid=userid).get()
        return json.loads(setting.settings)

    threads.deferToThread(_query)

When run in twisted.trial unit tests. The test that uses above code always fails with

Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.

DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
<DelayedCall 0x10e0a2dd8 [9.98250699043274s] called=0 cancelled=0 TwistedLoop._on_loop_timer()

In the autobahn worker where this code used, however works fine.

The cassandra driver code for TwistedConnection, keeps on calling callLater, and I could not find a way to find if any of these calls are still pending, as these calls are hidden in the TwistedLoop class.

Questions:

  • Is this correct way of handling cassandra query (which in turn would call twisted reactor)
  • If yes, is there a way to address DelayedCall resulting from cassandra driver timeout (reactor.callLater).
Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Yogesh Sajanikar
  • 1,086
  • 7
  • 19

1 Answers1

0

Just my understanding:

  1. Maybe you will need to call .filter function while filtering? as mentioned in docs setting = model.UserSettings.objects.filter(userid=userid).get()

  2. Maybe work around by change response time in Cassandra conf yaml file?

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
陈海栋
  • 90
  • 5