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
[email protected]
https://lists.sourceforge.net/lists/listinfo/sedna-discussion

Reply via email to