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 AF6FD6EC5F; Tue, 2 Mar 2021 00:23:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AF6FD6EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1614633830; bh=v4qWgkSWbyD/qkNtkPt6dHD6q1+xVuNnmjX7z/o7Rmg=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=dURUYBzT8xXuMu+XV2mavaaV7eRp4/SzNii3cW99NxbPpvGJz5bDYyj/cEvDgkWwy +jwFdGm/o53ldr5XoBSynteQVTOVF/RgqXdpf5oZTigBAfy4QzmYYsy2t8Qyf+6bBF gJRvGUyK+araeU9RoaSFSQLHx6a/99qej/0YRObc= Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 1BD556EC5F for ; Tue, 2 Mar 2021 00:23:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1BD556EC5F Received: by mail-lf1-f50.google.com with SMTP id n16so10934997lfb.4 for ; Mon, 01 Mar 2021 13:23:49 -0800 (PST) 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=6izAoPg74uSlGa1PN1+qzRzLAaNldDUTEtqXk2IjDiM=; b=CVsOp9fgabFj5MpVqAaLRcK0WrKaLwlvfP3KImqVoQLTNdDh04JgDSi4ByRn9l+2BT tAVtQago5hMzYJgMPau9At0eua8Fw2svRnX5DV+p4eMfgCMhJMrHh2BHgmJ6k+9LzvKx DkYCuaux6ayXZRK+UJnP0xzXtvNnYKfWlbXrv+NxGCDeqq9KcBV1OumE/CBsb1nYjzwv 5JAlZpTuZJm2MG8ELLlQMA0cUXMlXXYyb1ApzHQiY7WkMo6ulveiScAWzUzUJ1R2TfOE z8lEGZCSgserswU9sw9MFO3dICNmIlBCw611bDwrj3I1IrJmSFSJp6akHvYaStKiazNf jBhw== X-Gm-Message-State: AOAM530ArWfrEL5pIvwV6XmjiecjtDYr9ixZJP097SOWxa4V6ZaJccs3 cJ0trB9K+qxytQ/kOUyr6Ga2uL4H/6TWqw== X-Google-Smtp-Source: ABdhPJzO2ZudUGjoNiMiQHrnL5EOSy2QN5vI0PTAUAYrSBpke32XNCpVcKDGo3hFFdJQyNo4iRltYQ== X-Received: by 2002:ac2:4350:: with SMTP id o16mr10538609lfl.585.1614633827856; Mon, 01 Mar 2021 13:23:47 -0800 (PST) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id s22sm1625552ljd.28.2021.03.01.13.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 13:23:46 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 0346156017D; Tue, 2 Mar 2021 00:23:45 +0300 (MSK) To: tml Date: Tue, 2 Mar 2021 00:23:37 +0300 Message-Id: <20210301212343.422372-1-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v19 0/6] box: implement cmod 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. branch gorcunov/gh-4642-func-ro-19 issue https://github.com/tarantool/tarantool/issues/4642 Cyrill Gorcunov (6): box/func: module_reload -- drop redundant argument box/func: prepare for transition to modules subsystem box/module_cache: introduce modules subsystem box/func: switch to module_cache interface box/cmod: implement cmod Lua module test: box/cfunc -- add cmod test src/box/CMakeLists.txt | 2 + src/box/box.cc | 4 +- src/box/call.c | 11 +- src/box/call.h | 2 +- src/box/func.c | 573 ++++++++++++++++--------------------- src/box/func.h | 26 +- src/box/func_def.h | 14 - src/box/lua/call.c | 2 +- src/box/lua/cmod.c | 605 ++++++++++++++++++++++++++++++++++++++++ src/box/lua/cmod.h | 25 ++ src/box/lua/init.c | 2 + src/box/module_cache.c | 476 +++++++++++++++++++++++++++++++ src/box/module_cache.h | 206 ++++++++++++++ src/main.cc | 3 + test/box/CMakeLists.txt | 4 + test/box/cfunc1.c | 58 ++++ test/box/cfunc2.c | 137 +++++++++ test/box/cfunc3.c | 25 ++ test/box/cfunc4.c | 28 ++ test/box/cmod.result | 530 +++++++++++++++++++++++++++++++++++ test/box/cmod.test.lua | 203 ++++++++++++++ test/box/suite.ini | 2 +- 22 files changed, 2556 insertions(+), 382 deletions(-) create mode 100644 src/box/lua/cmod.c create mode 100644 src/box/lua/cmod.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/cmod.result create mode 100644 test/box/cmod.test.lua base-commit: 1583ec241c25c0efb706d6401f5d28e145189cc2 -- 2.29.2