Revision a2c5a4cb
include/DocumentPool.h | ||
---|---|---|
27 | 27 |
{ |
28 | 28 |
public: |
29 | 29 |
|
30 |
DocumentPool(SqlDB * db) : PoolSQL(db, Document::table, true, false){};
|
|
30 |
DocumentPool(SqlDB * db) : PoolSQL(db, Document::table){}; |
|
31 | 31 |
|
32 | 32 |
~DocumentPool(){}; |
33 | 33 |
|
include/MarketPlaceAppPool.h | ||
---|---|---|
24 | 24 |
class MarketPlaceAppPool : public PoolSQL |
25 | 25 |
{ |
26 | 26 |
public: |
27 |
MarketPlaceAppPool( |
|
28 |
SqlDB * db, |
|
29 |
bool is_federation_slave) |
|
30 |
:PoolSQL(db,MarketPlaceApp::table,!is_federation_slave,true){}; |
|
27 |
MarketPlaceAppPool(SqlDB * db):PoolSQL(db, MarketPlaceApp::table){}; |
|
31 | 28 |
|
32 | 29 |
~MarketPlaceAppPool(){}; |
33 | 30 |
|
include/PoolSQL.h | ||
---|---|---|
45 | 45 |
* @param _db a pointer to the database |
46 | 46 |
* @param _table the name of the table supporting the pool (to set the oid |
47 | 47 |
* counter). If null the OID counter is not updated. |
48 |
* @param cache True to enable the cache |
|
49 |
* @param cache_by_name True if the objects can be retrieved by name |
|
50 | 48 |
*/ |
51 |
PoolSQL(SqlDB * _db, const char * _table, bool cache, bool cache_by_name);
|
|
49 |
PoolSQL(SqlDB * _db, const char * _table); |
|
52 | 50 |
|
53 | 51 |
virtual ~PoolSQL(); |
54 | 52 |
|
... | ... | |
353 | 351 |
* The pool is implemented with a Map of SQL object pointers, using the |
354 | 352 |
* OID as key. |
355 | 353 |
*/ |
356 |
map<int,PoolObjectSQL *> pool; |
|
357 |
|
|
358 |
/** |
|
359 |
* Whether or not this pool uses the name_pool index |
|
360 |
*/ |
|
361 |
bool uses_name_pool; |
|
362 |
|
|
363 |
/** |
|
364 |
* This is a name index for the pool map. The key is the name of the object |
|
365 |
* , that may be combained with the owner id. |
|
366 |
*/ |
|
367 |
map<string,PoolObjectSQL *> name_pool; |
|
354 |
vector<PoolObjectSQL *> pool; |
|
368 | 355 |
|
369 | 356 |
/** |
370 | 357 |
* Factory method, must return an ObjectSQL pointer to an allocated pool |
include/VMGroupPool.h | ||
---|---|---|
25 | 25 |
class VMGroupPool : public PoolSQL |
26 | 26 |
{ |
27 | 27 |
public: |
28 |
VMGroupPool(SqlDB * db):PoolSQL(db, VMGroup::table, true, true){};
|
|
28 |
VMGroupPool(SqlDB * db):PoolSQL(db, VMGroup::table){}; |
|
29 | 29 |
|
30 | 30 |
~VMGroupPool(){}; |
31 | 31 |
|
include/VMTemplatePool.h | ||
---|---|---|
27 | 27 |
{ |
28 | 28 |
public: |
29 | 29 |
|
30 |
VMTemplatePool(SqlDB * db) : PoolSQL(db, VMTemplate::table, true, true){};
|
|
30 |
VMTemplatePool(SqlDB * db) : PoolSQL(db, VMTemplate::table){}; |
|
31 | 31 |
|
32 | 32 |
~VMTemplatePool(){}; |
33 | 33 |
|
include/VirtualRouterPool.h | ||
---|---|---|
28 | 28 |
public: |
29 | 29 |
|
30 | 30 |
VirtualRouterPool(SqlDB * db, vector<const VectorAttribute *> hook_mads, |
31 |
const string& remotes_location) : PoolSQL(db, VirtualRouter::table, true, true)
|
|
31 |
const string& remotes_location) : PoolSQL(db, VirtualRouter::table) |
|
32 | 32 |
{ |
33 | 33 |
register_hooks(hook_mads, remotes_location); |
34 | 34 |
}; |
src/cluster/ClusterPool.cc | ||
---|---|---|
36 | 36 |
/* -------------------------------------------------------------------------- */ |
37 | 37 |
|
38 | 38 |
ClusterPool::ClusterPool(SqlDB * db, const VectorAttribute * _vnc_conf): |
39 |
PoolSQL(db, Cluster::table, true, true), vnc_conf(_vnc_conf)
|
|
39 |
PoolSQL(db, Cluster::table), vnc_conf(_vnc_conf) |
|
40 | 40 |
{ |
41 | 41 |
ostringstream oss; |
42 | 42 |
string error_str; |
src/datastore/DatastorePool.cc | ||
---|---|---|
41 | 41 |
DatastorePool::DatastorePool( |
42 | 42 |
SqlDB * db, |
43 | 43 |
const vector<const SingleAttribute *>& _inherit_attrs) : |
44 |
PoolSQL(db, Datastore::table, true, true)
|
|
44 |
PoolSQL(db, Datastore::table) |
|
45 | 45 |
|
46 | 46 |
{ |
47 | 47 |
ostringstream oss; |
src/group/GroupPool.cc | ||
---|---|---|
39 | 39 |
|
40 | 40 |
GroupPool::GroupPool(SqlDB * db, vector<const VectorAttribute *> hook_mads, |
41 | 41 |
const string& remotes_location, bool is_federation_slave) : |
42 |
PoolSQL(db, Group::table, !is_federation_slave, true)
|
|
42 |
PoolSQL(db, Group::table) |
|
43 | 43 |
{ |
44 | 44 |
ostringstream oss; |
45 | 45 |
string error_str; |
src/host/HostPool.cc | ||
---|---|---|
41 | 41 |
const string& hook_location, |
42 | 42 |
const string& remotes_location, |
43 | 43 |
time_t expire_time) |
44 |
: PoolSQL(db, Host::table, true, true)
|
|
44 |
: PoolSQL(db, Host::table) |
|
45 | 45 |
{ |
46 | 46 |
|
47 | 47 |
_monitor_expiration = expire_time; |
src/image/ImagePool.cc | ||
---|---|---|
42 | 42 |
vector<const VectorAttribute *>& hook_mads, |
43 | 43 |
const string& remotes_location, |
44 | 44 |
const vector<const SingleAttribute *>& _inherit_attrs) |
45 |
:PoolSQL(db, Image::table, true, true)
|
|
45 |
:PoolSQL(db, Image::table) |
|
46 | 46 |
{ |
47 | 47 |
// Init static defaults |
48 | 48 |
_default_type = __default_type; |
src/market/MarketPlacePool.cc | ||
---|---|---|
21 | 21 |
|
22 | 22 |
/* -------------------------------------------------------------------------- */ |
23 | 23 |
|
24 |
MarketPlacePool::MarketPlacePool( |
|
25 |
SqlDB * db, |
|
26 |
bool is_federation_slave) |
|
27 |
:PoolSQL(db, MarketPlace::table, !is_federation_slave, true) |
|
24 |
MarketPlacePool::MarketPlacePool(SqlDB * db, bool is_federation_slave) |
|
25 |
:PoolSQL(db, MarketPlace::table) |
|
28 | 26 |
{ |
29 | 27 |
//Federation slaves do not need to init the pool |
30 | 28 |
if (is_federation_slave) |
src/nebula/Nebula.cc | ||
---|---|---|
663 | 663 |
secgrouppool = new SecurityGroupPool(logdb); |
664 | 664 |
|
665 | 665 |
marketpool = new MarketPlacePool(db_ptr, is_federation_slave()); |
666 |
apppool = new MarketPlaceAppPool(db_ptr, is_federation_slave());
|
|
666 |
apppool = new MarketPlaceAppPool(db_ptr); |
|
667 | 667 |
|
668 | 668 |
vmgrouppool = new VMGroupPool(logdb); |
669 | 669 |
|
src/pool/PoolSQL.cc | ||
---|---|---|
87 | 87 |
/* -------------------------------------------------------------------------- */ |
88 | 88 |
/* -------------------------------------------------------------------------- */ |
89 | 89 |
|
90 |
PoolSQL::PoolSQL(SqlDB * _db, const char * _table, bool _cache, bool by_name):
|
|
91 |
db(_db), table(_table), uses_name_pool(by_name)
|
|
90 |
PoolSQL::PoolSQL(SqlDB * _db, const char * _table): |
|
91 |
db(_db), table(_table) |
|
92 | 92 |
{ |
93 | 93 |
pthread_mutex_init(&mutex,0); |
94 | 94 |
}; |
... | ... | |
98 | 98 |
|
99 | 99 |
PoolSQL::~PoolSQL() |
100 | 100 |
{ |
101 |
map<int,PoolObjectSQL *>::iterator it;
|
|
101 |
vector<PoolObjectSQL *>::iterator it;
|
|
102 | 102 |
|
103 | 103 |
pthread_mutex_lock(&mutex); |
104 | 104 |
|
105 |
for ( it = pool.begin(); it != pool.end(); it++)
|
|
105 |
for ( it = pool.begin(); it != pool.end(); ++it)
|
|
106 | 106 |
{ |
107 |
it->second->lock();
|
|
107 |
(*it)->lock();
|
|
108 | 108 |
|
109 |
delete it->second;
|
|
109 |
delete *it;
|
|
110 | 110 |
} |
111 | 111 |
|
112 | 112 |
pthread_mutex_unlock(&mutex); |
... | ... | |
192 | 192 |
return 0; |
193 | 193 |
} |
194 | 194 |
|
195 |
pool.insert(make_pair(objectsql->oid, objectsql)); |
|
196 |
|
|
197 |
if ( uses_name_pool ) |
|
198 |
{ |
|
199 |
string okey = key(objectsql->name, objectsql->uid); |
|
200 |
|
|
201 |
name_pool.insert(make_pair(okey, objectsql)); |
|
202 |
} |
|
195 |
pool.push_back(objectsql); |
|
203 | 196 |
|
204 | 197 |
if ( olock == true ) |
205 | 198 |
{ |
... | ... | |
216 | 209 |
|
217 | 210 |
PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock) |
218 | 211 |
{ |
219 |
if ( uses_name_pool == false ) |
|
220 |
{ |
|
221 |
return 0; |
|
222 |
} |
|
223 |
|
|
224 | 212 |
lock(); |
225 | 213 |
|
226 | 214 |
string name_key = key(name, ouid); |
... | ... | |
242 | 230 |
return 0; |
243 | 231 |
} |
244 | 232 |
|
245 |
pool.insert(make_pair(objectsql->oid, objectsql)); |
|
246 |
|
|
247 |
name_pool.insert(make_pair(name_key, objectsql)); |
|
233 |
pool.push_back(objectsql); |
|
248 | 234 |
|
249 | 235 |
if ( olock == true ) |
250 | 236 |
{ |
... | ... | |
261 | 247 |
|
262 | 248 |
void PoolSQL::flush_cache(int oid) |
263 | 249 |
{ |
264 |
int rc; |
|
265 |
PoolObjectSQL * tmp_ptr; |
|
266 |
|
|
267 |
map<int,PoolObjectSQL *>::iterator it; |
|
268 |
|
|
269 |
for (it = pool.begin(); it != pool.end(); ) |
|
250 |
for (vector<PoolObjectSQL *>::iterator it = pool.begin(); it != pool.end();) |
|
270 | 251 |
{ |
271 | 252 |
// The object we are looking for in ::get(). Wait until it is unlocked() |
272 |
if (it->first == oid)
|
|
253 |
if ((*it)->oid == oid)
|
|
273 | 254 |
{ |
274 |
it->second->lock();
|
|
255 |
(*it)->lock();
|
|
275 | 256 |
} |
276 | 257 |
else |
277 | 258 |
{ |
278 | 259 |
// Any other locked object is just ignored |
279 |
rc = pthread_mutex_trylock(&(it->second->mutex));
|
|
260 |
int rc = pthread_mutex_trylock(&((*it)->mutex));
|
|
280 | 261 |
|
281 | 262 |
if ( rc == EBUSY ) // In use by other thread |
282 | 263 |
{ |
... | ... | |
285 | 266 |
} |
286 | 267 |
} |
287 | 268 |
|
288 |
tmp_ptr = it->second;
|
|
269 |
delete *it;
|
|
289 | 270 |
|
290 |
// map::erase does not invalidate iterator, except for the current one |
|
291 | 271 |
it = pool.erase(it); |
292 |
|
|
293 |
if ( uses_name_pool ) |
|
294 |
{ |
|
295 |
string okey = key(tmp_ptr->name, tmp_ptr->uid); |
|
296 |
|
|
297 |
name_pool.erase(okey); |
|
298 |
} |
|
299 |
|
|
300 |
delete tmp_ptr; |
|
301 | 272 |
} |
302 | 273 |
} |
303 | 274 |
|
... | ... | |
306 | 277 |
|
307 | 278 |
void PoolSQL::flush_cache(const string& name_key) |
308 | 279 |
{ |
309 |
int rc; |
|
310 |
PoolObjectSQL * tmp_ptr; |
|
311 |
|
|
312 |
map<string,PoolObjectSQL *>::iterator it; |
|
313 |
|
|
314 |
for (it = name_pool.begin(); it != name_pool.end(); ) |
|
280 |
for (vector<PoolObjectSQL *>::iterator it = pool.begin(); it != pool.end();) |
|
315 | 281 |
{ |
282 |
string okey = key((*it)->name, (*it)->uid); |
|
283 |
|
|
316 | 284 |
// The object we are looking for in ::get(). Wait until it is unlocked() |
317 |
if (name_key == it->first)
|
|
285 |
if ( name_key == okey)
|
|
318 | 286 |
{ |
319 |
it->second->lock();
|
|
287 |
(*it)->lock();
|
|
320 | 288 |
} |
321 | 289 |
else |
322 | 290 |
{ |
323 | 291 |
// Any other locked object is just ignored |
324 |
rc = pthread_mutex_trylock(&(it->second->mutex));
|
|
292 |
int rc = pthread_mutex_trylock(&((*it)->mutex));
|
|
325 | 293 |
|
326 | 294 |
if ( rc == EBUSY ) // In use by other thread |
327 | 295 |
{ |
... | ... | |
330 | 298 |
} |
331 | 299 |
} |
332 | 300 |
|
333 |
tmp_ptr = it->second; |
|
334 |
|
|
335 |
// map::erase does not invalidate iterator, except for the current one |
|
336 |
it = name_pool.erase(it); |
|
337 |
|
|
338 |
pool.erase(tmp_ptr->oid); |
|
301 |
delete *it; |
|
339 | 302 |
|
340 |
delete tmp_ptr;
|
|
303 |
it = pool.erase(it);
|
|
341 | 304 |
} |
342 | 305 |
} |
343 | 306 |
|
... | ... | |
346 | 309 |
|
347 | 310 |
void PoolSQL::clean() |
348 | 311 |
{ |
349 |
map<int,PoolObjectSQL *>::iterator it;
|
|
312 |
vector<PoolObjectSQL *>::iterator it;
|
|
350 | 313 |
|
351 | 314 |
lock(); |
352 | 315 |
|
353 |
for ( it = pool.begin(); it != pool.end(); it++)
|
|
316 |
for (it = pool.begin(); it != pool.end(); ++it)
|
|
354 | 317 |
{ |
355 |
it->second->lock();
|
|
318 |
(*it)->lock();
|
|
356 | 319 |
|
357 |
delete it->second;
|
|
320 |
delete *it;
|
|
358 | 321 |
} |
359 | 322 |
|
360 | 323 |
pool.clear(); |
361 | 324 |
|
362 |
name_pool.clear(); |
|
363 |
|
|
364 | 325 |
unlock(); |
365 | 326 |
} |
366 | 327 |
|
src/secgroup/SecurityGroupPool.cc | ||
---|---|---|
21 | 21 |
|
22 | 22 |
/* -------------------------------------------------------------------------- */ |
23 | 23 |
|
24 |
SecurityGroupPool::SecurityGroupPool(SqlDB * db) |
|
25 |
:PoolSQL(db, SecurityGroup::table, true, true) |
|
24 |
SecurityGroupPool::SecurityGroupPool(SqlDB * db):PoolSQL(db,SecurityGroup::table) |
|
26 | 25 |
{ |
27 | 26 |
//lastOID is set in PoolSQL::init_cb |
28 | 27 |
if (get_lastOID() == -1) |
src/um/UserPool.cc | ||
---|---|---|
56 | 56 |
vector<const VectorAttribute *> hook_mads, |
57 | 57 |
const string& remotes_location, |
58 | 58 |
bool is_federation_slave): |
59 |
PoolSQL(db, User::table, !is_federation_slave, true)
|
|
59 |
PoolSQL(db, User::table) |
|
60 | 60 |
{ |
61 | 61 |
int one_uid = -1; |
62 | 62 |
int server_uid = -1; |
src/vdc/VdcPool.cc | ||
---|---|---|
25 | 25 |
|
26 | 26 |
/* -------------------------------------------------------------------------- */ |
27 | 27 |
|
28 |
VdcPool::VdcPool(SqlDB * db, bool is_federation_slave) |
|
29 |
:PoolSQL(db, Vdc::table, !is_federation_slave, true) |
|
28 |
VdcPool::VdcPool(SqlDB * db, bool is_federation_slave): PoolSQL(db, Vdc::table) |
|
30 | 29 |
{ |
31 | 30 |
string error_str; |
32 | 31 |
|
src/vm/VirtualMachinePool.cc | ||
---|---|---|
47 | 47 |
float default_cpu_cost, |
48 | 48 |
float default_mem_cost, |
49 | 49 |
float default_disk_cost) |
50 |
: PoolSQL(db, VirtualMachine::table, true, false),
|
|
50 |
: PoolSQL(db, VirtualMachine::table), |
|
51 | 51 |
_monitor_expiration(expire_time), _submit_on_hold(on_hold), |
52 | 52 |
_default_cpu_cost(default_cpu_cost), _default_mem_cost(default_mem_cost), |
53 | 53 |
_default_disk_cost(default_disk_cost) |
src/vnm/VirtualNetworkPool.cc | ||
---|---|---|
48 | 48 |
const vector<const SingleAttribute *>& _inherit_attrs, |
49 | 49 |
const VectorAttribute * _vlan_conf, |
50 | 50 |
const VectorAttribute * _vxlan_conf): |
51 |
PoolSQL(db, VirtualNetwork::table, true, true), vlan_conf(_vlan_conf),
|
|
51 |
PoolSQL(db, VirtualNetwork::table), vlan_conf(_vlan_conf), |
|
52 | 52 |
vlan_id_bitmap(vlan_conf, VLAN_BITMAP_ID, vlan_table), |
53 | 53 |
vxlan_conf(_vxlan_conf) |
54 | 54 |
{ |
src/zone/ZonePool.cc | ||
---|---|---|
28 | 28 |
|
29 | 29 |
/* -------------------------------------------------------------------------- */ |
30 | 30 |
|
31 |
ZonePool::ZonePool(SqlDB * db, bool is_federation_slave) |
|
32 |
:PoolSQL(db, Zone::table, !is_federation_slave, true) |
|
31 |
ZonePool::ZonePool(SqlDB * db, bool is_federation_slave):PoolSQL(db,Zone::table) |
|
33 | 32 |
{ |
34 | 33 |
string error_str; |
35 | 34 |
|
Also available in: Unified diff