Skip to content

Commit

Permalink
Add query tx modes to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvoleg committed Sep 10, 2024
1 parent 3f81746 commit cdae01e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
38 changes: 38 additions & 0 deletions docs/apireference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,44 @@ QueryTxContext (AsyncIO)
:undoc-members:


Query Tx Mode
^^^^^^^^^^^^^

.. autoclass:: ydb.BaseQueryTxMode
:members:
:inherited-members:
:undoc-members:
:exclude-members: name, to_proto


.. autoclass:: ydb.QueryOnlineReadOnly
:members:
:inherited-members:
:undoc-members:
:exclude-members: name, to_proto


.. autoclass:: ydb.QuerySerializableReadWrite
:members:
:inherited-members:
:undoc-members:
:exclude-members: name, to_proto


.. autoclass:: ydb.QuerySnapshotReadOnly
:members:
:inherited-members:
:undoc-members:
:exclude-members: name, to_proto


.. autoclass:: ydb.QueryStaleReadOnly
:members:
:inherited-members:
:undoc-members:
:exclude-members: name, to_proto


------------------------

Table Service
Expand Down
22 changes: 22 additions & 0 deletions ydb/_grpc/grpcwrapper/ydb_query_public_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@


class BaseQueryTxMode(IToProto):
"""Abstract class for Query Transaction Modes."""
@property
@abc.abstractmethod
def name(self) -> str:
pass


class QuerySnapshotReadOnly(BaseQueryTxMode):
"""All the read operations within a transaction access the database snapshot.
All the data reads are consistent. The snapshot is taken when the transaction begins,
meaning the transaction sees all changes committed before it began.
"""
def __init__(self):
self._name = "snapshot_read_only"

Expand All @@ -30,6 +35,9 @@ def to_proto(self) -> ydb_query_pb2.SnapshotModeSettings:


class QuerySerializableReadWrite(BaseQueryTxMode):
"""This mode guarantees that the result of successful parallel transactions is equivalent
to their serial execution, and there are no read anomalies for successful transactions.
"""
def __init__(self):
self._name = "serializable_read_write"

Expand All @@ -42,6 +50,15 @@ def to_proto(self) -> ydb_query_pb2.SerializableModeSettings:


class QueryOnlineReadOnly(BaseQueryTxMode):
"""Each read operation in the transaction is reading the data that is most recent at execution time.
The consistency of retrieved data depends on the allow_inconsistent_reads setting:
* false (consistent reads): Each individual read operation returns consistent data,
but no consistency is guaranteed between reads.
Reading the same table range twice may return different results.
* true (inconsistent reads): Even the data fetched by a particular
read operation may contain inconsistent results.
"""

def __init__(self, allow_inconsistent_reads: bool = False):
self.allow_inconsistent_reads = allow_inconsistent_reads
self._name = "online_read_only"
Expand All @@ -55,6 +72,11 @@ def to_proto(self) -> ydb_query_pb2.OnlineModeSettings:


class QueryStaleReadOnly(BaseQueryTxMode):
"""Read operations within a transaction may return results that are slightly out-of-date
(lagging by fractions of a second). Each individual read returns consistent data,
but no consistency between different reads is guaranteed.
"""

def __init__(self):
self._name = "stale_read_only"

Expand Down
4 changes: 3 additions & 1 deletion ydb/query/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
__all__ = [
"BaseQueryTxMode",
"QueryOnlineReadOnly",
"QuerySerializableReadWrite",
"QuerySnapshotReadOnly",
"QueryStaleReadOnly",
"QuerySessionPool",
"QueryClientSync",
"QueryClientSettings",
"QuerySession",
"QueryTxContext",
]
Expand All @@ -20,6 +21,7 @@

from .._grpc.grpcwrapper import common_utils
from .._grpc.grpcwrapper.ydb_query_public_types import (
BaseQueryTxMode,
QueryOnlineReadOnly,
QuerySerializableReadWrite,
QuerySnapshotReadOnly,
Expand Down

0 comments on commit cdae01e

Please sign in to comment.