Skip to content

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
@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.

4 participants