forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: support iproto feature discovery
Since version 2.10.0 Tarantool supports feature discovery [1]. Client can send the schema version and supported features and receive server-side schema version and supported features information to tune its behavior. After this patch, the request will be send on `Connect`. Connector stores server info in connection internals. After that, user may call `IsProtocolVersionSupported` and `IsProtocolFeatureSupported` handles to check if it is possible to use a feature. `IsProtocolFeatureSupported` iterates over lists to check if feature is enabled. It seems that iterating over a small list is way faster than building a map, see [3]. Benchmark tests show that this check is rather fast (0.5 ns on HP ProBook 440 G5) so it is not necessary to cache it in any way. Traces of IPROTO_FEATURE_GRACEFUL_SHUTDOWN flag and protocol version 4 could be found in Tarantool source code but they were removed in the following commits before the release and treated like they never existed. We also ignore them here too. See [2] for more info. 1. tarantool/tarantool#6253 2. tarantool/tarantool-python#262 3. https://stackoverflow.com/a/52710077/11646599 Closes #120
- Loading branch information
1 parent
48cf0c7
commit 6afeb6a
Showing
8 changed files
with
283 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tarantool | ||
|
||
type ProtocolVersion uint64 | ||
type ProtocolFeature uint64 | ||
|
||
type protocolInfo struct { | ||
version ProtocolVersion | ||
features []ProtocolFeature | ||
} | ||
|
||
const ProtocolVersionUnsupported ProtocolVersion = 0 | ||
|
||
const ( | ||
// Streams support. | ||
ProtocolFeatureStreams ProtocolFeature = 0 | ||
// Interactive tranactions support. | ||
ProtocolFeatureTransactions ProtocolFeature = 1 | ||
// Support of MP_ERROR object over MessagePack. | ||
ProtocolFeatureErrorExtension ProtocolFeature = 2 | ||
// Support of watchers. | ||
ProtocolFeatureWatchers ProtocolFeature = 3 | ||
) | ||
|
||
// Protocol version supported by connector. Version 3 | ||
// was introduced in Tarantool 2.10.0 and used in latest 2.10.4. | ||
const ClientProtocolVersion ProtocolVersion = 3 | ||
|
||
// Protocol features supported by connector. | ||
var ClientProtocolFeatures = []ProtocolFeature{ | ||
ProtocolFeatureStreams, | ||
ProtocolFeatureTransactions, | ||
} | ||
|
||
func isFeatureSupported(feature ProtocolFeature, supportedFeatures []ProtocolFeature) bool { | ||
// It seems that iterating over a small list is way faster | ||
// than building a map: https://stackoverflow.com/a/52710077/11646599 | ||
for _, supportedFeature := range supportedFeatures { | ||
if feature == supportedFeature { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters