diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 2892bb3d30df..31a8c16b73ec 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -84,6 +84,14 @@ local function decode_push(raw_data) return response[IPROTO_DATA_KEY][1], raw_end end +local function version_id(major, minor, patch) + return bit.bor(bit.lshift(major, 16), bit.lshift(minor, 8), patch) +end + +local function version_at_least(peer_version_id, major, minor, patch) + return peer_version_id >= version_id(major, minor, patch) +end + local method_encoder = { ping = internal.encode_ping, call_16 = internal.encode_call_16, @@ -735,17 +743,23 @@ local function create_transport(host, port, user, password, callback, set_state('active') return iproto_sm(schema_version) end + -- _vcollation view was added in 2.2.0-389-g3e3ef182f + local peer_has_vcollation = version_at_least(greeting.version_id, + 2, 2, 1) local select1_id = new_request_id() local select2_id = new_request_id() - local select3_id = new_request_id() + local select3_id local response = {} -- fetch everything from space _vspace, 2 = ITER_ALL encode_select(send_buf, select1_id, VSPACE_ID, 0, 2, 0, 0xFFFFFFFF, nil) -- fetch everything from space _vindex, 2 = ITER_ALL encode_select(send_buf, select2_id, VINDEX_ID, 0, 2, 0, 0xFFFFFFFF, nil) -- fetch everything from space _vcollation, 2 = ITER_ALL - encode_select(send_buf, select3_id, VCOLLATION_ID, 0, 2, 0, 0xFFFFFFFF, - nil) + if peer_has_vcollation then + select3_id = new_request_id() + encode_select(send_buf, select3_id, VCOLLATION_ID, 0, 2, 0, + 0xFFFFFFFF, nil) + end schema_version = nil -- any schema_version will do provided that -- it is consistent across responses @@ -754,6 +768,8 @@ local function create_transport(host, port, user, password, callback, if err then return error_sm(err, hdr) end dispatch_response_iproto(hdr, body_rpos, body_end) local id = hdr[IPROTO_SYNC_KEY] + -- trick: omit check for peer_has_vcollation: id is + -- not nil if id == select1_id or id == select2_id or id == select3_id then -- response to a schema query we've submitted local status = hdr[IPROTO_STATUS_KEY] @@ -774,9 +790,10 @@ local function create_transport(host, port, user, password, callback, response[id] = body[IPROTO_DATA_KEY] end until response[select1_id] and response[select2_id] and - response[select3_id] + (not peer_has_vcollation or response[select3_id]) + -- trick: response[select3_id] is nil when the key is nil callback('did_fetch_schema', schema_version, response[select1_id], - response[select2_id],response[select3_id]) + response[select2_id], response[select3_id]) set_state('active') return iproto_sm(schema_version) end @@ -1269,17 +1286,23 @@ function remote_methods:_install_schema(schema_version, spaces, indices, local pkcollationid = index[PARTS][k].collation local pktype = index[PARTS][k][2] or index[PARTS][k].type local pkfield = index[PARTS][k][1] or index[PARTS][k].field + -- resolve a collation name if a peer has + -- _vcollation view local pkcollation = nil - if pkcollationid ~= nil then + if pkcollationid ~= nil and collations ~= nil then pkcollation = collations[pkcollationid + 1][2] end local pk = { type = pktype, fieldno = pkfield + 1, - collation = pkcollation, is_nullable = pknullable } + if collations == nil then + pk.collation_id = pkcollationid + else + pk.collation = pkcollation + end idx.parts[k] = pk end idx.unique = not not index[OPTS].unique diff --git a/test/box/net.box.result b/test/box/net.box.result index 1d9f43400e97..e3dabf7d96ee 100644 --- a/test/box/net.box.result +++ b/test/box/net.box.result @@ -2905,18 +2905,41 @@ c = net:connect(box.cfg.listen) box.internal.collation.create('test', 'ICU', 'ru-RU') --- ... +collation_id = box.internal.collation.id_by_name('test') +--- +... _ = space:create_index('sk', { type = 'tree', parts = {{1, 'str', collation = 'test'}}, unique = true }) --- ... c:reload_schema() --- ... -c.space.test.index.sk.parts +parts = c.space.test.index.sk.parts --- -- - type: string - is_nullable: false - collation: test - fieldno: 1 +... +#parts == 1 +--- +- true +... +parts[1].fieldno == 1 +--- +- true +... +parts[1].type == 'string' +--- +- true +... +parts[1].is_nullable == false +--- +- true +... +if _TARANTOOL >= '2.2.1' then \ + return parts[1].collation == 'test' \ +else \ + return parts[1].collation_id == collation_id \ +end +--- +- true ... c:close() --- diff --git a/test/box/net.box.test.lua b/test/box/net.box.test.lua index de629ab59ac8..8e65ff470c82 100644 --- a/test/box/net.box.test.lua +++ b/test/box/net.box.test.lua @@ -1195,9 +1195,19 @@ c:close() box.schema.user.grant('guest', 'read', 'space', 'test') c = net:connect(box.cfg.listen) box.internal.collation.create('test', 'ICU', 'ru-RU') +collation_id = box.internal.collation.id_by_name('test') _ = space:create_index('sk', { type = 'tree', parts = {{1, 'str', collation = 'test'}}, unique = true }) c:reload_schema() -c.space.test.index.sk.parts +parts = c.space.test.index.sk.parts +#parts == 1 +parts[1].fieldno == 1 +parts[1].type == 'string' +parts[1].is_nullable == false +if _TARANTOOL >= '2.2.1' then \ + return parts[1].collation == 'test' \ +else \ + return parts[1].collation_id == collation_id \ +end c:close() box.internal.collation.drop('test') space:drop() diff --git a/test/box/stat_net.result b/test/box/stat_net.result index 9eeada7eccfc..2cf567d5736e 100644 --- a/test/box/stat_net.result +++ b/test/box/stat_net.result @@ -83,9 +83,9 @@ box.stat.net.CONNECTIONS.total --- - 4 ... -box.stat.net.REQUESTS.total +box.stat.net.REQUESTS.total > 0 --- -- 17 +- true ... box.stat.net.CONNECTIONS.current --- @@ -115,6 +115,9 @@ test_run:wait_cond(function() return box.stat.net.CONNECTIONS.current == 1 end, --- - true ... +requests_total_saved = box.stat.net.REQUESTS.total +--- +... future1 = cn:call('tweedledee', {}, {is_async = true}) --- ... @@ -149,9 +152,9 @@ test_run:wait_cond(function() return box.stat.net.REQUESTS.current == 0 end, WAI --- - true ... -box.stat.net.REQUESTS.total +box.stat.net.REQUESTS.total - requests_total_saved == 2 --- -- 19 +- true ... -- reset box.stat.reset() diff --git a/test/box/stat_net.test.lua b/test/box/stat_net.test.lua index 830deb36b4ef..a1dd324bd62a 100644 --- a/test/box/stat_net.test.lua +++ b/test/box/stat_net.test.lua @@ -29,7 +29,7 @@ cn.space.tweedledum:select() --small request box.stat.net.SENT.total > 0 box.stat.net.RECEIVED.total > 0 box.stat.net.CONNECTIONS.total -box.stat.net.REQUESTS.total +box.stat.net.REQUESTS.total > 0 box.stat.net.CONNECTIONS.current box.stat.net.REQUESTS.current @@ -41,6 +41,7 @@ test_run:wait_cond(function() return box.stat.net.CONNECTIONS.current == 2 end, cn3:close() test_run:wait_cond(function() return box.stat.net.CONNECTIONS.current == 1 end, WAIT_COND_TIMEOUT) +requests_total_saved = box.stat.net.REQUESTS.total future1 = cn:call('tweedledee', {}, {is_async = true}) test_run:wait_cond(function() return box.stat.net.REQUESTS.current == 1 end, WAIT_COND_TIMEOUT) future2 = cn:call('tweedledee', {}, {is_async = true}) @@ -50,7 +51,7 @@ ch:put(true) future1:wait_result() future2:wait_result() test_run:wait_cond(function() return box.stat.net.REQUESTS.current == 0 end, WAIT_COND_TIMEOUT) -box.stat.net.REQUESTS.total +box.stat.net.REQUESTS.total - requests_total_saved == 2 -- reset box.stat.reset()