B #5186: Exit HA node in case of DB failure (#712)

(cherry picked from commit b36cf9f339)
This commit is contained in:
Pavel Czerný authored and Ruben S. Montero committed 2021-01-25 19:05:43 +01:00
1 parent 9ab9abf7cc
commit d24e3ea1bc
5 files changed
+80 -12

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ Import('env')
lib_name='nebula_sql'
source_files=['LogDB.cc']
source_files=['LogDB.cc', 'SqlDB.cc']
# Sources to generate the library
if env['sqlite']=='yes':
+48
View File
@@ -0,0 +1,48 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "SqlDB.h"
#include "NebulaLog.h"
#include <unistd.h>
#include <csignal>
#include <thread>
int SqlDB::exec(std::ostringstream& cmd, Callbackable* obj, bool quiet)
{
int rc = exec_ext(cmd, obj, quiet);
if (rc != 0)
{
consecutive_errors++;
rc = -1;
if (errors_limit > 0 && consecutive_errors > errors_limit)
{
NebulaLog::error("SQL", "Lost connection to DB server, exiting...");
// Kill the master process. The call is in the thread to avoid deadlock
std::thread thr([]{ kill(getpid(), SIGTERM); });
thr.detach();
}
}
else
{
consecutive_errors = 0;
}
return rc;
}