Tarantool development patches archive
 help / color / mirror / Atom feed
From: sergeyb@tarantool.org
To: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org,
	sergepetrenko@tarantool.org, gorcunov@gmail.com,
	lvasiliev@tarantool.org
Subject: [Tarantool-patches] [PATCH 3/3] replication: add test with random leaders promotion and demotion
Date: Thu,  9 Jul 2020 20:16:46 +0300	[thread overview]
Message-ID: <b6a0c7b42d71fd263c51d44c96748587092dda1e.1594314820.git.sergeyb@tarantool.org> (raw)
In-Reply-To: <cover.1593472477.git.v.shpilevoy@tarantool.org

From: Sergey Bronnikov <sergeyb@tarantool.org>

Part of #5055
---
 test/replication/qsync.lua                    |  62 ++++++++++
 test/replication/qsync1.lua                   |   1 +
 test/replication/qsync10.lua                  |   1 +
 test/replication/qsync11.lua                  |   1 +
 test/replication/qsync12.lua                  |   1 +
 test/replication/qsync13.lua                  |   1 +
 test/replication/qsync14.lua                  |   1 +
 test/replication/qsync15.lua                  |   1 +
 test/replication/qsync16.lua                  |   1 +
 test/replication/qsync17.lua                  |   1 +
 test/replication/qsync18.lua                  |   1 +
 test/replication/qsync19.lua                  |   1 +
 test/replication/qsync2.lua                   |   1 +
 test/replication/qsync20.lua                  |   1 +
 test/replication/qsync21.lua                  |   1 +
 test/replication/qsync22.lua                  |   1 +
 test/replication/qsync23.lua                  |   1 +
 test/replication/qsync24.lua                  |   1 +
 test/replication/qsync25.lua                  |   1 +
 test/replication/qsync26.lua                  |   1 +
 test/replication/qsync27.lua                  |   1 +
 test/replication/qsync28.lua                  |   1 +
 test/replication/qsync29.lua                  |   1 +
 test/replication/qsync3.lua                   |   1 +
 test/replication/qsync30.lua                  |   1 +
 test/replication/qsync31.lua                  |   1 +
 test/replication/qsync4.lua                   |   1 +
 test/replication/qsync5.lua                   |   1 +
 test/replication/qsync6.lua                   |   1 +
 test/replication/qsync7.lua                   |   1 +
 test/replication/qsync8.lua                   |   1 +
 test/replication/qsync9.lua                   |   1 +
 test/replication/qsync_random_leader.result   | 117 ++++++++++++++++++
 test/replication/qsync_random_leader.test.lua |  52 ++++++++
 34 files changed, 262 insertions(+)
 create mode 100644 test/replication/qsync.lua
 create mode 120000 test/replication/qsync1.lua
 create mode 120000 test/replication/qsync10.lua
 create mode 120000 test/replication/qsync11.lua
 create mode 120000 test/replication/qsync12.lua
 create mode 120000 test/replication/qsync13.lua
 create mode 120000 test/replication/qsync14.lua
 create mode 120000 test/replication/qsync15.lua
 create mode 120000 test/replication/qsync16.lua
 create mode 120000 test/replication/qsync17.lua
 create mode 120000 test/replication/qsync18.lua
 create mode 120000 test/replication/qsync19.lua
 create mode 120000 test/replication/qsync2.lua
 create mode 120000 test/replication/qsync20.lua
 create mode 120000 test/replication/qsync21.lua
 create mode 120000 test/replication/qsync22.lua
 create mode 120000 test/replication/qsync23.lua
 create mode 120000 test/replication/qsync24.lua
 create mode 120000 test/replication/qsync25.lua
 create mode 120000 test/replication/qsync26.lua
 create mode 120000 test/replication/qsync27.lua
 create mode 120000 test/replication/qsync28.lua
 create mode 120000 test/replication/qsync29.lua
 create mode 120000 test/replication/qsync3.lua
 create mode 120000 test/replication/qsync30.lua
 create mode 120000 test/replication/qsync31.lua
 create mode 120000 test/replication/qsync4.lua
 create mode 120000 test/replication/qsync5.lua
 create mode 120000 test/replication/qsync6.lua
 create mode 120000 test/replication/qsync7.lua
 create mode 120000 test/replication/qsync8.lua
 create mode 120000 test/replication/qsync9.lua
 create mode 100644 test/replication/qsync_random_leader.result
 create mode 100644 test/replication/qsync_random_leader.test.lua

