-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 mnesia:repair_continuation for continuing a select in a new activity #1184
Conversation
The summary line of the commit message is too long and/or ends with a "." Bad message: Add mnesia:repair_continuation/[12] for continuing a select in a new activity I am a script, I am not human |
984acb6
to
69b9def
Compare
Fixed commit message format. |
Patch has passed first testings and has been assigned to be reviewed I am a script, I am not human |
I'm not sure I like that you allow the function to be called in transactions, as you said the use case I can see the use case for dirty selection so I'm not opposed of a fix to that part. |
First of all, I don't like automagically fixing things, because
On the other hand, limiting the repair to dirty contexts only would let us integrate the repair into select_cont(Tid,Ts,State=#mnesia_select{}) when ?some_guard_for_dirty_contexts(Tid) ->
RepairedState = State#mnesia_select{tid = Tid, written = [], spec = undefined, type = undefined},
select_cont(Tid,Ts,RepairedState); This would work with |
Ok so remove the transaction support. I'll let you make a decision about the auto-repair or new-function, I think backwards compatibility argument can be ignored, I can't see that a dirty select continuation call suddenly starts working is a big problem. |
OK, but what do you mean by "remove transaction support"? A continuation can be created in one of 5 possible contexts:
And it may be used the next time in one of these 5 contexts as well. So we have 25 combinations, which ones would you like to deny? |
ContinueStates should not be allowed to be repaired and continued in a ContinueStates created in transactions and repaired in *dirty|ets activity, On Wed, Oct 5, 2016 at 4:34 PM Dániel Szoboszlay notifications@github.com
|
As the person pushing for us (Klarna) to use this feature (and we're doing a field test with a version of it right now), the only use case I care about is async_dirty-to-async_dirty. That is, a continuation created by a select in one async_dirty context shall work with a select/1 in another async_dirty context. Crossing between dirty and non-dirty context is not needed right now, and I frankly have a hard time imagining what the corresponding use case might be. However, if supporting that can be done safely and without complicating the code I'm not opposed to doing so. |
A continuation returned by mnesia:select/[14] should be reusable in different, non-transactional activities. Aborting with wrong_transaction doesn't make sense in a dirty context.
69b9def
to
1b4969d
Compare
Now the import happens automatically in dirty contexts regardless of the originating context of the continuation. |
Patch has passed first testings and has been assigned to be reviewed I am a script, I am not human |
I think the problem this PR fixes is best explained via the use case behind it. I have a web app implementing paginated search results using
mnesia:select/4
:Unfortunately this doesn't work when the
mnesia:select/1
call is done from a different process (which is typical for web apps). It crashes with{aborted,wrong_transaction}
, because the activity id forasync_dirty
contains the pid, so it will only match in the same process.I understand this check is important for transactional contexts: reusing a continuation in a different transaction would break the transactional guarantees. However, for dirty (or
ets
) contexts it simply doesn't make sense.One option would be to remove the check on the activity context in non-transactional uses. But that seems to be a bit too much magic to me, and also opens up a lot of questions about edge cases like continuing a select that was started in a transactional context in a non-transactional activity.
I decided on adding an explicit call,
mnesia:repair_continuation/1
(named afterets:repair_continuation/1
), for importing a continuation into the current activity. It works across both transactional and non-transactional contexts. Maybe the first use case would not make much sense in practice, but if you actually need it, well, feel free to do it at your own risk! And since the new feature is introduced in a new function, it will not break existing code either.So this PR makes possible to do things like this, regardless which process uses
C2
:I tried to describe
mnesia:repair_continuation/1
in the docs as well as I could, but suggestions for improvements are welcome.