11using System . Collections . Concurrent ;
22using System . Collections . Immutable ;
3- using System . Net . Sockets ;
43using System . Threading . Channels ;
5- using Google . Protobuf ;
6- using Google . Protobuf . Collections ;
74using Google . Protobuf . WellKnownTypes ;
85using Microsoft . Extensions . Logging ;
96using Ydb . Topic ;
@@ -310,46 +307,62 @@ await Stream.Write(new MessageFromClient
310307 }
311308 catch ( Driver . TransportException e )
312309 {
310+ Logger . LogError ( e , "ReaderSession[{SessionId}] have transport error on Commit" , SessionId ) ;
311+
313312 ReconnectSession ( ) ;
314313 }
315314 } ) ;
316315
317- while ( await Stream . MoveNextAsync ( ) )
316+ try
318317 {
319- switch ( Stream . Current . ServerMessageCase )
318+ while ( await Stream . MoveNextAsync ( ) )
320319 {
321- case ServerMessageOneofCase . ReadResponse :
322- await HandleReadResponse ( ) ;
323- break ;
324- case ServerMessageOneofCase . StartPartitionSessionRequest :
325- var startPartitionSessionRequest = Stream . Current . StartPartitionSessionRequest ;
326- var partitionSession = startPartitionSessionRequest . PartitionSession ;
327-
328- _partitionSessions [ partitionSession . PartitionSessionId ] = new PartitionSession (
329- partitionSession . PartitionSessionId ,
330- partitionSession . Path ,
331- partitionSession . PartitionId ,
332- startPartitionSessionRequest . CommittedOffset
333- ) ;
334- break ;
335- case ServerMessageOneofCase . CommitOffsetResponse :
336- // foreach (var offset in Stream.Current.CommitOffsetResponse.PartitionsCommittedOffsets)
337- // {
338- // offset.CommittedOffset;
339- // offset.PartitionSessionId;
340- // }
341-
342- break ;
343- case ServerMessageOneofCase . PartitionSessionStatusResponse :
344- case ServerMessageOneofCase . UpdateTokenResponse :
345- case ServerMessageOneofCase . StopPartitionSessionRequest :
346- case ServerMessageOneofCase . InitResponse :
347- case ServerMessageOneofCase . None :
348- break ;
349- default :
350- throw new ArgumentOutOfRangeException ( ) ;
320+ switch ( Stream . Current . ServerMessageCase )
321+ {
322+ case ServerMessageOneofCase . ReadResponse :
323+ await HandleReadResponse ( ) ;
324+ break ;
325+ case ServerMessageOneofCase . StartPartitionSessionRequest :
326+ var startPartitionSessionRequest = Stream . Current . StartPartitionSessionRequest ;
327+ var partitionSession = startPartitionSessionRequest . PartitionSession ;
328+
329+ _partitionSessions [ partitionSession . PartitionSessionId ] = new PartitionSession (
330+ partitionSession . PartitionSessionId ,
331+ partitionSession . Path ,
332+ partitionSession . PartitionId ,
333+ startPartitionSessionRequest . CommittedOffset
334+ ) ;
335+
336+ Logger . LogInformation ( "ReaderSession[{SessionId}] started PartitionSession[]" , SessionId ) ;
337+ break ;
338+ case ServerMessageOneofCase . CommitOffsetResponse :
339+ // foreach (var offset in Stream.Current.CommitOffsetResponse.PartitionsCommittedOffsets)
340+ // {
341+ // offset.CommittedOffset;
342+ // offset.PartitionSessionId;
343+ // }
344+
345+ break ;
346+ case ServerMessageOneofCase . PartitionSessionStatusResponse :
347+ case ServerMessageOneofCase . UpdateTokenResponse :
348+ case ServerMessageOneofCase . StopPartitionSessionRequest :
349+ case ServerMessageOneofCase . InitResponse :
350+ case ServerMessageOneofCase . None :
351+ break ;
352+ default :
353+ throw new ArgumentOutOfRangeException ( ) ;
354+ }
351355 }
352356 }
357+ catch ( Driver . TransportException e )
358+ {
359+ Logger . LogError ( e , "ReaderSession[{SessionId}] have transport error on processing server messages" ,
360+ SessionId ) ;
361+ }
362+ finally
363+ {
364+ ReconnectSession ( ) ;
365+ }
353366 }
354367
355368 public async Task < TopicPartitionOffset > CommitOffsetRange ( OffsetsRange offsetsRange , long partitionId )
@@ -367,7 +380,7 @@ private async Task HandleReadResponse()
367380
368381 Interlocked . Add ( ref _memoryUsageMaxBytes , - readResponse . BytesSize ) ;
369382 var readResponsesInBatch = 0 ;
370-
383+
371384 foreach ( var partition in readResponse . PartitionData )
372385 {
373386 var partitionSessionId = partition . PartitionSessionId ;
@@ -376,7 +389,7 @@ private async Task HandleReadResponse()
376389 {
377390 var startOffsetBatch = partitionSession . CommitedOffset ;
378391 var endOffsetBatch = partitionSession . CommitedOffset ;
379-
392+
380393 var batch = partition . Batches ;
381394 for ( var i = 0 ; i < partition . Batches . Count ; i ++ )
382395 {
@@ -386,7 +399,7 @@ private async Task HandleReadResponse()
386399 foreach ( var messageData in batch [ i ] . MessageData )
387400 {
388401 actuallySummaryBatchPayload += messageData . Data . Length ;
389-
402+
390403 internalBatchMessages . Enqueue ( new InternalMessage (
391404 data : messageData . Data ,
392405 topic : partitionSession . TopicPath ,
0 commit comments