Hi Jocelyn,
Sorry for the delay.
Yes, exists function written this way may cause such problem. There was a
discussion around XMLDB API which in some cases behaves exactly the same
way. It also uses doc("$documents") to check if document is available in
the given collection.
To fix this issue, we've implemented doc-available("col", "doc") function.
Unlike doc("$documents") which locks whole database, this function locks
only the collection it works with. As soon as possible, I will commit
implementation and you will be able to use it.
Considering your UPDATE REPLACE question. No, I don't think this is a good
idea. As far as I understand, UPDATE REPLACE have a lot of overhead. Since
it's a query, Sedna will parse it, analyze, create query execution plan (it
will be very big if document to replace with is big enough). Then all
direct element constructors will be executed to actually create the
document in memory. And so on...
Ivan Shcheklein,
Sedna Team
On Fri, Mar 22, 2013 at 7:20 PM, Jocelyn Raymond <jraym...@ualberta.ca>wrote:
> Hi Sedna Team,
> Just few weeks ago I sent the sedna Team an issue regarding
> deadlocks occurrence in sedna when we were having high volume. We were
> able to resolve the deadlock issue and was able to get some interesting
> result which will lead to a question at the end.
> First, here is the code that caused the deadlock:
>
> ...
> this.cn.begin();
> SednaStatement st1 = this.cn.createStatement();
>
> for (XmlDocument4Sedna xmlDocument : xmlDocuments) {
> try{
> if (this.exists(xmlDocument)) { // THIS CAUSE DEADLOCK
> st1.execute("DROP DOCUMENT '" + xmlDocument.getDocumentname() + "' IN
> COLLECTION '" + xmlDocument.getCollectionName() + "'");
> }
> InputStream in = new
> ByteArrayInputStream(xmlDocument.getXmlDocument().getBytes("UTF-8"));
> st1.loadDocument(in,xmlDocument.getDocumentname(),
> xmlDocument.getCollectionName());
> }catch (Exception es){
> ...
> }
> }
> }
> this.cn.commit();
> this.cn.close();
> ...
>
> As shown in the java comment above, when we have the line to check if a
> document exist, it caused the deadlock. If we removed the exist line (and
> we knew that during our test all document existed), it did not cause the
> deadlock. Our test simulated 50 concurrent users. Our architecture is
> simply that we drop the document if it exist and insert the full new
> document with the new data.
>
> SOLUTION:
> Our solution was to make the "save" method static synchronized such that
> only one user would be able to "drop"/"load" document. Surprisingly, this
> serialization was faster than if we remove the line that caused the
> deadlock. I believe (but I may be wrong) that there are more lock handling
> during concurrency than serialization and hence making it slower. Our
> result show:
> Serialization: ~4.1 document saved per second.
> Concurrent: ~2.8 document saved per second.
> Note: 50 users simulation saved a total of 402 documents.
>
> Some of my questions are (I am asking just in case you know an efficient
> way of doing this):
> Is it a good idea/solution to "DROP" and "LOAD" the new document to
> replace the old one each time it need to be persisted?
> Should we use "UPDATE replace ..." statement instead i.e. replacing the
> entire document from the root of the document? (still require to see if
> document exist).
> Should the app keep track if a document is new or not (hence would not
> have to check if exists on sedna)?
> Which way do you usually use?
>
> Thanks you for your support; always appreciated.
> Jocelyn Raymond
>
>
> FYI: our exists(xmlDocument) call above does the following:
>
> private boolean exists(String documentName, String collectionName)
> throws Exception {
> boolean doesExists = false;
>
> SednaStatement st1 = this.cn.createStatement();
> boolean hasResult =
> st1.execute("exists(doc('$documents')/documents/collection[@name='" +
> collectionName + "']/document[@name='" + documentName + "'])");
> if (hasResult) {
> SednaSerializedResult result = st1.getSerializedResult();
> String exists = result.next();
> doesExists = (exists != null && exists.equals("true")) ? true : false;
> }
> return doesExists;
> }
>
> --
> Team Lead
> Information Systems
> Office of the Registrar
> University of Alberta
> 780.492.3874
>
>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_mar
> _______________________________________________
> Sedna-discussion mailing list
> Sedna-discussion@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sedna-discussion
>
>
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Sedna-discussion mailing list
Sedna-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sedna-discussion