1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-12 08:58:17 +03:00

F #4809: Update SqlDB method name. DO NOT replicate monitoring data

This commit is contained in:
Ruben S. Montero 2017-04-21 19:16:45 +02:00
parent dd0598aaa6
commit bca17f4ee6
31 changed files with 72 additions and 47 deletions

View File

@ -283,13 +283,13 @@ private:
ostringstream oss; ostringstream oss;
oss.str(Cluster::db_bootstrap); oss.str(Cluster::db_bootstrap);
rc = db->exec_bootstrap(oss); rc = db->exec_local_wr(oss);
oss.str(Cluster::datastore_db_bootstrap); oss.str(Cluster::datastore_db_bootstrap);
rc += db->exec_bootstrap(oss); rc += db->exec_local_wr(oss);
oss.str(Cluster::network_db_bootstrap); oss.str(Cluster::network_db_bootstrap);
rc += db->exec_bootstrap(oss); rc += db->exec_local_wr(oss);
return rc; return rc;
}; };

View File

@ -201,7 +201,7 @@ public:
int rc; int rc;
rc = Cluster::bootstrap(_db); rc = Cluster::bootstrap(_db);
rc += _db->exec_bootstrap( rc += _db->exec_local_wr(
BitMap<0>::bootstrap(Cluster::bitmap_table, oss_bitmap)); BitMap<0>::bootstrap(Cluster::bitmap_table, oss_bitmap));
return rc; return rc;

View File

