Skip to content

Commit f0a8921

Browse files
committed
api: use msgpack/v5 instead of msgpack.v2
We found several critical bugs in the library msgpack.v2. It was decided to update the library to msgpack/v5. Closes #211 Closes #236
1 parent 0bc4366 commit f0a8921

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+555
-1087
lines changed

.github/workflows/testing.yml

-38
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,6 @@ jobs:
104104
make test TAGS="go_tarantool_call_17"
105105
make testrace TAGS="go_tarantool_call_17"
106106
107-
- name: Run regression tests with msgpack.v5
108-
run: |
109-
make test TAGS="go_tarantool_msgpack_v5"
110-
make testrace TAGS="go_tarantool_msgpack_v5"
111-
112-
- name: Run regression tests with msgpack.v5 and call_17
113-
run: |
114-
make test TAGS="go_tarantool_msgpack_v5,go_tarantool_call_17"
115-
make testrace TAGS="go_tarantool_msgpack_v5,go_tarantool_call_17"
116-
117107
- name: Run fuzzing tests
118108
if: ${{ matrix.fuzzing }}
119109
run: make fuzzing TAGS="go_tarantool_decimal_fuzzing"
@@ -207,22 +197,6 @@ jobs:
207197
env:
208198
TEST_TNT_SSL: ${{matrix.ssl}}
209199

210-
- name: Run regression tests with msgpack.v5
211-
run: |
212-
source tarantool-enterprise/env.sh
213-
make test TAGS="go_tarantool_msgpack_v5"
214-
make testrace TAGS="go_tarantool_msgpack_v5"
215-
env:
216-
TEST_TNT_SSL: ${{matrix.ssl}}
217-
218-
- name: Run regression tests with msgpack.v5 and call_17
219-
run: |
220-
source tarantool-enterprise/env.sh
221-
make test TAGS="go_tarantool_msgpack_v5,go_tarantool_call_17"
222-
make testrace TAGS="go_tarantool_msgpack_v5,go_tarantool_call_17"
223-
env:
224-
TEST_TNT_SSL: ${{matrix.ssl}}
225-
226200
- name: Run fuzzing tests
227201
if: ${{ matrix.fuzzing }}
228202
run: make fuzzing TAGS="go_tarantool_decimal_fuzzing"
@@ -395,18 +369,6 @@ jobs:
395369
make test TAGS="go_tarantool_call_17"
396370
make testrace TAGS="go_tarantool_call_17"
397371
398-
- name: Run regression tests with msgpack.v5
399-
run: |
400-
cd "${SRCDIR}"
401-
make test TAGS="go_tarantool_msgpack_v5"
402-
make testrace TAGS="go_tarantool_msgpack_v5"
403-
404-
- name: Run regression tests with msgpack.v5 and call_17
405-
run: |
406-
cd "${SRCDIR}"
407-
make test TAGS="go_tarantool_msgpack_v5,go_tarantool_call_17"
408-
make testrace TAGS="go_tarantool_msgpack_v5,go_tarantool_call_17"
409-
410372
- name: Run fuzzing tests
411373
if: ${{ matrix.fuzzing }}
412374
run: |

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1313
### Changed
1414

