88use Ydb \Table \Query ;
99use Ydb \Table \V1 \TableServiceClient as ServiceClient ;
1010use YdbPlatform \Ydb \Contracts \SessionPoolContract ;
11+ use YdbPlatform \Ydb \Exceptions \Grpc \InvalidArgumentException ;
12+ use YdbPlatform \Ydb \Exceptions \Grpc \UnknownException ;
1113use YdbPlatform \Ydb \Exceptions \NonRetryableException ;
1214use YdbPlatform \Ydb \Exceptions \RetryableException ;
1315use YdbPlatform \Ydb \Exceptions \Ydb \BadSessionException ;
16+ use YdbPlatform \Ydb \Exceptions \Ydb \SessionBusyException ;
17+ use YdbPlatform \Ydb \Exceptions \Ydb \SessionExpiredException ;
1418use YdbPlatform \Ydb \Retry \Backoff ;
1519use YdbPlatform \Ydb \Retry \Retry ;
1620use YdbPlatform \Ydb \Retry \RetryParams ;
@@ -448,14 +452,32 @@ public function setRetryParams(RetryParams $params): void
448452 */
449453 public function retrySession (Closure $ userFunc , bool $ idempotent = false , RetryParams $ params = null ){
450454 return $ this ->retry ->withParams ($ params )->retry (function () use ($ userFunc ){
451- $ sessionId = null ;
452- try {
455+ $ session = null ;
456+ try {
453457 $ session = $ this ->session ();
454- $ sessionId = $ session ->id ();
455458 return $ userFunc ($ session );
456- }catch (BadSessionException $ bse ){
457- $ this ->dropSession ($ sessionId );
458- throw $ bse ;
459+ } catch (UnknownException $ unknownException ) {
460+ $ this ->dropSession ($ session ->id ());
461+ throw $ unknownException ;
462+ } catch (InvalidArgumentException $ invalidArgumentException ){
463+ $ this ->dropSession ($ session ->id ());
464+ throw $ invalidArgumentException ;
465+ } catch (BadSessionException $ badSessionException ){
466+ $ this ->dropSession ($ session ->id ());
467+ throw $ badSessionException ;
468+ } catch (SessionBusyException $ sessionBusyException ){
469+ $ this ->dropSession ($ session ->id ());
470+ throw $ sessionBusyException ;
471+ } catch (SessionExpiredException $ sessionExpiredException ){
472+ $ this ->dropSession ($ session ->id ());
473+ throw $ sessionExpiredException ;
474+ } catch (Exception $ exception ){
475+ try {
476+ $ session ->rollbackTransaction ();
477+ } catch (Exception $ e ){
478+
479+ }
480+ throw $ exception ;
459481 }
460482 }, $ idempotent );
461483
@@ -464,18 +486,31 @@ public function retrySession(Closure $userFunc, bool $idempotent = false, RetryP
464486 public function retryTransaction (Closure $ userFunc , bool $ idempotent = false , RetryParams $ params = null ){
465487
466488 return $ this ->retry ->withParams ($ params )->retry (function () use ($ userFunc ){
467- $ sessionId = null ;
489+ $ session = null ;
468490 try {
469491 $ session = $ this ->session ();
470- $ sessionId = $ session ->id ();
471492 $ session ->beginTransaction ();
472493 $ result = $ userFunc ($ session );
473494 $ session ->commitTransaction ();
474495 return $ result ;
475- }catch (BadSessionException $ bse ){
476- $ this ->dropSession ($ sessionId );
477- throw $ bse ;
496+ } catch (BadSessionException $ badSessionException ){
497+ $ this ->dropSession ($ session ->id ());
498+ throw $ badSessionException ;
499+ } catch (SessionBusyException $ sessionBusyException ){
500+ $ this ->dropSession ($ session ->id ());
501+ throw $ sessionBusyException ;
502+ } catch (SessionExpiredException $ sessionExpiredException ){
503+ $ this ->dropSession ($ session ->id ());
504+ throw $ sessionExpiredException ;
505+ } catch (Exception $ exception ){
506+ try {
507+ $ session ->rollbackTransaction ();
508+ } catch (Exception $ e ){
509+
510+ }
511+ throw $ exception ;
478512 }
513+
479514 }, $ idempotent );
480515
481516 }
0 commit comments