Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crud: support vshard with no UUIDs in config #408

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions .github/workflows/test_on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ jobs:
- tarantool-version: "2.11"
external-merger-version: "0.0.5"
external-keydef-version: "0.0.4"
- tarantool-version: "master"
metrics-version: "1.0.0"
- tarantool-version: "3.0.0"
vshard-version: "0.1.25"
fail-fast: false
# Can't install older versions on 22.04,
Expand All @@ -51,8 +50,8 @@ jobs:
steps:
- uses: actions/checkout@master

- name: Setup Tarantool CE
if: matrix.tarantool-version != 'master'
- name: Setup Tarantool CE (1.x, 2.x)
if: ${{ startsWith( matrix.tarantool-version, '1.' ) || startsWith( matrix.tarantool-version, '2.' ) }}
uses: tarantool/setup-tarantool@v2
with:
tarantool-version: ${{ matrix.tarantool-version }}
Expand All @@ -63,6 +62,20 @@ jobs:
sudo apt install -y tt
tt version

- name: Cache Tarantool 3.x
if: ${{ startsWith( matrix.tarantool-version, '3.' ) }}
id: cache-v3
uses: actions/cache@v3
with:
path: "${GITHUB_WORKSPACE}/bin"
key: cache-${{ matrix.tarantool-version }}

- name: Setup Tarantool CE (3.x)
if: ${{ startsWith( matrix.tarantool-version, '3.' ) && steps.cache-latest.outputs.cache-hit != 'true' }}
run: |
tt init
tt install tarantool ${{ matrix.tarantool-version }}

- name: Get Tarantool master latest commit
if: matrix.tarantool-version == 'master'
run: |
Expand All @@ -78,14 +91,14 @@ jobs:
path: "${GITHUB_WORKSPACE}/bin"
key: cache-latest-${{ env.LATEST_COMMIT }}

- name: Setup Tarantool master
- name: Setup Tarantool CE (master)
if: matrix.tarantool-version == 'master' && steps.cache-latest.outputs.cache-hit != 'true'
run: |
tt init
tt install tarantool master

- name: Add Tarantool master to PATH
if: matrix.tarantool-version == 'master'
- name: Add tt Tarantool to PATH
DifferentialOrange marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ startsWith( matrix.tarantool-version, '3.' ) || matrix.tarantool-version == 'master' }}
run: echo "${GITHUB_WORKSPACE}/bin" >> $GITHUB_PATH

- name: Fix luarocks in Tarantool CE 1.10.6
Expand Down Expand Up @@ -139,16 +152,15 @@ jobs:
metrics-version: ["1.0.0"]
cartridge-version: ["2.8.0"]
include:
- tarantool-version: "master"
metrics-version: "1.0.0"
- tarantool-version: "3.0.0"
vshard-version: "0.1.25"
fail-fast: false
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master

- name: Setup Tarantool CE
if: matrix.tarantool-version != 'master'
- name: Setup Tarantool CE (1.x, 2.x)
if: ${{ startsWith( matrix.tarantool-version, '1.' ) || startsWith( matrix.tarantool-version, '2.' ) }}
uses: tarantool/setup-tarantool@v2
with:
tarantool-version: ${{ matrix.tarantool-version }}
Expand All @@ -159,6 +171,20 @@ jobs:
sudo apt install -y tt
tt version

- name: Cache Tarantool 3.x
if: ${{ startsWith( matrix.tarantool-version, '3.' ) }}
id: cache-v3
uses: actions/cache@v3
with:
path: "${GITHUB_WORKSPACE}/bin"
key: cache-${{ matrix.tarantool-version }}

- name: Setup Tarantool CE (3.x)
if: ${{ startsWith( matrix.tarantool-version, '3.' ) && steps.cache-latest.outputs.cache-hit != 'true' }}
run: |
tt init
tt install tarantool ${{ matrix.tarantool-version }}

- name: Get Tarantool master latest commit
if: matrix.tarantool-version == 'master'
run: |
Expand All @@ -174,14 +200,14 @@ jobs:
path: "${GITHUB_WORKSPACE}/bin"
key: cache-latest-${{ env.LATEST_COMMIT }}

- name: Setup Tarantool master
- name: Setup Tarantool CE (master)
if: matrix.tarantool-version == 'master' && steps.cache-latest.outputs.cache-hit != 'true'
run: |
tt init
tt install tarantool master

