Skip to content

Instantly share code, notes, and snippets.

@R-omk
Created October 4, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R-omk/163950ced360dd3321ef5acc9a0053ed to your computer and use it in GitHub Desktop.
Save R-omk/163950ced360dd3321ef5acc9a0053ed to your computer and use it in GitHub Desktop.
docker swarm tarantool test cluster
-- other options setup in tarantool-entrypoint.lua see: https://github.com/tarantool/docker
box.cfg {
log_level = tonumber(os.getenv("TARANTOOL_LOG_LEVEL"));
replicaset_uuid = os.getenv("TARANTOOL_REPLICASET_UUID");
instance_uuid = os.getenv("TARANTOOL_INSTANCE_UUID");
memtx_max_tuple_size = 1048576 + 200;
force_recovery = true;
checkpoint_interval = 30;
checkpoint_count = 3;
}
local log = require("log")
local fiber = require("fiber")
log.info("Info version %s", box.info.version)
log.info("box.info.id %s", box.info.id)
box.once(
"schema",
function()
box.schema.space.create("test")
box.space.test:create_index("primary", {unique = true, parts = {1, "integer"}})
end
)
local testspace = box.space.test
fiber_test_sleep = 0
fiber_test =
fiber.create(
function()
while true do
local status, call_res =
pcall(
function()
local t = fiber.time64();
testspace:upsert({box.info.id, t}, {{"=", 2, t}})
end
)
if not status then
log.warn("call_res err %s", call_res)
end
fiber.testcancel()
fiber.sleep(fiber_test_sleep)
-- fiber.yield()
end
end
)
version: '3.7'
x-tarantool-env: &tarantool-env
TARANTOOL_REPLICATION_SOURCE: master@tarantool1:3301,master@tarantool2:3301,master@tarantool3:3301
TARANTOOL_MEMTX_MEMORY: 1073741824
TARANTOOL_USER_NAME: master
x-tarantool: &tarantool
image: tarantool/tarantool:1.9.2
environment:
<<: *tarantool-env
deploy:
replicas: 1
endpoint_mode: dnsrr
restart_policy:
condition: on-failure
healthcheck:
disable: true
command: [ "tarantool" , "/opt/tarantool/app.lua"]
networks:
- tnt_cluster
services:
tarantool1:
<<: *tarantool
volumes:
- ./app.lua:/opt/tarantool/app.lua
- tarantool1_cfg:/etc/tarantool/
- tarantool1_data:/var/lib/tarantool
tarantool2:
<<: *tarantool
volumes:
- ./app.lua:/opt/tarantool/app.lua
- tarantool2_cfg:/etc/tarantool/
- tarantool2_data:/var/lib/tarantool
tarantool3:
<<: *tarantool
volumes:
- ./app.lua:/opt/tarantool/app.lua
- tarantool3_cfg:/etc/tarantool/
- tarantool3_data:/var/lib/tarantool
networks:
tnt_cluster:
volumes:
tarantool1_cfg:
tarantool1_data:
tarantool2_cfg:
tarantool2_data:
tarantool3_cfg:
tarantool3_data:
@R-omk
Copy link
Author

R-omk commented Oct 4, 2018

#install docker
#install docker compose 


docker swarm init 

cd /tmp
#clone this gist
git clone https://gist.github.com/163950ced360dd3321ef5acc9a0053ed.git tnt_swarm_test
cd tnt_swarm_test

#deploy cluster
docker stack deploy --compose-file docker-compose.yml  tnt_bug


#show containers 
docker ps  -a -f "is-task=true"  -f "label=com.docker.stack.namespace=tnt_bug"

# go to tarantool console and look  state
exec  -it <ID FROM PREVIOUS COMMAND> console

# runt in tarantool console
# > box.info

# ctrl + c

#show logs 
docker service logs  tnt_bug_tarantool1  2>&1 | less 
docker service logs  tnt_bug_tarantool2  2>&1 | less 
docker service logs  tnt_bug_tarantool3  2>&1 | less 


#cleanup cluster
docker stack rm   tnt_bug
docker wait $(docker ps -a -f "is-task=true"  -f "label=com.docker.stack.namespace=tnt_bug" -q) 
docker rm $(docker ps -a -f "is-task=true"  -f "label=com.docker.stack.namespace=tnt_bug" -q)
docker volume rm $(docker volume ls -q -f "label=com.docker.stack.namespace=tnt_bug")
# can rerun deploy cluster

after some time
box.info can show something like

---
- version: 1.9.2-0-g113ade24e
  id: 3
  ro: false
  vinyl: []
  vclock: {1: 639876, 2: 423748, 3: 19947810}
  uptime: 669
  lsn: 19947810
  memory: []
  cluster:
    uuid: 1f1e66e3-eb21-4716-b2c3-98575784f022
  pid: 1
  status: running
  signature: 21011434
  replication:
    1:
      id: 1
      uuid: 278c02ca-d1aa-4f65-ab24-7cc15151c770
      lsn: 639876
      upstream:
        peer: master@tarantool2:3301
        lag: 17.504976272583
        status: stopped
        idle: 621.15813
        message: Invalid MsgPack - packet body
    2:
      id: 2
      uuid: 460ec362-3b82-4d91-98a7-10d5fbe69907
      lsn: 423748
      upstream:
        peer: master@tarantool1:3301
        lag: 14.004667520523
        status: stopped
        idle: 620.64983493392
        message: Invalid MsgPack - packet body
    3:
      id: 3
      uuid: b0489307-ce3a-46a4-8ddd-5124d70d5436
      lsn: 19947810
  uuid: b0489307-ce3a-46a4-8ddd-5124d70d5436
...

where message can be

message: Invalid MsgPack - packet body
message: Invalid MsgPack - packet header
message: Missing mandatory field 'tuple' in request

and logs like

relay/10.0.68.4:48630/101/main recovery.cc:228 E> can't apply row: 
relay/10.0.68.4:48630/101/main I> fiber `main' has been cancelled
relay/10.0.68.4:48630/101/main I> fiber `main': exiting

--

 main/113/applierw/master@tarantool3:3301 sio.cc:303 !> SystemError writev(2), called on fd 18, aka 10.0.68.4:33766: Connection reset by peer
 main/106/applier/master@tarantool3:3301 I> can't read row
 main/106/applier/master@tarantool3:3301 coio.cc:368 !> SystemError unexpected EOF when reading from socket, called on fd 18, aka 10.0.68.4:33766: Broken pipe
 main/106/applier/master@tarantool3:3301 I> will retry every 1.00 second
 main/104/applier/master@tarantool1:3301 I> can't read row
 main/104/applier/master@tarantool1:3301 xrow.c:54 E> ER_INVALID_MSGPACK: Invalid MsgPack - packet header
 main/106/applier/master@tarantool3:3301 I> authenticated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment