[Tarantool-patches] [PATCH v3 2/2] memtx: allow quota overuse for truncation and deletion
Ilya Kosarev
i.kosarev at tarantool.org
Mon Jan 20 21:13:20 MSK 2020
Trying to perform space:truncate() and space:delete() while reaching
memtx_memory limit we could experience slab allocator failure. This
behavior seems to be quite surprising for users. Now we are allowing
to overuse memtx quota if needed for truncation or deletion, using flag
in struct quota. After performing truncation or deletion we reset the
flag so that quota can be overused any more.
Closes #3807
---
src/box/box.cc | 5 +++++
src/box/memtx_engine.c | 9 +++++++++
src/box/memtx_engine.h | 3 +++
src/box/memtx_space.c | 13 +++++++++----
src/lib/small | 2 +-
5 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/box/box.cc b/src/box/box.cc
index 1b2b27d61..678c9ffe3 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1321,9 +1321,14 @@ space_truncate(struct space *space)
ops_buf_end = mp_encode_uint(ops_buf_end, 1);
assert(ops_buf_end < buf + buf_size);
+ struct space *truncate_space = space_cache_find_xc(BOX_TRUNCATE_ID);
+ memtx_engine_set_quota_strictness(truncate_space->engine, false);
+
if (box_upsert(BOX_TRUNCATE_ID, 0, tuple_buf, tuple_buf_end,
ops_buf, ops_buf_end, 0, NULL) != 0)
diag_raise();
+
+ memtx_engine_set_quota_strictness(truncate_space->engine, true);
}
int
diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
index 4da80824a..c19205d34 100644
--- a/src/box/memtx_engine.c
+++ b/src/box/memtx_engine.c
@@ -1090,6 +1090,15 @@ memtx_engine_set_memory(struct memtx_engine *memtx, size_t size)
return 0;
}
+void
+memtx_engine_set_quota_strictness(struct engine *engine, bool strict)
+{
+ if (strncmp(engine->name, "memtx", 5) != 0)
+ return;
+ struct memtx_engine *memtx = (struct memtx_engine *)engine;
+ quota_set_strictness(&memtx->quota, strict);
+}
+
void
memtx_engine_set_max_tuple_size(struct memtx_engine *memtx, size_t max_size)
{
diff --git a/src/box/memtx_engine.h b/src/box/memtx_engine.h
index f562c66df..0793fc2ab 100644
--- a/src/box/memtx_engine.h
+++ b/src/box/memtx_engine.h
@@ -213,6 +213,9 @@ memtx_engine_set_snap_io_rate_limit(struct memtx_engine *memtx, double limit);
int
memtx_engine_set_memory(struct memtx_engine *memtx, size_t size);
+void
+memtx_engine_set_quota_strictness(struct engine *engine, bool strict);
+
void
memtx_engine_set_max_tuple_size(struct memtx_engine *memtx, size_t max_size);
diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index 6ef84e045..20ce2f974 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -354,10 +354,15 @@ memtx_space_execute_delete(struct space *space, struct txn *txn,
struct tuple *old_tuple;
if (index_get(pk, key, part_count, &old_tuple) != 0)
return -1;
- if (old_tuple != NULL &&
- memtx_space->replace(space, old_tuple, NULL,
- DUP_REPLACE_OR_INSERT, &stmt->old_tuple) != 0)
- return -1;
+ if (old_tuple != NULL) {
+ memtx_engine_set_quota_strictness(space->engine, false);
+ int rc = memtx_space->replace(space, old_tuple, NULL,
+ DUP_REPLACE_OR_INSERT,
+ &stmt->old_tuple);
+ memtx_engine_set_quota_strictness(space->engine, true);
+ if (rc != 0)
+ return -1;
+ }
stmt->engine_savepoint = stmt;
*result = stmt->old_tuple;
return 0;
diff --git a/src/lib/small b/src/lib/small
index 50cb78743..bdcd569f9 160000
--- a/src/lib/small
+++ b/src/lib/small
@@ -1 +1 @@
-Subproject commit 50cb7874380b286f3b34c82299cf5eb88b0d0059
+Subproject commit bdcd569f9ed753efb805f708089ca86e2520a44f
--
2.17.1
More information about the Tarantool-patches
mailing list