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

Add ets:delete/1, ets:delete refactor #1461

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheSobkiewicz
Copy link
Contributor

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

Changes:

Use Cases for the Helper Functions:

The new helper functions can be utilized in the following ETS operations to reduce code duplication:

  • ets:take/2
  • ets:delete_object/2

@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_delete branch 3 times, most recently from 1a801a2 to c91b514 Compare January 9, 2025 15:46
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_delete branch 5 times, most recently from d657d7a to c8b5a2c Compare February 17, 2025 16:35
Comment on lines +456 to +458
SMP_UNLOCK(ets_table);
list_remove(&ets_table->head);
ets_table_destroy(ets_table, ctx->global);
Copy link
Contributor

Choose a reason for hiding this comment

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

So, what happens if we unlock here and somebody locks it for other operation when we destroy it in the meantime?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to deal with it, without SMP_UNLOCK it results in abort

fun() -> ets:insert(Tid, {gnu, gnat}) end
),
Ntid = ets:new(test_delete_table, []),
true = ets:delete(Ntid),
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also test what happens both when deleting something that has been already deleted, and when deleting twice the same thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

We also don't test for deleting non-existent table. Additionally, I don't get why we're doing insert + lookup if we don't do anything with it.

@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_delete branch from c8b5a2c to 152632a Compare February 25, 2025 18:46
@@ -141,3 +142,12 @@ update_counter(_Table, _Key, _Params) ->
) -> integer().
update_counter(_Table, _Key, _Params, _Default) ->
erlang:nif_error(undefined).
%%-----------------------------------------------------------------------------
%% @param Table a reference to the ets table
%% @returns true; otherwise, an error is raised if arguments are bad
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I don't find this @returns much of an help to be honest.

return EtsPermissionDenied;
}

struct ListHead *_ets_tables_list = synclist_wrlock(&ctx->global->ets.ets_tables);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why it starts with underscore?

fun() -> ets:insert(Tid, {gnu, gnat}) end
),
Ntid = ets:new(test_delete_table, []),
true = ets:delete(Ntid),
Copy link
Contributor

Choose a reason for hiding this comment

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

We also don't test for deleting non-existent table. Additionally, I don't get why we're doing insert + lookup if we don't do anything with it.

@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_delete branch 2 times, most recently from ba8a90b to 27a6254 Compare February 26, 2025 10:02
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_delete branch from 27a6254 to 5fccfb9 Compare March 3, 2025 11:11
@jakub-gonet
Copy link
Contributor

@bettio, @TheSobkiewicz maybe ready for review?

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.

3 participants