@@ -84,54 +84,39 @@ func do(
8484 return nil
8585}
8686
87- func doWithAttempts (
88- ctx context.Context ,
89- pool * pool.Pool [* Session , Session ],
90- op query.Operation ,
91- t * trace.Query ,
92- opts ... options.DoOption ,
93- ) (attempts int , finalErr error ) {
94- doOpts := options .ParseDoOpts (t , opts ... )
95-
96- err := do (ctx , pool , op ,
97- append (doOpts .RetryOpts (), retry .WithTrace (& trace.Retry {
98- OnRetry : func (info trace.RetryLoopStartInfo ) func (trace.RetryLoopDoneInfo ) {
99- return func (info trace.RetryLoopDoneInfo ) {
100- attempts = info .Attempts
101- }
102- },
103- }))... ,
104- )
105- if err != nil {
106- return attempts , xerrors .WithStackTrace (err )
107- }
108-
109- return attempts , nil
110- }
111-
112- func (c * Client ) Do (ctx context.Context , op query.Operation , opts ... options.DoOption ) error {
87+ func (c * Client ) Do (ctx context.Context , op query.Operation , opts ... options.DoOption ) (finalErr error ) {
11388 ctx , cancel := xcontext .WithDone (ctx , c .done )
11489 defer cancel ()
11590
116- onDone := trace .QueryOnDo (c .config .Trace (), & ctx ,
117- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).Do" ),
91+ var (
92+ onDone = trace .QueryOnDo (c .config .Trace (), & ctx ,
93+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).Do" ),
94+ )
95+ attempts = 0
11896 )
119- attempts , err := doWithAttempts (ctx , c .pool , op , c .config .Trace (), opts ... )
120- onDone (attempts , err )
97+ defer func () {
98+ onDone (attempts , finalErr )
99+ }()
100+
101+ err := do (ctx , c .pool , func (ctx context.Context , s query.Session ) error {
102+ attempts ++
103+
104+ return op (ctx , s )
105+ }, options .ParseDoOpts (c .config .Trace (), opts ... ).RetryOpts ()... )
121106
122107 return err
123108}
124109
125- func doTxWithAttempts (
110+ func doTx (
126111 ctx context.Context ,
127112 pool * pool.Pool [* Session , Session ],
128113 op query.TxOperation ,
129114 t * trace.Query ,
130115 opts ... options.DoTxOption ,
131- ) (attempts int , err error ) {
116+ ) (finalErr error ) {
132117 doTxOpts := options .ParseDoTxOpts (t , opts ... )
133118
134- attempts , err = doWithAttempts (ctx , pool , func (ctx context.Context , s query.Session ) (err error ) {
119+ err := do (ctx , pool , func (ctx context.Context , s query.Session ) (err error ) {
135120 tx , err := s .Begin (ctx , doTxOpts .TxSettings ())
136121 if err != nil {
137122 return xerrors .WithStackTrace (err )
@@ -156,12 +141,12 @@ func doTxWithAttempts(
156141 }
157142
158143 return nil
159- }, t , doTxOpts .DoOpts ()... )
144+ }, doTxOpts .RetryOpts ()... )
160145 if err != nil {
161- return attempts , xerrors .WithStackTrace (err )
146+ return xerrors .WithStackTrace (err )
162147 }
163148
164- return attempts , nil
149+ return nil
165150}
166151
167152// ReadRow is a helper which read only one row from first result set in result
@@ -273,17 +258,30 @@ func (c *Client) ReadResultSet(
273258 return rs , nil
274259}
275260
276- func (c * Client ) DoTx (ctx context.Context , op query.TxOperation , opts ... options.DoTxOption ) (err error ) {
261+ func (c * Client ) DoTx (ctx context.Context , op query.TxOperation , opts ... options.DoTxOption ) (finalErr error ) {
277262 ctx , cancel := xcontext .WithDone (ctx , c .done )
278263 defer cancel ()
279264
280- onDone := trace .QueryOnDoTx (c .config .Trace (), & ctx ,
281- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).DoTx" ),
265+ var (
266+ onDone = trace .QueryOnDoTx (c .config .Trace (), & ctx ,
267+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/3/internal/query.(*Client).DoTx" ),
268+ )
269+ attempts = 0
282270 )
283- attempts , err := doTxWithAttempts (ctx , c .pool , op , c .config .Trace (), opts ... )
284- onDone (attempts , err )
271+ defer func () {
272+ onDone (attempts , finalErr )
273+ }()
285274
286- return err
275+ err := doTx (ctx , c .pool , func (ctx context.Context , tx query.TxActor ) error {
276+ attempts ++
277+
278+ return op (ctx , tx )
279+ }, c .config .Trace (), opts ... )
280+ if err != nil {
281+ return xerrors .WithStackTrace (err )
282+ }
283+
284+ return nil
287285}
288286
289287func New (ctx context.Context , balancer balancer , cfg * config.Config ) * Client {
0 commit comments