diff --git a/test/replication/qsync.lua b/test/replication/qsync.lua
new file mode 100644
index 000000000..383aa5272
--- /dev/null
+++ b/test/replication/qsync.lua
@@ -0,0 +1,62 @@
+#!/usr/bin/env tarantool
+
+-- get instance name from filename (qsync1.lua => qsync1)
+local INSTANCE_ID = string.match(arg[0], "%d")
+
+local SOCKET_DIR = require('fio').cwd()
+
+local TIMEOUT = tonumber(arg[1])
+
+local function instance_uri(instance_id)
+    return SOCKET_DIR..'/qsync'..instance_id..'.sock';
+end
+
+-- start console first
+require('console').listen(os.getenv('ADMIN'))
+
+box.cfg({
+    listen = instance_uri(INSTANCE_ID);
+    replication_timeout = TIMEOUT;
+    replication_sync_lag = 0.01;
+    replication_connect_quorum = 3;
+    replication = {
+        instance_uri(1);
+        instance_uri(2);
+        instance_uri(3);
+        instance_uri(4);
+        instance_uri(5);
+        instance_uri(6);
+        instance_uri(7);
+        instance_uri(8);
+        instance_uri(9);
+        instance_uri(10);
+        instance_uri(11);
+        instance_uri(12);
+        instance_uri(13);
+        instance_uri(14);
+        instance_uri(15);
+        instance_uri(16);
+        instance_uri(17);
+        instance_uri(18);
+        instance_uri(19);
+        instance_uri(20);
+        instance_uri(21);
+        instance_uri(22);
+        instance_uri(23);
+        instance_uri(24);
+        instance_uri(25);
+        instance_uri(26);
+        instance_uri(27);
+        instance_uri(28);
+        instance_uri(29);
+        instance_uri(30);
+        instance_uri(31);
+    };
+})
+
+box.once("bootstrap", function()
+    local test_run = require('test_run').new()
+    box.schema.user.grant("guest", 'replication')
+    box.schema.space.create('test', {engine = test_run:get_cfg('engine')})
+    box.space.test:create_index('primary')
+end)
diff --git a/test/replication/qsync1.lua b/test/replication/qsync1.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync1.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync10.lua b/test/replication/qsync10.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync10.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync11.lua b/test/replication/qsync11.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync11.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync12.lua b/test/replication/qsync12.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync12.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync13.lua b/test/replication/qsync13.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync13.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync14.lua b/test/replication/qsync14.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync14.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync15.lua b/test/replication/qsync15.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync15.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync16.lua b/test/replication/qsync16.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync16.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync17.lua b/test/replication/qsync17.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync17.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync18.lua b/test/replication/qsync18.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync18.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync19.lua b/test/replication/qsync19.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync19.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync2.lua b/test/replication/qsync2.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync2.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync20.lua b/test/replication/qsync20.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync20.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync21.lua b/test/replication/qsync21.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync21.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync22.lua b/test/replication/qsync22.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync22.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync23.lua b/test/replication/qsync23.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync23.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync24.lua b/test/replication/qsync24.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync24.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync25.lua b/test/replication/qsync25.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync25.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync26.lua b/test/replication/qsync26.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync26.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync27.lua b/test/replication/qsync27.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync27.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync28.lua b/test/replication/qsync28.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync28.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync29.lua b/test/replication/qsync29.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync29.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync3.lua b/test/replication/qsync3.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync3.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync30.lua b/test/replication/qsync30.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync30.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync31.lua b/test/replication/qsync31.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync31.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync4.lua b/test/replication/qsync4.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync4.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync5.lua b/test/replication/qsync5.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync5.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync6.lua b/test/replication/qsync6.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync6.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync7.lua b/test/replication/qsync7.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync7.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync8.lua b/test/replication/qsync8.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync8.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync9.lua b/test/replication/qsync9.lua
new file mode 120000
index 000000000..df9f3a883
--- /dev/null
+++ b/test/replication/qsync9.lua
@@ -0,0 +1 @@
+qsync.lua
\ No newline at end of file
diff --git a/test/replication/qsync_random_leader.result b/test/replication/qsync_random_leader.result
new file mode 100644
index 000000000..5d0c5d18f
--- /dev/null
+++ b/test/replication/qsync_random_leader.result
@@ -0,0 +1,117 @@
+-- test-run result file version 2
+env = require('test_run')
+ | ---
+ | ...
+math = require('math')
+ | ---
+ | ...
+fiber = require('fiber')
+ | ---
+ | ...
+test_run = env.new()
+ | ---
+ | ...
+engine = test_run:get_cfg('engine')
+ | ---
+ | ...
+
+MAX_REPLICAS = 3
+ | ---
+ | ...
+NUM_INSTANCES = MAX_REPLICAS + 1
+ | ---
+ | ...
+BROKEN_QUORUM = NUM_INSTANCES + 1
+ | ---
+ | ...
+
+SERVERS = {}
+ | ---
+ | ...
+test_run:cmd("setopt delimiter ';'")
+ | ---
+ | - true
+ | ...
+for i=1,MAX_REPLICAS do
+    SERVERS[i] = 'qsync' .. i
+end;
+ | ---
+ | ...
+test_run:cmd("setopt delimiter ''");
+ | ---
+ | - true
+ | ...
+SERVERS -- print instance names
+ | ---
+ | - - qsync1
+ |   - qsync2
+ |   - qsync3
+ | ...
+
+test_run:create_cluster(SERVERS, "replication", {args="0.1"})
+ | ---
+ | ...
+test_run:wait_fullmesh(SERVERS)
+ | ---
+ | ...
+box.schema.user.grant('guest', 'replication')
+ | ---
+ | ...
+test_run:switch('default')
+ | ---
+ | - true
+ | ...
+box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
+ | ---
+ | ...
+_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
+ | ---
+ | ...
+_ = box.space.sync:create_index('pk')
+ | ---
+ | ...
+
+-- Testcase body.
+current_leader = 'default'
+ | ---
+ | ...
+for i=1,100 do                                               \
+    new_leader_id = math.random(1, #SERVERS)                 \
+    new_leader = SERVERS[new_leader_id]                      \
+    test_run:switch(new_leader)                              \
+    box.cfg{read_only=false}                                 \
+    fiber = require('fiber')                                 \
+    f = fiber.create(function() box.space.sync:delete{} end) \
+    f = fiber.create(function() for i=1,10 do box.space.sync:insert{i} end end) \
+    f.status()                                               \
+    test_run:switch('default')                               \
+    test_run:switch(current_leader)                          \
+    box.cfg{read_only=true}                                  \
+    test_run:switch('default')                               \
+    current_leader = new_leader                              \
+    fiber.sleep(0.1)                                         \
+end
+ | ---
+ | ...
+
+-- Teardown.
+test_run:switch(current_leader)
+ | ---
+ | - true
+ | ...
+box.cfg{read_only=true} -- demote master to replica
+ | ---
+ | ...
+test_run:switch('default')
+ | ---
+ | - true
+ | ...
+box.cfg{read_only=false} -- promote replica to master
+ | ---
+ | ...
+box.space.sync:drop()
+ | ---
+ | ...
+test_run:drop_cluster(SERVERS)
+ | ---
+ | ...
diff --git a/test/replication/qsync_random_leader.test.lua b/test/replication/qsync_random_leader.test.lua
new file mode 100644
index 000000000..3bf534e23
--- /dev/null
+++ b/test/replication/qsync_random_leader.test.lua
@@ -0,0 +1,52 @@
+env = require('test_run')
+math = require('math')
+fiber = require('fiber')
+test_run = env.new()
+engine = test_run:get_cfg('engine')
+
+MAX_REPLICAS = 3
+NUM_INSTANCES = MAX_REPLICAS + 1
+BROKEN_QUORUM = NUM_INSTANCES + 1
+
+SERVERS = {}
+test_run:cmd("setopt delimiter ';'")
+for i=1,MAX_REPLICAS do
+    SERVERS[i] = 'qsync' .. i
+end;
+test_run:cmd("setopt delimiter ''");
+SERVERS -- print instance names
+
+test_run:create_cluster(SERVERS, "replication", {args="0.1"})
+test_run:wait_fullmesh(SERVERS)
+box.schema.user.grant('guest', 'replication')
+test_run:switch('default')
+box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
+_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
+_ = box.space.sync:create_index('pk')
+
+-- Testcase body.
+current_leader = 'default'
+for i=1,100 do                                               \
+    new_leader_id = math.random(1, #SERVERS)                 \
+    new_leader = SERVERS[new_leader_id]                      \
+    test_run:switch(new_leader)                              \
+    box.cfg{read_only=false}                                 \
+    fiber = require('fiber')                                 \
+    f = fiber.create(function() box.space.sync:delete{} end) \
+    f = fiber.create(function() for i=1,10 do box.space.sync:insert{i} end end) \
+    f.status()                                               \
+    test_run:switch('default')                               \
+    test_run:switch(current_leader)                          \
+    box.cfg{read_only=true}                                  \
+    test_run:switch('default')                               \
+    current_leader = new_leader                              \
+    fiber.sleep(0.1)                                         \
+end
+
+-- Teardown.
+test_run:switch(current_leader)
+box.cfg{read_only=true} -- demote master to replica
+test_run:switch('default')
+box.cfg{read_only=false} -- promote replica to master
+box.space.sync:drop()
+test_run:drop_cluster(SERVERS)
-- 
2.26.2

  parent reply	other threads:[~2020-07-09 17:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1594314820.git.sergeyb@tarantool.org>
2020-07-09 17:16 ` [Tarantool-patches] [PATCH 1/3] replication: print number of txs in limbo before its clear sergeyb
2020-07-09 20:07   ` Vladislav Shpilevoy
2020-07-10 12:55     ` Sergey Bronnikov
2020-07-20 21:59   ` Vladislav Shpilevoy
2020-07-09 17:16 ` [Tarantool-patches] [PATCH 2/3] replication: test clear_synchro_queue function sergeyb
2020-07-20 22:00   ` Vladislav Shpilevoy
2020-08-25 12:49     ` Sergey Bronnikov
2020-08-26  7:31       ` Serge Petrenko
2020-08-26 14:48         ` Sergey Bronnikov
2020-07-09 17:16 ` sergeyb [this message]
2020-07-09 20:07   ` [Tarantool-patches] [PATCH 3/3] replication: add test with random leaders promotion and demotion Vladislav Shpilevoy
2020-07-10  8:05     ` Sergey Bronnikov
2020-07-20 22:01   ` Vladislav Shpilevoy
2020-08-26 14:45     ` Sergey Bronnikov
2020-08-27 10:49       ` Serge Petrenko
2020-08-31 10:05         ` Sergey Bronnikov
2020-09-01 13:03           ` Serge Petrenko
2020-11-12  9:32             ` Sergey Bronnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b6a0c7b42d71fd263c51d44c96748587092dda1e.1594314820.git.sergeyb@tarantool.org \
    --to=sergeyb@tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=lvasiliev@tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 3/3] replication: add test with random leaders promotion and demotion' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox