X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fredis%2Fasynchirediscommanddispatcher.cpp;h=03ca0122f24e31cf3cdbc2dc671ec70e58c9690a;hb=refs%2Fchanges%2F93%2F6593%2F4;hp=e4195a945cb2d3ac4d7d44bd515bdef32f6dcc76;hpb=ef2bf51d04aaf01fa0cabdcaf905b23423067662;p=ric-plt%2Fsdl.git diff --git a/src/redis/asynchirediscommanddispatcher.cpp b/src/redis/asynchirediscommanddispatcher.cpp index e4195a9..03ca012 100644 --- a/src/redis/asynchirediscommanddispatcher.cpp +++ b/src/redis/asynchirediscommanddispatcher.cpp @@ -14,6 +14,11 @@ limitations under the License. */ +/* + * This source code is part of the near-RT RIC (RAN Intelligent Controller) + * platform project (RICP). +*/ + #include "private/redis/asynchirediscommanddispatcher.hpp" #include #include @@ -80,7 +85,8 @@ AsyncHiredisCommandDispatcher::AsyncHiredisCommandDispatcher(Engine& engine, uint16_t port, std::shared_ptr contentsBuilder, bool usePermanentCommandCallbacks, - std::shared_ptr logger): + std::shared_ptr logger, + bool usedForSentinel): AsyncHiredisCommandDispatcher(engine, address, port, @@ -88,7 +94,8 @@ AsyncHiredisCommandDispatcher::AsyncHiredisCommandDispatcher(Engine& engine, usePermanentCommandCallbacks, HiredisSystem::getHiredisSystem(), std::make_shared(engine), - logger) + logger, + usedForSentinel) { } @@ -99,7 +106,8 @@ AsyncHiredisCommandDispatcher::AsyncHiredisCommandDispatcher(Engine& engine, bool usePermanentCommandCallbacks, HiredisSystem& hiredisSystem, std::shared_ptr adapter, - std::shared_ptr logger): + std::shared_ptr logger, + bool usedForSentinel): engine(engine), address(address), port(ntohs(port)), @@ -113,7 +121,8 @@ AsyncHiredisCommandDispatcher::AsyncHiredisCommandDispatcher(Engine& engine, connectionRetryTimer(engine), connectionRetryTimerDuration(std::chrono::seconds(1)), connectionVerificationRetryTimerDuration(std::chrono::seconds(10)), - logger(logger) + logger(logger), + usedForSentinel(usedForSentinel) { connect(); @@ -140,28 +149,33 @@ void AsyncHiredisCommandDispatcher::connect() void AsyncHiredisCommandDispatcher::verifyConnection() { - /* When Redis has max amount of users, it will still accept new connections but will - * close them immediately. Therefore, we need to verify that just established connection - * really works. This prevents calling client readyAck callback for a connection that - * will be terminated immediately. - */ - /* Connection verification is now done by doing redis command list query. Because we anyway - * need to verify that Redis has required commands, we can now combine these two operations - * (command list query and connection verification). If either one of the functionalities - * is not needed in the future and it is removed, remember to still leave the other one. - */ - serviceState = ServiceState::CONNECTION_VERIFICATION; - /* Disarm retry timer as now we are connected to hiredis. This ensures timer disarm if - * we are spontaneously connected to redis while timer is running. If connection verification - * fails, timer is armed again (normal handling in connection verification). - */ - connectionRetryTimer.disarm(); - dispatchAsync(std::bind(&AsyncHiredisCommandDispatcher::verifyConnectionReply, - this, - std::placeholders::_1, - std::placeholders::_2), - contentsBuilder->build("COMMAND"), - false); + if (usedForSentinel) + setConnected(); + else + { + /* When Redis has max amount of users, it will still accept new connections but will + * close them immediately. Therefore, we need to verify that just established connection + * really works. This prevents calling client readyAck callback for a connection that + * will be terminated immediately. + */ + /* Connection verification is now done by doing redis command list query. Because we anyway + * need to verify that Redis has required commands, we can now combine these two operations + * (command list query and connection verification). If either one of the functionalities + * is not needed in the future and it is removed, remember to still leave the other one. + */ + serviceState = ServiceState::CONNECTION_VERIFICATION; + /* Disarm retry timer as now we are connected to hiredis. This ensures timer disarm if + * we are spontaneously connected to redis while timer is running. If connection verification + * fails, timer is armed again (normal handling in connection verification). + */ + connectionRetryTimer.disarm(); + dispatchAsync(std::bind(&AsyncHiredisCommandDispatcher::verifyConnectionReply, + this, + std::placeholders::_1, + std::placeholders::_2), + contentsBuilder->build("COMMAND"), + false); + } } void AsyncHiredisCommandDispatcher::verifyConnectionReply(const std::error_code& error,