@@ -3,6 +3,7 @@ package tarantool
33import (
44 "context"
55 "errors"
6+ "github.com/tarantool/go-tarantool/v2/internal/utils"
67 "time"
78
89 "github.com/tarantool/go-iproto"
@@ -42,6 +43,7 @@ type BeginRequest struct {
4243 baseRequest
4344 txnIsolation TxnIsolationLevel
4445 timeout time.Duration
46+ isSync utils.Optional [bool ]
4547}
4648
4749// NewBeginRequest returns a new BeginRequest.
@@ -59,12 +61,18 @@ func (req *BeginRequest) TxnIsolation(txnIsolation TxnIsolationLevel) *BeginRequ
5961 return req
6062}
6163
62- // WithTimeout allows to set up a timeout for call BeginRequest.
64+ // Timeout allows to set up a timeout for call BeginRequest.
6365func (req * BeginRequest ) Timeout (timeout time.Duration ) * BeginRequest {
6466 req .timeout = timeout
6567 return req
6668}
6769
70+ // IsSync allows to set up a IsSync flag for call BeginRequest.
71+ func (req * BeginRequest ) IsSync (isSync bool ) * BeginRequest {
72+ req .isSync = utils .Some (isSync )
73+ return req
74+ }
75+
6876// Body fills an msgpack.Encoder with the begin request body.
6977func (req * BeginRequest ) Body (_ SchemaResolver , enc * msgpack.Encoder ) error {
7078 var (
@@ -81,6 +89,10 @@ func (req *BeginRequest) Body(_ SchemaResolver, enc *msgpack.Encoder) error {
8189 mapLen ++
8290 }
8391
92+ if req .isSync .HasValue () {
93+ mapLen ++
94+ }
95+
8496 err := enc .EncodeMapLen (mapLen )
8597 if err != nil {
8698 return err
@@ -110,6 +122,18 @@ func (req *BeginRequest) Body(_ SchemaResolver, enc *msgpack.Encoder) error {
110122 }
111123 }
112124
125+ if val , ok := req .isSync .Value (); ok {
126+ err = enc .EncodeUint (uint64 (iproto .IPROTO_IS_SYNC ))
127+ if err != nil {
128+ return err
129+ }
130+
131+ err = enc .EncodeBool (val )
132+ if err != nil {
133+ return err
134+ }
135+ }
136+
113137 return nil
114138}
115139
@@ -129,6 +153,8 @@ func (req *BeginRequest) Context(ctx context.Context) *BeginRequest {
129153// Commit request can not be processed out of stream.
130154type CommitRequest struct {
131155 baseRequest
156+
157+ isSync utils.Optional [bool ]
132158}
133159
134160// NewCommitRequest returns a new CommitRequest.
@@ -138,9 +164,37 @@ func NewCommitRequest() *CommitRequest {
138164 return req
139165}
140166
167+ // IsSync allows to set up a IsSync flag for call BeginRequest.
168+ func (req * CommitRequest ) IsSync (isSync bool ) * CommitRequest {
169+ req .isSync = utils .Some (isSync )
170+ return req
171+ }
172+
141173// Body fills an msgpack.Encoder with the commit request body.
142174func (req * CommitRequest ) Body (res SchemaResolver , enc * msgpack.Encoder ) error {
143- return enc .EncodeMapLen (0 )
175+ var (
176+ mapLen = 0
177+ )
178+
179+ if req .isSync .HasValue () {
180+ mapLen ++
181+ }
182+
183+ if err := enc .EncodeMapLen (mapLen ); err != nil {
184+ return err
185+ }
186+
187+ if val , ok := req .isSync .Value (); ok {
188+ if err := enc .EncodeUint (uint64 (iproto .IPROTO_IS_SYNC )); err != nil {
189+ return err
190+ }
191+
192+ if err := enc .EncodeBool (val ); err != nil {
193+ return err
194+ }
195+ }
196+
197+ return nil
144198}
145199
146200// Context sets a passed context to the request.
0 commit comments