Java 如何删除orientdb中的死锁

Java 如何删除orientdb中的死锁,java,spring-boot,orientdb,Java,Spring Boot,Orientdb,在使用JavaAPI查询顶点时,OrientDb上出现了太多死锁。死锁发生后,整个数据库变得无响应,我必须杀死守护进程并重新启动。例如,我从死锁中得到的错误是: com.orientechnologies.common.concur.OTimeoutException: Can not lock record for 2000 ms. seems record is deadlocked by other record at com.orientechnologies.orient.co

在使用JavaAPI查询顶点时,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;
}
public User generateFriend(String-mobile,String-userRID){
StringBuilder errorMsg=新建StringBuilder();
可调顶点;
//检索用户的朋友
List friendsList=新建ArrayList();
顶点=db.query属性(“从“+userRID,errorMsg”中选择展开(unionAll(inE('E_-Friend').out,outE('E_-Friend').in));
如果(!errorMsg.toString().equals(“”){
抛出新的DbException(“发生了Db异常,”+errorMsg);
}
用于(方向顶点v:顶点){
friendsList.add(用户(v));
}
//如果在用户和列表中具有移动电话号码的其他用户之间以及如果尚未创建边缘,则创建边缘
用户u=findUserByMobileNo(手机好友列表);
如果(u==null){
u=findByMobileNo(移动);
如果(u!=null){
//创建边
db.executeQuery(“从“+userRID,new HashMap(),errorMsg”中选择createEdge('E_Friend',“+userRID+”,“+u.getRid()+”)));
如果(!errorMsg.toString().equals(“”){
抛出新的DbException(“发生了Db异常,”+errorMsg);
}
}
}
返回u;
}
公共Iterable查询权限(字符串查询、StringBuilder errMsg){
error(“在getGraph之前,+errMsg.toString());
graph=getGraph(errMsg);
如果(!errMsg.toString().equals(“”){
返回null;
}
error(“在getGraph之后,+errMsg.toString());
Iterable顶点=空;
试一试{
OSQLSynchQuery qr=新OSQLSynchQuery(查询);
顶点=graph.command(qr.execute();
error(“在执行图形命令之后,”+errMsg.toString());
}
捕获(例外情况除外){
errMsg.append(例如getMessage());
logger.error(“图形命令异常,+errMsg.toString());
}
error(“在返回顶点之前,+errMsg.toString());
返回顶点;
}
公共列表执行程序(字符串sql、HashMap参数、StringBuilder errMsg){
列表结果=新建ArrayList();
试一试{
db=getDatabase(errMsg);
如果(!errMsg.toString().equals(“”){
返回null;
}
OSQLSynchQuery查询=新的OSQLSynchQuery(sql);
if(params.isEmpty()){
结果=db.command(query.execute();
}否则{
结果=db.command(query).execute(params);
}
}捕获(例外e){
errMsg.append(e.getMessage());
//TODO:添加线程错误日志保存机制
}
返回结果;
}

由于表中缺少索引,所以请检查此操作所涉及的所有表,并找出列中是否存在索引。
请参阅其中有相同死锁问题的部分。

哪个版本的OrientDB?最新版本,OrientDB-community-2.1.2