1515
- connection_pool renamed to pool (#239)
16+
- Use msgpack/v5 instead of msgpack.v2 (#236)
1617

1718
### Removed
1819

1920
- multi subpackage (#240)
21+
- msgpack.v2 support (#236)
2022

2123
### Fixed
2224

README.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,7 @@ This allows us to introduce new features without losing backward compatibility.
7272
go_tarantool_call_17
7373
```
7474
**Note:** In future releases, `Call17` may be used as default `Call` behavior.
75-
3. To replace usage of `msgpack.v2` with `msgpack.v5`, you can use the build
76-
tag:
77-
```
78-
go_tarantool_msgpack_v5
79-
```
80-
**Note:** In future releases, `msgpack.v5` may be used by default. We recommend
81-
to read [msgpack.v5 migration notes](#msgpackv5-migration) and try to
82-
use msgpack.v5 before the changes.
83-
4. To run fuzz tests with decimals, you can use the build tag:
75+
3. To run fuzz tests with decimals, you can use the build tag:
8476
```
8577
go_tarantool_decimal_fuzzing
8678
```

box_error.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package tarantool
33
import (
44
"bytes"
55
"fmt"
6+
7+
"github.com/vmihailenco/msgpack/v5"
68
)
79

810
const errorExtID = 3
@@ -69,7 +71,7 @@ func (e *BoxError) Depth() int {
6971
return depth
7072
}
7173

72-
func decodeBoxError(d *decoder) (*BoxError, error) {
74+
func decodeBoxError(d *msgpack.Decoder) (*BoxError, error) {
7375
var l, larr, l1, l2 int
7476
var errorStack []BoxError
7577
var err error
@@ -169,15 +171,15 @@ func decodeBoxError(d *decoder) (*BoxError, error) {
169171
return &errorStack[0], nil
170172
}
171173

172-
func encodeBoxError(enc *encoder, boxError *BoxError) error {
174+
func encodeBoxError(enc *msgpack.Encoder, boxError *BoxError) error {
173175
if boxError == nil {
174176
return fmt.Errorf("msgpack: unexpected nil BoxError on encode")
175177
}
176178

177179
if err := enc.EncodeMapLen(1); err != nil {
178180
return err
179181
}
180-
if err := encodeUint(enc, keyErrorStack); err != nil {
182+
if err := enc.EncodeUint(keyErrorStack); err != nil {
181183
return err
182184
}
183185

@@ -199,50 +201,50 @@ func encodeBoxError(enc *encoder, boxError *BoxError) error {
199201
}
200202
}
201203

202-
if err := encodeUint(enc, keyErrorType); err != nil {
204+
if err := enc.EncodeUint(keyErrorType); err != nil {
203205
return err
204206
}
205207
if err := enc.EncodeString(boxError.Type); err != nil {
206208
return err
207209
}
208210

209-
if err := encodeUint(enc, keyErrorFile); err != nil {
211+
if err := enc.EncodeUint(keyErrorFile); err != nil {
210212
return err
211213
}
212214
if err := enc.EncodeString(boxError.File); err != nil {
213215
return err
214216
}
215217

216-
if err := encodeUint(enc, keyErrorLine); err != nil {
218+
if err := enc.EncodeUint(keyErrorLine); err != nil {
217219
return err
218220
}
219221
if err := enc.EncodeUint64(boxError.Line); err != nil {
220222
return err
221223
}
222224

223-
if err := encodeUint(enc, keyErrorMessage); err != nil {
225+
if err := enc.EncodeUint(keyErrorMessage); err != nil {
224226
return err
225227
}
226228
if err := enc.EncodeString(boxError.Msg); err != nil {
227229
return err
228230
}
229231

230-
if err := encodeUint(enc, keyErrorErrno); err != nil {
232+
if err := enc.EncodeUint(keyErrorErrno); err != nil {
231233
return err
232234
}
233235
if err := enc.EncodeUint64(boxError.Errno); err != nil {
234236
return err
235237
}
236238

237-
if err := encodeUint(enc, keyErrorErrcode); err != nil {
239+
if err := enc.EncodeUint(keyErrorErrcode); err != nil {
238240
return err
239241
}
240242
if err := enc.EncodeUint64(boxError.Code); err != nil {
241243
return err
242244
}
243245

244246
if fieldsLen > 0 {
245-
if err := encodeUint(enc, keyErrorFields); err != nil {
247+
if err := enc.EncodeUint(keyErrorFields); err != nil {
246248
return err
247249
}
248250

@@ -276,7 +278,7 @@ func (e *BoxError) UnmarshalMsgpack(b []byte) error {
276278
}
277279

278280
buf := bytes.NewBuffer(b)
279-
dec := newDecoder(buf)
281+
dec := msgpack.NewDecoder(buf)
280282

281283
if val, err := decodeBoxError(dec); err != nil {
282284
return err
@@ -290,10 +292,14 @@ func (e *BoxError) UnmarshalMsgpack(b []byte) error {
290292
func (e *BoxError) MarshalMsgpack() ([]byte, error) {
291293
var buf bytes.Buffer
292294

293-
enc := newEncoder(&buf)
295+
enc := msgpack.NewEncoder(&buf)
294296
if err := encodeBoxError(enc, e); err != nil {
295297
return nil, err
296298
}
297299

298300
return buf.Bytes(), nil
299301
}
302+
303+
func init() {
304+
msgpack.RegisterExt(errorExtID, (*BoxError)(nil))
305+
}

box_error_test.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"testing"
77

88
"github.com/stretchr/testify/require"
9+
"github.com/vmihailenco/msgpack/v5"
10+
911
. "github.com/tarantool/go-tarantool/v2"
1012
"github.com/tarantool/go-tarantool/v2/test_helpers"
1113
)
@@ -217,7 +219,7 @@ type TupleBoxError struct {
217219
val BoxError
218220
}
219221

220-
func (t *TupleBoxError) EncodeMsgpack(e *encoder) error {
222+
func (t *TupleBoxError) EncodeMsgpack(e *msgpack.Encoder) error {
221223
if err := e.EncodeArrayLen(2); err != nil {
222224
return err
223225
}
@@ -229,7 +231,7 @@ func (t *TupleBoxError) EncodeMsgpack(e *encoder) error {
229231
return e.Encode(&t.val)
230232
}
231233

232-
func (t *TupleBoxError) DecodeMsgpack(d *decoder) error {
234+
func (t *TupleBoxError) DecodeMsgpack(d *msgpack.Decoder) error {
233235
var err error
234236
var l int
235237
if l, err = d.DecodeArrayLen(); err != nil {
@@ -278,11 +280,11 @@ var tupleCases = map[string]struct {
278280
func TestErrorTypeMPEncodeDecode(t *testing.T) {
279281
for name, testcase := range tupleCases {
280282
t.Run(name, func(t *testing.T) {
281-
buf, err := marshal(&testcase.tuple)
283+
buf, err := msgpack.Marshal(&testcase.tuple)
282284
require.Nil(t, err)
283285

284286
var res TupleBoxError
285-
err = unmarshal(buf, &res)
287+
err = msgpack.Unmarshal(buf, &res)
286288
require.Nil(t, err)
287289

288290
require.Equal(t, testcase.tuple, res)
@@ -302,9 +304,9 @@ func TestErrorTypeEval(t *testing.T) {
302304
require.Nil(t, err)
303305
require.NotNil(t, resp.Data)
304306
require.Equal(t, len(resp.Data), 1)
305-
actual, ok := toBoxError(resp.Data[0])
307+
actual, ok := resp.Data[0].(*BoxError)
306308
require.Truef(t, ok, "Response data has valid type")
307-
require.Equal(t, testcase.tuple.val, actual)
309+
require.Equal(t, testcase.tuple.val, *actual)
308310
})
309311
}
310312
}
@@ -440,14 +442,13 @@ func TestErrorTypeSelect(t *testing.T) {
440442
tpl, ok := resp.Data[0].([]interface{})
441443
require.Truef(t, ok, "Tuple has valid type")
442444
require.Equal(t, testcase.tuple.pk, tpl[0])
443-
var actual BoxError
444-
actual, ok = toBoxError(tpl[1])
445+
actual, ok := tpl[1].(*BoxError)
445446
require.Truef(t, ok, "BoxError tuple field has valid type")
446447
// In fact, CheckEqualBoxErrors does not check than File and Line
447448
// of connector BoxError are equal to the Tarantool ones
448449
// since they may differ between different Tarantool versions
449450
// and editions.
450-
test_helpers.CheckEqualBoxErrors(t, testcase.tuple.val, actual)
451+
test_helpers.CheckEqualBoxErrors(t, testcase.tuple.val, *actual)
451452
})
452453
}
453454
}

client_tools.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package tarantool
22

3+
import (
4+
"github.com/vmihailenco/msgpack/v5"
5+
)
6+
37
// IntKey is utility type for passing integer key to Select*, Update*,
48
// Delete* and GetTyped. It serializes to array with single integer element.
59
type IntKey struct {
610
I int
711
}
812

9-
func (k IntKey) EncodeMsgpack(enc *encoder) error {
13+
func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
1014
enc.EncodeArrayLen(1)
11-
encodeInt(enc, int64(k.I))
15+
enc.EncodeInt(int64(k.I))
1216
return nil
1317
}
1418

@@ -19,9 +23,9 @@ type UintKey struct {
1923
I uint
2024
}
2125

22-
func (k UintKey) EncodeMsgpack(enc *encoder) error {
26+
func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error {
2327
enc.EncodeArrayLen(1)
24-
encodeUint(enc, uint64(k.I))
28+
enc.EncodeUint(uint64(k.I))
2529
return nil
2630
}
2731

@@ -31,7 +35,7 @@ type StringKey struct {
3135
S string
3236
}
3337

34-
func (k StringKey) EncodeMsgpack(enc *encoder) error {
38+
func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error {
3539
enc.EncodeArrayLen(1)
3640
enc.EncodeString(k.S)
3741
return nil
@@ -43,10 +47,10 @@ type IntIntKey struct {
4347
I1, I2 int
4448
}
4549

46-
func (k IntIntKey) EncodeMsgpack(enc *encoder) error {
50+
func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
4751
enc.EncodeArrayLen(2)
48-
encodeInt(enc, int64(k.I1))
49-
encodeInt(enc, int64(k.I2))
52+
enc.EncodeInt(int64(k.I1))
53+
enc.EncodeInt(int64(k.I2))
5054
return nil
5155
}
5256

@@ -57,10 +61,10 @@ type Op struct {
5761
Arg interface{}
5862
}
5963

60-
func (o Op) EncodeMsgpack(enc *encoder) error {
64+
func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error {
6165
enc.EncodeArrayLen(3)
6266
enc.EncodeString(o.Op)
63-
encodeInt(enc, int64(o.Field))
67+
enc.EncodeInt(int64(o.Field))
6468
return enc.Encode(o.Arg)
6569
}
6670

@@ -145,12 +149,12 @@ type OpSplice struct {
145149
Replace string
146150
}
147151

148-
func (o OpSplice) EncodeMsgpack(enc *encoder) error {
152+
func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error {
149153
enc.EncodeArrayLen(5)
150154
enc.EncodeString(o.Op)
151-
encodeInt(enc, int64(o.Field))
152-
encodeInt(enc, int64(o.Pos))
153-
encodeInt(enc, int64(o.Len))
155+
enc.EncodeInt(int64(o.Field))
156+
enc.EncodeInt(int64(o.Pos))
157+
enc.EncodeInt(int64(o.Len))
154158
enc.EncodeString(o.Replace)
155159
return nil
156160
}

0 commit comments

Comments
 (0)