Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [PATCH 2/2] schema: expose space_mt and index_mt on `box.schema` table
Date: Mon, 2 Apr 2018 14:28:43 +0300	[thread overview]
Message-ID: <20180402112843.k5szaedwomi4gtl3@esperanza> (raw)
In-Reply-To: <95fd6df65760120d64d3dc7cd4f2c2c322ff76ff.1522580337.git.v.shpilevoy@tarantool.org>

On Sun, Apr 01, 2018 at 02:02:46PM +0300, Vladislav Shpilevoy wrote:
>  function box.schema.space.bless(space)
> -    local index_mt = table.deepcopy(index_mt)
> -    local space_mt = table.deepcopy(space_mt)
> +    -- At first, reference all global index functions. At second,
> +    -- choose an implementation for read operations. They are not
> +    -- in a global index_mt, because they are engine specific.
> +    -- All common index_mt functions must be referenced here to
> +    -- be able to get them using getmetatable(index_object) - if
> +    -- they are only in index_mt, then getmetatable() returns only
> +    -- read ops.
> +    local local_index_mt = table.deepcopy(index_mt)
> +    local_index_mt.__index = function(index, key)
> +        return local_index_mt[key] or index_mt[key]
> +    end

I don't really like that you use the same metatable for all spaces, but
a separate metatable for each index. Besides, because of this one can't
overwrite a built-in method (e.g. 'get') as it will be masked by
local_index_mt. AFAIU you do this, because vinyl and memtx use different
methods (luac vs ffi) for certain operations.

I see the following alternatives:

 1. Leave as is. This isn't all so bad. After all, I doubt anybody's
    actually willing to overwrite built-in methods.

 2. Use two metatables, one for all memtx indexes, another for vinyl,
    and push all changes from the public index_mt to both of these
    metatables. Not quite sure it's technically possible in Lua.

 3. Same as #2, but proscribe modification of built-in methods.

 4. Add a separate engine-specific metatable for the method that differ
    between memtx and vinyl, then define __index as:

    local engine_index_mt = (engine == 'memtx' and
                             memtx_index_mt or vinyl_index_mt)
    index_mt.__index = function(index, key)
        return index_mt[key] or engine_index_mt[key]

Personally, I like #4 most, but it may affect performance.
Anyway, I guess this is up to Kostja to decide which one to choose.

I don't see any other technical problems in the patch, nor in the test.

>      -- true if reading operations may yield
>      local read_yields = space.engine == 'vinyl'
>      local read_ops = {'select', 'get', 'min', 'max', 'count', 'random', 'pairs'}
>      for _, op in ipairs(read_ops) do
>          if read_yields then
>              -- use Lua/C implmenetation
> -            index_mt[op] = index_mt[op .. "_luac"]
> +            local_index_mt[op] = index_mt[op .. "_luac"]
>          else
>              -- use FFI implementation
> -            index_mt[op] = index_mt[op .. "_ffi"]
> +            local_index_mt[op] = index_mt[op .. "_ffi"]
>          end
>      end
>      index_mt.__pairs = index_mt.pairs -- Lua 5.2 compatibility
> @@ -1430,7 +1441,7 @@ function box.schema.space.bless(space)
>      if type(space.index) == 'table' and space.enabled then
>          for j, index in pairs(space.index) do
>              if type(j) == 'number' then
> -                setmetatable(index, index_mt)
> +                setmetatable(index, local_index_mt)
>              end
>          end
>      end

  reply	other threads:[~2018-04-02 11:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-23 13:07 [PATCH 0/2] schema: expose space_mt and index_mt on table Vladislav Shpilevoy
2018-03-23 13:07 ` [PATCH 1/2] schema: expose space_mt and index_mt on `box.schema` table Vladislav Shpilevoy
2018-03-23 13:07 ` [PATCH 2/2] schema: review fixes for box.schema.space/index metatables Vladislav Shpilevoy
2018-03-29 10:54 ` [PATCH 0/2] schema: expose space_mt and index_mt on table Vladimir Davydov
2018-03-29 14:31   ` [PATCH v2 0/2] schema: expose space_mt and index_mt on box.schema table Vladislav Shpilevoy
2018-03-29 14:31     ` [PATCH v2 1/2] schema: move space_mt and index_mt definition out of space bless Vladislav Shpilevoy
2018-04-01  9:33       ` Vladimir Davydov
2018-04-01 11:02         ` [PATCH 0/2] schema: expose space_mt and index_mt on box.schema table Vladislav Shpilevoy
2018-04-01 11:02           ` [PATCH 1/2] schema: move space_mt and index_mt definition out of space bless Vladislav Shpilevoy
2018-04-01 11:02           ` [PATCH 2/2] schema: expose space_mt and index_mt on `box.schema` table Vladislav Shpilevoy
2018-04-02 11:28             ` Vladimir Davydov [this message]
2018-04-03 16:50               ` [PATCH v2 0/3] schema: expose space_mt and index_mt on box.schema table Vladislav Shpilevoy
2018-04-03 16:50                 ` [PATCH v2 1/3] schema: move space_mt and index_mt definition out of space bless Vladislav Shpilevoy
2018-04-03 16:50                 ` [PATCH v2 2/3] schema: inherit vinyl/memtx_index_mt from base index mt Vladislav Shpilevoy
2018-04-03 16:50                 ` [PATCH v2 3/3] schema: expose space_mt and index_mt on box.schema table Vladislav Shpilevoy
2018-05-05 12:47                   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-08 16:48                     ` Konstantin Osipov
2018-05-08 17:33                       ` Vladislav Shpilevoy
2018-03-29 14:31     ` [PATCH v2 2/2] schema: expose space_mt and index_mt on `box.schema` table Vladislav Shpilevoy
2018-04-01  9:37     ` [PATCH v2 0/2] schema: expose space_mt and index_mt on box.schema table Vladimir Davydov

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=20180402112843.k5szaedwomi4gtl3@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [PATCH 2/2] schema: expose space_mt and index_mt on `box.schema` table' \
    /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