Redland transactions API (was Re: [redland-dev] Perl/BDB question:
atomicity and transactions question)
Dave Beckett
dave.beckett at bristol.ac.uk
Fri Jan 14 06:03:44 PST 2005
i found my earlier thoughts on transactions, tidied them up.
Dave
---
Transactions ideas and API for redland storages
For Sleepycat / BerkleyDB alone
All redland storages have options which can be used by any of the
store implementations. It would be quite easy to add a
bdb-transactions='yes' option which could be used by the hashes storage
(rdf_hashes_storage.c) when it tries to open a hash. This calls
librdf_hash_open (rdf_hash.c) with the same options passed to the
hash implementations such as the BDB hash (rdf_hash_bdb.c) where the
actual BDB open is done, in librdf_hash_bdb_open and there a small
patch would allow the DB_TXN or whatever to be added to the flags for
bdb->open / bdb->set_flags.
The other way, passing down an (existing) BDB DB_TXN transaction
handle, that would mean modifying the APIs. Unless you did it at
open time using the bdb-transactions='0x234567' with some C pointer.
Which is pretty ugly.
More general API
I was thinking about transaction support, and however you do it
internally, it is a good idea to allow the users to explicitly
request it from the system. I've got a sketch of the API calls that
would be needed at the user level, so here goes, in pseudo code:
class model {
...
int transaction_start()
int transaction_start_with_handle(void* handle)
int transaction_commit()
int transaction_abort()
int transaction_rollback()
void* transaction_get_handle()
...
}
So what is a handle? A store-specific transaction pointer that you
can use if you know what you are doing.
Here's an example of when you know the store provides Sleepycat
DB_TXN, and you'd do
storage=new hashes_storage (hash-type='bdb', transactions='yes')
model=new model_storage(storage)
then
model.transaction_start()
DB_TXN tx=(DB_TXN)model.transaction_get_handle()
... commit other stuff using tx ...
model.transaction_commit()
OR
DB_TXN tx;
... init tx ...
model.transaction_start_with_handle((void*)tx)
... commit other stuff with tx ...
model.transaction_commit()
... delete TX ...
I'm not sure if you'd really want to pass it in at redland
transaction start time, but it seems plausible.
For a SQL-backed store, it'd be something similar, however you'd
likely not get the internal handle directly but just use the
transaction_start/commit/abort/rollback.
More information about the redland-dev
mailing list