- name: Add Tarantool master to PATH
if: matrix.tarantool-version == 'master'
- name: Add tt Tarantool to PATH
DifferentialOrange marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ startsWith( matrix.tarantool-version, '3.' ) || matrix.tarantool-version == 'master' }}
run: echo "${GITHUB_WORKSPACE}/bin" >> $GITHUB_PATH

- name: Install requirements for community
Expand Down Expand Up @@ -216,6 +242,12 @@ jobs:
bundle: "tarantool-enterprise-sdk-nogc64-2.11.0-0-r563.linux.x86_64"
metrics-version: ["", "1.0.0"]
cartridge-version: ["2.8.0"]
include:
- tarantool-version:
folder: "3.0"
bundle: "tarantool-enterprise-sdk-gc64-3.0.0-0-gf58f7d82a-r23.linux.x86_64"
vshard-version: "0.1.25"

fail-fast: false
runs-on: ubuntu-20.04
steps:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed
* Compatibility with vshard configuration if UUIDs are omitted (#407).

## [1.4.2] - 25-12-23

### Added
Expand Down
9 changes: 5 additions & 4 deletions crud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ function crud.init_storage()

local user = nil
if not box.info.ro then
local replicaset_uuid, replicaset = utils.get_self_vshard_replicaset()
local replicaset_key, replicaset = utils.get_self_vshard_replicaset()

if replicaset == nil or replicaset.master == nil then
error(string.format('Failed to find a vshard configuration for ' ..
' replicaset with replicaset_uuid %s.',
replicaset_uuid))
error(string.format(
'Failed to find a vshard configuration ' ..
'for storage replicaset with key %q.',
replicaset_key))
end
user = luri.parse(replicaset.master.uri).login or 'guest'
end
Expand Down
30 changes: 18 additions & 12 deletions crud/common/call.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,34 @@ function call.get_vshard_call_name(mode, prefer_replica, balance)
return 'callbre'
end

local function wrap_vshard_err(vshard_router, err, func_name, replicaset_uuid, bucket_id)
local function wrap_vshard_err(vshard_router, err, func_name, replicaset_id, bucket_id)
-- Do not rewrite ShardingHashMismatchError class.
if err.class_name == sharding_utils.ShardingHashMismatchError.name then
return errors.wrap(err)
end

if replicaset_uuid == nil then
if replicaset_id == nil then
local replicaset, _ = vshard_router:route(bucket_id)
if replicaset == nil then
return CallError:new(
"Function returned an error, but we couldn't figure out the replicaset: %s", err
)
end

replicaset_uuid = replicaset.uuid
replicaset_id = utils.get_replicaset_id(vshard_router, replicaset)

if replicaset_id == nil then
return CallError:new(
"Function returned an error, but we couldn't figure out the replicaset id: %s", err
)
end
end

err = utils.update_storage_call_error_description(err, func_name, replicaset_uuid)
err = utils.update_storage_call_error_description(err, func_name, replicaset_id)
err = errors.wrap(err)

return CallError:new(utils.format_replicaset_error(
replicaset_uuid, "Function returned an error: %s", err
replicaset_id, "Function returned an error: %s", err
))
end

Expand Down Expand Up @@ -104,13 +110,13 @@ function call.map(vshard_router, func_name, func_args, opts)
local futures_by_replicasets = {}
local call_opts = {is_async = true}
while iter:has_next() do
local args, replicaset = iter:get()
local args, replicaset, replicaset_id = iter:get()
local future = replicaset[vshard_call_name](replicaset, func_name, args, call_opts)
futures_by_replicasets[replicaset.uuid] = future
futures_by_replicasets[replicaset_id] = future
end

local deadline = fiber_clock() + timeout
for replicaset_uuid, future in pairs(futures_by_replicasets) do
for replicaset_id, future in pairs(futures_by_replicasets) do
local wait_timeout = deadline - fiber_clock()
if wait_timeout < 0 then
wait_timeout = 0
Expand All @@ -119,14 +125,14 @@ function call.map(vshard_router, func_name, func_args, opts)
local result, err = future:wait_result(wait_timeout)

local result_info = {
key = replicaset_uuid,
key = replicaset_id,
value = result,
}

local err_info = {
err_wrapper = wrap_vshard_err,
err = err,
wrapper_args = {func_name, replicaset_uuid},
wrapper_args = {func_name, replicaset_id},
}

local early_exit = postprocessor:collect(result_info, err_info)
Expand Down Expand Up @@ -179,13 +185,13 @@ function call.any(vshard_router, func_name, func_args, opts)
if replicasets == nil then
return nil, CallError:new("Failed to get router replicasets: %s", err.err)
end
local replicaset = select(2, next(replicasets))
local replicaset_id, replicaset = next(replicasets)

local res, err = replicaset:call(func_name, func_args, {
timeout = timeout,
})
if err ~= nil then
return nil, wrap_vshard_err(vshard_router, err, func_name, replicaset.uuid)
return nil, wrap_vshard_err(vshard_router, err, func_name, replicaset_id)
end

if res == box.NULL then
Expand Down
4 changes: 3 additions & 1 deletion crud/common/map_call_cases/base_iter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ end
--
-- @return[1] table func_args
-- @return[2] table replicaset
-- @return[3] string replicaset_id
function BaseIterator:get()
local replicaset_id = self.next_index
local replicaset = self.next_replicaset
self.next_index, self.next_replicaset = next(self.replicasets, self.next_index)

return self.func_args, replicaset
return self.func_args, replicaset, replicaset_id
end

return BaseIterator
10 changes: 6 additions & 4 deletions crud/common/map_call_cases/batch_insert_iter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function BatchInsertIterator:new(opts)
return nil, SplitTuplesError:new("Failed to split tuples by replicaset: %s", err.err)
end

local next_replicaset, next_batch = next(sharding_data.batches)
local next_index, next_batch = next(sharding_data.batches)

local execute_on_storage_opts = opts.execute_on_storage_opts
execute_on_storage_opts.sharding_func_hash = sharding_data.sharding_func_hash
Expand All @@ -51,7 +51,7 @@ function BatchInsertIterator:new(opts)
space_name = opts.space.name,
opts = execute_on_storage_opts,
batches_by_replicasets = sharding_data.batches,
next_index = next_replicaset,
next_index = next_index,
next_batch = next_batch,
}

