forked from Mons/tnt-config
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto step down when ETCD is not reachable
* This patch introduces background fiber config._fencing_f which auto enables on rw nodes and watches ETCD * It is executed after on_after_cfg callback and watches /<prefix>/clusters/<shard-name>/master path in ETCD during etcd.fencing_timeout (default: 10s) * Fiber is enabled only in topology etcd.cluster.master and only if etcd.fencing_enabled flag is specified (in conf.lua or in common config) * Since network drops are indistinguishable from HTTP timeouts after each :wait() time out, fencing rechecks ETCD via :list() method * If nothing changed (99% chance) fiber will try again after fencing_timeout * If another node is specified in ETCD, node will automatically steps down (executes box.cfg{read_only=true}) and will wait to become master * fencing fiber never returns node to be rw (it never calls box.cfg{read_only=false} or package.reload()) * to bring instance back rw you should manually call package.reload() or use switchover.
- Loading branch information
Vladislav Grubov
committed
Jan 17, 2023
1 parent
5c64a4c
commit 78326ef
Showing
9 changed files
with
967 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM tarantool/tarantool:2.10 | ||
RUN apk add --no-cache -u iproute2 make bind-tools | ||
|
||
WORKDIR /opt/tarantool | ||
|
||
CMD ["tarantool" "/opt/tarantool/init.lua"] |
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,19 @@ | ||
etcd = { | ||
instance_name = os.getenv("TT_INSTANCE_NAME"), | ||
prefix = '/instance', | ||
endpoints = {"http://etcd:2379"}, | ||
fencing_enabled = true, | ||
} | ||
|
||
box = { | ||
background = false, | ||
log_level = 6, | ||
log_format = 'plain', | ||
|
||
memtx_dir = '/var/lib/tarantool/snaps/', | ||
wal_dir = '/var/lib/tarantool/xlogs', | ||
} | ||
|
||
app = { | ||
|
||
} |
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,45 @@ | ||
local fiber = require "fiber" | ||
|
||
require 'config' { | ||
mkdir = true, | ||
print_config = true, | ||
instance_name = os.getenv("TT_INSTANCE_NAME"), | ||
file = 'conf.lua', | ||
master_selection_policy = 'etcd.cluster.master', | ||
|
||
on_after_cfg = function() | ||
if not box.info.ro then | ||
box.schema.user.grant('guest', 'super', nil, nil, { if_not_exists = true }) | ||
|
||
box.schema.space.create('T', {if_not_exists = true}) | ||
box.space.T:create_index('I', { if_not_exists = true }) | ||
end | ||
end, | ||
} | ||
|
||
fiber.create(function() | ||
fiber.name('pusher') | ||
|
||
while true do | ||
repeat | ||
pcall(box.ctl.wait_rw, 3) | ||
fiber.testcancel() | ||
until not box.info.ro | ||
|
||
local fibers = {} | ||
for _ = 1, 10 do | ||
local f = fiber.create(function() | ||
fiber.self():set_joinable(true) | ||
for i = 1, 100 do | ||
box.space.T:replace{i, box.info.id, box.info.vclock} | ||
end | ||
end) | ||
table.insert(fibers, f) | ||
end | ||
|
||
for _, f in ipairs(fibers) do | ||
f:join() | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
version: "3" | ||
|
||
x-etcd: &etcd | ||
image: quay.io/coreos/etcd:v2.3.8 | ||
container_name: etcd | ||
networks: | ||
- tarantool | ||
environment: | ||
ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380 | ||
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 | ||
ETCDCTL_API: 2 | ||
ETCD_INITIAL_CLUSTER_TOKEN: etcd-cluster | ||
ETCD_INITIAL_CLUSTER: etcd=http://etcd:2380 | ||
ETCD_NAME: etcd | ||
ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379 | ||
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd:2380 | ||
|
||
x-tt: &tt | ||
build: . | ||
volumes: | ||
- $PWD/../:/opt/tarantool/.rocks/share/tarantool:ro | ||
- $PWD/app:/opt/tarantool | ||
- $PWD/net:/opt/tarantool/net:ro | ||
depends_on: | ||
etcd: | ||
condition: service_started | ||
privileged: true | ||
networks: | ||
- tarantool | ||
command: ["/bin/sh", "-c", "sleep 5 && tarantool /opt/tarantool/init.lua"] | ||
|
||
networks: | ||
tarantool: | ||
name: tt_net | ||
driver: bridge | ||
|
||
services: | ||
etcd: | ||
<<: *etcd | ||
etcd_load: | ||
image: registry.gitlab.com/ochaton/switchover:010a6965 | ||
networks: | ||
- tarantool | ||
volumes: | ||
- $PWD/instance.etcd.yaml:/instance.etcd.yaml:ro | ||
depends_on: | ||
etcd: | ||
condition: service_started | ||
entrypoint: [''] | ||
command: ["/bin/sh", "-c", "sleep 3 && switchover -v -e http://etcd:2379 etcd load / /instance.etcd.yaml"] | ||
instance_01: | ||
<<: *tt | ||
container_name: instance_01 | ||
environment: | ||
TT_INSTANCE_NAME: instance_01 | ||
instance_02: | ||
<<: *tt | ||
container_name: instance_02 | ||
environment: | ||
TT_INSTANCE_NAME: instance_02 |
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,26 @@ | ||
--- | ||
instance: | ||
clusters: | ||
instance: | ||
master: instance_01 | ||
replicaset_uuid: 91157a11-0001-0000-0000-000000000000 | ||
common: | ||
etcd: | ||
fencing_timeout: 5 | ||
fencing_pause: 3 | ||
box: | ||
replication_connect_quorum: 1 | ||
log_level: 5 | ||
memtx_memory: 268435456 | ||
instances: | ||
instance_01: | ||
cluster: instance | ||
box: | ||
instance_uuid: 91157a11-0000-0001-0000-000000000000 | ||
listen: instance_01:3301 | ||
instance_02: | ||
cluster: instance | ||
box: | ||
instance_uuid: 91157a11-0000-0002-0000-000000000000 | ||
listen: instance_02:3302 | ||
... |
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,22 @@ | ||
setup: | ||
tc qdisc add dev eth0 root handle 1: prio | ||
tc qdisc add dev eth0 parent 1:3 handle 10: netem loss 100% | ||
|
||
offline-dport-%: | ||
tc filter add dev eth0 parent 1: protocol ip prio 1 u32 match ip dport $* 0xffff flowid 1:3 | ||
|
||
offline-dst-%: | ||
tc filter add dev eth0 parent 1: protocol ip prio 1 u32 match ip dst $(shell host -T4 $* | cut -f 4 -d' ') flowid 1:3 | ||
|
||
online: | ||
tc filter del dev eth0 parent 1: protocol ip pref 1 u32 | ||
|
||
filter: | ||
tc -s -d filter show dev eth0 | ||
|
||
qdisc: | ||
tc -d -s qdisc show dev eth0 | ||
|
||
clear: | ||
tc fliter del dev eth0 parent 1: | ||
tc qdisc del dev eth0 root |
Oops, something went wrong.