[PATCH v2 0/3] schema: expose space_mt and index_mt on box.schema table

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Apr 3 19:50:44 MSK 2018

Branch: http://github.com/tarantool/tarantool/tree/pr-3204-expose-space-index-mt
Issue: https://github.com/tarantool/tarantool/issues/3204

Space_mt and index_mt are created individually for each space
inside a giant space.bless function. It consumes lua memory by
duplicating these metatables (which is very limited), and does not
allow to add new functions or redefine existing ones, which would
be visible in all spaces and indexes. Lets solve the problems one
by one.

At first, move space_mt and index_mt definitions out of
space.bless function. Now space.bless just copy space_mt and
inherit a needed index_mt depending on egine.

At second, instead of customization of index_mt copy on each
space.bless lets once create separate index metatables for memtx
and for vinyl, and just copy needed in space.bless. With no
selecting yielding/non-yielding methods inside the function.

At third, just stop copying in bless, start reference metatables
instead, and open them to users via box.schema:
box.schema.space_mt - metatable of all spaces;
box.schema.index_mt - base metatable of all indexes - replicated
                      into the vinyl and memtx. See below how.
box.schema.vinyl_index_mt - metatable of all vinyl indexes;
box.schema.memtx_index_mt - metatable of all memtx indexes. 

Once metatables become global and shared, they can be easy
extended. However there is a non-trival task how to make index
metatable extension be transparent for a user, if a user modifies
not vinyl or memtx metatable, but box.schema.index_mt. It would be
good to replicate all changes of a base metatable over engine
specific ones.

This is solved using "metatable for a metatable". When a user
modifies box.schema.index_mt, these changes via __newindex method
of box.schema.index_mt are replicated both into memtx and vinyl
index metatables.

Vladislav Shpilevoy (3):
  schema: move space_mt and index_mt definition out of space bless
  schema: inherit vinyl/memtx_index_mt from base index mt
  schema: expose space_mt and index_mt on box.schema table

 src/box/lua/schema.lua          | 663 +++++++++++++++++++++-------------------
 test/box-tap/schema_mt.test.lua |  80 +++++
 2 files changed, 424 insertions(+), 319 deletions(-)
 create mode 100755 test/box-tap/schema_mt.test.lua

2.14.3 (Apple Git-98)

More information about the Tarantool-patches mailing list