//------------------------------------------------------------------------------------- bool DBInterfaceMysql::processException(std::exception & e) { DBException* dbe = static_cast<DBException*>(&e); bool retry = false; if (dbe->isLostConnection()) { INFO_MSG(boost::format("DBInterfaceMysql::processException: " "Thread %p lost connection to database. Exception: %s. " "Attempting to reconnect.\n") % this % dbe->what() ); int attempts = 1; while (!this->reattach()) { ERROR_MSG(boost::format("DBInterfaceMysql::processException: " "Thread %p reconnect(%s) attempt %d failed(%s).\n") % this % db_name_ % attempts % getLastError()); KBEngine::sleep(30); ++attempts; } INFO_MSG(boost::format("DBInterfaceMysql::processException: " "Thread %p reconnected(%s). Attempts = %d\n") % this % db_name_ % attempts); retry = true; } else if (dbe->shouldRetry()) { WARNING_MSG(boost::format("DBInterfaceMysql::processException: Retrying %1%\nException:%2%\nnlastquery=%3%\n") % this % dbe->what() % lastquery_); retry = true; } else { WARNING_MSG(boost::format("DBInterfaceMysql::processException: " "Exception: %1%\nlastquery=%2%\n") % dbe->what() % lastquery_); } return retry; }
//------------------------------------------------------------------------------------- bool DBInterfaceMysql::processException(std::exception & e) { DBException* dbe = static_cast<DBException*>(&e); bool retry = false; if (dbe->isLostConnection()) { INFO_MSG(fmt::format("DBInterfaceMysql::processException: " "Thread {:p} lost connection to database. Exception: {}. " "Attempting to reconnect.\n", (void*)this, dbe->what())); int attempts = 1; while (!this->reattach()) { ERROR_MSG(fmt::format("DBInterfaceMysql::processException: " "Thread {:p} reconnect({}) attempt {} failed({}).\n", (void*)this, db_name_, attempts, getLastError())); KBEngine::sleep(30); ++attempts; } INFO_MSG(fmt::format("DBInterfaceMysql::processException: " "Thread {:p} reconnected({}). Attempts = {}\n", (void*)this, db_name_, attempts)); retry = true; } else if (dbe->shouldRetry()) { WARNING_MSG(fmt::format("DBInterfaceMysql::processException: Retrying {:p}\nException:{}\nnlastquery={}\n", (void*)this, dbe->what(), lastquery_)); retry = true; } else { WARNING_MSG(fmt::format("DBInterfaceMysql::processException: " "Exception: {}\nlastquery={}\n", dbe->what(), lastquery_)); } return retry; }
static BSONObj buildErrReply(const DBException& ex) { BSONObjBuilder errB; errB.append("$err", ex.what()); errB.append("code", ex.getCode()); if (!ex._shard.empty()) { errB.append("shard", ex._shard); } return errB.obj(); }