This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement new test framework with real tarantools
* build vshard cluster * bootstrap cluster by lua vshard router * run go tests over vshard cluster
- Loading branch information
1 parent
ea5470b
commit 24d580b
Showing
9 changed files
with
633 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
NREPLICASETS?=5 | ||
START_PORT?=33000 | ||
|
||
default: run | ||
|
||
all: default | ||
|
||
run: | clean cluster-up bootstrap gotest cluster-down | ||
|
||
clean: | ||
@echo "STAGE: CLEANUP" | ||
rm -rf tmp | ||
|
||
cluster-up: | ||
@echo "STAGE: STORAGE UP" | ||
mkdir -p tmp | ||
export TT_BACKGROUND=true | ||
export TT_LOG=/dev/null | ||
export NREPLICASETS=${NREPLICASETS} | ||
export START_PORT=${START_PORT} | ||
rsid=1 ; while [[ $$rsid -le ${NREPLICASETS} ]] ; do \ | ||
mkdir -p tmp/$${rsid}/master; \ | ||
mkdir -p tmp/$${rsid}/follower; \ | ||
ln -sf `(pwd)`/storage.lua tmp/$${rsid}/master/storage_$${rsid}_master.lua; \ | ||
ln -sf `(pwd)`/cfgmaker.lua tmp/$${rsid}/master/cfgmaker.lua; \ | ||
ln -sf `(pwd)`/storage.lua tmp/$${rsid}/follower/storage_$${rsid}_follower.lua; \ | ||
ln -sf `(pwd)`/cfgmaker.lua tmp/$${rsid}/follower/cfgmaker.lua; \ | ||
TT_WORK_DIR=tmp/$${rsid}/master/ TT_PID_FILE="tarantool.pid" TT_BACKGROUND=true START_PORT=${START_PORT} TT_LOG=/dev/null NREPLICASETS=${NREPLICASETS} tarantool tmp/$${rsid}/master/storage_$${rsid}_master.lua; \ | ||
TT_WORK_DIR=tmp/$${rsid}/follower/ TT_PID_FILE="tarantool.pid" TT_BACKGROUND=true START_PORT=${START_PORT} TT_LOG=/dev/null NREPLICASETS=${NREPLICASETS} tarantool tmp/$${rsid}/follower/storage_$${rsid}_follower.lua; \ | ||
((rsid = rsid + 1)) ; \ | ||
done | ||
|
||
bootstrap: | ||
@echo "STAGE: BOOTSTRAP CLUSTER" | ||
mkdir -p tmp/router_work_dir | ||
TT_WORK_DIR=tmp/router_work_dir/ NREPLICASETS=${NREPLICASETS} START_PORT=${START_PORT} tarantool router.lua | ||
|
||
cluster-down: | ||
rsid=1 ; while [[ $$rsid -le ${NREPLICASETS} ]] ; do \ | ||
kill -9 `cat tmp/$${rsid}/master/tarantool.pid`; \ | ||
kill -9 `cat tmp/$${rsid}/follower/tarantool.pid`; \ | ||
((rsid = rsid + 1)) ; \ | ||
done | ||
|
||
gotest: | ||
@echo "STAGE: RUN GOTESTS" | ||
-NREPLICASETS=${NREPLICASETS} START_PORT=${START_PORT} go test -race -parallel=20 -timeout=90s |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package tnt_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
vshardrouter "github.com/KaymeKaydex/go-vshard-router" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type cfgmaker struct { | ||
startPort int | ||
nreplicasets int | ||
} | ||
|
||
func (c cfgmaker) getUUID(rsID int, n int) uuid.UUID { | ||
const uuidTemplate = "00000000-0000-%04d-%04d-000000000000" | ||
|
||
uuidStr := fmt.Sprintf(uuidTemplate, rsID, n) | ||
|
||
uuid, err := uuid.Parse(uuidStr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return uuid | ||
} | ||
|
||
func (c cfgmaker) replicasetUUID(rsID int) uuid.UUID { | ||
return c.getUUID(rsID, 0) | ||
} | ||
|
||
func (c cfgmaker) masterUUID(rsID int) uuid.UUID { | ||
return c.getUUID(rsID, 1) | ||
} | ||
|
||
func (c cfgmaker) followerUUID(rsID int) uuid.UUID { | ||
return c.getUUID(rsID, 2) | ||
} | ||
|
||
func (c cfgmaker) getInstanceAddr(port int) string { | ||
const addrTemplate = "127.0.0.1:%d" | ||
|
||
return fmt.Sprintf(addrTemplate, port) | ||
} | ||
|
||
func (c cfgmaker) masterAddr(rsID int) string { | ||
port := c.startPort + 2*(rsID-1) | ||
return c.getInstanceAddr(port) | ||
} | ||
|
||
func (c cfgmaker) followerAddr(rsID int) string { | ||
port := c.startPort + 2*(rsID-1) + 1 | ||
return c.getInstanceAddr(port) | ||
} | ||
|
||
func (c cfgmaker) clusterCfg() map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo { | ||
cfg := make(map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo) | ||
|
||
for rsID := 1; rsID <= c.nreplicasets; rsID++ { | ||
cfg[vshardrouter.ReplicasetInfo{ | ||
Name: fmt.Sprintf("replicaset_%d", rsID), | ||
UUID: c.replicasetUUID(rsID), | ||
}] = []vshardrouter.InstanceInfo{{ | ||
Addr: c.masterAddr(rsID), | ||
UUID: c.masterUUID(rsID), | ||
}, { | ||
Addr: c.followerAddr(rsID), | ||
UUID: c.followerUUID(rsID), | ||
}} | ||
} | ||
|
||
return cfg | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/usr/bin/env tarantool | ||
|
||
require('strict').on() | ||
|
||
local config_example = { | ||
sharding = { | ||
['cbf06940-0790-498b-948d-042b62cf3d29'] = { -- replicaset #1 | ||
replicas = { | ||
['8a274925-a26d-47fc-9e1b-af88ce939412'] = { | ||
uri = 'storage:storage@127.0.0.1:3301', | ||
name = 'storage_1_a', | ||
master = true | ||
}, | ||
['3de2e3e1-9ebe-4d0d-abb1-26d301b84633'] = { | ||
uri = 'storage:storage@127.0.0.1:3302', | ||
name = 'storage_1_b' | ||
} | ||
}, | ||
}, -- replicaset #1 | ||
['ac522f65-aa94-4134-9f64-51ee384f1a54'] = { -- replicaset #2 | ||
replicas = { | ||
['1e02ae8a-afc0-4e91-ba34-843a356b8ed7'] = { | ||
uri = 'storage:storage@127.0.0.1:3303', | ||
name = 'storage_2_a', | ||
master = true | ||
}, | ||
['001688c3-66f8-4a31-8e19-036c17d489c2'] = { | ||
uri = 'storage:storage@127.0.0.1:3304', | ||
name = 'storage_2_b' | ||
} | ||
}, | ||
}, -- replicaset #2 | ||
}, -- sharding | ||
replication_connect_quorum = 0, | ||
} | ||
|
||
local uuid_template = "00000000-0000-%04d-%04d-000000000000" | ||
|
||
local function replicaset_uuid(rs_id) | ||
return string.format(uuid_template, rs_id, 0) | ||
end | ||
|
||
local function master_replica_uuid(rs_id) | ||
return string.format(uuid_template, rs_id, 1) | ||
end | ||
|
||
local function follower_replica_uuid(rs_id) | ||
return string.format(uuid_template, rs_id, 2) | ||
end | ||
|
||
local function master_replica_name(rs_id) | ||
return string.format("storage_%d_master", rs_id) | ||
end | ||
|
||
local function follower_replica_name(rs_id) | ||
return string.format("storage_%d_follower", rs_id) | ||
end | ||
|
||
local function replica_cfg(start_port, rs_id, is_master) | ||
local uri_template = 'storage:storage@127.0.0.1:%d' | ||
local port, name | ||
if is_master then | ||
port = start_port + 2 * (rs_id - 1) -- multiple to 2 because there are 2 instances per replicaset | ||
name = master_replica_name(rs_id) | ||
else | ||
port = start_port + 2 * (rs_id - 1) + 1 | ||
name = follower_replica_name(rs_id) | ||
end | ||
|
||
return { | ||
uri = string.format(uri_template, port), | ||
name = name, | ||
master = is_master, | ||
} | ||
end | ||
|
||
local function master_replica_cfg(start_port, rs_id) | ||
return replica_cfg(start_port, rs_id, true) | ||
end | ||
|
||
local function follower_replica_cfg(start_port, rs_id) | ||
return replica_cfg(start_port, rs_id, false) | ||
end | ||
|
||
local function clustercfg(start_port, nreplicasets) | ||
local cfg = { | ||
sharding = {}, | ||
replication_connect_quorum = 0, | ||
} | ||
|
||
for rs_id = 1, nreplicasets do | ||
local master_uuid = master_replica_uuid(rs_id) | ||
local follower_uuid = follower_replica_uuid(rs_id) | ||
|
||
local replicas = { | ||
[master_uuid] = master_replica_cfg(start_port, rs_id), | ||
[follower_uuid] = follower_replica_cfg(start_port, rs_id), | ||
} | ||
|
||
local rs_uuid = replicaset_uuid(rs_id) | ||
|
||
cfg.sharding[rs_uuid] = { | ||
replicas = replicas, | ||
} | ||
end | ||
|
||
return cfg | ||
end | ||
|
||
return { | ||
clustercfg = clustercfg, | ||
master_uuid = master_replica_uuid, | ||
follower_uuid = follower_replica_uuid, | ||
} |
Oops, something went wrong.