GridDB重复集群检测错误求助(Node.js+Ubuntu环境)
解决GridDB节点重复检测错误(180018)的方案
问题描述
在Linux Ubuntu 22.04.1 LTS环境下使用GridDB的Node.js连接器,初始化集群并创建容器加载CSV文件时,首次运行代码就收到如下错误:
[Server] 180018 [Description] Duplicated cluster detection [Message] Connection address, port no. of master node in an existing cluster
相关代码:
var griddb = require('griddb-node-api'); const createCsvWriter = require('csv-writer').createObjectCsvWriter; const csvWriter = createCsvWriter({ path: 'out.csv', header: [ {id: "country", title: "country"}, {id: "daily oil consumption (barrels)", title: "daily oil consumption (barrels)"}, {id: "world share", title: "world share"}, {id: "yearly gallons per capita", title: "yearly gallons per capita"}, {id: "price per gallon (USD)", title: "price per gallon(USD)"}, {id: "price per liter (USD)", title: "price per liter (USD)"}, {id: "price per liter (PKR)", title: "price per liter (PKR)"} ] }); const factory = griddb.StoreFactory.getInstance(); const store = factory.getStore({ "host": '239.0.0.1', "port": 31999, "clusterName": "defaultCluster", "username": "admin", "password": "admin" }); const conInfo = new griddb.ContainerInfo({ 'name': "globalfluctuationsfuelprices", 'columnInfoList': [ ["country", griddb.Type.STRING], ["daily oil consumption (barrels)", griddb.Type.INTEGER], ["world share", griddb.Type.STRING], ["yearly gallons per capita", griddb.Type.DOUBLE], ["price per gallon (USD)", griddb.Type.DOUBLE], ["price per liter (USD)", griddb.Type.DOUBLE], ["price per liter (PKR)", griddb.Type.DOUBLE] ], 'type': griddb.ContainerType.COLLECTION, 'rowKey': true }); const csv = require('csv-parser'); const fs = require('fs'); var lst = [] var lst2 = [] var i =0; fs.createReadStream('./dataset/Petrol Dataset June 20 2022.csv') .pipe(csv()) .on('data', (row) => { lst.push(row); }) .on('end', () => { var container; var idx = 0; for(let i=0;i<lst.length;i++){ lst[i]['daily oil consumption (barrels)'] = parseInt(lst[i]["daily oil consumption (barrels)"]) lst[i]['yearly gallons per capita'] = parseFloat(lst[i]["yearly gallons per capita"]) lst[i]['price per gallon(USD)'] = parseFloat(lst[i]["price per gallon (USD)"]) lst[i]['price per liter (USD)'] = parseFloat(lst[i]["price per liter (USD)"]) lst[i]['price per liter (PKR)'] = parseFloat(lst[i]["price per liter (PKR)"]) console.log(parseFloat(lst[i]["country"])) store.putContainer(conInfo, false) .then(cont => { container = cont; return container.createIndex({ 'columnName': 'name', 'indexType': griddb.IndexType.DEFAULT }); }) .then(() => { idx++; container.setAutoCommit(false); return container.put([String(idx), lst[i]['country'],lst[i]["daily oil consumption (barrels)"],lst[i]["world share"],lst[i]["yearly gallons per capita"],lst[i]["price per gallon (USD)"],lst[i]["price per liter(USD)"],lst[i]["price per liter (PKR)"]]); }) .then(() => { return container.commit(); }) .catch(err => { if (err.constructor.name == "GSException") { for (var i = 0; i < err.getErrorStackSize(); i++) { console.log("[", i, "]"); console.log(err.getErrorCode(i)); console.log(err.getMessage(i)); } } else { console.log(err); } }); } store.getContainer("globalfluctuationsfuelprices") .then(ts => { container = ts; query = container.query("select *") return query.fetch(); }) .then(rs => { while (rs.hasNext()) { console.log(rs.next()) lst2.push({ 'country': rs.next()[1], "daily oil consumption (barrels)": rs.next()[2], "world share": rs.next()[3], "yearly gallons per capita": rs.next()[4], "price per gallon (USD)": rs.next()[5], "price per liter (USD)": rs.next()[6], "price per liter (PKR)": rs.next()[7] }); } console.log(lst2) csvWriter .writeRecords(lst2) .then(()=> console.log('The CSV file was written successfully')); return }).catch(err => { if (err.constructor.name == "GSException") { for (var i = 0; i < err.getErrorStackSize(); i++) { console.log("[", i, "]"); console.log(err.getErrorCode(i)); console.log(err.getMessage(i)); } } else { console.log(err); } }); console.log(lst2); });
错误原因
错误码180018表示GridDB检测到重复集群:要么本地运行了多个GridDB实例,要么代码中存在重复的集群交互操作,导致连接地址/端口与现有集群冲突。
解决步骤
1. 检查并清理GridDB运行实例
在终端执行命令,查看当前GridDB进程:
ps aux | grep griddb
如果发现多个进程,杀掉多余的:
sudo kill -9 <进程ID>
随后重启GridDB服务:
sudo systemctl restart griddb
2. 修复代码中的重复操作
原代码存在核心问题:在CSV数据遍历循环内重复执行store.putContainer创建容器,同时多次提交事务,引发集群连接冲突。修改后的代码逻辑如下:
fs.createReadStream('./dataset/Petrol Dataset June 20 2022.csv') .pipe(csv()) .on('data', (row) => { lst.push(row); }) .on('end', () => { var container; var idx = 0; // 将容器创建、数据插入逻辑统一放到循环外,避免重复操作 store.putContainer(conInfo, false) .then(cont => { container = cont; // 修正索引列:原代码用了不存在的name列,改为country return container.createIndex({ 'columnName': 'country', 'indexType': griddb.IndexType.DEFAULT }); }) .then(() => { container.setAutoCommit(false); const insertTasks = []; // 批量处理数据转换 for(let i=0;i<lst.length;i++){ lst[i]['daily oil consumption (barrels)'] = parseInt(lst[i]["daily oil consumption (barrels)"]) lst[i]['yearly gallons per capita'] = parseFloat(lst[i]["yearly gallons per capita"]) lst[i]['price per gallon(USD)'] = parseFloat(lst[i]["price per gallon (USD)"]) lst[i]['price per liter (USD)'] = parseFloat(lst[i]["price per liter (USD)"]) lst[i]['price per liter (PKR)'] = parseFloat(lst[i]["price per liter (PKR)"]) idx++; insertTasks.push(container.put([String(idx), lst[i]['country'],lst[i]["daily oil consumption (barrels)"],lst[i]["world share"],lst[i]["yearly gallons per capita"],lst[i]["price per gallon (USD)"],lst[i]["price per liter(USD)"],lst[i]["price per liter (PKR)"]])); } // 批量执行插入,提升效率并避免冲突 return Promise.all(insertTasks); }) .then(() => { return container.commit(); }) .then(() => { // 提交完成后再执行查询与导出 return store.getContainer("globalfluctuationsfuelprices"); }) .then(ts => { container = ts; const query = container.query("select *") return query.fetch(); }) .then(rs => { while (rs.hasNext()) { // 仅调用一次rs.next(),避免数据跳过 const row = rs.next(); lst2.push({ 'country': row[1], "daily oil consumption (barrels)": row[2], "world share": row[3], "yearly gallons per capita": row[4], "price per gallon (USD)": row[5], "price per liter (USD)": row[6], "price per liter (PKR)": row[7] }); } console.log(lst2); return csvWriter.writeRecords(lst2); }) .then(()=> console.log('The CSV file was written successfully')) .catch(err => { if (err.constructor.name == "GSException") { for (var i = 0; i < err.getErrorStackSize(); i++) { console.log("[", i, "]"); console.log(err.getErrorCode(i)); console.log(err.getMessage(i)); } } else { console.log(err); } }); });
3. 校验GridDB集群配置
打开GridDB配置文件,确认集群参数与代码一致:
sudo nano /var/lib/griddb/conf/griddb.conf
检查以下参数:
clusterName:需与代码中的defaultCluster一致multicastAddress:需为239.0.0.1multicastPort:需为31999
4. 清理残留集群数据(可选,测试环境使用)
若上述方法无效,可清理GridDB数据目录后重启服务(会删除所有现有数据):
sudo systemctl stop griddb sudo rm -rf /var/lib/griddb/data/* sudo systemctl start griddb
内容的提问来源于stack exchange,提问作者Ismail Vohra
相关产品推荐
相关产品推荐

