Created
May 21, 2019 15:52
-
-
Save bofm/c7da0a1b57267ea151a32cdd0548b23d to your computer and use it in GitHub Desktop.
tarantool vshard gh-181
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
local M = {} | |
local vshard = require('vshard') | |
local fiber = require('fiber') | |
local log = require('log') | |
local digest = require('digest') | |
local json = require('json') | |
local cfg = { | |
bucket_count = 10000, | |
rebalancer_disbalance_threshold = 10, | |
rebalancer_max_receiving = 100, | |
sharding = { | |
['aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'] = { | |
replicas = { | |
['aaaaaaaa-aaaa-aaaa-aaaa-000000000001'] = { | |
uri = 'storage:storage@t1:3301', | |
name = 't1', | |
master = true | |
}, | |
['aaaaaaaa-aaaa-aaaa-aaaa-000000000002'] = { | |
uri = 'storage:storage@t2:3301', | |
name = 't2', | |
master = false | |
} | |
}, | |
weight = 100, | |
}, | |
['bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'] = { | |
replicas = { | |
['bbbbbbbb-bbbb-bbbb-bbbb-000000000001'] = { | |
uri = 'storage:storage@t3:3301', | |
name = 't3', | |
master = true | |
}, | |
['bbbbbbbb-bbbb-bbbb-bbbb-000000000002'] = { | |
uri = 'storage:storage@t4:3301', | |
name = 't4', | |
master = false | |
} | |
}, | |
weight = 100, | |
}, | |
}, | |
-- weights = ... -- See details below. | |
} | |
local function init_schema() | |
box.once('guest', box.schema.user.grant, 'guest', 'super') | |
box.once('schema:v1', function() | |
local s = box.schema.space.create('test') | |
s:format({ | |
{'id', 'unsigned'}, | |
{'bucket_id', 'unsigned'}, | |
{'data', 'string'}, | |
}) | |
s:create_index('pk') | |
s:create_index('bucket_id', {parts = {'bucket_id'}, unique = false}) | |
box.snapshot() | |
end) | |
end | |
local function init() | |
init_schema() | |
end | |
local function sput(i, k, v) | |
return box.space.test:put{k, i, v} | |
end | |
local function sget(k) | |
return box.space.test:get(k) | |
end | |
local function put(k, v) | |
local bucket_id = vshard.router.bucket_id(k) | |
return vshard.router.callrw(bucket_id, 'app.sput', {bucket_id, k, v}, {timeout = 0.2}) | |
end | |
local function get(k) | |
local bucket_id = vshard.router.bucket_id(k) | |
local t = vshard.router.callrw(bucket_id, 'app.sget', {k}, {timeout = 0.2}) | |
if t then return t[3] end | |
end | |
return { | |
cfg = cfg, | |
put = put, | |
sput = sput, | |
get = get, | |
sget = sget, | |
init_schema = init_schema, | |
} |
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
version: '3.7' | |
x-common: &common | |
volumes: | |
- ./app.lua:/opt/tarantool/app.lua:ro | |
build: . | |
image: tnt-vshard | |
entrypoint: '' | |
services: | |
t1: | |
<<: *common | |
ports: | |
- '3301:3301' | |
entrypoint: '' | |
hostname: t1 | |
command: | |
- tarantool | |
- '-e' | |
- | | |
vshard = require('vshard') | |
app = require('app') | |
cfg = app.cfg | |
cfg.listen = '0.0.0.0:3301' | |
vshard.storage.cfg(cfg, 'aaaaaaaa-aaaa-aaaa-aaaa-000000000001') | |
vshard.router.cfg(cfg) | |
app.init_schema() | |
t2: | |
<<: *common | |
hostname: t2 | |
ports: | |
- '3302:3301' | |
command: | |
- tarantool | |
- '-e' | |
- | | |
vshard = require('vshard') | |
app = require('app') | |
cfg = app.cfg | |
cfg.listen = '0.0.0.0:3301' | |
vshard.storage.cfg(cfg, 'aaaaaaaa-aaaa-aaaa-aaaa-000000000002') | |
vshard.router.cfg(cfg) | |
app.init_schema() | |
t3: | |
<<: *common | |
ports: | |
- '3303:3301' | |
hostname: t3 | |
command: | |
- tarantool | |
- '-e' | |
- | | |
vshard = require('vshard') | |
app = require('app') | |
cfg = app.cfg | |
cfg.listen = '0.0.0.0:3301' | |
vshard.storage.cfg(cfg, 'bbbbbbbb-bbbb-bbbb-bbbb-000000000001') | |
vshard.router.cfg(cfg) | |
app.init_schema() | |
t4: | |
<<: *common | |
hostname: t4 | |
ports: | |
- '3304:3301' | |
command: | |
- tarantool | |
- '-e' | |
- | | |
vshard = require('vshard') | |
app = require('app') | |
cfg = app.cfg | |
cfg.listen = '0.0.0.0:3301' | |
vshard.storage.cfg(cfg, 'bbbbbbbb-bbbb-bbbb-bbbb-000000000002') | |
vshard.router.cfg(cfg) | |
app.init_schema() | |
router: | |
<<: *common | |
hostname: router | |
depends_on: | |
- t1 | |
- t2 | |
- t3 | |
- t4 | |
ports: | |
- '3300:3301' | |
command: | |
- tarantool | |
- '-e' | |
- | | |
vshard = require('vshard') | |
yaml = require('yaml') | |
log = require('log') | |
app = require('app') | |
cfg = app.cfg | |
cfg.listen = '0.0.0.0:3301' | |
vshard.router.cfg(cfg) | |
box.once('guest', box.schema.user.grant, 'guest', 'super') | |
do | |
local b, err, info | |
repeat | |
require('fiber').sleep(1) | |
b, err = vshard.router.bootstrap() | |
info = vshard.router.info() | |
until err and err.code == 10 and info.bucket.available_rw == 10000 | |
end | |
vshard.router.callrw(1, 'dostring', {"require('ffi').cast('char *', 0)[0] = 48"}, {timeout=1}) | |
res, err = vshard.router.callrw(1, 'tostring', {1}, {timeout=1}) | |
if err then | |
log.error(yaml.encode({res=res, err=err})) | |
os.exit(1) | |
end |
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
FROM progaudi/tarantool:1.10.2 | |
ENV VSHARD_VERSION=fcb05f7609b5a050781fe79829439e9730cee3ae | |
RUN apk add -U --no-cache git \ | |
&& cd /tmp \ | |
&& git clone https://github.com/tarantool/vshard.git \ | |
&& ( cd vshard && git checkout ${VSHARD_VERSION} ) \ | |
&& mv vshard/vshard /opt/tarantool/vshard \ | |
&& rm -rf vshard | |
ENTRYPOINT "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HOW TO RUN
curl -L https://gist.github.com/bofm/c7da0a1b57267ea151a32cdd0548b23d/archive/72b27f3220f756a651fa21ce4be0f19fd3e27c56.zip -o test.zip && unzip test.zip && cd c* && docker-compose up router