Skip to content

Commit e9b9ba1

Browse files
committed
connection-pool: implement connection pool with 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 f388f6d commit e9b9ba1

13 files changed

+3050
-5
lines changed

CHANGELOG.md

+1
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

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ deps: clean
1414
test:
1515
go test ./... -v -p 1
1616

17+
.PHONY: test-connection-pool
18+
test-connection-pool:
19+
@echo "Running tests in connection_pool package"
20+
go clean -testcache
21+
go test ./connection_pool/ -v -p 1
22+
1723
.PHONY: test-multi
1824
test-multi:
1925
@echo "Running tests in multiconnection package"

connection_pool/config.lua

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
local function simple_incr(a)
27+
return a + 1
28+
end
29+
30+
rawset(_G, 'simple_incr', simple_incr)
31+
32+
-- Set listen only when every other thing is configured.
33+
box.cfg{
34+
listen = os.getenv("TEST_TNT_LISTEN"),
35+
}

0 commit comments

Comments
 (0)