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 E7BE26EC5D; Fri, 2 Apr 2021 15:34:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E7BE26EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617366867; bh=BmwEodHLsczGLjOP1iXofAJ1xYr1LX9wMmvjJg09xxk=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=whupYOOU/aRx4dgqhn5CDr6kn+X9ZRzylG4IGcR4Cn0IhnqW1TG2u3opGbHtoQ/kX vSMjkstyGWv5bi+ffT3H764uryX8SIMav/z/DpyCm4VvA1+u9oo1OwNbstcsrYEmRp jaZ/7p3tlq9ZGQslv+q/U6GzGL/T4bQsmMSY0mRE= Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 8FEEF6EC5D for ; Fri, 2 Apr 2021 15:34:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8FEEF6EC5D Received: by mail-lf1-f48.google.com with SMTP id d12so7368386lfv.11 for ; Fri, 02 Apr 2021 05:34:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tldzrCP/b5vJYzHcmprCcKQnQTQ69X37w+kKer3Dpi4=; b=JEAByiCukc9pWEW+mkpYMuDm4Udk/Va7p0nMj5sj7+NA0kUaxEi4FovR6j3zwASbE+ glinV2wySwoZhJjoh0CpZOmU+t4yB0O6COG19Ay7HCw/8ccKYKoExM/OHAm42ZJ1FB2D FC9h6RDrkmj46E0zpZdz+kaDFKmGTqDTrI1HyUAVBoGQ9YAXPQDmSgOYXX1R7muiwLAz 71Tw31Uv5U0ulIduJu6ikfPNIeVxdnBC1IGVvAI2w/iUb28pDn54w2dBdUu0x0fzMVrP qR8XiasYt6uP39W6WPoWWiThWfj2ERCty+DOouEwkfmbtMmM6pmyVdaKgDKDUPZwJm6q khkA== X-Gm-Message-State: AOAM532Xq1egN9OVLYusRYK5StpcBVWkzSqhdZT5VVmZXsjadVHFIfqG GBudj1Fd4GHWoihEyyh1FNG5EgjF0F4d2Q== X-Google-Smtp-Source: ABdhPJw0rtkjxT2bPLs1dD1GOOpo+918tgwbi8aLsbLITxFEUJdlY3TXpiwtSurXEerKnX/QsxlnTg== X-Received: by 2002:a19:c7c3:: with SMTP id x186mr8488677lff.76.1617366864409; Fri, 02 Apr 2021 05:34:24 -0700 (PDT) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id q25sm853594lfn.42.2021.04.02.05.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Apr 2021 05:34:22 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 1CAEC5601C4; Fri, 2 Apr 2021 15:34:22 +0300 (MSK) To: tml Date: Fri, 2 Apr 2021 15:34:13 +0300 Message-Id: <20210402123420.885834-1-gorcunov@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v20 0/7] box: implement box.lib Lua module 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: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Please take a look once time permit. v1-v3 are development ones and not sent. v5 (by vlad): - drop exists, list methods: they are redundant - rename cfunc to cbox - when create a function make it callable Lua object - initialize cbox out of modules - fix error in passing module name for reloading - make api been cbox.func.[create|drop] and cbox.module.reload - fix test for OSX sake v6 (by vlad): - move module handling into module_cache file. v7: - development v8: - use rbtree for function instance storage, since i don't like the idea of unexpected rehashing of values in case of massive number of functions allocated - use reference counter and free function instance if only load/unload are coupled - keep a pointer to the function inside Lua object so we don't need to lookup on every function call. this force us to implement __gc method - use new API and update docs v9: - development v10: - use hashes for function names lookup - simply function loads counting - use luaL_register_module and luaL_register_type for easier methods registering - carry functions as userdata object v11: - development v12: - switch to new API as been discussed in https://lists.tarantool.org/tarantool-patches/e186c454-6765-4776-6433-f3f791ff4c27@tarantool.org/ v13: - development v14: - switch to refs to carry module usage - drop func_name structure renaming - carry two hashes for backward compatibility with functions created via box.schema.func help - complete rework of cmod and most parts of module_cache - account for file statistics to invalidate module cache - new API for cmod, no more :reload, the :load procedure uses cache invalidation - update test cases - still there is no GC test since I didn't manage to deal with it v15: - report module state cached/orphan - update test cases - do not prevent functions lookup in orphan modules - there was an idea to use box.shema.func cache as on top of cmod's one, but this doesn't work because in case if module doesnt exist in any caches we would put it into into cmod's one as well but there wont be a module on cmod level which would clean it up later (which makes code a way more comple if we choose to track state of modules). v16: - internal v17: - drop idea of unifying box.schema.func and cmod functions cache, it brings more problems than solves due to too different context of execution; - make cmod self consistent, which shrink patch series size ~1/5 in compare with previous attempts; - improve tests to account internal states of modules and functions (tt_dev key in reports). v18: - implement pass-through cache for modules loading, for this sake 'struct module' uses cmod internally; - improve tests to cover sole cmod case and a mixture of box.schema.func and cmod to make sure the caches are not corrupted. v19: - move module handling into separate subsystem; - switch box.schema.func and cmod to use this shared code to eliminate code duplication; - update tests. v20: - fix potential nil dereference in schema_init while I'm in the code; - during working on the series found a bug in module recovery, fixed it in the series because my further work depends on it; - main module which allows to create C functions now named as box.lib; - structures renaming: - box.schema.func uses struct schema_module to carry underlied struct module; - box.lib uses struct module directly and struct box_module_func to carry cache of functions. - name unification: - schema_module variables are named as `mod`; - box.schema.func api prefixed as `schema_module_x`; - debug properties for module counting prefixed as `debug_x`; - the test remains disabled because - I run it locally all the time - better to have it in repo and enable then since patching test-run can take weeks, it is slow procedure Cyrill Gorcunov (7): box/schema: make sure hashes are created box/func: module_reload -- drop redundant argument box/func: fix modules functions restore box/module_cache: introduce modules subsystem box/schema.func: switch to new module api box: implement box.lib module test: add box.lib test changelogs/unreleased/fix-module-reload.md | 4 + src/box/CMakeLists.txt | 2 + src/box/box.cc | 4 +- src/box/call.c | 9 +- src/box/func.c | 545 ++++++++----------- src/box/func.h | 28 +- src/box/func_def.h | 14 - src/box/lua/box_lib.c | 590 +++++++++++++++++++++ src/box/lua/box_lib.h | 25 + src/box/lua/init.c | 2 + src/box/module_cache.c | 474 +++++++++++++++++ src/box/module_cache.h | 208 ++++++++ src/box/schema.cc | 7 + src/main.cc | 3 + test/box/CMakeLists.txt | 6 + test/box/cfunc1.c | 58 ++ test/box/cfunc2.c | 137 +++++ test/box/cfunc3.c | 25 + test/box/cfunc4.c | 28 + test/box/func_restore.result | 103 ++++ test/box/func_restore.test.lua | 43 ++ test/box/func_restore1.c | 34 ++ test/box/func_restore2.c | 28 + test/box/gh-4648-func-load-unload.result | 7 +- test/box/gh-4648-func-load-unload.test.lua | 7 +- test/box/lib.result | 530 ++++++++++++++++++ test/box/lib.test.lua | 203 +++++++ test/box/misc.result | 1 + test/box/suite.ini | 2 +- 29 files changed, 2757 insertions(+), 370 deletions(-) create mode 100644 changelogs/unreleased/fix-module-reload.md create mode 100644 src/box/lua/box_lib.c create mode 100644 src/box/lua/box_lib.h create mode 100644 src/box/module_cache.c create mode 100644 src/box/module_cache.h create mode 100644 test/box/cfunc1.c create mode 100644 test/box/cfunc2.c create mode 100644 test/box/cfunc3.c create mode 100644 test/box/cfunc4.c create mode 100644 test/box/func_restore.result create mode 100644 test/box/func_restore.test.lua create mode 100644 test/box/func_restore1.c create mode 100644 test/box/func_restore2.c create mode 100644 test/box/lib.result create mode 100644 test/box/lib.test.lua base-commit: 22e2e4eaad7796f7b0142cc7e603f9fe895f6642 -- 2.30.2