当前位置: 首页 > news >正文

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

相关文章:

  • 常见高速电路设计与信号完整性核心概念
  • SVA 断言16.9 Sequence operations序列运算翻译笔记(12)
  • 香港科技大学(广州)智能制造理学硕士招生宣讲会——深圳大学专场
  • Nextjs App Router 开发指南
  • leetcode 找到字符串中所有字母异位词 java
  • 百度网盘加速补丁v7.14.1.6使用指南|PC不限速下载实操教程
  • 你知道mysql的索引下推么?
  • Doris高性能读能力与实时性实现原理
  • 【优秀三方库研读】在 quill 开源库中 QUILL_MAGIC_SEPARATOR 的作用是什么,解决了什么问题
  • 【Java】封装在 Java 中是怎样实现的?
  • 基于springboot的网上学校超市商城系统【附源码】
  • [Vue]组件介绍和父子组件间传值
  • 广东省省考备考(第十五天5.20)—言语(第六节课)
  • MySQL基础关键_014_MySQL 练习题
  • 阿里云百炼(1) : 阿里云百炼应用问答_回答图片问题_方案1_提问时上传图片文件
  • 北斗导航 | 基于matlab的多波束技术的卫星通信系统性能仿真
  • 实战:基于Pangolin Scrape API,如何高效稳定采集亚马逊BSR数据并破解反爬虫?
  • Python数据可视化再探——Matplotlib模块 之二
  • 计算机视觉与深度学习 | Matlab实现EMD-GWO-SVR、EMD-SVR、GWO-SVR、SVR时间序列预测(完整源码和数据)
  • 分布式ID生成器:原理、对比与WorkerID实战
  • 北师大发布《短视频家长指南》,回应短视频时代家庭教育挑战
  • 前列腺癌真的难以早发现吗?如何治疗?专家回应
  • 家国万里·时光故事会|从徐光启到徐家汇,一颗甘薯里的家国
  • 安徽凤阳县明中都鼓楼楼宇顶部瓦片部分脱落,无人员伤亡
  • 中国驻美大使:远离故土的子弹库帛书正随民族复兴踏上归途
  • 美国将与阿联酋合作建立海外最大的人工智能数据中心