Skip to content

Commit

Permalink
connection-pool: implement connection pool with master discovery
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AnaNek committed Apr 25, 2022
1 parent f388f6d commit e9b9ba1
Show file tree
Hide file tree
Showing 13 changed files with 3,050 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- Support UUID type in msgpack (#90)
- Go modules support (#91)
- queue-utube handling (#85)
- Master discovery (#113)

### Fixed

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ deps: clean
test:
go test ./... -v -p 1

.PHONY: test-connection-pool
test-connection-pool:
@echo "Running tests in connection_pool package"
go clean -testcache
go test ./connection_pool/ -v -p 1

.PHONY: test-multi
test-multi:
@echo "Running tests in multiconnection package"
Expand Down
35 changes: 35 additions & 0 deletions connection_pool/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Do not set listen for now so connector won't be
-- able to send requests until everything is configured.
box.cfg{
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
}

box.once("init", function()
box.schema.user.create('test', { password = 'test' })
box.schema.user.grant('test', 'read,write,execute', 'universe')

local s = box.schema.space.create('testPool', {
id = 520,
if_not_exists = true,
format = {
{name = "key", type = "string"},
{name = "value", type = "string"},
},
})
s:create_index('pk', {
type = 'tree',
parts = {{ field = 1, type = 'string' }},
if_not_exists = true
})
end)

local function simple_incr(a)
return a + 1
end

rawset(_G, 'simple_incr', simple_incr)

-- Set listen only when every other thing is configured.
box.cfg{
listen = os.getenv("TEST_TNT_LISTEN"),
}
Loading

0 comments on commit e9b9ba1

Please sign in to comment.