Database / Mnesia intermediate to advanced Interview questions
How does mnesia:activity/4 let you customize the access context of an operation?
mnesia:activity(AccessContext, Fun, Args, Module) is the general-purpose entry point underlying
transaction/1, sync_transaction/1, and the dirty variants — those are really
just convenience wrappers around activity/4 with a specific context pre-selected.
mnesia:activity(transaction, fun update_balance/2, [AccountId, Amount], mnesia). mnesia:activity(async_dirty, fun log_event/1, [Event], mnesia).
Calling activity/4 directly is useful when you want to select the access context
dynamically — for example, choosing between a transactional and a dirty path for the same piece of
business logic based on a runtime flag, rather than hardcoding which wrapper function you call. The last
argument (Module) lets you plug in a completely custom access-context implementation, which is
also how table fragmentation's mnesia_frag module hooks into the same mechanism.
More Related questions...