From cbd9aee9122ee1fcd7a775fff48e99057fc180ca Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 12 Jun 2019 17:20:50 +0200 Subject: [PATCH] F #3393: Reduce number of updates referencing FTS field. Changed REPLACE operations to UPDATE to improve DB performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit co-authored-by: Christian González --- include/BitMap.h | 21 +++--- include/RequestManagerRename.h | 28 ++++++++ include/RequestManagerUpdateTemplate.h | 27 ++++++++ include/VirtualMachine.h | 41 +++++++++--- include/VirtualMachinePool.h | 22 +++++++ src/cluster/Cluster.cc | 33 ++++++---- src/datastore/Datastore.cc | 32 ++++++---- src/dm/DispatchManagerActions.cc | 25 ++++---- src/document/Document.cc | 35 +++++----- src/group/Group.cc | 19 +++--- src/host/Host.cc | 42 +++++++----- src/image/Image.cc | 32 ++++++---- src/lcm/LifeCycleActions.cc | 4 +- src/lcm/LifeCycleStates.cc | 13 ++-- src/market/MarketPlace.cc | 31 +++++---- src/market/MarketPlaceApp.cc | 31 +++++---- src/nebula/SystemDB.cc | 16 ++--- src/rm/RequestManagerRename.cc | 4 ++ src/rm/RequestManagerUpdateTemplate.cc | 2 + src/rm/RequestManagerVirtualMachine.cc | 12 ++-- src/secgroup/SecurityGroup.cc | 33 +++++----- src/sql/LogDB.cc | 24 ++++--- src/tm/TransferManager.cc | 2 +- src/um/User.cc | 31 +++++---- src/vdc/Vdc.cc | 33 +++++----- src/vm/History.cc | 20 +++--- src/vm/VirtualMachine.cc | 88 +++++++++++++++++--------- src/vm_group/VMGroup.cc | 32 ++++++---- src/vm_template/VMTemplate.cc | 32 ++++++---- src/vn_template/VNTemplate.cc | 33 +++++----- src/vnm/VirtualNetwork.cc | 33 ++++++---- src/vrouter/VirtualRouter.cc | 32 ++++++---- src/zone/Zone.cc | 33 +++++----- 33 files changed, 562 insertions(+), 334 deletions(-) diff --git a/include/BitMap.h b/include/BitMap.h index 7d797064e20..aba0e4b5f18 100644 --- a/include/BitMap.h +++ b/include/BitMap.h @@ -297,15 +297,6 @@ class BitMap : public Callbackable { std::ostringstream oss; - if (replace) - { - oss << "REPLACE "; - } - else - { - oss << "INSERT "; - } - std::string * zipped = one_util::zlib_compress(bs->to_string(), true); if (zipped == 0) @@ -315,8 +306,18 @@ class BitMap : public Callbackable char * ezipped64 = db->escape_str(zipped->c_str()); - oss << "INTO " << db_table << " (id, map) VALUES (" + + if (replace) + { + oss << "UPDATE " << db_table << " SET " + << "map = '" << ezipped64 << "' " + << "WHERE id = " << id; + } + else + { + oss << "INSERT INTO " << db_table << " (id, map) VALUES (" << id << ",'" << ezipped64 << "')"; + } int rc = db->exec_wr(oss); diff --git a/include/RequestManagerRename.h b/include/RequestManagerRename.h index 273318ad6a3..cc24f600666 100644 --- a/include/RequestManagerRename.h +++ b/include/RequestManagerRename.h @@ -86,6 +86,17 @@ class RequestManagerRename : public Request pthread_mutex_unlock(&mutex); } + /** + * Method por updating custom values not included in PoolSQL::update + * mainly used for updating search information in the VMs. + * @param object to be updated + * @return 0 on success + */ + virtual int extra_updates(PoolObjectSQL * obj) + { + return 0; + }; + private: /** * Mutex to control concurrent access to the ongoing rename operations @@ -121,6 +132,23 @@ class VirtualMachineRename : public RequestManagerRename { return -1; } + + + int extra_updates(PoolObjectSQL * obj) + { + VirtualMachine * vm; + + VirtualMachinePool * vmpool = static_cast(pool); + + if (obj == 0) + { + return -1; + } + + vm = static_cast(obj); + + return vmpool->update_search(vm); + }; }; /* ------------------------------------------------------------------------- */ diff --git a/include/RequestManagerUpdateTemplate.h b/include/RequestManagerUpdateTemplate.h index ad62b25fd43..44a8b49d80e 100644 --- a/include/RequestManagerUpdateTemplate.h +++ b/include/RequestManagerUpdateTemplate.h @@ -48,6 +48,17 @@ class RequestManagerUpdateTemplate: public Request virtual int append_template(PoolObjectSQL * object, const string & tmpl, const RequestAttributes &att, string &error_str); + + /** + * Method por updating custom values not included in PoolSQL::update + * mainly used for updating search information in the VMs. + * @param object to be updated + * @return 0 on success + */ + virtual int extra_updates(PoolObjectSQL * obj) + { + return 0; + }; }; /* ------------------------------------------------------------------------- */ @@ -104,6 +115,22 @@ class VirtualMachineUpdateTemplate: public RequestManagerUpdateTemplate }; ~VirtualMachineUpdateTemplate(){}; + + int extra_updates(PoolObjectSQL * obj) + { + VirtualMachine * vm; + + VirtualMachinePool * vmpool = static_cast(pool); + + if (obj == 0) + { + return -1; + } + + vm = static_cast(obj); + + return vmpool->update_search(vm); + }; }; /* ------------------------------------------------------------------------- */ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index cbf67c4a6a7..5ae211379cb 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1848,14 +1848,31 @@ class VirtualMachine : public PoolObjectSQL */ int update_history(SqlDB * db) { - if ( history != 0 ) + if ( history == 0 ) { - return history->update(db); - } - else return -1; + } + + return history->update(db); }; + /** + * Insert a new VM history record + * @param db pointer to the db + * @return 0 on success + */ + int insert_history(SqlDB * db) + { + std::string error; + + if ( history == 0 ) + { + return -1; + } + + return history->insert(db, error); + } + /** * Updates the previous history record * @param db pointer to the db @@ -1863,12 +1880,12 @@ class VirtualMachine : public PoolObjectSQL */ int update_previous_history(SqlDB * db) { - if ( previous_history != 0 ) + if ( previous_history == 0 ) { - return previous_history->update(db); - } - else return -1; + } + + return previous_history->update(db); }; /** @@ -1879,6 +1896,14 @@ class VirtualMachine : public PoolObjectSQL */ int update_monitoring(SqlDB * db); + /** + * Updates the VM search information. + * + * @param db pointer to the db + * @return 0 on success + */ + int update_search(SqlDB * db); + /** * Function that renders the VM in XML format optinally including * extended information (all history records) diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index 1027f50033b..78705c39f79 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -201,6 +201,17 @@ class VirtualMachinePool : public PoolSQL // Virtual Machine DB access functions //-------------------------------------------------------------------------- + /** + * Insert a new history record of a VM, the vm's mutex SHOULD be locked + * @param vm pointer to the virtual machine object + * @return 0 on success + */ + int insert_history( + VirtualMachine * vm) + { + return vm->insert_history(db); + } + /** * Updates the history record of a VM, the vm's mutex SHOULD be locked * @param vm pointer to the virtual machine object @@ -241,6 +252,17 @@ class VirtualMachinePool : public PoolSQL return vm->update_monitoring(db); }; + /** + * Updates the VM's search information + * @param vm pointer to the virtual machine object + * @return 0 on success + */ + int update_search( + VirtualMachine * vm) + { + return vm->update_search(db); + } + /** * Deletes the expired monitoring entries for all VMs * diff --git a/src/cluster/Cluster.cc b/src/cluster/Cluster.cc index 8c8a495b9f8..7d6033ee9b4 100644 --- a/src/cluster/Cluster.cc +++ b/src/cluster/Cluster.cc @@ -188,25 +188,30 @@ int Cluster::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; + } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - oss <<" INTO "<exec_wr(oss); db->free_str(sql_name); diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 27a269f380c..01155358489 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -701,25 +701,29 @@ int Datastore::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " ("<< db_names <<") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_name); diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 34314abefaf..f2e6dd72c60 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -1401,7 +1401,7 @@ int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl, vm->set_running_stime(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); //----------------------------------------------- @@ -1491,7 +1491,7 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra, vm->set_running_stime(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); //--------------------------------------------------- @@ -1648,14 +1648,14 @@ int DispatchManager::snapshot_delete(int vid, int snap_id, return -1; } - + bool is_keep_snapshots = false; - + if ( vm->hasHistory() ) { is_keep_snapshots = vmm->is_keep_snapshots(vm->get_vmm_mad()); } - + if ( (vm->get_state() != VirtualMachine::ACTIVE || vm->get_lcm_state() != VirtualMachine::RUNNING) && (!is_keep_snapshots || @@ -1786,7 +1786,7 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl, vm->set_running_stime(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); //----------------------------------------------- @@ -1795,8 +1795,8 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl, else { vm->log("DiM", Log::INFO, "VM NIC Successfully attached."); - vm->clear_attach_nic(); + vmpool->update_search(vm); } vmpool->update(vm); @@ -1884,7 +1884,7 @@ int DispatchManager::detach_nic(int vid, int nic_id,const RequestAttributes& ra, vm->set_running_stime(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); vm->set_state(VirtualMachine::HOTPLUG_NIC); @@ -1904,6 +1904,8 @@ int DispatchManager::detach_nic(int vid, int nic_id,const RequestAttributes& ra, vmpool->update(vm); + vmpool->update_search(vm); + vm->unlock(); vmpool->detach_nic_success(vid); @@ -2012,7 +2014,7 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, vm->set_running_stime(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmm->trigger(VMMAction::DISK_SNAPSHOT_CREATE, vid); break; @@ -2208,7 +2210,7 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, vm->set_running_stime(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); case VirtualMachine::POWEROFF: case VirtualMachine::SUSPENDED: @@ -2323,7 +2325,7 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, vm->set_running_stime(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmm->trigger(VMMAction::DISK_RESIZE, vid); break; @@ -2332,6 +2334,7 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, } vmpool->update(vm); + vmpool->update_search(vm); vm->unlock(); diff --git a/src/document/Document.cc b/src/document/Document.cc index d7e6fa4e4eb..295eeb5428a 100644 --- a/src/document/Document.cc +++ b/src/document/Document.cc @@ -131,26 +131,31 @@ int Document::insert_replace(SqlDB *db, bool replace, string& error_str) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "type = " << type << ", " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << type << "," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO " << table <<" ("<< db_names <<") VALUES (" - << oid << "," - << "'" << sql_name << "'," - << "'" << sql_xml << "'," - << type << "," - << uid << "," - << gid << "," - << owner_u << "," - << group_u << "," - << other_u << ")"; - rc = db->exec_wr(oss); db->free_str(sql_name); diff --git a/src/group/Group.cc b/src/group/Group.cc index 660d4080d19..9410879407f 100644 --- a/src/group/Group.cc +++ b/src/group/Group.cc @@ -141,16 +141,19 @@ int Group::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; - } - - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<
exec_wr(oss); diff --git a/src/host/Host.cc b/src/host/Host.cc index c20534eef57..74dd867ef97 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -115,28 +115,36 @@ int Host::insert_replace(SqlDB *db, bool replace, string& error_str) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_hostname << "', " + << "body = '" << sql_xml << "', " + << "state = " << state << ", " + << "last_mon_time = " << last_monitored << ", " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u << ", " + << "cid = " << cluster_id + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + // Construct the SQL statement to Insert or Replace + oss << "INSERT INTO "<< table <<" ("<< db_names <<") VALUES (" + << oid << "," + << "'" << sql_hostname << "'," + << "'" << sql_xml << "'," + << state << "," + << last_monitored << "," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << "," + << cluster_id << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_hostname); diff --git a/src/image/Image.cc b/src/image/Image.cc index 749121bc5c9..8dd295a388d 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -291,25 +291,29 @@ int Image::insert_replace(SqlDB *db, bool replace, string& error_str) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<< table <<" ("<< db_names <<") VALUES (" - << oid << "," - << "'" << sql_name << "'," - << "'" << sql_xml << "'," - << uid << "," - << gid << "," - << owner_u << "," - << group_u << "," - << other_u << ")"; - rc = db->exec_wr(oss); db->free_str(sql_name); diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 46373322029..8c98cd74ed4 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -746,7 +746,7 @@ void LifeCycleManager::restore_action(const LCMAction& la) vm->set_action(History::RESUME_ACTION, la.uid(), la.gid(), la.req_id()); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmpool->update(vm); @@ -805,7 +805,7 @@ void LifeCycleManager::restart_action(const LCMAction& la) vm->set_action(History::RESUME_ACTION, la.uid(), la.gid(), la.req_id()); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmpool->update(vm); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 694ffded0a8..debd83cf02c 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -111,7 +111,7 @@ void LifeCycleManager::revert_migrate_after_failure(VirtualMachine* vm) vm->set_last_poll(0); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmpool->update(vm); @@ -394,7 +394,7 @@ void LifeCycleManager::deploy_failure_action(int vid) vm->set_last_poll(0); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmpool->update(vm); @@ -859,7 +859,7 @@ void LifeCycleManager::prolog_failure_action(int vid) hpool->add_capacity(vm->get_hid(),vm->get_oid(),cpu,mem,disk,pci); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmpool->update(vm); @@ -1256,7 +1256,7 @@ void LifeCycleManager::monitor_poweron_action(int vid) vm->set_last_poll(the_time); - vmpool->update_history(vm); + vmpool->insert_history(vm); vmpool->update(vm); } @@ -1315,6 +1315,7 @@ void LifeCycleManager::attach_success_action(int vid) vm->set_state(VirtualMachine::RUNNING); vmpool->update(vm); + vmpool->update_search(vm); } else if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_PROLOG_POWEROFF ) { @@ -1322,6 +1323,7 @@ void LifeCycleManager::attach_success_action(int vid) vm->clear_attach_disk(); vmpool->update(vm); + vmpool->update_search(vm); dm->trigger(DMAction::POWEROFF_SUCCESS,vid); } @@ -1423,6 +1425,7 @@ void LifeCycleManager::detach_success_action(int vid) } vmpool->update(vm); + vmpool->update_search(vm); vm->unlock(); } @@ -1654,6 +1657,7 @@ void LifeCycleManager::attach_nic_success_action(int vid) vm->set_state(VirtualMachine::RUNNING); vmpool->update(vm); + vmpool->update_search(vm); } else { @@ -1733,6 +1737,7 @@ void LifeCycleManager::detach_nic_success_action(int vid) vm->set_state(VirtualMachine::RUNNING); vmpool->update(vm); + vmpool->update_search(vm); vm->unlock(); } diff --git a/src/market/MarketPlace.cc b/src/market/MarketPlace.cc index 64f4d8f86f6..ec613b2eb94 100644 --- a/src/market/MarketPlace.cc +++ b/src/market/MarketPlace.cc @@ -200,24 +200,29 @@ int MarketPlace::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "gid = " << gid << ", " + << "uid = " << uid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_name); diff --git a/src/market/MarketPlaceApp.cc b/src/market/MarketPlaceApp.cc index 7a4abb850dd..433a85714fb 100644 --- a/src/market/MarketPlaceApp.cc +++ b/src/market/MarketPlaceApp.cc @@ -176,24 +176,29 @@ int MarketPlaceApp::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table <<" (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_name); diff --git a/src/nebula/SystemDB.cc b/src/nebula/SystemDB.cc index e9ac1fd6415..ca3d94878fd 100644 --- a/src/nebula/SystemDB.cc +++ b/src/nebula/SystemDB.cc @@ -287,20 +287,16 @@ int SystemDB::insert_replace( if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << sys_table << " SET " + << "body = '" << sql_xml << "' " + << "WHERE name = '" << attr_name << "'"; } else { - oss << "INSERT"; + oss << "INSERT INTO " << sys_table << " (" << sys_names << ") VALUES (" + << "'" << attr_name << "'," + << "'" << sql_xml << "')"; } - - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<< sys_table << - " ("<< sys_names <<") VALUES (" - << "'" << attr_name << "'," - << "'" << sql_xml << "')"; - rc = db->exec_wr(oss); db->free_str(sql_xml); diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc index bf597188c52..ddbd2f13b27 100644 --- a/src/rm/RequestManagerRename.cc +++ b/src/rm/RequestManagerRename.cc @@ -118,6 +118,8 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, pool->update(object); + extra_updates(object); + object->unlock(); batch_rename(oid); @@ -239,7 +241,9 @@ void HostRename::batch_rename(int oid) if (vm->hasHistory() && vm->get_hid() == oid) { vm->set_hostname(host_name); + vmpool->update_history(vm); + vmpool->update_search(vm); } vm->unlock(); diff --git a/src/rm/RequestManagerUpdateTemplate.cc b/src/rm/RequestManagerUpdateTemplate.cc index 45623a28f21..9fc81a6edd9 100644 --- a/src/rm/RequestManagerUpdateTemplate.cc +++ b/src/rm/RequestManagerUpdateTemplate.cc @@ -119,6 +119,8 @@ void RequestManagerUpdateTemplate::request_execute( pool->update(object); + extra_updates(object); + object->unlock(); success_response(oid, att); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 423988a7ede..f30db1c3a21 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -465,7 +465,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm, vm->add_history(hid, cid, hostname, vmm_mad, tm_mad, ds_id); - if ( vmpool->update_history(vm) != 0 ) + if ( vmpool->insert_history(vm) != 0 ) { att.resp_msg = "Cannot update virtual machine history"; failure_response(INTERNAL, att); @@ -2207,6 +2207,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, } vmpool->update(vm); + vmpool->update_search(vm); break; case VirtualMachine::STOPPED: @@ -3074,14 +3075,14 @@ void VirtualMachineDiskSnapshotRename::request_execute(xmlrpc_c::paramList const if ( rc != 0 ) { failure_response(ACTION, att); - + vm->unlock(); - + return; } - + success_response(id, att); - + pool->update(vm); vm->unlock(); @@ -3189,6 +3190,7 @@ void VirtualMachineUpdateConf::request_execute( } static_cast(pool)->update(vm); + static_cast(pool)->update_search(vm); vm->unlock(); diff --git a/src/secgroup/SecurityGroup.cc b/src/secgroup/SecurityGroup.cc index 2c3bf7a08c8..c5aee76b833 100644 --- a/src/secgroup/SecurityGroup.cc +++ b/src/secgroup/SecurityGroup.cc @@ -144,26 +144,29 @@ int SecurityGroup::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_name); diff --git a/src/sql/LogDB.cc b/src/sql/LogDB.cc index 778d61ed4bf..288768b931b 100644 --- a/src/sql/LogDB.cc +++ b/src/sql/LogDB.cc @@ -326,21 +326,29 @@ int LogDB::insert(uint64_t index, unsigned int term, const std::string& sql, return -1; } + bool applied = tstamp != 0; + if (replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "term = " << term << ", " + << "sqlcmd = '" << sql_db << "', " + << "timestamp = " << tstamp << ", " + << "fed_index = " << fed_index << ", " + << "applied = " << applied + << " WHERE log_index = " << index; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " ("<< db_names <<") VALUES (" + << index << "," + << term << "," + << "'" << sql_db << "'," + << tstamp << "," + << fed_index << "," + << applied << ")"; } - bool applied = tstamp != 0; - - oss << " INTO " << table << " ("<< db_names <<") VALUES (" - << index << "," << term << "," << "'" << sql_db << "'," << tstamp - << "," << fed_index << "," << applied << ")"; - int rc = db->exec_wr(oss); if ( rc != 0 ) diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 57d26470aff..db8d8d369cf 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -670,7 +670,7 @@ void TransferManager::prolog_action(int vid) { vm->unlock(); - vm = vmpool->get(vid); + vm = vmpool->get(vid); if (vm == 0) { goto error_attributes; diff --git a/src/um/User.cc b/src/um/User.cc index 327dc7fd4c0..5b669eda15d 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -151,24 +151,29 @@ int User::insert_replace(SqlDB *db, bool replace, string& error_str) // Construct the SQL statement to Insert or Replace if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_username << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_username << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - oss << " INTO " << table << " ("<< db_names <<") VALUES (" - << oid << "," - << "'" << sql_username << "'," - << "'" << sql_xml << "'," - << uid << "," - << gid << "," - << owner_u << "," - << group_u << "," - << other_u << ")"; - - rc = db->exec_wr(oss); db->free_str(sql_username); diff --git a/src/vdc/Vdc.cc b/src/vdc/Vdc.cc index 072ff329e77..353599919e8 100644 --- a/src/vdc/Vdc.cc +++ b/src/vdc/Vdc.cc @@ -128,26 +128,29 @@ int Vdc::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_name); diff --git a/src/vm/History.cc b/src/vm/History.cc index 06680944366..96daee3bcce 100644 --- a/src/vm/History.cc +++ b/src/vm/History.cc @@ -177,20 +177,22 @@ int History::insert_replace(SqlDB *db, bool replace) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "body = '" << sql_xml << "', " + << "stime = " << stime << ", " + << "etime = " << etime + << " WHERE vid = " << oid << " AND seq = " << seq; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << seq << "," + << "'" << sql_xml << "'," + << stime << "," + << etime << ")"; } - oss << " INTO " << table << " ("<< db_names <<") VALUES (" - << oid << "," - << seq << "," - << "'" << sql_xml << "'," - << stime << "," - << etime << ")"; - rc = db->exec_wr(oss); db->free_str(sql_xml); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index e3b8e590af2..d2f5f5d634c 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1726,29 +1726,39 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace, string& error_str) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "last_poll = " << last_poll << ", " + << "state = " << state << ", " + << "lcm_state = " << lcm_state << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u << ", " + << "short_body = '" << sql_short_xml << "' " + << "WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " ("<< db_names <<") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << last_poll << "," + << state << "," + << lcm_state << "," + << owner_u << "," + << group_u << "," + << other_u << "," + << "'" << sql_short_xml << "'," + << "'" << sql_text << "'" + << ")"; } - oss << " INTO " << table << " ("<< db_names <<") VALUES (" - << oid << "," - << "'" << sql_name << "'," - << "'" << sql_xml << "'," - << uid << "," - << gid << "," - << last_poll << "," - << state << "," - << lcm_state << "," - << owner_u << "," - << group_u << "," - << other_u << "," - << "'" << sql_short_xml << "'," - << "'" << sql_text << "'" - << ")"; - db->free_str(sql_name); db->free_str(sql_xml); db->free_str(sql_short_xml); @@ -1785,6 +1795,31 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace, string& error_str) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VirtualMachine::update_search(SqlDB * db) +{ + std::ostringstream oss; + std::string text; + + char * sql_text = db->escape_str(to_token(text).c_str()); + + if ( sql_text == 0 ) + { + NebulaLog::log("ONE", Log::ERROR, "Error updating VM search token"); + return -1; + } + + oss << "UPDATE " << table << " SET " + << "search_token = '" << sql_text << "' " + << "WHERE oid = " << oid; + + db->free_str(sql_text); + + return db->exec_local_wr(oss); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int VirtualMachine::update_monitoring(SqlDB * db) { ostringstream oss; @@ -2301,21 +2336,14 @@ string& VirtualMachine::to_token(string& text) const ostringstream oss; oss << "UNAME="<< uname << "\n" - << "GNAME="<< gname << "\n"; + << "GNAME="<< gname << "\n" + << obj_template->to_token(template_text) << "\n" + << user_obj_template->to_token(user_template_text) + << "NAME="; - oss << "NAME="; one_util::escape_token(name, oss); - oss << "\n"; - oss << "LAST_POLL="<< last_poll << "\n" - << "PREV_STATE="<< prev_state << "\n" - << "PREV_LCM_STATE="<< prev_lcm_state << "\n" - << "RESCHED="<< resched << "\n" - << "STIME="<< stime << "\n" - << "ETIME="<< etime << "\n" - << "DEPLOY_ID="<< deploy_id << "\n" - << obj_template->to_token(template_text) << "\n" - << user_obj_template->to_token(user_template_text); + oss << "\n"; if ( hasHistory() ) { diff --git a/src/vm_group/VMGroup.cc b/src/vm_group/VMGroup.cc index 938b4061fdb..de10d29013d 100644 --- a/src/vm_group/VMGroup.cc +++ b/src/vm_group/VMGroup.cc @@ -176,25 +176,29 @@ int VMGroup::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_name); diff --git a/src/vm_template/VMTemplate.cc b/src/vm_template/VMTemplate.cc index d1b2af7a958..a344a8f1a8f 100644 --- a/src/vm_template/VMTemplate.cc +++ b/src/vm_template/VMTemplate.cc @@ -124,25 +124,29 @@ int VMTemplate::insert_replace(SqlDB *db, bool replace, string& error_str) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO " << table <<" ("<< db_names <<") VALUES (" - << oid << "," - << "'" << sql_name << "'," - << "'" << sql_xml << "'," - << uid << "," - << gid << "," - << owner_u << "," - << group_u << "," - << other_u << ")"; - rc = db->exec_wr(oss); db->free_str(sql_name); diff --git a/src/vn_template/VNTemplate.cc b/src/vn_template/VNTemplate.cc index 64dd96bc936..ef7bbcdb80d 100644 --- a/src/vn_template/VNTemplate.cc +++ b/src/vn_template/VNTemplate.cc @@ -156,25 +156,28 @@ int VNTemplate::insert_replace(SqlDB *db, bool replace, string& error_str) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - - // Construct the SQL statement to Insert or Replace - - oss <<" INTO " << table <<" ("<< db_names <<") VALUES (" - << oid << "," - << "'" << sql_name << "'," - << "'" << sql_xml << "'," - << uid << "," - << gid << "," - << owner_u << "," - << group_u << "," - << other_u << ")"; - rc = db->exec_wr(oss); db->free_str(sql_name); diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 116dede0ce9..15ec3094620 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -502,24 +502,31 @@ int VirtualNetwork::insert_replace(SqlDB *db, bool replace, string& error_str) // Construct the SQL statement to Insert or Replace if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u << ", " + << "pid = " << parent_vid + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << "," + << parent_vid << ")"; } - oss << " INTO " << table << " (" << db_names << ") VALUES (" - << oid << "," - << "'" << sql_name << "'," - << "'" << sql_xml << "'," - << uid << "," - << gid << "," - << owner_u << "," - << group_u << "," - << other_u << "," - << parent_vid << ")"; - rc = db->exec_wr(oss); db->free_str(sql_name); diff --git a/src/vrouter/VirtualRouter.cc b/src/vrouter/VirtualRouter.cc index 6188962dc44..5847aa5c6fd 100644 --- a/src/vrouter/VirtualRouter.cc +++ b/src/vrouter/VirtualRouter.cc @@ -273,25 +273,29 @@ int VirtualRouter::insert_replace(SqlDB *db, bool replace, string& error_str) if(replace) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO " << table <<" ("<< db_names <<") VALUES (" - << oid << "," - << "'" << sql_name << "'," - << "'" << sql_xml << "'," - << uid << "," - << gid << "," - << owner_u << "," - << group_u << "," - << other_u << ")"; - rc = db->exec_wr(oss); db->free_str(sql_name); diff --git a/src/zone/Zone.cc b/src/zone/Zone.cc index 444f3d4d975..4bbc3c35995 100644 --- a/src/zone/Zone.cc +++ b/src/zone/Zone.cc @@ -147,26 +147,29 @@ int Zone::insert_replace(SqlDB *db, bool replace, string& error_str) if ( replace ) { - oss << "REPLACE"; + oss << "UPDATE " << table << " SET " + << "name = '" << sql_name << "', " + << "body = '" << sql_xml << "', " + << "uid = " << uid << ", " + << "gid = " << gid << ", " + << "owner_u = " << owner_u << ", " + << "group_u = " << group_u << ", " + << "other_u = " << other_u + << " WHERE oid = " << oid; } else { - oss << "INSERT"; + oss << "INSERT INTO " << table << " (" << db_names << ") VALUES (" + << oid << "," + << "'" << sql_name << "'," + << "'" << sql_xml << "'," + << uid << "," + << gid << "," + << owner_u << "," + << group_u << "," + << other_u << ")"; } - // Construct the SQL statement to Insert or Replace - - oss <<" INTO "<
exec_wr(oss); db->free_str(sql_name);