[PATCH 2/2] vinyl: implement space.bsize, index.bsize, and index.len

Vladimir Davydov vdavydov.dev at gmail.com
Sun Feb 4 18:57:44 MSK 2018


 - space.bsize returns the size of data stored in the space.
   It is the sum of memory.bytes and disk.bytes as reported
   by the primary index.

 - index.bsize returns the size of memory used for indexing data.
   It is the sum of memory.index_size, disk.index_size, and
   disk.bloom_size as reported by index.info.

 - index.len returns the total number of rows stored in the index.
   It is the sum of memory.rows and disk.rows as reported by
   index.info. Note, it may be greater than the number of tuples
   stored in the space, because it includes DELETE and UPDATE
   statements.

Closes #2863
Closes #3056
---
 src/box/vinyl.c                |  19 +++--
 test/vinyl/constraint.result   |  16 -----
 test/vinyl/constraint.test.lua |   9 ---
 test/vinyl/ddl.result          |  30 --------
 test/vinyl/ddl.test.lua        |  15 ----
 test/vinyl/info.result         | 159 +++++++++++++++++++++++++++++++++++++++++
 test/vinyl/info.test.lua       |  52 ++++++++++++++
 7 files changed, 226 insertions(+), 74 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 65bcbc02..75ddaa5b 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -1200,15 +1200,26 @@ vinyl_space_build_secondary_key(struct space *old_space,
 static size_t
 vinyl_space_bsize(struct space *space)
 {
-	(void)space;
-	return 0;
+	struct index *pk_base = space_index(space, 0);
+	if (pk_base == NULL)
+		return 0;
+	struct vy_index *pk = vy_index(pk_base);
+	return pk->stat.memory.count.bytes + pk->stat.disk.count.bytes;
+}
+
+static ssize_t
+vinyl_index_size(struct index *base)
+{
+	struct vy_index *index = vy_index(base);
+	return index->stat.memory.count.rows + index->stat.disk.count.rows;
 }
 
 static ssize_t
 vinyl_index_bsize(struct index *base)
 {
 	struct vy_index *index = vy_index(base);
-	return index->stat.memory.count.bytes;
+	return vy_index_mem_tree_size(index) +
+		index->page_index_size + index->bloom_size;
 }
 
 /* {{{ Public API of transaction control: start/end transaction,
@@ -3998,7 +4009,7 @@ static const struct index_vtab vinyl_index_vtab = {
 	/* .destroy = */ vinyl_index_destroy,
 	/* .commit_create = */ vinyl_index_commit_create,
 	/* .commit_drop = */ vinyl_index_commit_drop,
-	/* .size = */ generic_index_size,
+	/* .size = */ vinyl_index_size,
 	/* .bsize = */ vinyl_index_bsize,
 	/* .min = */ generic_index_min,
 	/* .max = */ generic_index_max,
diff --git a/test/vinyl/constraint.result b/test/vinyl/constraint.result
index 4c9807b8..46ed1c9e 100644
--- a/test/vinyl/constraint.result
+++ b/test/vinyl/constraint.result
@@ -142,19 +142,3 @@ space = nil
 pk = nil
 ---
 ...
--------------------------------------------------------------------------------
--- space:len() is unsupported
--------------------------------------------------------------------------------
-space = box.schema.space.create('test_len', { engine = 'vinyl' })
----
-...
-_ = space:create_index('primary', { type = 'tree', parts = {1, 'string'}})
----
-...
-space:len()
----
-- error: Index 'primary' (TREE) of space 'test_len' (vinyl) does not support size()
-...
-space:drop()
----
-...
diff --git a/test/vinyl/constraint.test.lua b/test/vinyl/constraint.test.lua
index bdfa3780..4a785f7b 100644
--- a/test/vinyl/constraint.test.lua
+++ b/test/vinyl/constraint.test.lua
@@ -49,12 +49,3 @@ t3 = space:insert({string.rep('x', 102200)})
 space:drop()
 space = nil
 pk = nil
-
--------------------------------------------------------------------------------
--- space:len() is unsupported
--------------------------------------------------------------------------------
-
-space = box.schema.space.create('test_len', { engine = 'vinyl' })
-_ = space:create_index('primary', { type = 'tree', parts = {1, 'string'}})
-space:len()
-space:drop()
diff --git a/test/vinyl/ddl.result b/test/vinyl/ddl.result
index a0c41a1d..13a0f8d9 100644
--- a/test/vinyl/ddl.result
+++ b/test/vinyl/ddl.result
@@ -229,36 +229,6 @@ space:drop()
 ---
 ...
 --
--- gh-1632: index:bsize()
---
-space = box.schema.space.create('test', { engine = 'vinyl' })
----
-...
-pk = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}  })
----
-...
-for i=1,10 do box.space.test:replace({i}) end
----
-...
-box.space.test.index.primary:bsize() > 0
----
-- true
-...
-box.snapshot()
----
-- ok
-...
-while space.index.primary:info().run_count ~= 1 do fiber.sleep(0.01) end
----
-...
-box.space.test.index.primary:bsize() == 0
----
-- true
-...
-space:drop()
----
-...
---
 -- gh-1709: need error on altering space
 --
 space = box.schema.space.create('test', {engine='vinyl'})
diff --git a/test/vinyl/ddl.test.lua b/test/vinyl/ddl.test.lua
index 1761c430..031dc5fd 100644
--- a/test/vinyl/ddl.test.lua
+++ b/test/vinyl/ddl.test.lua
@@ -85,21 +85,6 @@ space.index.primary:alter({parts = {1, 'unsigned', 2, 'unsigned'}})
 space:drop()
 
 --
