Tarantool development patches archive
 help / color / mirror / Atom feed
From: AKhatskevich <avkhatskevich@tarantool.org>
To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH] Track spaces by name
Date: Thu,  4 Oct 2018 20:09:21 +0300	[thread overview]
Message-ID: <20181004170921.10177-1-avkhatskevich@tarantool.org> (raw)

Closes #152
---
Sending rebalancing packages with names instead of space ids
can prevent errors in case replicasets are created a little
differently.
@filonenko asked to implement ths issue with a higher priority.

Issue: https://github.com/tarantool/vshard/issues/152
Branch: https://github.com/tarantool/vshard/tree/kh/rebalance_by_name

 test/lua_libs/storage_template.lua  |  3 +++
 test/rebalancer/box_1_a.lua         |  3 +++
 test/rebalancer/rebalancer.result   | 18 ++++++++++++++++++
 test/rebalancer/rebalancer.test.lua |  7 +++++++
 test/storage/storage.result         |  8 ++++----
 vshard/storage/init.lua             | 14 +++++++-------
 6 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/test/lua_libs/storage_template.lua b/test/lua_libs/storage_template.lua
index 488c652..1ddcf64 100644
--- a/test/lua_libs/storage_template.lua
+++ b/test/lua_libs/storage_template.lua
@@ -16,6 +16,9 @@ cfg.replication_connect_timeout = 3
 vshard.storage.cfg(cfg, util.name_to_uuid[NAME])
 function bootstrap_storage(engine)
     box.once("testapp:schema:1", function()
+        if rawget(_G, 'CHANGE_SPACE_IDS') then
+            box.schema.create_space("CHANGE_SPACE_IDS")
+        end
         local format = {{'id', 'unsigned'}, {'bucket_id', 'unsigned'}}
         local s = box.schema.create_space('test', {engine = engine, format = format})
         s:create_index('pk', {parts = {{'id'}}})
diff --git a/test/rebalancer/box_1_a.lua b/test/rebalancer/box_1_a.lua
index d59248e..cb73b1f 100644
--- a/test/rebalancer/box_1_a.lua
+++ b/test/rebalancer/box_1_a.lua
@@ -31,4 +31,7 @@ end
 finish_refs = false
 function make_ref() while not finish_refs do fiber.sleep(0.01) end end
 
+if NAME ~= 'box_1_a' and NAME ~= 'box_1_b' then
+    CHANGE_SPACE_IDS = true
+end
 require('storage_template')
diff --git a/test/rebalancer/rebalancer.result b/test/rebalancer/rebalancer.result
index 8f58239..3607e93 100644
--- a/test/rebalancer/rebalancer.result
+++ b/test/rebalancer/rebalancer.result
@@ -491,6 +491,24 @@ test_run:cmd("setopt delimiter ''");
 ---
 - true
 ...
+-- gh-152: ensure that rebalancing is possible in case spaces
+-- have different ids on different replicasets.
+test_run:switch('box_1_a')
+---
+- true
+...
+box.space.test.id
+---
+- 513
+...
+test_run:switch('box_2_a')
+---
+- true
+...
+box.space.test.id
+---
+- 514
+...
 _ = test_run:cmd("switch default")
 ---
 ...
diff --git a/test/rebalancer/rebalancer.test.lua b/test/rebalancer/rebalancer.test.lua
index a37a1c1..63e690f 100644
--- a/test/rebalancer/rebalancer.test.lua
+++ b/test/rebalancer/rebalancer.test.lua
@@ -228,6 +228,13 @@ while _bucket.index.status:count{vshard.consts.BUCKET.ACTIVE} ~= 200 do
 end;
 test_run:cmd("setopt delimiter ''");
 
+-- gh-152: ensure that rebalancing is possible in case spaces
+-- have different ids on different replicasets.
+test_run:switch('box_1_a')
+box.space.test.id
+test_run:switch('box_2_a')
+box.space.test.id
+
 _ = test_run:cmd("switch default")
 test_run:drop_cluster(REPLICASET_2)
 test_run:drop_cluster(REPLICASET_1)
diff --git a/test/storage/storage.result b/test/storage/storage.result
index e3e9e7f..c59fe4f 100644
--- a/test/storage/storage.result
+++ b/test/storage/storage.result
@@ -471,21 +471,21 @@ box.space.test2:select()
 ...
 vshard.storage.bucket_collect(1)
 ---
-- - - 514
+- - - test2
     - - [10, 1, 1]
       - [11, 1, 1]
       - [12, 1, 1]
-  - - 513
+  - - test
     - - [1, 1]
       - [5, 1]
 ...
 vshard.storage.bucket_collect(2)
 ---
-- - - 514
+- - - test2
     - - [20, 2, 2]
       - [21, 2, 2]
       - [22, 2, 2]
-  - - 513
+  - - test
     - - [2, 2]
       - [6, 2]
 ...
diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua
index 7d3f427..4d57ee9 100644
--- a/vshard/storage/init.lua
+++ b/vshard/storage/init.lua
@@ -693,7 +693,7 @@ end
 -- @param bucket_id Bucket to receive.
 -- @param from Source UUID.
 -- @param data Bucket data in the format:
---        [{space_id, [space_tuples]}, ...].
+--        [{space_name, [space_tuples]}, ...].
 -- @param opts Options. Now the only possible option is 'is_last'.
 --        It is set to true when the data portion is last and the
 --        bucket can be activated here.
@@ -726,13 +726,13 @@ local function bucket_recv_xc(bucket_id, from, data, opts)
     local bucket_generation = M.bucket_generation
     local limit = consts.BUCKET_CHUNK_SIZE
     for _, row in ipairs(data) do
-        local space_id, space_data = row[1], row[2]
-        local space = box.space[space_id]
+        local space_name, space_data = row[1], row[2]
+        local space = box.space[space_name]
         if space == nil then
             -- Tarantool doesn't provide API to create box.error
             -- objects before 1.10.
             local _, boxerror = pcall(box.error, box.error.NO_SUCH_SPACE,
-                                      space_id)
+                                      space_name)
             return nil, lerror.box(boxerror)
         end
         box.begin()
@@ -833,7 +833,7 @@ local function bucket_collect(bucket_id)
     for k, space in pairs(spaces) do
         assert(space.index[idx] ~= nil)
         local space_data = space.index[idx]:select({bucket_id})
-        table.insert(data, {space.id, space_data})
+        table.insert(data, {space.name, space_data})
     end
     return data
 end
@@ -966,7 +966,7 @@ local function bucket_send_xc(bucket_id, destination, opts)
             table.insert(space_data, t)
             limit = limit - 1
             if limit == 0 then
-                table.insert(data, {space.id, space_data})
+                table.insert(data, {space.name, space_data})
                 status, err = replicaset:callrw('vshard.storage.bucket_recv',
                                                 {bucket_id, uuid, data}, opts)
                 bucket_generation =
@@ -980,7 +980,7 @@ local function bucket_send_xc(bucket_id, destination, opts)
                 space_data = {}
             end
         end
-        table.insert(data, {space.id, space_data})
+        table.insert(data, {space.name, space_data})
     end
     status, err = replicaset:callrw('vshard.storage.bucket_recv',
                                     {bucket_id, uuid, data}, opts)
-- 
2.14.1

             reply	other threads:[~2018-10-04 17:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 17:09 AKhatskevich [this message]
2018-10-10 12:55 ` [tarantool-patches] " Vladislav Shpilevoy

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=20181004170921.10177-1-avkhatskevich@tarantool.org \
    --to=avkhatskevich@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH] Track spaces by name' \
    /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