From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 819516EC40; Thu, 12 Aug 2021 20:49:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 819516EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628790587; bh=2oaWxR2JBeW5/hpUBPTKTKj9hXSjHEHw7DFEUmpoFwk=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=OvSOAlfEhbWukyQhZ6kymCvuHb2M1mbBImdpAow8/orIbK44zsR6QspkswGrSG4Ky OhlxKf3ISXB8/oYTabyKZohzuYVSfwRa/4/AmksacSy5iFDr7WEMbhzQCMeWvf5s92 LlkLbxSNlWZV4+jpi+mS4n1UxhOlGhhpUEiNS/yk= Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2816D6EC40 for ; Thu, 12 Aug 2021 20:49:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2816D6EC40 Received: by smtp54.i.mail.ru with esmtpa (envelope-from ) id 1mEEps-0006XR-NM; Thu, 12 Aug 2021 20:49:45 +0300 To: mechanik20051988 , tarantool-patches@dev.tarantool.org, vdavydov@tarantool.org Cc: mechanik20051988 References: Message-ID: Date: Thu, 12 Aug 2021 20:49:38 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9D5AC6413C25DCF08CC98B8FCC5CD86F3182A05F5380850404516560FD4D906063950AF82B66788FACC8175754004FAB6D6BBB947EF51BE71 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AEA4A6B3AFC9B957C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7C8DD139BC0BB8586EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2A5B362A2510AB84777A2A8339ABEDAC6CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F3E38EE449E3E2AE389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D2A98E5A6551E3E5117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFE52EFDB9F8BB5AAABA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B634F1AF545B6E310876E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C468D16C903838CAB43847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D94463893BF8742D0BDFC54D9BFA51BC4 X-C1DE0DAB: 0D63561A33F958A544D4B346D525B8374C55D76C757A6A0D8FC00A3461D52D1CD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75A130F49D908D5024410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3480A9008907CB2FD01903A5C7AA2A95FCF1B998EE622BA6650041ED4911DCFB778B279F4F2C985C5D1D7E09C32AA3244CC83FC54EA0216B48075B120094C8AC24853296C06374E602927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojKW4rnL99YhLX79OOr/kJUQ== X-Mailru-Sender: DCB18673505F245B5D9D3B35E842BD3CB1BFA0E3F0AA3B653569BBDF7577CA94E18FAA178FFD3B26841FB911095AA09146E8006E22572C39C920B61C43410E8717BDA556287159EE9437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 6/9] net.box: add stream support to net.box X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! See 2 comments below. > diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua > index 8f5671c15..8d707fb26 100644 > --- a/src/box/lua/net_box.lua > +++ b/src/box/lua/net_box.lua <...> > +-- Metatable for stream space indexes. When stream space being > +-- created there are no indexes in it. When accessing the space > +-- index, we look for corresponding space index in corresponding > +-- connection space. If it is found we create same index for the > +-- stream space but with corresponding stream ID. We do not need > +-- to compare stream _schema_version and connection schema_version, > +-- because all access to index is carried out through it's space. > +-- So we update schema_version when we access space. > +local stream_indexes_mt = { > + __index = function(self, key) > + local _space = self._space > + local src = _space._src.index[key] > + if not src then > + return nil > + end > + local res = stream_wrap_index(_space._stream_id, src) > + self[key] = res > + return res > + end, > + __serialize = stream_indexes_serialize > +} > + > +-- Create stream space, which is same as connection space, > +-- but have non zero stream ID. > +local function stream_wrap_space(stream, src) > + local res = setmetatable({ > + _stream_id = stream._stream_id, > + _src = src, > + index = setmetatable({ > + _space = nil, > + }, stream_indexes_mt) > + }, { > + __index = src, > + __serialize = stream_space_serialize > + }) 1. That is the thing I explicitly tried to avoid when proposed to make a light proxy of conn spaces - it is not good to create a new metatable for each space. Can you create it one time and use it for all space objects? Like stream_indexes_mt - it is shared by all 'index hashes'. The only reason you create the metatable here is to use 'src' as __index, but it might be done with a function. __index = function(self, key) return self._src[key] end And it does not need to be a closure. This should make possible to share the metatable by all spaces. The same for stream metatable in :new_stream(). > + res.index._space = res > + return res > +end > + > +-- Metatable for stream spaces. When stream being created there > +-- are no spaces in it. When user try to access some space in > +-- stream, we first of all compare _schema_version of stream with > +-- schema_version from connection and if they are not equal, we > +-- clear stream space cache and update it's schema_version. Then > +-- we look for corresponding space in the connection. If it is > +-- found we create same space for the stream but with corresponding > +-- stream ID. > +local stream_spaces_mt = { > + __index = function(self, key) > + local stream = self._stream > + if stream._schema_version ~= stream._conn.schema_version then > + stream._schema_version = stream._conn.schema_version > + self._stream_space_cache = {} > + end > + if self._stream_space_cache[key] then > + return self._stream_space_cache[key] > + end > + local src = stream._conn.space[key] 2. Please, try to cache 'stream._conn' into a local variable so as not to look it up more than once ('.' operator is not free). The same for stream._stream_space_cache. The same for stream._conn.schema_version. The same for _last_stream_id in :new_stream(). > + if not src then > + return nil > + end > + local res = stream_wrap_space(stream, src) > + self._stream_space_cache[key] = res > + return res > + end, > + __serialize = stream_spaces_serialize > +}