Skip to content

Commit 44016c8

Browse files
committed
Add FAQ section to docs
PYTHON-115
1 parent a5ca5ee commit 44016c8

3 files changed

Lines changed: 93 additions & 4 deletions

File tree

docs/cqlengine/faq.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
Frequently Asked Questions
33
==========================
44

5-
Q: Why don't updates work correctly on models instantiated as Model(field=value, field2=value2)?
5+
Why don't updates work correctly on models instantiated as Model(field=value, field2=value2)?
66
------------------------------------------------------------------------------------------------
77

8-
A: The recommended way to create new rows is with the models .create method. The values passed into a model's init method are interpreted by the model as the values as they were read from a row. This allows the model to "know" which rows have changed since the row was read out of cassandra, and create suitable update statements.
8+
The recommended way to create new rows is with the models .create method. The values passed into a model's init method are interpreted by the model as the values as they were read from a row. This allows the model to "know" which rows have changed since the row was read out of cassandra, and create suitable update statements.
99

10-
Q: How to preserve ordering in batch query?
10+
How to preserve ordering in batch query?
1111
-------------------------------------------
1212

13-
A: Statement Ordering is not supported by CQL3 batches. Therefore,
13+
Statement Ordering is not supported by CQL3 batches. Therefore,
1414
once cassandra needs resolving conflict(Updating the same column in one batch),
1515
The algorithm below would be used.
1616

docs/faq.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Frequently Asked Questions
2+
==========================
3+
4+
See also :doc:`cqlengine FAQ <cqlengine/faq>`
5+
6+
Why do connections or IO operations timeout in my WSGI application?
7+
-------------------------------------------------------------------
8+
Depending on your application process model, it may be forking after driver Session is created. Most IO reactors do not handle this, and problems will manifest as timeouts.
9+
10+
To avoid this, make sure to create sessions per process, after the fork. Using uWSGI and Flask for example:
11+
12+
.. code-block:: python
13+
14+
from flask import Flask
15+
from uwsgidecorators import postfork
16+
from cassandra.cluster import Cluster
17+
18+
session = None
19+
prepared = None
20+
21+
@postfork
22+
def connect():
23+
global session, prepared
24+
session = Cluster().connect()
25+
prepared = session.prepare("SELECT release_version FROM system.local WHERE key=?")
26+
27+
app = Flask(__name__)
28+
29+
@app.route('/')
30+
def server_version():
31+
row = session.execute(prepared, ('local',))[0]
32+
return row.release_version
33+
34+
uWSGI provides a ``postfork`` hook you can use to create sessions and prepared statements after the child process forks.
35+
36+
How do I trace a request?
37+
-------------------------
38+
Request tracing can be turned on for any request by setting ``trace=True`` in :meth:`.Session.execute_async`. View the results by waiting on the future, then :meth:`.ResponseFuture.get_query_trace`.
39+
Since tracing is done asynchronously to the request, this method polls until the trace is complete before querying data.
40+
41+
.. code-block:: python
42+
43+
>>> future = session.execute_async("SELECT * FROM system.local", trace=True)
44+
>>> result = future.result()
45+
>>> trace = future.get_query_trace()
46+
>>> for e in trace.events:
47+
>>> print e.source_elapsed, e.description
48+
49+
0:00:00.000077 Parsing select * from system.local
50+
0:00:00.000153 Preparing statement
51+
0:00:00.000309 Computing ranges to query
52+
0:00:00.000368 Submitting range requests on 1 ranges with a concurrency of 1 (279.77142 rows per range expected)
53+
0:00:00.000422 Submitted 1 concurrent range requests covering 1 ranges
54+
0:00:00.000480 Executing seq scan across 1 sstables for (min(-9223372036854775808), min(-9223372036854775808))
55+
0:00:00.000669 Read 1 live and 0 tombstone cells
56+
0:00:00.000755 Scanned 1 rows and matched 1
57+
58+
``trace`` is a :class:`QueryTrace` object.
59+
60+
How do I determine the replicas for a query?
61+
----------------------------------------------
62+
With prepared statements, the replicas are obtained by ``routing_key``, based on current cluster token metadata:
63+
64+
.. code-block:: python
65+
66+
>>> prepared = session.prepare("SELECT * FROM example.t WHERE key=?")
67+
>>> bound = prepared.bind((1,))
68+
>>> replicas = cluster.metadata.get_replicas(bound.keyspace, bound.routing_key)
69+
>>> for h in replicas:
70+
>>> print h.address
71+
127.0.0.1
72+
127.0.0.2
73+
74+
``replicas`` is a list of :class:`Host` objects.
75+
76+
How does the driver manage request retries?
77+
-------------------------------------------
78+
By default, retries are managed by the :attr:`.Cluster.default_retry_policy` set on the session Cluster. It can also
79+
be specialized per statement by setting :attr:`.Statement.retry_policy`.
80+
81+
Retries are presently attempted on the same coordinator, but this may change in the future.
82+
83+
Please see :class:`.policies.RetryPolicy` for further details.

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Contents
3939
:doc:`security`
4040
An overview of the security features of the driver.
4141

42+
:doc:`faq`
43+
A collection of Frequently Asked Questions
44+
4245
.. toctree::
4346
:hidden:
4447

@@ -51,9 +54,12 @@ Contents
5154
security
5255
user_defined_types
5356
object_mapper
57+
faq
5458

5559
Getting Help
5660
------------
61+
Visit the :doc:`FAQ section <faq>` in this documentation.
62+
5763
Please send questions to the `mailing list <https://groups.google.com/a/lists.datastax.com/forum/#!forum/python-driver-user>`_.
5864

5965
Alternatively, you can use IRC. Connect to the #datastax-drivers channel on irc.freenode.net.

0 commit comments

Comments
 (0)