2015-10-22 37 views
0

我在使用Java API查询顶点时在OrientDb上遇到了太多的死锁。发生死锁后,整个数据库变得无响应,我必须杀死守护进程并重新启动。作为例子,我从死锁得到的错误是:如何删除orientdb中的死锁

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) 

以下是我用来查询的边缘,创造顶点

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; 
} 
+1

OrientDB的哪个版本? – wolf4ood

+0

最新,Orientdb-community-2.1.2 – Noorul

回答

-1

由于指数缺少表僵局前来之间的关联块,因此请检查您的所有涉及此操作的表,并确定索引是否存在于列上。 请参阅link其中我有一个相同的死锁问题。