Expand All @@ -67,8 +67,10 @@ end
--
-- @return[1] table func_args
-- @return[2] table replicaset
-- @return[3] string replicaset_id
function BatchInsertIterator:get()
local replicaset = self.next_index
local replicaset_id = self.next_index
local replicaset = self.next_batch.replicaset
local func_args = {
self.space_name,
self.next_batch.tuples,
Expand All @@ -77,7 +79,7 @@ function BatchInsertIterator:get()

self.next_index, self.next_batch = next(self.batches_by_replicasets, self.next_index)

return func_args, replicaset
return func_args, replicaset, replicaset_id
end

return BatchInsertIterator
10 changes: 6 additions & 4 deletions crud/common/map_call_cases/batch_upsert_iter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function BatchUpsertIterator:new(opts)
return nil, SplitTuplesError:new("Failed to split tuples by replicaset: %s", err.err)
end

local next_replicaset, next_batch = next(sharding_data.batches)
local next_index, next_batch = next(sharding_data.batches)

local execute_on_storage_opts = opts.execute_on_storage_opts
execute_on_storage_opts.sharding_func_hash = sharding_data.sharding_func_hash
Expand All @@ -59,7 +59,7 @@ function BatchUpsertIterator:new(opts)
space_name = opts.space.name,
opts = execute_on_storage_opts,
batches_by_replicasets = sharding_data.batches,
next_index = next_replicaset,
next_index = next_index,
next_batch = next_batch,
}

Expand All @@ -75,8 +75,10 @@ end
--
-- @return[1] table func_args
-- @return[2] table replicaset
-- @return[3] string replicaset_id
function BatchUpsertIterator:get()
local replicaset = self.next_index
local replicaset_id = self.next_index
local replicaset = self.next_batch.replicaset
local func_args = {
self.space_name,
self.next_batch.tuples,
Expand All @@ -86,7 +88,7 @@ function BatchUpsertIterator:get()

self.next_index, self.next_batch = next(self.batches_by_replicasets, self.next_index)

return func_args, replicaset
return func_args, replicaset, replicaset_id
end

return BatchUpsertIterator
4 changes: 3 additions & 1 deletion crud/common/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local ReloadSchemaError = errors.new_class('ReloadSchemaError', {capture_stack =

local const = require('crud.common.const')
local dev_checks = require('crud.common.dev_checks')
local utils = require('crud.common.vshard_utils')

local schema = {}

Expand Down Expand Up @@ -234,7 +235,8 @@ function schema.wrap_func_result(space, func, args, opts)
replica_schema_version = box.internal.schema_version()
end
result.storage_info = {
replica_uuid = box.info().uuid,
replica_uuid = box.info().uuid, -- Backward compatibility.
replica_id = utils.get_self_vshard_replica_id(), -- Replacement for replica_uuid.
replica_schema_version = replica_schema_version,
}
end
Expand Down
Loading