3 ms·
> I think the only killer feature I'm left wanting from some RDBMS at this point is managed-sequences... I would like some RDBMS to give sharable transactions.
by tzs 15y ago
> I think the only killer feature I'm left wanting from some RDBMS at this point is managed-sequences...
I would like some RDBMS to give sharable transactions. What I mean by that is something like this.
1. When I begin a transaction, I can assign it a name.
2. If multiple connections to the database are in transactions with the same name, they can see the changes made by the others, as if none of them were in a transaction. Connections not party to the shared transaction do not see the changes until all of the connections in the shared transaction commit.
3. The connections in the shared transaction can do unnamed transactions, which isolate them from the others within the shared transaction.
The idea here is that sometimes I have some operation that I would like to do atomically, but that involves multiple processes acting on the database. Process A wants to make some changes, then pass responsibility on to process B (which may be on a separate machine) to make more changes, and then process C finishes up, and if any of them encounter an error I want to rollback to the state before A started.
- kanak 15y agoAt an initial glance, I think you're describing nested transactions.
- famousactress 15y agoInteresting. Without knowing what kind of system you're talking about I'm suspicious that I'd use this. I certainly have distributed problems like this where a logical concept is broken into a number of steps, and while I want to distribute the steps.. the effects of them to the entire system might not be realized until all of them are complete. I generally wouldn't defer that responsibility to the database though. I'd more often handle this as multiple database transactions that advance a state machine, at the end of which consequence-inducing-events are fired off. The idea that process A tickles the database into some state expected to be understood (and only seen by) process B seems like too flimsy a contract to me.
- _sh 15y agoI get your point, but there is value in delegating to the database--how do I roll back an external state machine?
- bad_user 15y agoSee the command pattern: http://en.wikipedia.org/wiki/Command_pattern http://en.wikipedia.org/wiki/Command_pattern Basically you encapsulate whatever you need to do with the database in objects (logic + parameters). And you describe for these objects not only the logic for updating the database (forward), but also for reverting the database to its previous state (rollback).
- _sh 15y agoYep, I know the command pattern--it requires knowledge of all state up front and breaks down in the presence of distributed state. It makes statements like 'update all records where value x is y' difficult. You need to gather all such records first, possibly guarding their current state with a timestamp/vector clock (we are talking distributed systems after all), make the change encapsulating the current state in the command pattern and commit. If you have to extend this model to multiple queries, you'll be rolling your own transaction protocol lest you expose partial state to other queries in transit. Or you could delegate all this to the database, which already has its own transaction protocol.
- andyzweb 15y agoperhaps prepared-transactions might have some of the functionality you are looking for http://www.postgresql.org/docs/9.1/static/sql-prepare-transaction.html http://www.postgresql.org/docs/9.1/static/sql-prepare-transa...
- j_s 15y agoI believe this is implemented application-side for SQL Server by the Microsoft Distributed Transaction Coordinator, which allows enlisting in existing transactions. Some explanation of how it works: http://stackoverflow.com/questions/494550/how-does-transactionscope-roll-back-transactions http://stackoverflow.com/questions/494550/how-does-transacti... Usage to 'forget' automated test database changes: http://amnesia.codeplex.com http://amnesia.codeplex.com