@@ -29,7 +29,8 @@ class QuerySessionPool:
29
29
30
30
def __init__ (self , driver : common_utils .SupportedDriverType , size : int = 100 ):
31
31
"""
32
- :param driver: A driver instance
32
+ :param driver: A driver instance.
33
+ :param size: Max size of Session Pool.
33
34
"""
34
35
35
36
logger .warning ("QuerySessionPool is an experimental API, which could be changed." )
@@ -47,6 +48,15 @@ def _create_new_session(self, timeout: Optional[float]):
47
48
return session
48
49
49
50
def acquire (self , timeout : Optional [float ] = None ) -> QuerySession :
51
+ """WARNING: This API is experimental and could be changed.
52
+
53
+ Acquire a session from Session Pool.
54
+
55
+ :param timeout: A timeout to wait in seconds.
56
+
57
+ :return A QuerySession object.
58
+ """
59
+
50
60
start = time .monotonic ()
51
61
52
62
lock_acquire_timeout = timeout if timeout is not None else - 1
@@ -92,18 +102,27 @@ def acquire(self, timeout: Optional[float] = None) -> QuerySession:
92
102
self ._lock .release ()
93
103
94
104
def release (self , session : QuerySession ) -> None :
105
+ """WARNING: This API is experimental and could be changed.
106
+
107
+ Release a session back to Session Pool.
108
+ """
109
+
95
110
self ._queue .put_nowait (session )
96
111
logger .debug ("Session returned to queue: %s" , session ._state .session_id )
97
112
98
113
def checkout (self , timeout : Optional [float ] = None ) -> "SimpleQuerySessionCheckout" :
99
114
"""WARNING: This API is experimental and could be changed.
100
- Return a Session context manager, that opens session on enter and closes session on exit.
115
+
116
+ Return a Session context manager, that acquires session on enter and releases session on exit.
117
+
118
+ :param timeout: A timeout to wait in seconds.
101
119
"""
102
120
103
121
return SimpleQuerySessionCheckout (self , timeout )
104
122
105
123
def retry_operation_sync (self , callee : Callable , retry_settings : Optional [RetrySettings ] = None , * args , ** kwargs ):
106
124
"""WARNING: This API is experimental and could be changed.
125
+
107
126
Special interface to execute a bunch of commands with session in a safe, retriable way.
108
127
109
128
:param callee: A function, that works with session.
@@ -129,6 +148,7 @@ def execute_with_retries(
129
148
** kwargs ,
130
149
) -> List [convert .ResultSet ]:
131
150
"""WARNING: This API is experimental and could be changed.
151
+
132
152
Special interface to execute a one-shot queries in a safe, retriable way.
133
153
Note: this method loads all data from stream before return, do not use this
134
154
method with huge read queries.
0 commit comments