当前位置: 首页 > 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;
}
http://www.xdnf.cn/news/551539.html

相关文章:

  • 五、central cache的设计
  • 多环境回测模拟不同市场条件下的策略表现
  • CSS专题之常见布局
  • 设备全生命周期管理:从采购到报废的数字化闭环方案
  • Varlet UI-Material Design风格Vue 3框架移动端组件库
  • SUI批量转账几种方法介绍
  • 构建AI时代的大数据基础设施-MaxCompute多模态数据处理最佳实践
  • 人工智能+:职业价值的重构与技能升级
  • LSM Tree算法原理
  • [特殊字符]车牌识别相机,到底用在哪?
  • 芯片分享之AD976性能介绍
  • NVM 安装与配置指南
  • Python中使用CUDA/GPU的方式比较
  • GMSL:汽车里的音视频传输
  • Python 包管理工具uv依赖分组概念解析
  • 瑞莎星睿 O6 (Radxa Orion O6)-ubuntu24.04-ROS2 运行深度估计模型
  • 数据分析_主播考核指标体系搭建
  • C++学习:六个月从基础到就业——多线程编程:互斥量与锁
  • Git 删除大文件教程
  • 如果用户点击微博的关注图标,但是app上面没有反应,应该怎么排查这个问题?
  • 集成飞书多维表格
  • 详解MySQL 的 binlog,redo log,undo log
  • 【razor】pacing平滑发送及调度机制分析
  • 物联网低功耗保活协同优化方案:软硬件与WiFi网关动态联动
  • MySQL--day4--排序与分页
  • 学习vue3:监听器
  • RK3588 IREE+Vulkan ResNet50推理测试
  • @ColorRes和@ColorInt什么区别
  • 基于天猫 API 的高效商品详情页实时数据接入方法解析
  • 2025年 全国青少年信息素养大赛 算法创意挑战赛C++ 小学组 初赛真题