Skip to content

Use 'try'/'catch' rather than 'ets:whereis/1' for Khepri projections #11700

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

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

the-mikedavis
Copy link
Collaborator

See #11667 (comment)

ets:whereis/1 adds some overhead - it's two ETS calls rather than one when ets:whereis/1 returns a table identifier. It's also not atomic: the table could disappear between ets:whereis/1 calls and the call to read data from a projection. We replace all ets:whereis/1 calls on projection tables with try/catch and return default values when we catch the badarg error which ETS emits when passed a non-existing table name.

One special case though is ets:info/2 which returns undefined when passed a non-existing table names. That block is refactored to use a case instead.

`ets:whereis/1` adds some overhead - it's two ETS calls rather than one
when `ets:whereis/1` returns a table identifier. It's also not atomic:
the table could disappear between `ets:whereis/1` calls and the call to
read data from a projection. We replace all `ets:whereis/1` calls on
projection tables with `try`/`catch` and return default values when we
catch the `badarg` `error` which ETS emits when passed a non-existing
table name.

One special case though is `ets:info/2` which returns `undefined` when
passed a non-existing table names. That block is refactored to use a
`case` instead.
@dcorbacho
Copy link
Contributor

Good point about the overhead @dumbbell I'm not so worried about tables disappearing but who knows!

@the-mikedavis the-mikedavis marked this pull request as ready for review July 12, 2024 15:50
@michaelklishin michaelklishin merged commit bd5e9fa into main Jul 12, 2024
191 checks passed
@michaelklishin michaelklishin deleted the md/khepri/projections-ets-try-catch branch July 12, 2024 21:09
@michaelklishin michaelklishin added this to the 4.0.0 milestone Jul 12, 2024
the-mikedavis added a commit that referenced this pull request Jul 12, 2024
Use 'try'/'catch' rather than 'ets:whereis/1' for Khepri projections (backport #11700)
the-mikedavis added a commit that referenced this pull request Jul 13, 2024
Use 'try'/'catch' rather than 'ets:whereis/1' for Khepri projections (backport #11700) (backport #11707)
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