1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

Bug #1237: Disable the cache name index for the VM pool

This commit is contained in:
Carlos Martín 2012-04-20 10:23:51 +02:00
parent ad80efd37e
commit 05f93acb38
13 changed files with 63 additions and 40 deletions

View File

@ -37,17 +37,16 @@ using namespace std;
class PoolSQL: public Callbackable, public Hookable
{
public:
/**
* Initializes the oid counter. This function sets lastOID to
* the last used Object identifier by querying the corresponding database
* table. This function SHOULD be called before any pool related function.
* @param _db a pointer to the database
* @param table the name of the table supporting the pool (to set the oid
* @param _table the name of the table supporting the pool (to set the oid
* counter). If null the OID counter is not updated.
* @param with_uid the Pool objects have an owner id (uid)
* @param cache_by_name True if the objects can be retrieved by name
*/
PoolSQL(SqlDB * _db, const char * _table);
PoolSQL(SqlDB * _db, const char * _table, bool cache_by_name);
virtual ~PoolSQL();
@ -71,17 +70,6 @@ public:
*/
PoolObjectSQL * get(int oid, bool lock);
/**
* Gets an object from the pool (if needed the object is loaded from the
* database).
* @param name of the object
* @param uid id of owner
* @param lock locks the object if true
*
* @return a pointer to the object, 0 in case of failure
*/
PoolObjectSQL * get(const string& name, int uid, bool lock);
/**
* Updates the cache name index. Must be called when the owner of an object
* is changed
@ -168,6 +156,17 @@ public:
protected:
/**
* Gets an object from the pool (if needed the object is loaded from the
* database).
* @param name of the object
* @param uid id of owner
* @param lock locks the object if true
*
* @return a pointer to the object, 0 in case of failure
*/
PoolObjectSQL * get(const string& name, int uid, bool lock);
/**
* Pointer to the database.
*/
@ -238,6 +237,11 @@ private:
*/
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.

View File

@ -27,7 +27,7 @@ class VMTemplatePool : public PoolSQL
{
public:
VMTemplatePool(SqlDB * db) : PoolSQL(db, VMTemplate::table){};
VMTemplatePool(SqlDB * db) : PoolSQL(db, VMTemplate::table, true){};
~VMTemplatePool(){};

View File

@ -32,7 +32,7 @@ const int ClusterPool::NONE_CLUSTER_ID = -1;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table)
ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table, true)
{
ostringstream oss;
string error_str;

View File

@ -36,7 +36,7 @@ const int DatastorePool::DEFAULT_DS_ID = 1;
/* -------------------------------------------------------------------------- */
DatastorePool::DatastorePool(SqlDB * db):
PoolSQL(db, Datastore::table)
PoolSQL(db, Datastore::table, true)
{
ostringstream oss;
string error_str;

View File

@ -37,7 +37,7 @@ const int GroupPool::USERS_ID = 1;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
GroupPool::GroupPool(SqlDB * db):PoolSQL(db, Group::table)
GroupPool::GroupPool(SqlDB * db):PoolSQL(db, Group::table, true)
{
ostringstream oss;
string error_str;

View File

@ -33,7 +33,7 @@ HostPool::HostPool(SqlDB* db,
vector<const Attribute *> hook_mads,
const string& hook_location,
const string& remotes_location)
: PoolSQL(db,Host::table)
: PoolSQL(db, Host::table, true)
{
// ------------------ Initialize Hooks for the pool ----------------------

View File

@ -513,7 +513,7 @@ int Image::disk_attribute( VectorAttribute * disk,
break;
case CDROM: //Always use CDROM type for these ones
disk_attr_type = "CDROM"
disk_attr_type = "CDROM";
disk->replace("READONLY","YES");
break;
}

View File

@ -35,7 +35,7 @@ ImagePool::ImagePool(SqlDB * db,
const string& __default_type,
const string& __default_dev_prefix,
vector<const Attribute *>& restricted_attrs):
PoolSQL(db,Image::table)
PoolSQL(db, Image::table, true)
{
ostringstream sql;

View File

@ -50,8 +50,8 @@ int PoolSQL::init_cb(void *nil, int num, char **values, char **names)
/* -------------------------------------------------------------------------- */
PoolSQL::PoolSQL(SqlDB * _db, const char * _table):
db(_db), lastOID(-1), table(_table)
PoolSQL::PoolSQL(SqlDB * _db, const char * _table, bool cache_by_name):
db(_db), lastOID(-1), table(_table), uses_name_pool(cache_by_name)
{
ostringstream oss;
@ -216,23 +216,28 @@ PoolObjectSQL * PoolSQL::get(
return 0;
}
string okey = key(objectsql->name,objectsql->uid);
name_index = name_pool.find(okey);
if ( uses_name_pool )
{
string okey = key(objectsql->name,objectsql->uid);
if ( name_index != name_pool.end() )
{
name_index->second->lock();
name_index = name_pool.find(okey);
PoolObjectSQL * tmp_ptr = name_index->second;
if ( name_index != name_pool.end() )
{
name_index->second->lock();
name_pool.erase(okey);
pool.erase(tmp_ptr->oid);
PoolObjectSQL * tmp_ptr = name_index->second;
delete tmp_ptr;
name_pool.erase(okey);
pool.erase(tmp_ptr->oid);
delete tmp_ptr;
}
name_pool.insert(make_pair(okey, objectsql));
}
pool.insert(make_pair(objectsql->oid,objectsql));
name_pool.insert(make_pair(okey, objectsql));
if ( olock == true )
{
@ -257,6 +262,11 @@ PoolObjectSQL * PoolSQL::get(
PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock)
{
if ( uses_name_pool == false )
{
return 0;
}
map<string,PoolObjectSQL *>::iterator index;
PoolObjectSQL * objectsql;
@ -344,6 +354,11 @@ void PoolSQL::update_cache_index(string& old_name,
string& new_name,
int new_uid)
{
if ( uses_name_pool == false )
{
return;
}
map<string,PoolObjectSQL *>::iterator index;
lock();
@ -398,10 +413,14 @@ void PoolSQL::replace()
else
{
PoolObjectSQL * tmp_ptr = index->second;
string okey = key(tmp_ptr->name,tmp_ptr->uid);
pool.erase(index);
name_pool.erase(okey);
if ( uses_name_pool )
{
string okey = key(tmp_ptr->name,tmp_ptr->uid);
name_pool.erase(okey);
}
delete tmp_ptr;

View File

@ -118,7 +118,7 @@ class TestPool : public PoolSQL
{
public:
TestPool(SqlDB *db):PoolSQL(db,"test_pool"){};
TestPool(SqlDB *db):PoolSQL(db,"test_pool",true){};
~TestPool(){};
TestObjectSQL * get(

View File

@ -54,7 +54,7 @@ string UserPool::oneadmin_name;
UserPool::UserPool(SqlDB * db,
time_t __session_expiration_time):
PoolSQL(db,User::table)
PoolSQL(db, User::table, true)
{
int one_uid = -1;
int server_uid = -1;

View File

@ -29,7 +29,7 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db,
const string& hook_location,
const string& remotes_location,
vector<const Attribute *>& restricted_attrs)
: PoolSQL(db,VirtualMachine::table)
: PoolSQL(db, VirtualMachine::table, false)
{
const VectorAttribute * vattr;

View File

@ -34,7 +34,7 @@ unsigned int VirtualNetworkPool::_default_size;
VirtualNetworkPool::VirtualNetworkPool(SqlDB * db,
const string& prefix,
int __default_size):
PoolSQL(db,VirtualNetwork::table)
PoolSQL(db, VirtualNetwork::table, true)
{
istringstream iss;
size_t pos = 0;