欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > NebulaGraph学习笔记-SessionPool之Session not existed

NebulaGraph学习笔记-SessionPool之Session not existed

2025/5/21 14:30:45 来源:https://blog.csdn.net/wulinshishen/article/details/148058548  浏览:    关键词:NebulaGraph学习笔记-SessionPool之Session not existed
NebulaGraph的SessionPool使用过程中有时会出现如下异常:
Get sessionId[1747361254442548] failed: Session `1747361254442548’ not found: Session not existed!
主要原因在于NebulaGraph服务器端的Session有默认超时时间,长时间没有使用会被自动回收清理,可以通过graphd服务的session_timeout_ms参数查看或修改调整。NebulaGraph客户端尝试使用一个不存在的Session ID进行查询操作,便会导致出现以上的异常提示。
看了一下语句执行的源码,发现NebulaGraph的SessionPool在执行查询操作的时候,已经针对SessionError的异常情况增加了一次重试机制,避免异常的发生。
public String executeJsonWithParameter(String stmt, Map<String, Object> parameterMap)throws ClientServerIncompatibleException, AuthFailedException, IOErrorException, BindSpaceFailedException {stmtCheck(stmt);checkSessionPool();NebulaSession nebulaSession = getSession();String result;try {result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);// re-execute for session errorif (isSessionErrorForJson(result)) {sessionList.remove(nebulaSession);nebulaSession = getSession();result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);}} catch (IOErrorException e) {if (e.getType() == IOErrorException.E_CONNECT_BROKEN) {sessionList.remove(nebulaSession);nebulaSession = getSession();result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);return result;}useSpace(nebulaSession, null);throw e;}useSpaceForJson(nebulaSession, result);return result;
}
private boolean isSessionErrorForJson(String result) {if (result == null) {return true;}int code = JSON.parseObject(result).getJSONArray("errors").getJSONObject(0).getIntValue("code");return code == ErrorCode.E_SESSION_INVALID.getValue()|| code == ErrorCode.E_SESSION_NOT_FOUND.getValue()|| code == ErrorCode.E_SESSION_TIMEOUT.getValue();
}
然而在 NebulaGraph学习笔记-SessionPool之getSession 可以知道,每次都是从sessionList中取出NebulaSession,如果sessionList里面的Session在服务端的某一刻全部被回收清理了,那么即便重试一次,客户端依旧会取出一个无效的Session出来。
针对这种情况可以考虑下面几个方式处理:
1、尝试增加重试次数,但是重试的次数不好确定,需要根据自身实际的情况确认。
public String executeJsonWithParameter(String stmt, Map<String, Object> parameterMap)throws ClientServerIncompatibleException, AuthFailedException, IOErrorException, BindSpaceFailedException {stmtCheck(stmt);checkSessionPool();NebulaSession nebulaSession = getSession();String result;try {result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);// re-execute for session errorint retrySessionCount = 0;while (isSessionErrorForJson(result) && retrySessionCount < 10) {long sessionID = nebulaSession.getSessionID();sessionList.remove(nebulaSession);nebulaSession = getSession();result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);retrySessionCount++;log.debug("ng session error {} {} {}", sessionID, nebulaSession.getSessionID(), retrySessionCount);}} catch (IOErrorException e) {if (e.getType() == IOErrorException.E_CONNECT_BROKEN) {sessionList.remove(nebulaSession);nebulaSession = getSession();result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);return result;}useSpace(nebulaSession, null);throw e;}useSpaceForJson(nebulaSession, result);return result;
}
2、SessionError的时候不再从sessionList里面取Session,而是每次都重新创建一个新的Session。
public String executeJsonWithParameter(String stmt, Map<String, Object> parameterMap)throws ClientServerIncompatibleException, AuthFailedException, IOErrorException, BindSpaceFailedException {stmtCheck(stmt);checkSessionPool();NebulaSession nebulaSession = getSession();String result;try {result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);// re-execute for session errorif (isSessionErrorForJson(result)) {long sessionID = nebulaSession.getSessionID();sessionList.remove(nebulaSession);nebulaSession = createSessionObject(SessionState.USED);result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);log.debug("ng session error {} {}", sessionID, nebulaSession.getSessionID());}} catch (IOErrorException e) {if (e.getType() == IOErrorException.E_CONNECT_BROKEN) {sessionList.remove(nebulaSession);nebulaSession = getSession();result = nebulaSession.executeJsonWithParameter(stmt, parameterMap);return result;}useSpace(nebulaSession, null);throw e;}useSpaceForJson(nebulaSession, result);return result;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词