Skip to content

TNTP-3334: IPROTO_IS_SYNC support for begin/commit #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

- Implemented all box.schema.user operations requests and sugar interface (#426).
- Implemented box.session.su request and sugar interface only for current session granting (#426).
- Implemented support for `IPROTO_IS_SYNC` flag in stream transactions,
added `IsSync(bool)` method for `BeginRequest`/`CommitRequest` (#447).

### Changed

Expand Down
3 changes: 3 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,9 @@ func ExampleBeginRequest_TxnIsolation() {
fmt.Printf("Select after Rollback: response is %#v\n", data)
}

func ExampleBeginRequest_IsSync() {
}

func ExampleErrorNo() {
conn := exampleConnect(dialer, opts)
defer conn.Close()
Expand Down
158 changes: 0 additions & 158 deletions export_test.go

This file was deleted.

64 changes: 38 additions & 26 deletions prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ type Prepared struct {
Conn *Connection
}

func fillPrepare(enc *msgpack.Encoder, expr string) error {
enc.EncodeMapLen(1)
enc.EncodeUint(uint64(iproto.IPROTO_SQL_TEXT))
return enc.EncodeString(expr)
}

func fillUnprepare(enc *msgpack.Encoder, stmt Prepared) error {
enc.EncodeMapLen(1)
enc.EncodeUint(uint64(iproto.IPROTO_STMT_ID))
return enc.EncodeUint(uint64(stmt.StatementID))
}

func fillExecutePrepared(enc *msgpack.Encoder, stmt Prepared, args interface{}) error {
enc.EncodeMapLen(2)
enc.EncodeUint(uint64(iproto.IPROTO_STMT_ID))
enc.EncodeUint(uint64(stmt.StatementID))
enc.EncodeUint(uint64(iproto.IPROTO_SQL_BIND))
return encodeSQLBind(enc, args)
}

// NewPreparedFromResponse constructs a Prepared object.
func NewPreparedFromResponse(conn *Connection, resp Response) (*Prepared, error) {
if resp == nil {
Expand Down Expand Up @@ -81,8 +61,16 @@ func NewPrepareRequest(expr string) *PrepareRequest {
}

// Body fills an msgpack.Encoder with the execute request body.
func (req *PrepareRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
return fillPrepare(enc, req.expr)
func (req *PrepareRequest) Body(_ SchemaResolver, enc *msgpack.Encoder) error {
err := enc.EncodeMapLen(1)
if err != nil {
return err
}
err = enc.EncodeUint(uint64(iproto.IPROTO_SQL_TEXT))
if err != nil {
return err
}
return enc.EncodeString(req.expr)
}

// Context sets a passed context to the request.
Expand Down Expand Up @@ -126,8 +114,16 @@ func (req *UnprepareRequest) Conn() *Connection {
}

// Body fills an msgpack.Encoder with the execute request body.
func (req *UnprepareRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
return fillUnprepare(enc, *req.stmt)
func (req *UnprepareRequest) Body(_ SchemaResolver, enc *msgpack.Encoder) error {
err := enc.EncodeMapLen(1)
if err != nil {
return err
}
err = enc.EncodeUint(uint64(iproto.IPROTO_STMT_ID))
if err != nil {
return err
}
return enc.EncodeUint(uint64(req.stmt.StatementID))
}

// Context sets a passed context to the request.
Expand Down Expand Up @@ -171,8 +167,24 @@ func (req *ExecutePreparedRequest) Args(args interface{}) *ExecutePreparedReques
}

// Body fills an msgpack.Encoder with the execute request body.
func (req *ExecutePreparedRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
return fillExecutePrepared(enc, *req.stmt, req.args)
func (req *ExecutePreparedRequest) Body(_ SchemaResolver, enc *msgpack.Encoder) error {
err := enc.EncodeMapLen(2)
if err != nil {
return err
}
err = enc.EncodeUint(uint64(iproto.IPROTO_STMT_ID))
if err != nil {
return err
}
err = enc.EncodeUint(uint64(req.stmt.StatementID))
if err != nil {
return err
}
err = enc.EncodeUint(uint64(iproto.IPROTO_SQL_BIND))
if err != nil {
return err
}
return encodeSQLBind(enc, req.args)
}

// Context sets a passed context to the request.
Expand Down
51 changes: 28 additions & 23 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,43 +68,48 @@ type IdRequest struct {
protocolInfo ProtocolInfo
}

func fillId(enc *msgpack.Encoder, protocolInfo ProtocolInfo) error {
enc.EncodeMapLen(2)
// NewIdRequest returns a new IdRequest.
func NewIdRequest(protocolInfo ProtocolInfo) *IdRequest {
req := new(IdRequest)
req.rtype = iproto.IPROTO_ID
req.protocolInfo = protocolInfo.Clone()
return req
}

enc.EncodeUint(uint64(iproto.IPROTO_VERSION))
if err := enc.Encode(protocolInfo.Version); err != nil {
// Body fills an msgpack.Encoder with the id request body.
func (req *IdRequest) Body(_ SchemaResolver, enc *msgpack.Encoder) error {
err := enc.EncodeMapLen(2)
if err != nil {
return err
}

enc.EncodeUint(uint64(iproto.IPROTO_FEATURES))

t := len(protocolInfo.Features)
if err := enc.EncodeArrayLen(t); err != nil {
err = enc.EncodeUint(uint64(iproto.IPROTO_VERSION))
if err != nil {
return err
}
err = enc.Encode(req.protocolInfo.Version)
if err != nil {
return err
}

for _, feature := range protocolInfo.Features {
if err := enc.Encode(feature); err != nil {
err = enc.EncodeUint(uint64(iproto.IPROTO_FEATURES))
if err != nil {
return err
}
err = enc.EncodeArrayLen(len(req.protocolInfo.Features))
if err != nil {
return err
}
for _, feature := range req.protocolInfo.Features {
err = enc.Encode(feature)
if err != nil {
return err
}
}

return nil
}

// NewIdRequest returns a new IdRequest.
func NewIdRequest(protocolInfo ProtocolInfo) *IdRequest {
req := new(IdRequest)
req.rtype = iproto.IPROTO_ID
req.protocolInfo = protocolInfo.Clone()
return req
}

// Body fills an msgpack.Encoder with the id request body.
func (req *IdRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
return fillId(enc, req.protocolInfo)
}

// Context sets a passed context to the request.
//
// Pay attention that when using context with request objects,
Expand Down
Loading
Loading