Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hotreloadability #10

Closed
wants to merge 1 commit into from
Closed

Fix hotreloadability #10

wants to merge 1 commit into from

Conversation

rosik
Copy link
Contributor

@rosik rosik commented May 25, 2021

Gracefully handle hotreload. It didn't work because postload.lua always tried to call ffi.metatype(), but luajit doesn't allow to do it twice for the same type.

Fixes #9.

@rosik rosik requested review from Totktonada and olegrok May 25, 2021 16:54
@Totktonada
Copy link
Member

Thanks! I got the idea and it looks okay on the first glance. I'll look deeper soon.

Copy link

@olegrok olegrok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patch. I left several comments. They are quite minor and some of them maybe could be skipped.

test:test('hotreload', function(test)
test:plan(2)

_G.tuple = nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that "tuple" defined in global affect something. It seems an artefact of luaL_register usage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I think it should not be so, it is the mistake.

Anyway, while the global is set at the module initialization, it looks meaningful to drop it in the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll propose a fix after PR #15. Too much PRs in the fly :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The draft commit is a56ff5d (as said, I'll open a PR later).

Copy link
Member

@Totktonada Totktonada Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened PR #16.

collectgarbage()
collectgarbage()

tuple_keydef = require('tuple.keydef')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case when this line fails all following tests will be stopped. I suggest to use something like:

local ok, tuple_keydef = pcall(require, 'tuple.keydef')
test:ok(ok)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However a next test case definitely will fail due to tuple_keydef = nil. We can move the test to a separate file or pass it over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PR #15 I moved those test cases into its own file. I wrapped require() into pcall(), where the goal of a test case is to verify, whether it succeeds. However I found it unconvenient to wrap a preparation code into pcall() (or wrap each test case into pcall()). So, in fact, nothing changes: if one test case will fail, others will not run.

If we'll move toward luatest, it'll handle this problem for us. But prior that I would disregard it.

Comment on lines +655 to +656
CTID_STRUCT_TUPLE_KEY_DEF_REF =
luaL_ctypeid(L, "struct tuple_keydef *");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's related to current patch and current problem. But is it possible to eliminate this call at all (https://github.com/tarantool/tarantool/blob/35dd826460e876c6cdb1ab7395ef7a5064615d2b/src/lua/utils.c#L141)?

E.g. initialize CTID_STRUCT_TUPLE_KEY_DEF_REF by default (with e.g. 0) and then call luaL_ctypeid only if value is 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm not sure I got the idea. Do you propose to set it at the first load and don't touch on next reloads?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you propose to set it at the first load and don't touch on next reloads?

Yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I don't know, whether I should do or don't. The behaviour is exactly same. I left it as is in PR #15, it is out of scope there.

@Totktonada
Copy link
Member

I proposed an alternative fix in PR #15.

My doubts about this implementation (PR #10) are the following:

  1. It produces implicit dependencies between the Lua/C code and the Lua code: we should call all those ffi.cdef() / ffi.metatype() / luaL_ctypeid() in a particular order. (That's why luaL_ctypeid() is moved here. And it makes the postload code being a kind of… middle load?)
  2. It leans on persence of the struct tuple_keydef ctype as on indicator that we set a metatype on it. So, it is impossible to declare the ctype prior to a first load of the module. (BTW, it is easy to fix in this implementation too.)
  3. It moves more code to the postload.lua file, but I would prefer to keep it as small as possible. A module is more readable, when tightly coupled parts are not spread across different files. Here I need the Lua part only to call ffi.metatype() (there is no corresponding C API). But the 'direct' bundling into the Lua/C code using loadstring() would look even worse. I think that currrent solution with the separate postload.lua (which is bundled into .so) is the least evil way, while we'll keep the postload.lua small and simple.

Since all those points may be eliminated, I think that they should be eliminated. I did it in PR #15.

@Totktonada Totktonada mentioned this pull request Jun 2, 2021
@Totktonada
Copy link
Member

Superseded by PR #15.

@Totktonada Totktonada closed this Jun 3, 2021
@Totktonada Totktonada deleted the 9-fix-hotreloadability branch June 3, 2021 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

module is not reloadable
3 participants