mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-01 06:50:25 +03:00
M #-: Configurable timeout for SQLite DB (#4882)
This commit is contained in:
parent
45ebdfe9be
commit
3fa04ee2d5
@ -45,7 +45,7 @@ class SqliteDB : public SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
SqliteDB(const string& db_name);
|
||||
SqliteDB(const string& db_name, int timeout);
|
||||
|
||||
~SqliteDB();
|
||||
|
||||
@ -107,7 +107,7 @@ class SqliteDB : public SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
SqliteDB(const string& db_name)
|
||||
SqliteDB(const string& db_name, int timeout)
|
||||
{
|
||||
throw runtime_error("Aborting oned, Sqlite support not compiled!");
|
||||
}
|
||||
|
@ -36,6 +36,8 @@
|
||||
# compare_binary: (mysql) compare strings using BINARY clause
|
||||
# makes name searches case sensitive.
|
||||
# encoding: charset to use for the db connections
|
||||
# timeout : (sqlite) timeout in ms for acquiring lock to DB,
|
||||
# should be at least 100 ms
|
||||
#
|
||||
# VNC_PORTS: VNC port pool for automatic VNC port assignment, if possible the
|
||||
# port will be set to ``START`` + ``VMID``
|
||||
@ -71,7 +73,8 @@ MONITORING_INTERVAL_DB_UPDATE = 0
|
||||
SCRIPTS_REMOTE_DIR=/var/tmp/one
|
||||
|
||||
|
||||
DB = [ BACKEND = "sqlite" ]
|
||||
DB = [ BACKEND = "sqlite",
|
||||
TIMEOUT = 2500 ]
|
||||
|
||||
# Sample configuration for MySQL
|
||||
# DB = [ BACKEND = "mysql",
|
||||
|
@ -100,7 +100,10 @@ void Monitor::start()
|
||||
|
||||
if (db_backend == "sqlite")
|
||||
{
|
||||
sqlDB.reset(new SqliteDB(get_var_location() + "one.db"));
|
||||
int timeout;
|
||||
_db->vector_value("TIMEOUT", timeout, 2500);
|
||||
|
||||
sqlDB.reset(new SqliteDB(get_var_location() + "one.db", timeout));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -389,6 +389,7 @@ void Nebula::start(bool bootstrap_only)
|
||||
string db_name;
|
||||
string encoding;
|
||||
string compare_binary;
|
||||
int timeout;
|
||||
int connections;
|
||||
|
||||
const VectorAttribute * _db = nebula_configuration->get("DB");
|
||||
@ -404,12 +405,13 @@ void Nebula::start(bool bootstrap_only)
|
||||
_db->vector_value<string>("DB_NAME", db_name, "opennebula");
|
||||
_db->vector_value<string>("ENCODING", encoding, "");
|
||||
_db->vector_value<string>("COMPARE_BINARY", compare_binary, "NO");
|
||||
_db->vector_value("TIMEOUT", timeout, 2500);
|
||||
_db->vector_value("CONNECTIONS", connections, 25);
|
||||
}
|
||||
|
||||
if ( db_backend_type == "sqlite" )
|
||||
{
|
||||
db_backend = new SqliteDB(var_location + "one.db");
|
||||
db_backend = new SqliteDB(var_location + "one.db", timeout);
|
||||
}
|
||||
else if ( db_backend_type == "mysql" )
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ extern "C" int sqlite_callback (
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
SqliteDB::SqliteDB(const string& db_name)
|
||||
SqliteDB::SqliteDB(const string& db_name, int timeout)
|
||||
{
|
||||
pthread_mutex_init(&mutex,0);
|
||||
|
||||
@ -60,6 +60,8 @@ SqliteDB::SqliteDB(const string& db_name)
|
||||
|
||||
sqlite3_extended_result_codes(db, 1);
|
||||
|
||||
sqlite3_busy_timeout(db, timeout);
|
||||
|
||||
features = {
|
||||
{SqlFeature::MULTIPLE_VALUE, false},
|
||||
{SqlFeature::LIMIT, enable_limit == 1},
|
||||
@ -87,7 +89,6 @@ int SqliteDB::exec_ext(std::ostringstream& cmd, Callbackable *obj, bool quiet)
|
||||
const char * c_str;
|
||||
string str;
|
||||
|
||||
int counter = 0;
|
||||
char * err_msg = 0;
|
||||
|
||||
int (*callback)(void*,int,char**,char**);
|
||||
@ -110,22 +111,7 @@ int SqliteDB::exec_ext(std::ostringstream& cmd, Callbackable *obj, bool quiet)
|
||||
|
||||
lock();
|
||||
|
||||
do
|
||||
{
|
||||
counter++;
|
||||
|
||||
rc = sqlite3_exec(db, c_str, callback, arg, &err_msg);
|
||||
|
||||
if (rc == SQLITE_BUSY || rc == SQLITE_IOERR)
|
||||
{
|
||||
struct timeval timeout;
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 250000;
|
||||
|
||||
select(0, NULL, NULL, NULL, &timeout);
|
||||
}
|
||||
}while((rc == SQLITE_BUSY || rc == SQLITE_IOERR) && (counter < 10));
|
||||
rc = sqlite3_exec(db, c_str, callback, arg, &err_msg);
|
||||
|
||||
if (obj != 0 && obj->get_affected_rows() == 0)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user