You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java使用mwcloud GridStore连接Fixed模式GridDB报错排查

GridDB Java GridStore客户端连接错误排查:TXN_CLIENT_VERSION_NOT_ACCEPTABLE

问题背景

GridDB实例运行在FIXED_LIST模式,通过JDBC(20001端口)连接正常,但使用官方GridStore Java库(com.toshiba.mwcloud.gs)连接时,执行store.putCollection抛出版本不兼容错误,错误码10054。

错误信息

Exception in thread "main" com.toshiba.mwcloud.gs.common.GSStatementException: [10054:TXN_CLIENT_VERSION_NOT_ACCEPTABLE] (connectClientVersion=15, serverVersion=-9) (address=192.168.139.234:20001, partitionId=0)

核心原因分析

  1. 端口使用错误:GridStore客户端与JDBC客户端依赖不同服务端口。JDBC连接的是20001端口(SQL服务端口),而GridStore客户端需要连接GridDB的集群管理端口(默认10040)。错误使用JDBC端口会导致协议不匹配,服务端无法正确识别客户端请求,返回无效版本号(-9)。
  2. 监听地址配置问题:从gs_stat输出看,GridDB节点仅监听127.0.0.1:10040,但客户端尝试连接192.168.139.234,若GridDB未配置对外网卡监听,会导致连接异常。
  3. 版本不匹配:若GridStore客户端版本与服务端版本(5.3.0 CE)不一致,也会触发该版本兼容错误。

解决方案

1. 修改连接端口为集群管理端口

将notificationMember的端口从20001改为10040:

props.setProperty("notificationMember", "192.168.139.234:10040");

2. 调整GridDB监听地址

修改GridDB集群配置文件gs_cluster.json,将notificationAddress设置为对外可访问IP(如192.168.139.234)或0.0.0.0(监听所有网卡),然后重启GridDB服务。

3. 确保客户端与服务端版本一致

确认GridStore Java库版本与服务端版本(5.3.0 CE)完全匹配,使用对应版本的依赖包。

代码修正(含其他小问题修复)

原代码存在变量名错误(people.query应为students.query,Person student1应为Student student1),修正后的完整代码:

public static void main(String[] args) throws GSException {
    Properties props = new Properties();
    props.setProperty("notificationMember", "192.168.139.234:10040"); // 修改端口为10040
    props.setProperty("clusterName", "myCluster");
    props.setProperty("user", "admin");
    props.setProperty("password", "admin");

    GridStore store = GridStoreFactory.getInstance().getGridStore(props);

    Collection<String, Student> students = store.putCollection("STUDENT", Student.class);
    
    // 示例:插入测试数据
    Student student = students.createRow();
    student.name = "John";
    student.age = 20;
    students.put(student);

    Query<Student> query = students.query("select * where name = 'John'"); // 修正变量名
    RowSet<Student> rs = query.fetch(false);
    while (rs.hasNext()) {
        Student student1 = rs.next(); // 修正类型为Student
        System.out.println("Name: "+ student1.name +" Age: "+ student1.age);
    }
    store.close(); // 关闭连接
    System.out.println("Connection ended");
}

static class Student {
    @RowKey
    String name;
    int age;
}

验证步骤

  1. 若修改了监听地址,重启GridDB服务
  2. 运行修正后的代码,检查是否成功创建Collection、插入并查询数据
  3. 若仍有问题,执行gs_stat确认集群状态正常,节点监听地址正确

内容的提问来源于stack exchange,提问作者Omi A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 11:27:33