@ -364,7 +364,7 @@ private:
{ {
ostringstream oss(Datastore::db_bootstrap); ostringstream oss(Datastore::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -107,7 +107,7 @@ private:
{ {
ostringstream oss(Document::db_bootstrap); ostringstream oss(Document::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -210,7 +210,7 @@ private:
{ {
ostringstream oss_group(Group::db_bootstrap); ostringstream oss_group(Group::db_bootstrap);
return db->exec_bootstrap(oss_group); return db->exec_local_wr(oss_group);
}; };
/** /**

View File

@ -532,8 +532,8 @@ private:
ostringstream oss_host(Host::db_bootstrap); ostringstream oss_host(Host::db_bootstrap);
ostringstream oss_monit(Host::monit_db_bootstrap); ostringstream oss_monit(Host::monit_db_bootstrap);
rc = db->exec_bootstrap(oss_host); rc = db->exec_local_wr(oss_host);
rc += db->exec_bootstrap(oss_monit); rc += db->exec_local_wr(oss_monit);
return rc; return rc;
}; };

View File

@ -696,7 +696,7 @@ private:
{ {
ostringstream oss_image(Image::db_bootstrap); ostringstream oss_image(Image::db_bootstrap);
return db->exec_bootstrap(oss_image); return db->exec_local_wr(oss_image);
}; };
/** /**

View File

@ -62,9 +62,9 @@ public:
*/ */
int exec_wr(ostringstream& cmd); int exec_wr(ostringstream& cmd);
int exec_bootstrap(ostringstream& cmd) int exec_local_wr(ostringstream& cmd)
{ {
return db->exec_bootstrap(cmd); return db->exec_local_wr(cmd);
} }
int exec_rd(ostringstream& cmd, Callbackable* obj) int exec_rd(ostringstream& cmd, Callbackable* obj)
@ -94,7 +94,7 @@ public:
{ {
ostringstream oss(db_bootstrap); ostringstream oss(db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
} }
protected: protected:

View File

@ -221,7 +221,7 @@ private:
{ {
ostringstream oss(db_bootstrap); ostringstream oss(db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -393,7 +393,7 @@ private:
{ {
ostringstream oss(db_bootstrap); ostringstream oss(db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -167,7 +167,7 @@ public:
{ {
ostringstream oss_quota(GroupQuotas::db_bootstrap); ostringstream oss_quota(GroupQuotas::db_bootstrap);
return db->exec_bootstrap(oss_quota); return db->exec_local_wr(oss_quota);
}; };
protected: protected:
@ -220,7 +220,7 @@ public:
{ {
ostringstream oss_quota(UserQuotas::db_bootstrap); ostringstream oss_quota(UserQuotas::db_bootstrap);
return db->exec_bootstrap(oss_quota); return db->exec_local_wr(oss_quota);
}; };
protected: protected:

View File

@ -217,7 +217,7 @@ private:
{ {
ostringstream oss(SecurityGroup::db_bootstrap); ostringstream oss(SecurityGroup::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -38,13 +38,15 @@ public:
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/** /**
* * Operations on the database:
* - exec_local_wr, perform modifications locally, without replication
* - exec_rd, read only access to local DB
* - exec_wr, update DB and replicate changes
* @param sql_cmd the SQL command * @param sql_cmd the SQL command
* @param callbak function to execute on each data returned * @param callbak function to execute on each data returned
* @return 0 on success * @return 0 on success
*
*/ */
virtual int exec_bootstrap(ostringstream& cmd) virtual int exec_local_wr(ostringstream& cmd)
{ {
return exec(cmd, 0, false); return exec(cmd, 0, false);
} }

View File

@ -309,7 +309,7 @@ private:
{ {
ostringstream oss_user(User::db_bootstrap); ostringstream oss_user(User::db_bootstrap);
return db->exec_bootstrap(oss_user); return db->exec_local_wr(oss_user);
}; };
/** /**

View File

@ -166,7 +166,7 @@ private:
{ {
ostringstream oss(VMGroup::db_bootstrap); ostringstream oss(VMGroup::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -149,7 +149,7 @@ private:
{ {
ostringstream oss(VMTemplate::db_bootstrap); ostringstream oss(VMTemplate::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -343,7 +343,7 @@ private:
{ {
ostringstream oss(Vdc::db_bootstrap); ostringstream oss(Vdc::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -1750,10 +1750,10 @@ private:
ostringstream oss_hist(History::db_bootstrap); ostringstream oss_hist(History::db_bootstrap);
ostringstream oss_showback(VirtualMachine::showback_db_bootstrap); ostringstream oss_showback(VirtualMachine::showback_db_bootstrap);
rc = db->exec_bootstrap(oss_vm); rc = db->exec_local_wr(oss_vm);
rc += db->exec_bootstrap(oss_monit); rc += db->exec_local_wr(oss_monit);
rc += db->exec_bootstrap(oss_hist); rc += db->exec_local_wr(oss_hist);
rc += db->exec_bootstrap(oss_showback); rc += db->exec_local_wr(oss_showback);
return rc; return rc;
}; };

View File

@ -236,7 +236,7 @@ public:
ostringstream oss_import(import_db_bootstrap); ostringstream oss_import(import_db_bootstrap);
rc = VirtualMachine::bootstrap(_db); rc = VirtualMachine::bootstrap(_db);
rc += _db->exec_bootstrap(oss_import); rc += _db->exec_local_wr(oss_import);
return rc; return rc;
}; };

View File

@ -596,7 +596,7 @@ private:
{ {
ostringstream oss_vnet(VirtualNetwork::db_bootstrap); ostringstream oss_vnet(VirtualNetwork::db_bootstrap);
return db->exec_bootstrap(oss_vnet); return db->exec_local_wr(oss_vnet);
}; };
/** /**

View File

@ -122,7 +122,7 @@ public:
int rc; int rc;
rc = VirtualNetwork::bootstrap(_db); rc = VirtualNetwork::bootstrap(_db);
rc += _db->exec_bootstrap(BitMap<0>::bootstrap(vlan_table, oss)); rc += _db->exec_local_wr(BitMap<0>::bootstrap(vlan_table, oss));
return rc; return rc;
}; };

View File

@ -216,7 +216,7 @@ private:
{ {
ostringstream oss(VirtualRouter::db_bootstrap); ostringstream oss(VirtualRouter::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -129,7 +129,7 @@ private:
{ {
ostringstream oss(Zone::db_bootstrap); ostringstream oss(Zone::db_bootstrap);
return db->exec_bootstrap(oss); return db->exec_local_wr(oss);
}; };
/** /**

View File

@ -108,6 +108,7 @@ public:
{ {
return match; return match;
} }
/** /**
* Initialized follower data * Initialized follower data
* @param last log index * @param last log index
@ -126,6 +127,14 @@ public:
return state == OFFLINE; return state == OFFLINE;
} }
/**
* @return true if the server is the leader of the zone
*/
bool is_leader()
{
return state == LEADER;
}
private: private:
State state; State state;

View File

@ -1094,7 +1094,7 @@ int AclManager::bootstrap(SqlDB * _db)
{ {
ostringstream oss(db_bootstrap); ostringstream oss(db_bootstrap);
return _db->exec_bootstrap(oss); return _db->exec_local_wr(oss);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -553,7 +553,7 @@ int Host::update_monitoring(SqlDB * db)
db->free_str(sql_xml); db->free_str(sql_xml);
rc = db->exec_wr(oss); rc = db->exec_local_wr(oss);
return rc; return rc;

View File

@ -303,7 +303,7 @@ int HostPool::clean_expired_monitoring()
oss << "DELETE FROM " << Host::monit_table oss << "DELETE FROM " << Host::monit_table
<< " WHERE last_mon_time < " << max_mon_time; << " WHERE last_mon_time < " << max_mon_time;
rc = db->exec_wr(oss); rc = db->exec_local_wr(oss);
return rc; return rc;
} }
@ -318,7 +318,7 @@ int HostPool::clean_all_monitoring()
oss << "DELETE FROM " << Host::monit_table; oss << "DELETE FROM " << Host::monit_table;
rc = db->exec_wr(oss); rc = db->exec_local_wr(oss);
return rc; return rc;
} }

View File

@ -80,6 +80,8 @@ int LogDB::exec_wr(ostringstream& cmd)
ZoneServer * server = 0; ZoneServer * server = 0;
unsigned int term = 0; unsigned int term = 0;
bool is_leader;
if ( server_id != -1 ) if ( server_id != -1 )
{ {
Zone * zone = zpool->get(zone_id, true); Zone * zone = zpool->get(zone_id, true);
@ -92,6 +94,11 @@ int LogDB::exec_wr(ostringstream& cmd)
term = server->get_term(); term = server->get_term();
} }
if ( server != 0 )
{
is_leader = server->is_leader();
}
zone->unlock(); zone->unlock();
} }
} }
@ -120,6 +127,13 @@ int LogDB::exec_wr(ostringstream& cmd)
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Insert log entry in the database and replicate on followers // Insert log entry in the database and replicate on followers
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
if ( ! is_leader )
{
NebulaLog::log("DBM", Log::ERROR,"Tried to modify DB being a follower");
return -1;
}
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
LogDBRequest * lr = new LogDBRequest(next_index, term, cmd); LogDBRequest * lr = new LogDBRequest(next_index, term, cmd);

View File

@ -65,14 +65,14 @@ int SystemDB::shared_bootstrap()
// db versioning, version of OpenNebula. // db versioning, version of OpenNebula.
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
oss.str(shared_ver_bootstrap); oss.str(shared_ver_bootstrap);
rc = db->exec_bootstrap(oss); rc = db->exec_local_wr(oss);
oss.str(""); oss.str("");
oss << "INSERT INTO " << shared_ver_table << " (" << shared_ver_names << ") " oss << "INSERT INTO " << shared_ver_table << " (" << shared_ver_names << ") "
<< "VALUES (0, '" << Nebula::shared_db_version() << "', " << time(0) << "VALUES (0, '" << Nebula::shared_db_version() << "', " << time(0)
<< ", '" << Nebula::version() << " daemon bootstrap')"; << ", '" << Nebula::version() << " daemon bootstrap')";
rc += db->exec_bootstrap(oss); rc += db->exec_local_wr(oss);
return rc; return rc;
}; };
@ -89,14 +89,14 @@ int SystemDB::local_bootstrap()
// pool control, tracks the last ID's assigned to objects // pool control, tracks the last ID's assigned to objects
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
oss.str(pc_bootstrap); oss.str(pc_bootstrap);
rc = db->exec_bootstrap(oss); rc = db->exec_local_wr(oss);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// local db versioning, version of tables that are not replicated in a // local db versioning, version of tables that are not replicated in a
// slave OpenNebula. // slave OpenNebula.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
oss.str(local_ver_bootstrap); oss.str(local_ver_bootstrap);
rc += db->exec_bootstrap(oss); rc += db->exec_local_wr(oss);
oss.str(""); oss.str("");
oss << "INSERT INTO " << local_ver_table << " (" << local_ver_names << ") " oss << "INSERT INTO " << local_ver_table << " (" << local_ver_names << ") "
@ -104,13 +104,13 @@ int SystemDB::local_bootstrap()
<< ", '" << Nebula::version() << " daemon bootstrap', " << ", '" << Nebula::version() << " daemon bootstrap', "
<< Nebula::instance().is_federation_slave() << ")"; << Nebula::instance().is_federation_slave() << ")";
rc += db->exec_bootstrap(oss); rc += db->exec_local_wr(oss);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// system // system
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
oss.str(sys_bootstrap); oss.str(sys_bootstrap);
rc += db->exec_bootstrap(oss); rc += db->exec_local_wr(oss);
return rc; return rc;
}; };

View File

@ -1594,7 +1594,7 @@ int VirtualMachine::update_monitoring(SqlDB * db)
db->free_str(sql_xml); db->free_str(sql_xml);
rc = db->exec_wr(oss); rc = db->exec_local_wr(oss);
return rc; return rc;

View File

@ -469,7 +469,7 @@ int VirtualMachinePool::clean_expired_monitoring()
oss << "DELETE FROM " << VirtualMachine::monit_table oss << "DELETE FROM " << VirtualMachine::monit_table
<< " WHERE last_poll < " << max_last_poll; << " WHERE last_poll < " << max_last_poll;
rc = db->exec_wr(oss); rc = db->exec_local_wr(oss);
return rc; return rc;
} }
@ -484,7 +484,7 @@ int VirtualMachinePool::clean_all_monitoring()
oss << "DELETE FROM " << VirtualMachine::monit_table; oss << "DELETE FROM " << VirtualMachine::monit_table;
rc = db->exec_wr(oss); rc = db->exec_local_wr(oss);
return rc; return rc;
} }