concurrency - OpenRDF Sesame: how to handle locking? -
on apache tomcat server have openrdf sesame triplestore handle rdf triples related users , documents , bidirectional links between such entities:
http://local/id/doc/123456 myvocabulary:title "eu economy" http://local/id/doc/456789 myvocabulary:title "united states economy" http://local/id/user/johndoe myvocabulary:email "john@doe.com" http://local/id/user/johndoe myvocabylary:haswritten http://local/id/doc/123456 this triple state user john doe email "john@doe.com" has written "eu economy" book.
a java application running on multiples clients used such server through httprespository insert/update/remove such triples.
problems comes concurrent connections. if java client delete book "456789" , other client simultaneously link same book "john doe", there may have situation "john doe" links book doesn't exists more.
to seek find solution have made 2 transactions. first 1 (t1):
(a) check if book id exists (i.e. "456789").
(b) if yes, link given profile (i.e. "johndoe") book.
(c) if no, homecoming error.
the sec 1 (t2):
(d) delete book id (i.e. "456789").the problem if sequence (t1,a) (t2,d) (t1,b) (t1,c), there 1 time again consistency issues.
my question is: how handle locking (like mysql update or get_lock) isolate such transactions sesame ?
older versions of sesame (2.7.x , older) back upwards no transaction isolation on http. in http connection, transactions simply batch operations @ client side, no lock obtained server, there no way command isolation in scenario.
so way deal in older sesame versions robust in queries, rather relying on total info consistency (which bit of odd concept in schemaless/semi-structured info paradigm anyway). illustration in particular case, create sure when query books linked profile, book info there - don't rely on reference.
in sesame 2.8 , newer, however, total transaction isolation back upwards available on http, , additional command on exact transaction isolation level available well, on per-transaction basis. locking scheme dependent on specific triplestore implementation use.
sesame's native store uses optimistic locking, means assumes transaction able create update wants to, , throws exception when conflict occurs. setting isolation level transaction controls how store handles locking concurrent transactions. sesame programmers manual has more details on transaction handling , available isolation levels. default isolation level transactions on native store snapshot_read.
as illustration transactions: in default isolation level, t1 , t2 both observe consistent snapshots of store queries, , sequence sketch plays out: t1 sees book exists, adds profile, , t2 gets delete it. end result profile linked non-existent book - actually, not technically inconsistency, because t2 not verification on whether particular book used in profile, or not. no matter transaction isolation level use, if in scenario t2 gets executed after t1, end result link non-existent book. if want ensure cannot situation, need extend t2 check book deleted not linked profile, , create isolation level snapshot or serializable.
concurrency transactions sparql sesame openrdf
No comments:
Post a Comment