我正在通过HTTP代理访问的ComposeIO上运行3个分片设置。
我的服务器是NodeJS,使用官方RethinkDB驱动程序的最新版本(2.2.2)(http://www.rethinkdb.com/api/javascript/)
更改Feed失败,并显示消息Changefeed aborted (unavailable).
RethinkDB文档说明“如果表变得不可用,则更改源将被断开,并且驱动程序将抛出运行时异常。”但没有提供如何预防/恢复的建议。
答案 0 :(得分:1)
只有在群集中存在连接问题或您正在重新配置时,该表才会变为不可用。如果是前者,则应联系Compose,看看他们是否能够找出群集出现连接问题的原因。如果你经常重新配置表格,那么最好的办法就是尝试重做工作,这样你就不必这样做了。
至于恢复的时候,唯一要做的就是重新启动更改源。
答案 1 :(得分:1)
问题是,如果RethinkDB更改源因任何原因失败,则Web套接字连接将失败,即使重新连接更改源,也不会向客户端发送通知。
解决方案是在失败后第一次请求时重新启动套接字连接。
在任何API调用之前调用restartLiveUpdates()
(理想情况下使用拦截器在所有适用的请求上调用它),以便在需要时重新启动套接字。
// setup express and socketIO
const app = express();
const httpServer = http.createServer(app);
const io = socketIO(httpServer);
// socketIO connection
eventService.liveUpdates(io);
// serve
httpServer.listen(port);
let restart = false;
let socket;
function connect() {
return r.connect(config.get('rethinkdb'));
}
export function liveUpdates(io) {
// store io ref for restarting connection
if (io && !socket) {
socket = io;
}
console.log('Setting up listener...');
// so we can close connection on error
let conn;
connect().then((c) => {
conn = c;
r.table('pulses')
.changes()
.run(conn)
.then((cursor) => {
console.log('Listening for changes...');
cursor.each((err, change) => {
if (err) {
restart = true;
if (conn) {
console.log('Close changes connection');
conn.close();
}
} else {
restart = false;
socket.emit('event-change', change);
}
});
});
});
}
// restart changes feed if it has timed out
function restartLiveUpdates() {
if (restart) {
// set false immediately so we do not get multiple restarts due to different client requests
restart = false;
liveUpdates();
}
}