1

I am getting too many deadlocks on OrientDb while I am using Java API to query the vertices. After the deadlock happens, the entire database becomes unresponsive and I have to kill the daemon and start again. As example, the error that I get from deadlocks is :

com.orientechnologies.common.concur.OTimeoutException: Can not lock record for 2000 ms. seems record is deadlocked by other record
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.acquireReadLock(OAbstractPaginatedStorage.java:1300)
    at com.orientechnologies.orient.core.tx.OTransactionAbstract.lockRecord(OTransactionAbstract.java:120)
    at com.orientechnologies.orient.core.id.ORecordId.lock(ORecordId.java:282)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.lockRecord(OAbstractPaginatedStorage.java:1776)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.java:1416)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.readRecord(OAbstractPaginatedStorage.java:694)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeReadRecord(ODatabaseDocumentTx.java:1569)
    at com.orientechnologies.orient.core.tx.OTransactionNoTx.loadRecord(OTransactionNoTx.java:80)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.load(ODatabaseDocumentTx.java:1434)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.readRecord(ONetworkProtocolBinary.java:1456)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:346)
    at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:216)
    at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:65)

Following is the block that I use to query edges and create associations between vertices

public User generateFriend(String mobile, String userRID) {
    StringBuilder errorMsg = new StringBuilder();
    Iterable<OrientVertex> vertexes;

    //Retrieve friends of the user
    List<User> friendsList = new ArrayList<User>();
    vertexes = db.queryVertices("select expand( unionAll(inE('E_Friend').out,outE('E_Friend').in) ) from  " + userRID,errorMsg);
    if (!errorMsg.toString().equals("")) {
        throw new DbException("Db exception occured, " + errorMsg);
    }
    for (OrientVertex v : vertexes){
        friendsList.add(vertexToUser(v));
    }
    //Create edges if between the user and other users with mobile number in the list and if the edge is not yet created
    User u = findUserByMobileNo(friendsList,mobile);
    if ( u == null){
            u = findByMobileNo(mobile);
            if (u != null) {
                //create edge
                db.executeQuery("select createEdge('E_Friend','" + userRID + "','" + u.getRid() + "') from " + userRID, new HashMap<String, Object>(), errorMsg);
                if (!errorMsg.toString().equals("")) {
                    throw new DbException("Db exception occured, " + errorMsg);
                }
            }
    }
    return u;
}



public Iterable<OrientVertex> queryVertices(String query, StringBuilder errMsg){
    logger.error("before getGraph, " + errMsg.toString());
    graph = getGraph(errMsg);
    if (!errMsg.toString().equals("")){
        return null;
    }
    logger.error("after getGraph, " + errMsg.toString());
    Iterable<OrientVertex> vertices = null;
    try {
        OSQLSynchQuery<OrientVertex> qr = new OSQLSynchQuery<OrientVertex>(query);
        vertices = graph.command(qr).execute();
        logger.error("after graph command execute, " + errMsg.toString());
    }
    catch (Exception ex){
        errMsg.append(ex.getMessage());
        logger.error("graph command exception, " + errMsg.toString());
    }
    logger.error("before return vertices, " + errMsg.toString());
    return vertices;
}


public List<ODocument> executeQuery(String sql, HashMap<String,Object> params,StringBuilder errMsg) {
    List<ODocument> result = new ArrayList<ODocument>();
    try {
        db = getDatabase(errMsg);
        if (!errMsg.toString().equals("")){
            return null;
        }
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);

        if (params.isEmpty()) {
            result = db.command(query).execute();
        } else {
            result = db.command(query).execute(params);
        }

    } catch (Exception e) {
        errMsg.append(e.getMessage());
        //TODO: Add threaded error log saving mechanism
    }
    return result;
}
Noorul
  • 939
  • 1
  • 11
  • 21

1 Answers1

-1

Due to index missing on table deadlock come, so check your all table which are involved in this operation and find out that indexes are present or not on column. Refer link in which I have a same problem of deadlock.

Community
  • 1
  • 1
NIrav Modi
  • 6,038
  • 8
  • 32
  • 47