--- gh-1632: index:bsize()
---
-space = box.schema.space.create('test', { engine = 'vinyl' })
-pk = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}  })
-for i=1,10 do box.space.test:replace({i}) end
-box.space.test.index.primary:bsize() > 0
-
-box.snapshot()
-while space.index.primary:info().run_count ~= 1 do fiber.sleep(0.01) end
-
-box.space.test.index.primary:bsize() == 0
-
-space:drop()
-
---
 -- gh-1709: need error on altering space
 --
 space = box.schema.space.create('test', {engine='vinyl'})
diff --git a/test/vinyl/info.result b/test/vinyl/info.result
index 2724cc3d..517cf056 100644
--- a/test/vinyl/info.result
+++ b/test/vinyl/info.result
@@ -912,6 +912,165 @@ stat_diff(gstat(), st, 'tx')
 ---
 - commit: 1
 ...
+--
+-- space.bsize, index.len, index.bsize
+--
+s:truncate()
+---
+...
+s:bsize()
+---
+- 0
+...
+s.index.pk:len()
+---
+- 0
+...
+s.index.pk:bsize()
+---
+- 0
+...
+for i = 1, 100, 2 do put(i) end
+---
+...
+st = istat()
+---
+...
+s:bsize()
+---
+- 53050
+...
+s:bsize() == st.memory.bytes
+---
+- true
+...
+s.index.pk:len()
+---
+- 50
+...
+s.index.pk:len() == st.memory.rows
+---
+- true
+...
+s.index.pk:bsize()
+---
+- 49152
+...
+s.index.pk:bsize() == st.memory.index_size
+---
+- true
+...
+box.snapshot()
+---
+- ok
+...
+st = istat()
+---
+...
+s:bsize()
+---
+- 52191
+...
+s:bsize() == st.disk.bytes
+---
+- true
+...
+s.index.pk:len()
+---
+- 50
+...
+s.index.pk:len() == st.disk.rows
+---
+- true
+...
+s.index.pk:bsize()
+---
+- 4642
+...
+s.index.pk:bsize() == st.disk.index_size + st.disk.bloom_size
+---
+- true
+...
+for i = 1, 100, 2 do s:delete(i) end
+---
+...
+for i = 2, 100, 2 do put(i) end
+---
+...
+st = istat()
+---
+...
+s:bsize()
+---
+- 106941
+...
+s:bsize() == st.memory.bytes + st.disk.bytes
+---
+- true
+...
+s.index.pk:len()
+---
+- 150
+...
+s.index.pk:len() == st.memory.rows + st.disk.rows
+---
+- true
+...
+s.index.pk:bsize()
+---
+- 53794
+...
+s.index.pk:bsize() == st.memory.index_size + st.disk.index_size + st.disk.bloom_size
+---
+- true
+...
+st = istat()
+---
+...
+box.snapshot()
+---
+- ok
+...
+wait(istat, st, 'disk.compact.count', 1)
+---
+...
+st = istat()
+---
+...
+s:bsize()
+---
+- 52191
+...
+s:bsize() == st.disk.bytes
+---
+- true
+...
+s.index.pk:len()
+---
+- 50
+...
+s.index.pk:len() == st.disk.rows
+---
+- true
+...
+s.index.pk:bsize()
+---
+- 4642
+...
+s.index.pk:bsize() == st.disk.index_size + st.disk.bloom_size
+---
+- true
+...
+s.index.pk:drop()
+---
+...
+s:bsize()
+---
+- 0
+...
+s:drop()
+---
+...
 test_run:cmd('switch default')
 ---
 - true
diff --git a/test/vinyl/info.test.lua b/test/vinyl/info.test.lua
index b1c9bd5f..55a07b13 100644
--- a/test/vinyl/info.test.lua
+++ b/test/vinyl/info.test.lua
@@ -309,6 +309,58 @@ stat_diff(gstat(), st, 'tx')
 box.commit()
 stat_diff(gstat(), st, 'tx')
 
+--
+-- space.bsize, index.len, index.bsize
+--
+
+s:truncate()
+s:bsize()
+s.index.pk:len()
+s.index.pk:bsize()
+
+for i = 1, 100, 2 do put(i) end
+st = istat()
+s:bsize()
+s:bsize() == st.memory.bytes
+s.index.pk:len()
+s.index.pk:len() == st.memory.rows
+s.index.pk:bsize()
+s.index.pk:bsize() == st.memory.index_size
+
+box.snapshot()
+st = istat()
+s:bsize()
+s:bsize() == st.disk.bytes
+s.index.pk:len()
+s.index.pk:len() == st.disk.rows
+s.index.pk:bsize()
+s.index.pk:bsize() == st.disk.index_size + st.disk.bloom_size
+
+for i = 1, 100, 2 do s:delete(i) end
+for i = 2, 100, 2 do put(i) end
+st = istat()
+s:bsize()
+s:bsize() == st.memory.bytes + st.disk.bytes
+s.index.pk:len()
+s.index.pk:len() == st.memory.rows + st.disk.rows
+s.index.pk:bsize()
+s.index.pk:bsize() == st.memory.index_size + st.disk.index_size + st.disk.bloom_size
+
+st = istat()
+box.snapshot()
+wait(istat, st, 'disk.compact.count', 1)
+st = istat()
+s:bsize()
+s:bsize() == st.disk.bytes
+s.index.pk:len()
+s.index.pk:len() == st.disk.rows
+s.index.pk:bsize()
+s.index.pk:bsize() == st.disk.index_size + st.disk.bloom_size
+
+s.index.pk:drop()
+s:bsize()
+s:drop()
+
 test_run:cmd('switch default')
 test_run:cmd('stop server test')
 test_run:cmd('cleanup server test')
-- 
2.11.0




More information about the Tarantool-patches mailing list