mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-10 01:17:40 +03:00
F #4809. Fix index in PoolSQL. Update interface in all classes
This commit is contained in:
parent
826cf76016
commit
a2c5a4cbaa
@ -27,7 +27,7 @@ class DocumentPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
DocumentPool(SqlDB * db) : PoolSQL(db, Document::table, true, false){};
|
||||
DocumentPool(SqlDB * db) : PoolSQL(db, Document::table){};
|
||||
|
||||
~DocumentPool(){};
|
||||
|
||||
|
@ -24,10 +24,7 @@ class SqlDB;
|
||||
class MarketPlaceAppPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
MarketPlaceAppPool(
|
||||
SqlDB * db,
|
||||
bool is_federation_slave)
|
||||
:PoolSQL(db,MarketPlaceApp::table,!is_federation_slave,true){};
|
||||
MarketPlaceAppPool(SqlDB * db):PoolSQL(db, MarketPlaceApp::table){};
|
||||
|
||||
~MarketPlaceAppPool(){};
|
||||
|
||||
|
@ -45,10 +45,8 @@ public:
|
||||
* @param _db a pointer to the database
|
||||
* @param _table the name of the table supporting the pool (to set the oid
|
||||
* counter). If null the OID counter is not updated.
|
||||
* @param cache True to enable the cache
|
||||
* @param cache_by_name True if the objects can be retrieved by name
|
||||
*/
|
||||
PoolSQL(SqlDB * _db, const char * _table, bool cache, bool cache_by_name);
|
||||
PoolSQL(SqlDB * _db, const char * _table);
|
||||
|
||||
virtual ~PoolSQL();
|
||||
|
||||
@ -353,18 +351,7 @@ private:
|
||||
* The pool is implemented with a Map of SQL object pointers, using the
|
||||
* OID as key.
|
||||
*/
|
||||
map<int,PoolObjectSQL *> pool;
|
||||
|
||||
/**
|
||||
* Whether or not this pool uses the name_pool index
|
||||
*/
|
||||
bool uses_name_pool;
|
||||
|
||||
/**
|
||||
* This is a name index for the pool map. The key is the name of the object
|
||||
* , that may be combained with the owner id.
|
||||
*/
|
||||
map<string,PoolObjectSQL *> name_pool;
|
||||
vector<PoolObjectSQL *> pool;
|
||||
|
||||
/**
|
||||
* Factory method, must return an ObjectSQL pointer to an allocated pool
|
||||
|
@ -25,7 +25,7 @@ class AuthRequest;
|
||||
class VMGroupPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
VMGroupPool(SqlDB * db):PoolSQL(db, VMGroup::table, true, true){};
|
||||
VMGroupPool(SqlDB * db):PoolSQL(db, VMGroup::table){};
|
||||
|
||||
~VMGroupPool(){};
|
||||
|
||||
|
@ -27,7 +27,7 @@ class VMTemplatePool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
VMTemplatePool(SqlDB * db) : PoolSQL(db, VMTemplate::table, true, true){};
|
||||
VMTemplatePool(SqlDB * db) : PoolSQL(db, VMTemplate::table){};
|
||||
|
||||
~VMTemplatePool(){};
|
||||
|
||||
|
@ -28,7 +28,7 @@ class VirtualRouterPool : public PoolSQL
|
||||
public:
|
||||
|
||||
VirtualRouterPool(SqlDB * db, vector<const VectorAttribute *> hook_mads,
|
||||
const string& remotes_location) : PoolSQL(db, VirtualRouter::table, true, true)
|
||||
const string& remotes_location) : PoolSQL(db, VirtualRouter::table)
|
||||
{
|
||||
register_hooks(hook_mads, remotes_location);
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ const int ClusterPool::DEFAULT_CLUSTER_ID = 0;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
ClusterPool::ClusterPool(SqlDB * db, const VectorAttribute * _vnc_conf):
|
||||
PoolSQL(db, Cluster::table, true, true), vnc_conf(_vnc_conf)
|
||||
PoolSQL(db, Cluster::table), vnc_conf(_vnc_conf)
|
||||
{
|
||||
ostringstream oss;
|
||||
string error_str;
|
||||
|
@ -41,7 +41,7 @@ const int DatastorePool::FILE_DS_ID = 2;
|
||||
DatastorePool::DatastorePool(
|
||||
SqlDB * db,
|
||||
const vector<const SingleAttribute *>& _inherit_attrs) :
|
||||
PoolSQL(db, Datastore::table, true, true)
|
||||
PoolSQL(db, Datastore::table)
|
||||
|
||||
{
|
||||
ostringstream oss;
|
||||
|
@ -39,7 +39,7 @@ const int GroupPool::USERS_ID = 1;
|
||||
|
||||
GroupPool::GroupPool(SqlDB * db, vector<const VectorAttribute *> hook_mads,
|
||||
const string& remotes_location, bool is_federation_slave) :
|
||||
PoolSQL(db, Group::table, !is_federation_slave, true)
|
||||
PoolSQL(db, Group::table)
|
||||
{
|
||||
ostringstream oss;
|
||||
string error_str;
|
||||
|
@ -41,7 +41,7 @@ HostPool::HostPool(SqlDB* db,
|
||||
const string& hook_location,
|
||||
const string& remotes_location,
|
||||
time_t expire_time)
|
||||
: PoolSQL(db, Host::table, true, true)
|
||||
: PoolSQL(db, Host::table)
|
||||
{
|
||||
|
||||
_monitor_expiration = expire_time;
|
||||
|
@ -42,7 +42,7 @@ ImagePool::ImagePool(
|
||||
vector<const VectorAttribute *>& hook_mads,
|
||||
const string& remotes_location,
|
||||
const vector<const SingleAttribute *>& _inherit_attrs)
|
||||
:PoolSQL(db, Image::table, true, true)
|
||||
:PoolSQL(db, Image::table)
|
||||
{
|
||||
// Init static defaults
|
||||
_default_type = __default_type;
|
||||
|
@ -21,10 +21,8 @@
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
MarketPlacePool::MarketPlacePool(
|
||||
SqlDB * db,
|
||||
bool is_federation_slave)
|
||||
:PoolSQL(db, MarketPlace::table, !is_federation_slave, true)
|
||||
MarketPlacePool::MarketPlacePool(SqlDB * db, bool is_federation_slave)
|
||||
:PoolSQL(db, MarketPlace::table)
|
||||
{
|
||||
//Federation slaves do not need to init the pool
|
||||
if (is_federation_slave)
|
||||
|
@ -663,7 +663,7 @@ void Nebula::start(bool bootstrap_only)
|
||||
secgrouppool = new SecurityGroupPool(logdb);
|
||||
|
||||
marketpool = new MarketPlacePool(db_ptr, is_federation_slave());
|
||||
apppool = new MarketPlaceAppPool(db_ptr, is_federation_slave());
|
||||
apppool = new MarketPlaceAppPool(db_ptr);
|
||||
|
||||
vmgrouppool = new VMGroupPool(logdb);
|
||||
|
||||
|
@ -87,8 +87,8 @@ void PoolSQL::set_lastOID(int _last_oid)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
PoolSQL::PoolSQL(SqlDB * _db, const char * _table, bool _cache, bool by_name):
|
||||
db(_db), table(_table), uses_name_pool(by_name)
|
||||
PoolSQL::PoolSQL(SqlDB * _db, const char * _table):
|
||||
db(_db), table(_table)
|
||||
{
|
||||
pthread_mutex_init(&mutex,0);
|
||||
};
|
||||
@ -98,15 +98,15 @@ PoolSQL::PoolSQL(SqlDB * _db, const char * _table, bool _cache, bool by_name):
|
||||
|
||||
PoolSQL::~PoolSQL()
|
||||
{
|
||||
map<int,PoolObjectSQL *>::iterator it;
|
||||
vector<PoolObjectSQL *>::iterator it;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
for ( it = pool.begin(); it != pool.end(); it++)
|
||||
for ( it = pool.begin(); it != pool.end(); ++it)
|
||||
{
|
||||
it->second->lock();
|
||||
(*it)->lock();
|
||||
|
||||
delete it->second;
|
||||
delete *it;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
@ -192,14 +192,7 @@ PoolObjectSQL * PoolSQL::get(int oid, bool olock)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pool.insert(make_pair(objectsql->oid, objectsql));
|
||||
|
||||
if ( uses_name_pool )
|
||||
{
|
||||
string okey = key(objectsql->name, objectsql->uid);
|
||||
|
||||
name_pool.insert(make_pair(okey, objectsql));
|
||||
}
|
||||
pool.push_back(objectsql);
|
||||
|
||||
if ( olock == true )
|
||||
{
|
||||
@ -216,11 +209,6 @@ PoolObjectSQL * PoolSQL::get(int oid, bool olock)
|
||||
|
||||
PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock)
|
||||
{
|
||||
if ( uses_name_pool == false )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
lock();
|
||||
|
||||
string name_key = key(name, ouid);
|
||||
@ -242,9 +230,7 @@ PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pool.insert(make_pair(objectsql->oid, objectsql));
|
||||
|
||||
name_pool.insert(make_pair(name_key, objectsql));
|
||||
pool.push_back(objectsql);
|
||||
|
||||
if ( olock == true )
|
||||
{
|
||||
@ -261,22 +247,17 @@ PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock)
|
||||
|
||||
void PoolSQL::flush_cache(int oid)
|
||||
{
|
||||
int rc;
|
||||
PoolObjectSQL * tmp_ptr;
|
||||
|
||||
map<int,PoolObjectSQL *>::iterator it;
|
||||
|
||||
for (it = pool.begin(); it != pool.end(); )
|
||||
for (vector<PoolObjectSQL *>::iterator it = pool.begin(); it != pool.end();)
|
||||
{
|
||||
// The object we are looking for in ::get(). Wait until it is unlocked()
|
||||
if (it->first == oid)
|
||||
if ((*it)->oid == oid)
|
||||
{
|
||||
it->second->lock();
|
||||
(*it)->lock();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Any other locked object is just ignored
|
||||
rc = pthread_mutex_trylock(&(it->second->mutex));
|
||||
int rc = pthread_mutex_trylock(&((*it)->mutex));
|
||||
|
||||
if ( rc == EBUSY ) // In use by other thread
|
||||
{
|
||||
@ -285,19 +266,9 @@ void PoolSQL::flush_cache(int oid)
|
||||
}
|
||||
}
|
||||
|
||||
tmp_ptr = it->second;
|
||||
delete *it;
|
||||
|
||||
// map::erase does not invalidate iterator, except for the current one
|
||||
it = pool.erase(it);
|
||||
|
||||
if ( uses_name_pool )
|
||||
{
|
||||
string okey = key(tmp_ptr->name, tmp_ptr->uid);
|
||||
|
||||
name_pool.erase(okey);
|
||||
}
|
||||
|
||||
delete tmp_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -306,22 +277,19 @@ void PoolSQL::flush_cache(int oid)
|
||||
|
||||
void PoolSQL::flush_cache(const string& name_key)
|
||||
{
|
||||
int rc;
|
||||
PoolObjectSQL * tmp_ptr;
|
||||
|
||||
map<string,PoolObjectSQL *>::iterator it;
|
||||
|
||||
for (it = name_pool.begin(); it != name_pool.end(); )
|
||||
for (vector<PoolObjectSQL *>::iterator it = pool.begin(); it != pool.end();)
|
||||
{
|
||||
string okey = key((*it)->name, (*it)->uid);
|
||||
|
||||
// The object we are looking for in ::get(). Wait until it is unlocked()
|
||||
if (name_key == it->first)
|
||||
if ( name_key == okey)
|
||||
{
|
||||
it->second->lock();
|
||||
(*it)->lock();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Any other locked object is just ignored
|
||||
rc = pthread_mutex_trylock(&(it->second->mutex));
|
||||
int rc = pthread_mutex_trylock(&((*it)->mutex));
|
||||
|
||||
if ( rc == EBUSY ) // In use by other thread
|
||||
{
|
||||
@ -330,14 +298,9 @@ void PoolSQL::flush_cache(const string& name_key)
|
||||
}
|
||||
}
|
||||
|
||||
tmp_ptr = it->second;
|
||||
delete *it;
|
||||
|
||||
// map::erase does not invalidate iterator, except for the current one
|
||||
it = name_pool.erase(it);
|
||||
|
||||
pool.erase(tmp_ptr->oid);
|
||||
|
||||
delete tmp_ptr;
|
||||
it = pool.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,21 +309,19 @@ void PoolSQL::flush_cache(const string& name_key)
|
||||
|
||||
void PoolSQL::clean()
|
||||
{
|
||||
map<int,PoolObjectSQL *>::iterator it;
|
||||
vector<PoolObjectSQL *>::iterator it;
|
||||
|
||||
lock();
|
||||
|
||||
for ( it = pool.begin(); it != pool.end(); it++)
|
||||
for (it = pool.begin(); it != pool.end(); ++it)
|
||||
{
|
||||
it->second->lock();
|
||||
(*it)->lock();
|
||||
|
||||
delete it->second;
|
||||
delete *it;
|
||||
}
|
||||
|
||||
pool.clear();
|
||||
|
||||
name_pool.clear();
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,7 @@
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
SecurityGroupPool::SecurityGroupPool(SqlDB * db)
|
||||
:PoolSQL(db, SecurityGroup::table, true, true)
|
||||
SecurityGroupPool::SecurityGroupPool(SqlDB * db):PoolSQL(db,SecurityGroup::table)
|
||||
{
|
||||
//lastOID is set in PoolSQL::init_cb
|
||||
if (get_lastOID() == -1)
|
||||
|
@ -56,7 +56,7 @@ UserPool::UserPool(SqlDB * db,
|
||||
vector<const VectorAttribute *> hook_mads,
|
||||
const string& remotes_location,
|
||||
bool is_federation_slave):
|
||||
PoolSQL(db, User::table, !is_federation_slave, true)
|
||||
PoolSQL(db, User::table)
|
||||
{
|
||||
int one_uid = -1;
|
||||
int server_uid = -1;
|
||||
|
@ -25,8 +25,7 @@ const int VdcPool::DEFAULT_ID = 0;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
VdcPool::VdcPool(SqlDB * db, bool is_federation_slave)
|
||||
:PoolSQL(db, Vdc::table, !is_federation_slave, true)
|
||||
VdcPool::VdcPool(SqlDB * db, bool is_federation_slave): PoolSQL(db, Vdc::table)
|
||||
{
|
||||
string error_str;
|
||||
|
||||
|
@ -47,7 +47,7 @@ VirtualMachinePool::VirtualMachinePool(
|
||||
float default_cpu_cost,
|
||||
float default_mem_cost,
|
||||
float default_disk_cost)
|
||||
: PoolSQL(db, VirtualMachine::table, true, false),
|
||||
: PoolSQL(db, VirtualMachine::table),
|
||||
_monitor_expiration(expire_time), _submit_on_hold(on_hold),
|
||||
_default_cpu_cost(default_cpu_cost), _default_mem_cost(default_mem_cost),
|
||||
_default_disk_cost(default_disk_cost)
|
||||
|
@ -48,7 +48,7 @@ VirtualNetworkPool::VirtualNetworkPool(
|
||||
const vector<const SingleAttribute *>& _inherit_attrs,
|
||||
const VectorAttribute * _vlan_conf,
|
||||
const VectorAttribute * _vxlan_conf):
|
||||
PoolSQL(db, VirtualNetwork::table, true, true), vlan_conf(_vlan_conf),
|
||||
PoolSQL(db, VirtualNetwork::table), vlan_conf(_vlan_conf),
|
||||
vlan_id_bitmap(vlan_conf, VLAN_BITMAP_ID, vlan_table),
|
||||
vxlan_conf(_vxlan_conf)
|
||||
{
|
||||
|
@ -28,8 +28,7 @@ const int ZonePool::STANDALONE_ZONE_ID = 0;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
ZonePool::ZonePool(SqlDB * db, bool is_federation_slave)
|
||||
:PoolSQL(db, Zone::table, !is_federation_slave, true)
|
||||
ZonePool::ZonePool(SqlDB * db, bool is_federation_slave):PoolSQL(db,Zone::table)
|
||||
{
|
||||
string error_str;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user