From: Timur Safin <tsafin@tarantool.org>
To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 1.10 v4 4/5] module api: box_ibuf_* wrappers
Date: Wed, 14 Oct 2020 03:15:43 +0300 [thread overview]
Message-ID: <897bee05462bf6c32613f87a84c170bec1f3d113.1602634213.git.tsafin@tarantool.org> (raw)
In-Reply-To: <cover.1602634213.git.tsafin@tarantool.org>
Introduced the bare minimum of ibuf accessors, which make
external merger possible:
- box_ibuf_reserve
- box_ibuf_read_range
- box_ibuf_write_range
Part of #5384
---
| 3 ++
src/CMakeLists.txt | 1 +
src/box/CMakeLists.txt | 1 +
src/box/ibuf.c | 65 +++++++++++++++++++++++++++++++
src/box/ibuf.h | 67 ++++++++++++++++++++++++++++++++
test/app-tap/module_api.c | 44 +++++++++++++++++++++
test/app-tap/module_api.test.lua | 2 +-
7 files changed, 182 insertions(+), 1 deletion(-)
create mode 100644 src/box/ibuf.c
create mode 100644 src/box/ibuf.h
--git a/extra/exports b/extra/exports
index 37077120d..d918b7e59 100644
--- a/extra/exports
+++ b/extra/exports
@@ -181,6 +181,9 @@ box_tuple_extract_key
box_tuple_compare
box_tuple_compare_with_key
box_tuple_validate
+box_ibuf_reserve
+box_ibuf_read_range
+box_ibuf_write_range
box_return_tuple
box_space_id_by_name
box_index_id_by_name
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 45a8f7733..87c9ccc0e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -204,6 +204,7 @@ set(api_headers
${CMAKE_SOURCE_DIR}/src/box/tuple_extract_key.h
${CMAKE_SOURCE_DIR}/src/box/schema_def.h
${CMAKE_SOURCE_DIR}/src/box/box.h
+ ${CMAKE_SOURCE_DIR}/src/box/ibuf.h
${CMAKE_SOURCE_DIR}/src/box/index.h
${CMAKE_SOURCE_DIR}/src/box/iterator_type.h
${CMAKE_SOURCE_DIR}/src/box/error.h
diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt
index 52413d3cf..4dbdb66cd 100644
--- a/src/box/CMakeLists.txt
+++ b/src/box/CMakeLists.txt
@@ -113,6 +113,7 @@ add_library(box STATIC
journal.c
wal.c
call.c
+ ibuf.c
${lua_sources}
lua/init.c
lua/call.c
diff --git a/src/box/ibuf.c b/src/box/ibuf.c
new file mode 100644
index 000000000..12b9f2781
--- /dev/null
+++ b/src/box/ibuf.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2020, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+#include "ibuf.h"
+#include <small/ibuf.h>
+
+void *
+box_ibuf_reserve(box_ibuf_t *ibuf, size_t size)
+{
+ return ibuf_reserve(ibuf, size);
+}
+
+void
+box_ibuf_read_range(box_ibuf_t *ibuf, char ***rpos, char ***wpos)
+{
+ assert(ibuf != NULL);
+ if (ibuf == NULL)
+ return;
+ if (rpos != NULL)
+ *rpos = &ibuf->rpos;
+ if (wpos != NULL)
+ *wpos = &ibuf->wpos;
+}
+
+void
+box_ibuf_write_range(box_ibuf_t *ibuf, char ***wpos, char ***end)
+{
+ if (ibuf == NULL)
+ return;
+ if (wpos != NULL)
+ *wpos = &ibuf->wpos;
+ if (end != NULL)
+ *end = &ibuf->end;
+
+}
diff --git a/src/box/ibuf.h b/src/box/ibuf.h
new file mode 100644
index 000000000..d17f8f4b4
--- /dev/null
+++ b/src/box/ibuf.h
@@ -0,0 +1,67 @@
+#pragma once
+/*
+ * Copyright 2020, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+
+#include <trivia/util.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+/** \cond public */
+
+typedef struct ibuf box_ibuf_t;
+
+/**
+ * Reserve requested amount of bytes in ibuf buffer
+ */
+API_EXPORT void *
+box_ibuf_reserve(box_ibuf_t *ibuf, size_t size);
+
+/**
+ * Return pointers to read range pointers used [rpos..wpos)
+ */
+API_EXPORT void
+box_ibuf_read_range(box_ibuf_t *ibuf, char ***rpos, char ***wpos);
+
+/**
+ * Return pointers to write range pointers used [wpos..end)
+ */
+API_EXPORT void
+box_ibuf_write_range(box_ibuf_t *ibuf, char ***wpos, char ***end);
+
+/** \endcond public */
+
+#if defined(__cplusplus)
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
diff --git a/test/app-tap/module_api.c b/test/app-tap/module_api.c
index e29abcb85..35df2403b 100644
--- a/test/app-tap/module_api.c
+++ b/test/app-tap/module_api.c
@@ -164,6 +164,49 @@ test_checkibuf(lua_State *L)
return 1;
}
+static int
+test_box_ibuf(lua_State *L)
+{
+ struct slab_cache *slabc = cord_slab_cache();
+ assert(slabc != NULL);
+ box_ibuf_t ibuf;
+
+ ibuf_create(&ibuf, slabc, 16320);
+ assert(ibuf_used(&ibuf) == 0);
+ void *ptr = box_ibuf_reserve(&ibuf, 65536);
+ assert(ptr != NULL);
+ char **rpos;
+ char **wpos;
+ box_ibuf_read_range(&ibuf, &rpos, &wpos);
+
+ ptr = ibuf_alloc(&ibuf, 10);
+ assert(ptr != NULL);
+
+ assert(ibuf_used(&ibuf) == 10);
+ assert((*wpos - *rpos) == 10);
+
+ /* let be a little bit paranoid and double check */
+ box_ibuf_read_range(&ibuf, &rpos, &wpos);
+ assert((*wpos - *rpos) == 10);
+
+ ptr = ibuf_alloc(&ibuf, 10000);
+ assert(ptr);
+ assert(ibuf_used(&ibuf) == 10010);
+ assert((*wpos - *rpos) == 10010);
+
+ size_t unused = ibuf_unused(&ibuf);
+ char **end;
+ box_ibuf_write_range(&ibuf, &wpos, &end);
+ assert((*end - *wpos) == (ptrdiff_t)unused);
+
+ ibuf_reset(&ibuf);
+ assert(ibuf_used(&ibuf) == 0);
+ assert(*rpos == *wpos);
+
+ lua_pushboolean(L, 1);
+ return 1;
+}
+
static int
test_touint64(lua_State *L)
{
@@ -1924,6 +1967,7 @@ luaopen_module_api(lua_State *L)
{"test_key_def_dup", test_key_def_dup},
{"tuple_validate_def", test_tuple_validate_default},
{"tuple_validate_fmt", test_tuple_validate_formatted},
+ {"test_box_ibuf", test_box_ibuf},
{NULL, NULL}
};
luaL_register(L, "module_api", lib);
diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua
index acda3deec..b8c10a310 100755
--- a/test/app-tap/module_api.test.lua
+++ b/test/app-tap/module_api.test.lua
@@ -141,7 +141,7 @@ local function test_iscdata(test, module)
end
local test = require('tap').test("module_api", function(test)
- test:plan(36)
+ test:plan(37)
local status, module = pcall(require, 'module_api')
test:is(status, true, "module")
test:ok(status, "module is loaded")
--
2.20.1
next prev parent reply other threads:[~2020-10-14 0:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-14 0:15 [Tarantool-patches] [PATCH 1.10 v4 0/5] module api: extend for external merger Lua module Timur Safin
2020-10-14 0:15 ` [Tarantool-patches] [PATCH 1.10 v4 1/5] module api: export box_tuple_validate Timur Safin
2020-10-14 0:15 ` [Tarantool-patches] [PATCH 1.10 v4 2/5] module api: export box_key_def_dup Timur Safin
2020-10-15 22:30 ` Alexander Turenko
2020-10-14 0:15 ` [Tarantool-patches] [PATCH 1.10 v4 3/5] module api: introduced luaT_toibuf instead of luaL_checkibuf Timur Safin
2020-10-14 0:15 ` Timur Safin [this message]
2020-10-14 0:15 ` [Tarantool-patches] [PATCH 1.10 v4 5/5] module api: add luaL_iscallable with support of cdata metatype Timur Safin
2020-10-14 0:18 ` [Tarantool-patches] [PATCH 1.10 v4 0/5] module api: extend for external merger Lua module Timur Safin
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=897bee05462bf6c32613f87a84c170bec1f3d113.1602634213.git.tsafin@tarantool.org \
--to=tsafin@tarantool.org \
--cc=alexander.turenko@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 1.10 v4 4/5] module api: box_ibuf_* wrappers' \
/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