Skip to content

Commit 976f1f5

Browse files
committed
connection_pool: implement connection pool with automatic master discovery
Main features: - Check active connection with configurable time interval and on connection fail switch to next in pool. - Automatic master discovery by `mode` parameter. Additional options (configurable via `ConnectWithOpts`): * `CheckTimeout` - time interval to check for connection timeout and try to switch connection `Mode` parameter: * `RW` (writteable instance (master)) - the request can only be executed on master. * `PREFER_RO` (read only instance (replica)) - if there is one, otherwise fallback to a writteable one (master). * `PREFER_RW` (write only instance (master)) - if there is one, otherwise fallback to a read only one (replica). Closes #113
1 parent 7897baf commit 976f1f5

File tree

11 files changed

+2153
-5
lines changed

11 files changed

+2153
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1616
- Support UUID type in msgpack (#90)
1717
- Go modules support (#91)
1818
- queue-utube handling (#85)
19+
- Master discovery (#113)
1920

2021
### Fixed
2122

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,38 @@ Additional options (configurable via `ConnectWithOpts`):
676676
* `ClusterDiscoveryTime` - time interval to ask server for updated address list (works on with `NodesGetFunctionName` set)
677677
* `NodesGetFunctionName` - server lua function name to call for getting address list
678678

679+
## Connection pool with automatic master discovery
680+
681+
You can use connection pool config with tarantool/connection_pool.
682+
683+
Main features:
684+
685+
- Check active connection with configurable time interval and on connection fail switch to next in pool.
686+
- Automatic master discovery by `mode` parameter.
687+
688+
Additional options (configurable via `ConnectWithOpts`):
689+
690+
* `CheckTimeout` - time interval to check for connection timeout and try to switch connection
691+
692+
`Mode` parameter:
693+
694+
* `RW` (writteable instance (master)) - the request can only be executed on master.
695+
* `PREFER_RO` (read only instance (replica)) - if there is one, otherwise fallback to a writteable one (master).
696+
* `PREFER_RW` (write only instance (master)) - if there is one, otherwise fallback to a read only one (replica).
697+
698+
|Request | Default mode | User mode support |
699+
|---|---|---|
700+
| call | no default | Yes |
701+
| eval | no default | Yes |
702+
| ping | no default | Yes |
703+
| insert | RW | No |
704+
| delete | RW | No |
705+
| replace | RW | No |
706+
| update | RW | No |
707+
| upsert | RW | No |
708+
| select | PreferRO | Yes |
709+
| get | PreferRO | Yes |
710+
679711
## Tests
680712

681713
You need to [install Tarantool](https://www.tarantool.io/en/download/) to run tests.

connection_pool/config.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- Do not set listen for now so connector won't be
2+
-- able to send requests until everything is configured.
3+
box.cfg{
4+
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
5+
}
6+
7+
box.once("init", function()
8+
box.schema.user.create('test', { password = 'test' })
9+
box.schema.user.grant('test', 'read,write,execute', 'universe')
10+
11+
local s = box.schema.space.create('testPool', {
12+
id = 520,
13+
if_not_exists = true,
14+
format = {
15+
{name = "key", type = "string"},
16+
{name = "value", type = "string"},
17+
},
18+
})
19+
s:create_index('pk', {
20+
type = 'tree',
21+
parts = {{ field = 1, type = 'string' }},
22+
if_not_exists = true
23+
})
24+
end)
25+
26+
-- Set listen only when every other thing is configured.
27+
box.cfg{
28+
listen = os.getenv("TEST_TNT_LISTEN"),
29+
}

0 commit comments

Comments
 (0)