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
Plain begin - read transactions promoting to write transactions. #161
Conversation
Example:
NB Current |
Hm, just a first gut reaction about that example API: I would not want to initiate a promotion just by signalling system-wide and then writing. I'd much rather some positive step be taken on that particular dataset, to record very clear intent. I'm guessing that although it's really not good style, there are folks out there depending on the system to throw an exception for writing in a read txn as part of their logic. New modes for |
At first look, I would prefer the second option for dealing with intervening writes. It's blunter, but it seems a good deal easier for application writers to reason about. But maybe I'm not giving enough weight to the value of greater concurrency. |
It means for exploration, so you can swap modes. It will removed when the code is real. |
I'd like to get his code into master even if it is switched off. If we are comfortable with it the general way to go, it's easier to have it live. If not enabled, the code should make no difference to current behaviour. |
Sorry, I let this go without replying. No, the |
The proposal is not to adopt every detail of this PR; it's to include but not activate it. I think we should try to add the feature to all the transactional implementations (TDB, TIM, MRSW - not SDB) together. Having this in the code base, not activated by default, is a step on that road. Automatically allowing writes is normal behaviour for JDBC which has implicit Exceptions don't work well. Some transaction-unaware library code might make the update causing the transaction to promote. An exception will crash out of the middle of the library code. The name |
Eventually, a |
Proposal: the default behaviour is "no read commited" for |
I like the proposal, basically, although I suspect it might be a little tricky to do the original suggestion of "limited read committed" in current TIM. Adding Do you think it would be useful to offer a "block until promoted" option? Or is that basically covered by "end your current xaction and open a new WRITE xaction"? |
(mis-closed - another "close next to comment" incident) |
See JENA-1223 for overall discussion of API issues and to record changes in subsystems. |
0c2c2fe
to
f90e2b4
Compare
Squash development commits to a few important ones. |
After that fix, the tests have reasonable coverage of all modes so this is ready to merge from my point-of-view. |
Setup for JENA-1123 (txn promotion) Remove pointless private constructor. Make some methods package access.
Graphs across transaction boundaries. Do not cache default model. Assumes too much about the DatasetGraph. Switchable promotion. Select txn/non-txn graph versions
To track whether a promotion is possible for fully serialized, the code now checks a version number. The necessary information is available elsewhere (whether a new transaction would see the same dataset as one wanting promotion) but it's crypt and in TIM, that's in the indexes, not the transaction control in the dataset. Keeping the version is also a nice statistic to keep. The version moves on one when a transaction commits. That leaves one case - what to do when a writer is already active. That writer may commit later (and hence the promotion is not possible) to abort (the promotion may be possible if no other writer comes and goes). The current refuses promotion if there is an active writer on the basis that most writers commit, and abort is unusual. Blocking maybe possible but leads to issues of what happens when another reader that tries to promote at about the same time and of a long running writer (e.g. bulk upload) causing the reader to block for a long time. |
So ideally, it would be another writer committing that would throw a switch to refuse promotion to extant transactions? Instead of another writer simply existing? |
Yes. |
I guess I'm confused as to why one can't determine (from the version numbers) whether another transaction has committed? If you know a transaction's version number and you know the transaction manager's version number... I think I'm surely missing something about how these classes work, since I only worked with the simpler "thread-is-transaction" thinking in TIM. |
Version number only tell you about the past (see When a writer is active and has not committed or aborted. So how do you wait for the active writer to decide which way it's going to go? (what would be block on to wait for it?) |
Oh, okay, I get it now. And even if you could block, as you wrote above, that could be a really long time in some cases. Do you want me to write something for TIM to bring a version number to the dataset? I don't think that would be too hard. (Famous last words.) |
Let's get this into the codebase first (inactive). JENA-1222 and JENA-1224 are both changes to TDB's I've tried to write a test for snapshot isolation promotion but it relies on a thread pause which elsewhere has been unstable on a heavily loaded CI server ( Until we get the contract details settled, changing TIM seems premature. |
Okay, I'll hang tight. |
This PR is for discussion and is not yet ready for merging.
It adds to TDB the ability for a read transaction to promote to a write transaction.
Currently (to avoid general API changes outside TDB) this happens automatically in
DatasetGraphTransaction.getW()
.It needs to be enabled with
DatasetGraphTransaction.promotion = true
If this is useful, we can add new modes to
ReadWrite
and/or addbegin()
(no args).There is a big design point: at the point at which a transaction becomes a writer their are two choices as to what to do if another write transaction happened between this one starting and this one promoting.
Having it as a choice is possible - one should be the default for
begin()
.