Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
* Fixed storage compatibility with routers < 1.7.0 by handling nil bucket_id
in get, update, and delete operations.

## [1.7.4] - 12-02-26

### Fixed
Expand Down
21 changes: 14 additions & 7 deletions crud/delete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local CRUD_DELETE_FUNC_NAME = utils.get_storage_call(DELETE_FUNC_NAME)

local function delete_on_storage(space_name, key, field_names, opts)
dev_checks('string', '?', '?table', {
bucket_id = 'number|cdata',
bucket_id = '?number|cdata',
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
Expand All @@ -44,9 +44,14 @@ local function delete_on_storage(space_name, key, field_names, opts)
return nil, err
end

local ref_ok, bucket_ref_err, unref = bucket_ref_unref.bucket_refrw(opts.bucket_id, space.engine)
if not ref_ok then
return nil, bucket_ref_err
-- Skip bucket reference if bucket_id is not provided to support old routers.
local unref = nil
if opts.bucket_id ~= nil then
local ref_ok, bucket_ref_err, unref_func = bucket_ref_unref.bucket_refrw(opts.bucket_id, space.engine)
if not ref_ok then
return nil, bucket_ref_err
end
unref = unref_func
end

-- add_space_schema_hash is false because
Expand All @@ -58,9 +63,11 @@ local function delete_on_storage(space_name, key, field_names, opts)
fetch_latest_metadata = opts.fetch_latest_metadata,
}, space, key)

local unref_ok, err_unref = unref(opts.bucket_id, space.engine)
if not unref_ok then
return nil, err_unref
if unref ~= nil then
local unref_ok, err_unref = unref(opts.bucket_id, space.engine)
if not unref_ok then
return nil, err_unref
end
end

return result
Expand Down
21 changes: 14 additions & 7 deletions crud/get.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local CRUD_GET_FUNC_NAME = utils.get_storage_call(GET_FUNC_NAME)

local function get_on_storage(space_name, key, field_names, opts)
dev_checks('string', '?', '?table', {
bucket_id = 'number|cdata',
bucket_id = '?number|cdata',
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
Expand All @@ -43,9 +43,14 @@ local function get_on_storage(space_name, key, field_names, opts)
return nil, err
end

local ref_ok, bucket_ref_err, unref = bucket_ref_unref.bucket_refro(opts.bucket_id, space.engine)
if not ref_ok then
return nil, bucket_ref_err
-- Skip bucket reference if bucket_id is not provided to support old routers.
local unref = nil
if opts.bucket_id ~= nil then
local ref_ok, bucket_ref_err, unref_func = bucket_ref_unref.bucket_refro(opts.bucket_id, space.engine)
if not ref_ok then
return nil, bucket_ref_err
end
unref = unref_func
end

-- add_space_schema_hash is false because
Expand All @@ -56,9 +61,11 @@ local function get_on_storage(space_name, key, field_names, opts)
fetch_latest_metadata = opts.fetch_latest_metadata,
}, space, key)

local unref_ok, err_unref = unref(opts.bucket_id, space.engine)
if not unref_ok then
return nil, err_unref
if unref ~= nil then
local unref_ok, err_unref = unref(opts.bucket_id, space.engine)
if not unref_ok then
return nil, err_unref
end
end

return result
Expand Down
21 changes: 14 additions & 7 deletions crud/update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local CRUD_UPDATE_FUNC_NAME = utils.get_storage_call(UPDATE_FUNC_NAME)

local function update_on_storage(space_name, key, operations, field_names, opts)
dev_checks('string', '?', 'table', '?table', {
bucket_id = 'number|cdata',
bucket_id = '?number|cdata',
sharding_key_hash = '?number',
sharding_func_hash = '?number',
skip_sharding_hash_check = '?boolean',
Expand All @@ -44,9 +44,14 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
return nil, err
end

local ref_ok, bucket_ref_err, unref = bucket_ref_unref.bucket_refrw(opts.bucket_id, space.engine)
if not ref_ok then
return nil, bucket_ref_err
-- Skip bucket reference if bucket_id is not provided to support old routers.
local unref = nil
if opts.bucket_id ~= nil then
local ref_ok, bucket_ref_err, unref_func = bucket_ref_unref.bucket_refrw(opts.bucket_id, space.engine)
if not ref_ok then
return nil, bucket_ref_err
end
unref = unref_func
end

-- add_space_schema_hash is false because
Expand All @@ -73,9 +78,11 @@ local function update_on_storage(space_name, key, operations, field_names, opts)
}, space, key, operations)
end

local unref_ok, err_unref = unref(opts.bucket_id, space.engine)
if not unref_ok then
return nil, err_unref
if unref ~= nil then
local unref_ok, err_unref = unref(opts.bucket_id, space.engine)
if not unref_ok then
return nil, err_unref
end
end

return res, err
Expand Down
44 changes: 44 additions & 0 deletions test/integration/simple_operations_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1931,3 +1931,47 @@ pgroup.test_get_invalid_bucket_id = function(g)
t.assert_str_contains(err.err or err.str, expected_err)
end
end

pgroup.before_test('test_storage_compat_nil_bucket_id', function(g)
local storage = g.cluster:server('s1-master')

-- Disable yield checks to avoid 'fiber is not registered' error
storage:eval([[
local yield_checks = require('crud.common.yield_checks')
rawset(_G, '_old_check_no_yields', yield_checks.check_no_yields)
yield_checks.check_no_yields = function() end
]])
end)

pgroup.after_test('test_storage_compat_nil_bucket_id', function(g)
local storage = g.cluster:server('s1-master')

storage:eval([[
local yield_checks = require('crud.common.yield_checks')
yield_checks.check_no_yields = rawget(_G, '_old_check_no_yields')
rawset(_G, '_old_check_no_yields', nil)
]])
end)

pgroup.test_storage_compat_nil_bucket_id = function(g)
local storage = g.cluster:server('s1-master')

-- get_on_storage with nil bucket_id (emulating old router < 1.7.0)
local _, err = storage:call('_crud.get_on_storage', {
'customers', 1, nil, {bucket_id = nil, skip_sharding_hash_check = true},
})
t.assert_equals(err, nil)

-- update_on_storage with nil bucket_id
local _, err = storage:call('_crud.update_on_storage', {
'customers', 1, {{'=', 'name', 'UpdatedUser'}}, nil,
{bucket_id = nil, skip_sharding_hash_check = true},
})
t.assert_equals(err, nil)

-- delete_on_storage with nil bucket_id
local _, err = storage:call('_crud.delete_on_storage', {
'customers', 1, nil, {bucket_id = nil, skip_sharding_hash_check = true},
})
t.assert_equals(err, nil)
end
Loading