|
| 1 | +# Migration guide |
| 2 | + |
| 3 | +## Migration from v1.x.x to v2.x.x |
| 4 | + |
| 5 | +* [Major changes](#major-changes) |
| 6 | +* [Main package](#main-package) |
| 7 | + * [Go version](#go-version) |
| 8 | + * [msgpack/v5](#msgpackv5) |
| 9 | + * [Call = Call17](#call--call17) |
| 10 | + * [IPROTO constants](#iproto-constants) |
| 11 | + * [Request interface](#request-interface) |
| 12 | + * [Request changes](#request-changes) |
| 13 | + * [Response interface](#response-interface) |
| 14 | + * [Response changes](#response-changes) |
| 15 | + * [Future type](#future-type) |
| 16 | + * [Protocol types](#protocol-types) |
| 17 | + * [Connector interface](#connector-interface) |
| 18 | + * [Connect function](#connect-function) |
| 19 | + * [Connection schema](#connection-schema) |
| 20 | + * [Schema type](#schema-type) |
| 21 | +* [datetime package](#datetime-package) |
| 22 | +* [decimal package](#decimal-package) |
| 23 | +* [multi package](#multi-package) |
| 24 | +* [pool package](#pool-package) |
| 25 | +* [crud package](#crud-package) |
| 26 | +* [test_helpers package](#test_helpers-package) |
| 27 | + |
| 28 | +### Major changes |
| 29 | + |
| 30 | +* The `go_tarantool_call_17` build tag is no longer needed, since by default |
| 31 | + the `CallRequest` is `Call17Request`. |
| 32 | +* The `go_tarantool_msgpack_v5` build tag is no longer needed, since only the |
| 33 | + `msgpack/v5` library is used. |
| 34 | +* The `go_tarantool_ssl_disable` build tag is no longer needed, since the |
| 35 | + connector is no longer depends on `OpenSSL` by default. You could use the |
| 36 | + external library [go-tlsdialer](https://github.com/tarantool/go-tlsdialer) to |
| 37 | + create a connection with the `ssl` transport. |
| 38 | +* Required Go version is `1.20` now. |
| 39 | +* The `Connect` function became more flexible. It now allows to create a |
| 40 | + connection with cancellation and a custom `Dialer` implementation. |
| 41 | +* It is required to use `Request` implementation types with the `Connection.Do` |
| 42 | + method instead of `Connection.<Request>` methods. |
| 43 | +* The `connection_pool` package renamed to `pool`. |
| 44 | + |
| 45 | +The basic code for the `v1.12.2` release: |
| 46 | +```Go |
| 47 | +package tarantool |
| 48 | + |
| 49 | +import ( |
| 50 | + "fmt" |
| 51 | + |
| 52 | + "github.com/tarantool/go-tarantool" |
| 53 | +) |
| 54 | + |
| 55 | +func main() { |
| 56 | + opts := tarantool.Opts{User: "guest"} |
| 57 | + conn, err := tarantool.Connect("127.0.0.1:3301", opts) |
| 58 | + if err != nil { |
| 59 | + fmt.Println("Connection refused:", err) |
| 60 | + return |
| 61 | + } |
| 62 | + |
| 63 | + resp, err := conn.Insert(999, []interface{}{99999, "BB"}) |
| 64 | + if err != nil { |
| 65 | + fmt.Println("Error:", err) |
| 66 | + fmt.Println("Code:", resp.Code) |
| 67 | + } else { |
| 68 | + fmt.Println("Data:", resp.Data) |
| 69 | + } |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +At now became: |
| 74 | +```Go |
| 75 | +package tarantool |
| 76 | + |
| 77 | +import ( |
| 78 | + "context" |
| 79 | + "fmt" |
| 80 | + "time" |
| 81 | + |
| 82 | + "github.com/tarantool/go-tarantool/v2" |
| 83 | +) |
| 84 | + |
| 85 | +func main() { |
| 86 | + ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 87 | + defer cancel() |
| 88 | + dialer := tarantool.NetDialer{ |
| 89 | + Address: "127.0.0.1:3301", |
| 90 | + User: "guest", |
| 91 | + } |
| 92 | + opts := tarantool.Opts{ |
| 93 | + Timeout: time.Second, |
| 94 | + } |
| 95 | + |
| 96 | + conn, err := tarantool.Connect(ctx, dialer, opts) |
| 97 | + if err != nil { |
| 98 | + fmt.Println("Connection refused:", err) |
| 99 | + return |
| 100 | + } |
| 101 | + |
| 102 | + data, err := conn.Do( |
| 103 | + tarantool.NewInsertRequest(999).Tuple([]interface{}{99999, "BB"})).Get() |
| 104 | + if err != nil { |
| 105 | + fmt.Println("Error:", err) |
| 106 | + } else { |
| 107 | + fmt.Println("Data:", data) |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### Main package |
| 113 | + |
| 114 | +#### Go version |
| 115 | + |
| 116 | +Required Go version is updated from `1.13` to `1.20`. |
| 117 | + |
| 118 | +#### msgpack/v5 |
| 119 | + |
| 120 | +At now the `msgpack/v5` library is used for the `msgpack` encoding/decondig. |
| 121 | + |
| 122 | +Most function names and argument types in `msgpack/v5` and `msgpack.v2` |
| 123 | +have not changed (in our code, we noticed changes in `EncodeInt`, `EncodeUint` |
| 124 | +and `RegisterExt`). But there are a lot of changes in a logic of encoding and |
| 125 | +decoding. On the plus side the migration seems easy, but on the minus side you |
| 126 | +need to be very careful. |
| 127 | + |
| 128 | +First of all, `EncodeInt8`, `EncodeInt16`, `EncodeInt32`, `EncodeInt64` |
| 129 | +and `EncodeUint*` analogues at `msgpack/v5` encode numbers as is without loss of |
| 130 | +type. In `msgpack.v2` the type of a number is reduced to a value. |
| 131 | + |
| 132 | +Secondly, a base decoding function does not convert numbers to `int64` or |
| 133 | +`uint64`. It converts numbers to an exact type defined by MessagePack. The |
| 134 | +change makes manual type conversions much more difficult and can lead to |
| 135 | +runtime errors with an old code. We do not recommend to use type conversions |
| 136 | +and give preference to `*Typed` functions (besides, it's faster). |
| 137 | + |
| 138 | +There are also changes in the logic that can lead to errors in the old code, |
| 139 | +[as example](https://github.com/vmihailenco/msgpack/issues/327). Although in |
| 140 | +`msgpack/v5` some functions for the logic tuning were added (see |
| 141 | +[UseLooseInterfaceDecoding](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#Decoder.UseLooseInterfaceDecoding), [UseCompactInts](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#Encoder.UseCompactInts) etc), it is still impossible |
| 142 | +to achieve full compliance of behavior between `msgpack/v5` and `msgpack.v2`. |
| 143 | +So we don't go this way. We use standard settings if it possible. |
| 144 | + |
| 145 | +#### Call = Call17 |
| 146 | + |
| 147 | +Call requests uses `IPROTO_CALL` instead of `IPROTO_CALL_16`. |
| 148 | + |
| 149 | +So now `Call` = `Call17` and `NewCallRequest` = `NewCall17Request`. A result |
| 150 | +of the requests is an array instead of array of arrays. |
| 151 | + |
| 152 | +#### IPROTO constants |
| 153 | + |
| 154 | +* IPROTO constants have been moved to a separate package [go-iproto](https://github.com/tarantool/go-iproto). |
| 155 | +* `PushCode` constant is removed. To check whether the current response is |
| 156 | + a push response, use `IsPush()` method of the response iterator instead. |
| 157 | +* `ErrorNo` constant is added to indicate that no error has occurred while |
| 158 | + getting the response. It should be used instead of the removed `OkCode`. |
| 159 | + See `ExampleErrorNo`. |
| 160 | + |
| 161 | +#### Request interface |
| 162 | + |
| 163 | +* The method `Code() uint32` replaced by the `Type() iproto.Type`. |
| 164 | +* `Response` method added to the `Request` interface. |
| 165 | + |
| 166 | +#### Request changes |
| 167 | + |
| 168 | +* Requests `Update`, `UpdateAsync`, `UpdateTyped`, `Upsert`, `UpsertAsync` no |
| 169 | +longer accept `ops` argument (operations) as an `interface{}`. `*Operations` |
| 170 | +needs to be passed instead. |
| 171 | +* `Op` struct for update operations made private. |
| 172 | +* Removed `OpSplice` struct. |
| 173 | +* `Operations.Splice` method now accepts 5 arguments instead of 3. |
| 174 | +* `UpdateRequest` and `UpsertRequest` structs no longer accept `interface{}` |
| 175 | +for an `ops` field. `*Operations` needs to be used instead. |
| 176 | + |
| 177 | +#### Response interface |
| 178 | + |
| 179 | +* `Response` is now an interface. |
| 180 | +* Response header stored in a new `Header` struct. It could be accessed via |
| 181 | + `Header()` method. |
| 182 | + |
| 183 | +#### Response changes |
| 184 | + |
| 185 | +* `ResponseIterator` interface now has `IsPush()` method. |
| 186 | + It returns true if the current response is a push response. |
| 187 | +* For each request type, a different response type is created. They all |
| 188 | + implement a `Response` interface. `SelectResponse`, `PrepareResponse`, |
| 189 | + `ExecuteResponse`, `PushResponse` are a part of a public API. |
| 190 | + `Pos()`, `MetaData()`, `SQLInfo()` methods created for them to get specific |
| 191 | + info. Special types of responses are used with special requests. |
| 192 | + |
| 193 | +#### Future type |
| 194 | + |
| 195 | +* Method `Get` now returns response data instead of the actual response. |
| 196 | +* New method `GetResponse` added to get an actual response. |
| 197 | +* `Future` constructors now accept `Request` as their argument. |
| 198 | +* Methods `AppendPush` and `SetResponse` accepts response `Header` and data |
| 199 | + as their arguments. |
| 200 | +* Method `Err` was removed because it was causing improper error handling. You |
| 201 | + You need to check an error from `Get`, `GetTyped` or `GetResponse` with |
| 202 | + an addition check of a value `Response.Header().Error`, see `ExampleErrorNo`. |
| 203 | + |
| 204 | +#### Connector interface |
| 205 | + |
| 206 | +* Operations `Ping`, `Select`, `Insert`, `Replace`, `Delete`, `Update`, |
| 207 | + `Upsert`, `Call`, `Call16`, `Call17`, `Eval`, `Execute` of a `Connector` |
| 208 | + return response data instead of an actual responses. |
| 209 | +* New interface `Doer` is added as a child-interface instead of a `Do` method. |
| 210 | + |
| 211 | +#### Connect function |
| 212 | + |
| 213 | +`connection.Connect` no longer return non-working connection objects. This |
| 214 | +function now does not attempt to reconnect and tries to establish a connection |
| 215 | +only once. Function might be canceled via context. Context accepted as first |
| 216 | +argument, and user may cancel it in process. |
| 217 | + |
| 218 | +Now you need to pass `Dialer` as the second argument instead of URI. |
| 219 | +If you were using a non-SSL connection, you need to create `NetDialer`. |
| 220 | +For SSL-enabled connections, use `OpenSSLDialer` from the |
| 221 | +[go-tlsdialer](https://github.com/tarantool/go-tlsdialer) package. |
| 222 | + |
| 223 | +Please note that the options for creating a connection are now stored in |
| 224 | +corresponding `Dialer`, not in `Opts`. |
| 225 | + |
| 226 | +#### Connection schema |
| 227 | + |
| 228 | +* Removed `Schema` field from the `Connection` struct. Instead, new |
| 229 | + `GetSchema(Doer)` function was added to get the actual connection |
| 230 | + schema on demand. |
| 231 | +* `OverrideSchema(*Schema)` method replaced with the `SetSchema(Schema)`. |
| 232 | + |
| 233 | +#### Protocol types |
| 234 | + |
| 235 | +* `iproto.Feature` type used instead of `ProtocolFeature`. |
| 236 | +* `iproto.IPROTO_FEATURE_` constants used instead of local ones. |
| 237 | + |
| 238 | +#### Schema type |
| 239 | + |
| 240 | +* `ResolveSpaceIndex` function for `SchemaResolver` interface split into two: |
| 241 | +`ResolveSpace` and `ResolveIndex`. `NamesUseSupported` function added into the |
| 242 | +interface to get information if the usage of space and index names in requests |
| 243 | +is supported. |
| 244 | +* `Schema` structure no longer implements `SchemaResolver` interface. |
| 245 | +* `Spaces` and `SpacesById` fields of the `Schema` struct store spaces by value. |
| 246 | +* `Fields` and `FieldsById` fields of the `Space` struct store fields by value. |
| 247 | +`Index` and `IndexById` fields of the `Space` struct store indexes by value. |
| 248 | +* `Fields` field of the `Index` struct store `IndexField` by value. |
| 249 | + |
| 250 | +### datetime package |
| 251 | + |
| 252 | +Now you need to use objects of the Datetime type instead of pointers to it. A |
| 253 | +new constructor `MakeDatetime` returns an object. `NewDatetime` has been |
| 254 | +removed. |
| 255 | + |
| 256 | +### decimal package |
| 257 | + |
| 258 | +Now you need to use objects of the Decimal type instead of pointers to it. A |
| 259 | +new constructor `MakeDecimal` returns an object. `NewDecimal` has been removed. |
| 260 | + |
| 261 | +### multi package |
| 262 | + |
| 263 | +The subpackage has been deleted. You could use `pool` instead. |
| 264 | + |
| 265 | +### pool package |
| 266 | + |
| 267 | +* The `connection_pool` subpackage has been renamed to `pool`. |
| 268 | +* The type `PoolOpts` has been renamed to `Opts`. |
| 269 | +* `pool.Connect` and `pool.ConnectWithOpts` now accept context as the first |
| 270 | + argument, which user may cancel in process. If it is canceled in progress, |
| 271 | + an error will be returned and all created connections will be closed. |
| 272 | +* `pool.Connect` and `pool.ConnectWithOpts` now accept `[]pool.Instance` as |
| 273 | + the second argument instead of a list of addresses. Each instance is |
| 274 | + associated with a unique string name, `Dialer` and connection options which |
| 275 | + allows instances to be independently configured. |
| 276 | +* `pool.Connect`, `pool.ConnectWithOpts` and `pool.Add` add instances into |
| 277 | + the pool even it is unable to connect to it. The pool will try to connect to |
| 278 | + the instance later. |
| 279 | +* `pool.Add` now accepts context as the first argument, which user may cancel |
| 280 | + in process. |
| 281 | +* `pool.Add` now accepts `pool.Instance` as the second argument instead of |
| 282 | + an address, it allows to configure a new instance more flexible. |
| 283 | +* `pool.GetPoolInfo` has been renamed to `pool.GetInfo`. Return type has been |
| 284 | + changed to `map[string]ConnectionInfo`. |
| 285 | +* Operations `Ping`, `Select`, `Insert`, `Replace`, `Delete`, `Update`, `Upsert`, |
| 286 | + `Call`, `Call16`, `Call17`, `Eval`, `Execute` of a `Pooler` return |
| 287 | + response data instead of an actual responses. |
| 288 | + |
| 289 | +### crud package |
| 290 | + |
| 291 | +* `crud` operations `Timeout` option has `crud.OptFloat64` type |
| 292 | + instead of `crud.OptUint`. |
| 293 | +* A slice of a custom type could be used as tuples for `ReplaceManyRequest` and |
| 294 | + `InsertManyRequest`, `ReplaceObjectManyRequest`. |
| 295 | +* A slice of a custom type could be used as objects for `ReplaceObjectManyRequest` |
| 296 | + and `InsertObjectManyRequest`. |
| 297 | + |
| 298 | +### test_helpers package |
| 299 | + |
| 300 | +* Renamed `StrangerResponse` to `MockResponse`. |
0 commit comments