26
26
Codec ,
27
27
)
28
28
from .._errors import check_retriable_error
29
- from .. import topic
30
29
31
30
32
31
class TopicReaderError (YdbError ):
@@ -65,11 +64,11 @@ class PublicAsyncIOReader:
65
64
_parent : typing .Any # need for prevent close parent client by GC
66
65
67
66
def __init__ (
68
- self ,
69
- driver : Driver ,
70
- settings : topic_reader .PublicReaderSettings ,
71
- * ,
72
- _parent = None ,
67
+ self ,
68
+ driver : Driver ,
69
+ settings : topic_reader .PublicReaderSettings ,
70
+ * ,
71
+ _parent = None ,
73
72
):
74
73
self ._loop = asyncio .get_running_loop ()
75
74
self ._closed = False
@@ -87,7 +86,7 @@ def __del__(self):
87
86
self ._loop .create_task (self .close (flush = False ), name = "close reader" )
88
87
89
88
async def receive_batch (
90
- self ,
89
+ self ,
91
90
) -> typing .Union [datatypes .PublicBatch , None ]:
92
91
"""
93
92
Get one messages batch from reader.
@@ -108,7 +107,7 @@ async def receive_message(self) -> typing.Optional[datatypes.PublicMessage]:
108
107
return self ._reconnector .receive_message_nowait ()
109
108
110
109
def commit (
111
- self , batch : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]
110
+ self , batch : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]
112
111
):
113
112
"""
114
113
Write commit message to a buffer.
@@ -119,7 +118,7 @@ def commit(
119
118
self ._reconnector .commit (batch )
120
119
121
120
async def commit_with_ack (
122
- self , batch : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]
121
+ self , batch : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]
123
122
):
124
123
"""
125
124
write commit message to a buffer and wait ack from the server.
@@ -204,7 +203,7 @@ def receive_message_nowait(self):
204
203
return self ._stream_reader .receive_message_nowait ()
205
204
206
205
def commit (
207
- self , batch : datatypes .ICommittable
206
+ self , batch : datatypes .ICommittable
208
207
) -> datatypes .PartitionSession .CommitAckWaiter :
209
208
return self ._stream_reader .commit (batch )
210
209
@@ -263,10 +262,10 @@ class ReaderStream:
263
262
_get_token_function : Callable [[], str ]
264
263
265
264
def __init__ (
266
- self ,
267
- reader_reconnector_id : int ,
268
- settings : topic_reader .PublicReaderSettings ,
269
- get_token_function : Optional [Callable [[], str ]] = None ,
265
+ self ,
266
+ reader_reconnector_id : int ,
267
+ settings : topic_reader .PublicReaderSettings ,
268
+ get_token_function : Optional [Callable [[], str ]] = None ,
270
269
):
271
270
self ._loop = asyncio .get_running_loop ()
272
271
self ._id = ReaderStream ._static_id_counter .inc_and_get ()
@@ -295,9 +294,9 @@ def __init__(
295
294
296
295
@staticmethod
297
296
async def create (
298
- reader_reconnector_id : int ,
299
- driver : SupportedDriverType ,
300
- settings : topic_reader .PublicReaderSettings ,
297
+ reader_reconnector_id : int ,
298
+ driver : SupportedDriverType ,
299
+ settings : topic_reader .PublicReaderSettings ,
301
300
) -> "ReaderStream" :
302
301
stream = GrpcWrapperAsyncIO (StreamReadMessage .FromServer .from_proto )
303
302
@@ -315,7 +314,7 @@ async def create(
315
314
return reader
316
315
317
316
async def _start (
318
- self , stream : IGrpcWrapperAsyncIO , init_message : StreamReadMessage .InitRequest
317
+ self , stream : IGrpcWrapperAsyncIO , init_message : StreamReadMessage .InitRequest
319
318
):
320
319
if self ._started :
321
320
raise TopicReaderError ("Double start ReaderStream" )
@@ -381,7 +380,7 @@ def receive_message_nowait(self):
381
380
return message
382
381
383
382
def commit (
384
- self , batch : datatypes .ICommittable
383
+ self , batch : datatypes .ICommittable
385
384
) -> datatypes .PartitionSession .CommitAckWaiter :
386
385
partition_session = batch ._commit_get_partition_session ()
387
386
@@ -435,19 +434,19 @@ async def _read_messages_loop(self):
435
434
self ._on_read_response (message .server_message )
436
435
437
436
elif isinstance (
438
- message .server_message , StreamReadMessage .CommitOffsetResponse
437
+ message .server_message , StreamReadMessage .CommitOffsetResponse
439
438
):
440
439
self ._on_commit_response (message .server_message )
441
440
442
441
elif isinstance (
443
- message .server_message ,
444
- StreamReadMessage .StartPartitionSessionRequest ,
442
+ message .server_message ,
443
+ StreamReadMessage .StartPartitionSessionRequest ,
445
444
):
446
445
self ._on_start_partition_session (message .server_message )
447
446
448
447
elif isinstance (
449
- message .server_message ,
450
- StreamReadMessage .StopPartitionSessionRequest ,
448
+ message .server_message ,
449
+ StreamReadMessage .StopPartitionSessionRequest ,
451
450
):
452
451
self ._on_partition_session_stop (message .server_message )
453
452
@@ -479,12 +478,12 @@ async def _update_token(self, token: str):
479
478
self ._update_token_event .clear ()
480
479
481
480
def _on_start_partition_session (
482
- self , message : StreamReadMessage .StartPartitionSessionRequest
481
+ self , message : StreamReadMessage .StartPartitionSessionRequest
483
482
):
484
483
try :
485
484
if (
486
- message .partition_session .partition_session_id
487
- in self ._partition_sessions
485
+ message .partition_session .partition_session_id
486
+ in self ._partition_sessions
488
487
):
489
488
raise TopicReaderError (
490
489
"Double start partition session: %s"
@@ -515,7 +514,7 @@ def _on_start_partition_session(
515
514
self ._set_first_error (err )
516
515
517
516
def _on_partition_session_stop (
518
- self , message : StreamReadMessage .StopPartitionSessionRequest
517
+ self , message : StreamReadMessage .StopPartitionSessionRequest
519
518
):
520
519
if message .partition_session_id not in self ._partition_sessions :
521
520
# may if receive stop partition with graceful=false after response on stop partition
@@ -563,7 +562,7 @@ def _buffer_release_bytes(self, bytes_size):
563
562
)
564
563
565
564
def _read_response_to_batches (
566
- self , message : StreamReadMessage .ReadResponse
565
+ self , message : StreamReadMessage .ReadResponse
567
566
) -> typing .List [datatypes .PublicBatch ]:
568
567
batches = []
569
568
@@ -573,7 +572,7 @@ def _read_response_to_batches(
573
572
574
573
bytes_per_batch = message .bytes_size // batch_count
575
574
additional_bytes_to_last_batch = (
576
- message .bytes_size - bytes_per_batch * batch_count
575
+ message .bytes_size - bytes_per_batch * batch_count
577
576
)
578
577
579
578
for partition_data in message .partition_data :
0 commit comments