Skip to content

Commit d44850b

Browse files
committed
connection_pool: implement connection pool with automatic master discovery
Main features: - Return available connection from pool according to round-robin strategy. - 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: * `ANY` (use any instance) - the request can be executed on any instance (master or replica). * `RW` (writeable instance (master)) - the request can only be executed on master. * `RO` (read only instance (replica)) - the request can only be executed on replica. * `PREFER_RO` (prefer read only instance (replica)) - if there is one, otherwise fallback to a writeable one (master). * `PREFER_RW` (prefer write only instance (master)) - if there is one, otherwise fallback to a read only one (replica). Closes #113
1 parent 7897baf commit d44850b

File tree

11 files changed

+2477
-5
lines changed

11 files changed

+2477
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,40 @@ 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+
- Return available connection from pool according to round-robin strategy.
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+
* `ANY` (use any instance) - the request can be executed on any instance (master or replica).
695+
* `RW` (writeable instance (master)) - the request can only be executed on master.
696+
* `RO` (read only instance (replica)) - the request can only be executed on replica.
697+
* `PREFER_RO` (prefer read only instance (replica)) - if there is one, otherwise fallback to a writeable one (master).
698+
* `PREFER_RW` (prefer write only instance (master)) - if there is one, otherwise fallback to a read only one (replica).
699+
700+
|Request | Default mode |
701+
|---|---|
702+
| call | no default |
703+
| eval | no default |
704+
| ping | no default |
705+
| insert | RW |
706+
| delete | RW |
707+
| replace | RW |
708+
| update | RW |
709+
| upsert | RW |
710+
| select | ANY |
711+
| get | ANY |
712+
679713
## Tests
680714

681715
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)