[PATCH 2/3] vinyl: don't populate cache if box.cfg.vinyl_cache is 0

Vladimir Davydov vdavydov.dev at gmail.com
Mon Feb 26 20:47:11 MSK 2018


Currently, new entries are added to the cache even if the limit is set
to 0, which is obviously incorrect. Fix it. This might be useful for
debugging and/or performance evaluation.

Closes #3172
---
 src/box/vy_cache.c        |  5 +++++
 test/vinyl/cache.result   | 22 ++++++++++++++++++++++
 test/vinyl/cache.test.lua |  7 +++++++
 3 files changed, 34 insertions(+)

diff --git a/src/box/vy_cache.c b/src/box/vy_cache.c
index 8a6c53f7..121a4263 100644
--- a/src/box/vy_cache.c
+++ b/src/box/vy_cache.c
@@ -217,6 +217,11 @@ vy_cache_add(struct vy_cache *cache, struct tuple *stmt,
 	     struct tuple *prev_stmt, const struct tuple *key,
 	     enum iterator_type order)
 {
+	if (cache->env->mem_quota == 0) {
+		/* Cache is disabled. */
+		return;
+	}
+
 	/* Delete some entries if quota overused */
 	vy_cache_gc(cache->env);
 
diff --git a/test/vinyl/cache.result b/test/vinyl/cache.result
index 3ed4d0f9..b4812297 100644
--- a/test/vinyl/cache.result
+++ b/test/vinyl/cache.result
@@ -1051,6 +1051,28 @@ box.info.vinyl().cache.used
 ---
 - 0
 ...
+-- Make sure cache is not populated if box.cfg.vinyl_cache is set to 0
+st1 = s.index.pk:info().cache
+---
+...
+#s:select()
+---
+- 100
+...
+for i = 1, 100 do s:get{i} end
+---
+...
+st2 = s.index.pk:info().cache
+---
+...
+st2.put.rows - st1.put.rows
+---
+- 0
+...
+box.info.vinyl().cache.used
+---
+- 0
+...
 s:drop()
 ---
 ...
diff --git a/test/vinyl/cache.test.lua b/test/vinyl/cache.test.lua
index 40d55abf..9ff77cbb 100644
--- a/test/vinyl/cache.test.lua
+++ b/test/vinyl/cache.test.lua
@@ -373,5 +373,12 @@ box.cfg{vinyl_cache = 50 * 1000}
 box.info.vinyl().cache.used
 box.cfg{vinyl_cache = 0}
 box.info.vinyl().cache.used
+-- Make sure cache is not populated if box.cfg.vinyl_cache is set to 0
+st1 = s.index.pk:info().cache
+#s:select()
+for i = 1, 100 do s:get{i} end
+st2 = s.index.pk:info().cache
+st2.put.rows - st1.put.rows
+box.info.vinyl().cache.used
 s:drop()
 box.cfg{vinyl_cache = vinyl_cache}
-- 
2.11.0




More information about the Tarantool-patches mailing list