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 option to insert list in ets:insert, ets:lookup refactor #1405

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:

  • Enabled ets:insert/2 to accept lists for bulk insertion.
  • Extracted helper functions for ets:lookup/2 and ets:insert/2 that do not apply table locks.

Use Cases for the Helper Functions:

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

  • ets:update_element/3
  • ets:insert_new/2
  • ets:update_counter/3
  • ets:update_counter/4
  • ets:take/2
  • ets:delete_object/2

Every mentioned function will be implemented after merging of this PR.

}
EtsErrorCode result = ets_table_insert(ets_table, tuple, ctx);
if (result != EtsOk) {
AVM_ABORT(); // Abort because operation might not be atomic.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We usually don't do VM abort: calling AVM_ABORT() means that an unrecoverable happened, such as memory corruption, a bad internal bug and any other kind of situation that required an entire VM crash and reboot.
Are we in this specific situation?

Copy link
Contributor Author

@TheSobkiewicz TheSobkiewicz Jan 7, 2025

Choose a reason for hiding this comment

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

Now we don't have any other tool to ensure atomicity here. In case the insert fails at the Nth element, elements (0,N -1) will be inserted into the list, which could result in hard-to-debug behavior. It is unlikely to happen.

src/libAtomVM/ets.c Outdated Show resolved Hide resolved
src/libAtomVM/ets.c Show resolved Hide resolved
src/libAtomVM/ets.c Outdated Show resolved Hide resolved
tests/erlang_tests/test_ets.erl Show resolved Hide resolved
src/libAtomVM/ets.c Outdated Show resolved Hide resolved
src/libAtomVM/ets.c Outdated Show resolved Hide resolved
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch 3 times, most recently from ad7f86c to 76774f0 Compare January 9, 2025 15:11
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch from 76774f0 to 6ac7831 Compare January 9, 2025 15:44
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.

2 participants