1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-01 06:50:25 +03:00

Feature #2743: onedb keeps 3 different versions

1 the code version
2 the replicated (master) DB tables version
3 the slave (local) DB tables version
This commit is contained in:
Carlos Martín 2014-02-21 18:08:41 +01:00
parent 7744150944
commit 46e6688706
5 changed files with 89 additions and 67 deletions

View File

@ -366,11 +366,33 @@ public:
return "OpenNebula 4.5.0";
};
/**
* Returns the version of oned
* @return
*/
static string code_version()
{
return "4.5.0";
}
/**
* Version needed for the DB, replicated tables
* @return
*/
static string db_version()
{
return "4.5.0";
}
/**
* Version needed for the DB, local tables
* @return
*/
static string slave_db_version()
{
return "4.5.0";
}
/**
* Starts all the modules and services for OpenNebula
*/

View File

@ -119,14 +119,22 @@ private:
*
* @return 0 on success
*/
int bootstrap();
int bootstrap()
{
return bootstrap(true);
}
/**
* Bootstraps the database control tables for a slave DB
*
* @return 0 on success
*/
int slave_bootstrap();
int slave_bootstrap()
{
return bootstrap(false);
}
int bootstrap(bool do_master);
/**
* Callback function for the check_db_version method. Stores the read

View File

@ -313,10 +313,14 @@ void Nebula::start(bool bootstrap_only)
if( is_federation_slave() && rc == -2 )
{
throw runtime_error(
string error_str =
"Either the database was not bootstrapped by the "
"federation master, or the replication was "
"not configured.");
"not configured.";
NebulaLog::log("ONE",Log::ERROR,error_str);
throw runtime_error(error_str);
}
if( rc == -2 || rc == -3 )

View File

@ -40,11 +40,11 @@ const char * SystemDB::ver_bootstrap = "CREATE TABLE db_versioning "
// DB slave versioning table
const char * SystemDB::slave_ver_table = "slave_db_versioning";
const char * SystemDB::slave_ver_names = "oid, version, timestamp, comment";
const char * SystemDB::slave_ver_names = "oid, version, timestamp, comment, is_slave";
const char * SystemDB::slave_ver_bootstrap = "CREATE TABLE slave_db_versioning "
"(oid INTEGER PRIMARY KEY, version VARCHAR(256), timestamp INTEGER, "
"comment VARCHAR(256))";
"comment VARCHAR(256), is_slave BOOLEAN)";
// System attributes table
const char * SystemDB::sys_table = "system_attributes";
@ -56,7 +56,7 @@ const char * SystemDB::sys_bootstrap = "CREATE TABLE IF NOT EXISTS"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int SystemDB::bootstrap()
int SystemDB::bootstrap(bool do_master)
{
int rc;
ostringstream oss;
@ -67,52 +67,34 @@ int SystemDB::bootstrap()
oss.str(pc_bootstrap);
rc = db->exec(oss);
// ------------------------------------------------------------------------
// db versioning, version of OpenNebula.
// ------------------------------------------------------------------------
oss.str(ver_bootstrap);
rc += db->exec(oss);
if (do_master)
{
// ---------------------------------------------------------------------
// db versioning, version of OpenNebula.
// ---------------------------------------------------------------------
oss.str(ver_bootstrap);
rc += db->exec(oss);
oss.str("");
oss << "INSERT INTO " << ver_table << " (" << ver_names << ") "
<< "VALUES (0, '" << Nebula::db_version() << "', " << time(0)
<< ", '" << Nebula::version() << " daemon bootstrap')";
oss.str("");
oss << "INSERT INTO " << ver_table << " (" << ver_names << ") "
<< "VALUES (0, '" << Nebula::db_version() << "', " << time(0)
<< ", '" << Nebula::version() << " daemon bootstrap')";
rc += db->exec(oss);
rc += db->exec(oss);
}
// ------------------------------------------------------------------------
// system
// ------------------------------------------------------------------------
oss.str(sys_bootstrap);
rc += db->exec(oss);
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int SystemDB::slave_bootstrap()
{
int rc;
ostringstream oss;
// ------------------------------------------------------------------------
// pool control, tracks the last ID's assigned to objects
// ------------------------------------------------------------------------
oss.str(pc_bootstrap);
rc = db->exec(oss);
// ------------------------------------------------------------------------
// db versioning, version of OpenNebula.
// slave db versioning, version of tables that are not replicated in a
// slave OpenNebula.
// ------------------------------------------------------------------------
oss.str(slave_ver_bootstrap);
rc += db->exec(oss);
oss.str("");
oss << "INSERT INTO " << slave_ver_table << " (" << slave_ver_names << ") "
<< "VALUES (0, '" << Nebula::db_version() << "', " << time(0)
<< ", '" << Nebula::version() << " daemon bootstrap')";
<< "VALUES (0, '" << Nebula::slave_db_version() << "', " << time(0)
<< ", '" << Nebula::version() << " daemon bootstrap', "
<< Nebula::instance().is_federation_slave() << ")";
rc += db->exec(oss);
@ -201,39 +183,45 @@ int SystemDB::check_db_version(bool is_federation_slave)
return -1;
}
if (is_federation_slave)
loaded_db_version = "";
// Try to read latest version from the slave db version table
set_callback( static_cast<Callbackable::Callback>(&SystemDB::select_cb),
static_cast<void *>(&loaded_db_version) );
oss << "SELECT version FROM " << slave_ver_table
<< " WHERE oid=(SELECT MAX(oid) FROM " << slave_ver_table << ")";
db->exec(oss, this, true);
oss.str("");
unset_callback();
if( loaded_db_version == "" )
{
string loaded_db_version = "";
// Database needs bootstrap only for the slave tables
return -3;
}
// Try to read latest version from the slave db version table
set_callback( static_cast<Callbackable::Callback>(&SystemDB::select_cb),
static_cast<void *>(&loaded_db_version) );
oss << "SELECT version FROM " << slave_ver_table
<< " WHERE oid=(SELECT MAX(oid) FROM " << slave_ver_table << ")";
db->exec(oss, this, true);
oss.str("");
unset_callback();
if( loaded_db_version == "" )
if( Nebula::slave_db_version() != loaded_db_version )
{
if (!is_federation_slave)
{
return -3;
oss << "Database version mismatch. "
<< "Installed " << Nebula::version() << " uses DB version '"
<< Nebula::slave_db_version() << "', and existing DB version is '"
<< loaded_db_version << "'.";
}
if( Nebula::db_version() != loaded_db_version )
else
{
oss << "Database version mismatch. "
<< "Installed slave " << Nebula::version() << " uses DB version '"
<< Nebula::db_version() << "', and existing slave DB version is '"
<< Nebula::slave_db_version() << "', and existing slave DB version is '"
<< loaded_db_version << "'.";
NebulaLog::log("ONE",Log::ERROR,oss);
return -1;
}
return 0;
NebulaLog::log("ONE",Log::ERROR,oss);
return -1;
}
return 0;

View File

@ -30,7 +30,7 @@ void SystemVersion::request_execute(xmlrpc_c::paramList const& paramList,
// Should we make the version call accessible even
// if no user is provided?
success_response(Nebula::instance().db_version(), att);
success_response(Nebula::instance().code_version(), att);
return;
}