Skip to content
Snippets Groups Projects
Commit 9b0a767d authored by Georgiy Lebedev's avatar Georgiy Lebedev Committed by Vladimir Davydov
Browse files

box: export current session's identifier to C API

In order to send IPROTO packets using `box_iproto_send` (#7897) we need to
have some session identifier source in the C API: for now, export an analog
of `box.session.id`.

Closes #7895

@TarantoolBot document
Title: Document export of current session's identifier to C API
For the API description and usage examples, see:
* [design document](https://www.notion.so/tarantool/box-iproto-override-44935a6ac7e04fb5a2c81ca713ed1bce#0900ff9cb6b148378ce0b185d3f628b9);
* tarantool/tarantool#7895.
parent 42badb87
No related branches found
No related tags found
No related merge requests found
## feature/box
* Exported current session's identifier to C API via `box_session_id` (gh-7895).
......@@ -104,6 +104,7 @@ box_sequence_current
box_sequence_next
box_sequence_reset
box_sequence_set
box_session_id
box_session_push
box_space_id_by_name
box_truncate
......
......@@ -3201,6 +3201,12 @@ box_session_push(const char *data, const char *data_end)
return rc;
}
API_EXPORT uint64_t
box_session_id(void)
{
return current_session()->id;
}
static inline void
box_register_replica(uint32_t id, const struct tt_uuid *uuid)
{
......
......@@ -599,6 +599,12 @@ box_sequence_reset(uint32_t seq_id);
API_EXPORT int
box_session_push(const char *data, const char *data_end);
/**
* \return current session's unique monotonic identifier (\sa box.session.id)
*/
API_EXPORT uint64_t
box_session_id(void);
/** \endcond public */
/**
......
......@@ -73,17 +73,12 @@ lbox_session_create(struct lua_State *L)
}
/**
* Return a unique monotonic session
* identifier. The identifier can be used
* to check whether or not a session is alive.
* 0 means there is no session (e.g.
* a procedure is running in a detached
* fiber).
* Lua wrapper for `box_session_id`.
*/
static int
lbox_session_id(struct lua_State *L)
{
lua_pushnumber(L, current_session()->id);
luaL_pushuint64(L, box_session_id());
return 1;
}
......
......@@ -2994,6 +2994,19 @@ test_box_schema_version(struct lua_State *L)
/* }}} Helpers for schema version Lua/C API test cases */
/* {{{ Helpers for current session identifier Lua/C API test cases */
static int
test_box_session_id(struct lua_State *L)
{
fail_unless(lua_gettop(L) == 1);
fail_unless(lua_isnumber(L, 1));
lua_pushboolean(L, luaL_touint64(L, 1) == box_session_id());
return 1;
}
/* }}} Helpers for current session identifier Lua/C API test cases */
LUA_API int
luaopen_module_api(lua_State *L)
{
......@@ -3045,6 +3058,7 @@ luaopen_module_api(lua_State *L)
{"isdecimal", test_isdecimal},
{"isdecimal_ptr", test_isdecimal_ptr},
{"box_schema_version_matches", test_box_schema_version},
{"box_session_id_matches", test_box_session_id},
{NULL, NULL}
};
luaL_register(L, "module_api", lib);
......
......@@ -488,8 +488,16 @@ local function test_box_schema_version_matches(test, module)
s:drop()
end
local function test_box_session_id_matches(test, module)
test:plan(1)
test:ok(module.box_session_id_matches(box.session.id()),
'verify that Lua/C current session identifier APIs return the ' ..
'same value')
end
require('tap').test("module_api", function(test)
test:plan(44)
test:plan(45)
local status, module = pcall(require, 'module_api')
test:is(status, true, "module")
test:ok(status, "module is loaded")
......@@ -522,6 +530,7 @@ require('tap').test("module_api", function(test)
test:test("pushdecimal", test_pushdecimal, module)
test:test("isdecimal", test_isdecimal, module)
test:test("box_schema_version_matches", test_box_schema_version_matches, module)
test:test("box_session_id_matches", test_box_session_id_matches, module)
space:drop()
end)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment