@@ -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,14 @@ 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
+ :return A QuerySession object.
57
+ """
58
+
50
59
start = time .monotonic ()
51
60
52
61
lock_acquire_timeout = timeout if timeout is not None else - 1
@@ -92,18 +101,27 @@ def acquire(self, timeout: Optional[float] = None) -> QuerySession:
92
101
self ._lock .release ()
93
102
94
103
def release (self , session : QuerySession ) -> None :
104
+ """WARNING: This API is experimental and could be changed.
105
+
106
+ Release a session back to Session Pool.
107
+ """
108
+
95
109
self ._queue .put_nowait (session )
96
110
logger .debug ("Session returned to queue: %s" , session ._state .session_id )
97
111
98
112
def checkout (self , timeout : Optional [float ] = None ) -> "SimpleQuerySessionCheckout" :
99
113
"""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.
114
+
115
+ Return a Session context manager, that acquires session on enter and releases session on exit.
116
+
117
+ :param timeout: A timeout to wait in seconds.
101
118
"""
102
119
103
120
return SimpleQuerySessionCheckout (self , timeout )
104
121
105
122
def retry_operation_sync (self , callee : Callable , retry_settings : Optional [RetrySettings ] = None , * args , ** kwargs ):
106
123
"""WARNING: This API is experimental and could be changed.
124
+
107
125
Special interface to execute a bunch of commands with session in a safe, retriable way.
108
126
109
127
:param callee: A function, that works with session.
@@ -129,6 +147,7 @@ def execute_with_retries(
129
147
** kwargs ,
130
148
) -> List [convert .ResultSet ]:
131
149
"""WARNING: This API is experimental and could be changed.
150
+
132
151
Special interface to execute a one-shot queries in a safe, retriable way.
133
152
Note: this method loads all data from stream before return, do not use this
134
153
method with huge read queries.
0 commit comments