From 0f17508cac061e92d00e997a5a69fc1b7ed49553 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 20 May 2020 11:38:04 -0700 Subject: [PATCH] error recovery in redis online notification If a redis cluster member fails over to the slave, we'll get an error from not specifying the key for the insert. Recover from that instead of crashing the controller --- controller/PostgreSQL.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp index 28db4a867..fb3867cac 100644 --- a/controller/PostgreSQL.cpp +++ b/controller/PostgreSQL.cpp @@ -1540,15 +1540,19 @@ void PostgreSQL::onlineNotification_Redis() std::lock_guard l(_lastOnline_l); lastOnline.swap(_lastOnline); } - if (!lastOnline.empty()) { - if (_rc->clusterMode) { - auto tx = _cluster->redis(controllerId).transaction(true); - _doRedisUpdate(tx, controllerId, lastOnline); - } else { - auto tx = _redis->transaction(true); - _doRedisUpdate(tx, controllerId, lastOnline); + try { + if (!lastOnline.empty()) { + if (_rc->clusterMode) { + auto tx = _cluster->redis(controllerId).transaction(true); + _doRedisUpdate(tx, controllerId, lastOnline); + } else { + auto tx = _redis->transaction(true); + _doRedisUpdate(tx, controllerId, lastOnline); + } } - } + } catch (sw::redis::Error &e) { + fprintf(stderr, "Error in online notification thread (redis): %s\n", e.what()); + } std::this_thread::sleep_for(std::chrono::milliseconds(10)); } }