Liran Zelkha has uploaded a new change for review. Change subject: engine : Change VdsUpdateRuntimeInfo to work with BatchUpdates ......................................................................
engine : Change VdsUpdateRuntimeInfo to work with BatchUpdates Batch Updates greatly improve performance, and this patch aims to replace multiple updates in VdsUpdateRuntimeInfo to batch calls. Change-Id: I6dea40226cd1f3ec44367a27598b24b59ab49aae Bug-Url: https://bugzilla.redhat.com/?????? Signed-off-by: lzel...@redhat.com <liran.zel...@gmail.com> --- M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/BatchProcedureExecutionConnectionCallback.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java 17 files changed, 289 insertions(+), 65 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/19274/1 diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/BatchProcedureExecutionConnectionCallback.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/BatchProcedureExecutionConnectionCallback.java index 354d7a8..5763700 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/BatchProcedureExecutionConnectionCallback.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/BatchProcedureExecutionConnectionCallback.java @@ -1,16 +1,24 @@ package org.ovirt.engine.core.dal.dbbroker; +import java.lang.reflect.Method; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; +import java.sql.Types; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.utils.SerializationFactory; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; import org.springframework.dao.DataAccessException; @@ -155,11 +163,57 @@ Map<String, Object> values = paramSource.getValues(); for (Map.Entry<String, SqlCallParameter> paramOrderEntry : paramOrder.entrySet()) { + DateFormat sdf = SimpleDateFormat.getDateTimeInstance(); String paramName = paramOrderEntry.getKey(); Object value = values.get(paramName); + if (value == null && paramName.startsWith(DbFacade.getInstance().getDbEngineDialect().getParamNamePrefix())) { + value = + values.get(paramName.substring(DbFacade.getInstance() + .getDbEngineDialect() + .getParamNamePrefix() + .length())); + } + SqlCallParameter sqlParam = paramOrderEntry.getValue(); + + if (value != null) { + if (value.getClass().isEnum()) { + try { + Method method = value.getClass().getMethod("getValue"); + if (method == null) + method = value.getClass().getMethod("ordinal"); + value = method.invoke(value); + } catch (Exception e) { + log.error("Can't map Enum type " + value); + } + } + + if (value instanceof Guid) { + value = value.toString(); + } + + if (sqlParam.getDataType() == Types.TIMESTAMP) { + value = new Timestamp(((Date) value).getTime()); + } + + if (value instanceof Map) { + value = SerializationFactory.getSerializer().serialize(value); + } + } else { + if (sqlParam.getDataType() == Types.BOOLEAN || sqlParam.getDataType() == Types.BIT) { + value = false; + } + } + int ordinal = sqlParam.getOrdinal(); - stmt.setObject(ordinal, value); + try { + stmt.setObject(ordinal, value); + } catch (Exception e) { + log.error("Can't map " + value + " of type " + value.getClass().getName() + " to type " + + sqlParam.getDataType() + + " mapping to null value for parameter " + sqlParam.getName()); + stmt.setObject(ordinal, null); + } } log.debugFormat("Mapped params %s", values.keySet()); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java index ea7deaa..0a71eb6 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAODbFacadeImpl.java @@ -5,6 +5,7 @@ import org.ovirt.engine.core.common.businessentities.DiskImageDynamic; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -63,4 +64,24 @@ protected RowMapper<DiskImageDynamic> createEntityRowMapper() { return DiskImageDynamicRowMapper.instance; } + + @Override + public MapSqlParameterMapper<DiskImageDynamic> getBatchMapper() { + return new MapSqlParameterMapper<DiskImageDynamic>() { + + @Override + public MapSqlParameterSource map(DiskImageDynamic entity) { + MapSqlParameterSource paramValue = new MapSqlParameterSource() + .addValue("image_id", entity.getId()) + .addValue("read_rate", entity.getread_rate()) + .addValue("write_rate", entity.getwrite_rate()) + .addValue("actual_size", entity.getactual_size()) + .addValue("read_latency_seconds", entity.getReadLatency()) + .addValue("write_latency_seconds", entity.getWriteLatency()) + .addValue("flush_latency_seconds", entity.getFlushLatency()); + + return paramValue; + } + }; + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java index 9d8ac3b..5b6e267 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java @@ -4,7 +4,6 @@ import java.util.Collection; import org.ovirt.engine.core.common.businessentities.BusinessEntity; -import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; /** * Data Access Object which supports mass operations for the given entity type. @@ -49,7 +48,7 @@ * @param procedureName * @param entities */ - void updateAllInBatch(String procedureName, Collection<T> paramValues, MapSqlParameterMapper<T> mapper); + void updateAllInBatch(Collection<T> entities); /** * Saves the given entities using a more efficient method to save all of them at once, rather than each at a time. diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java index 12bb977..53726d4 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java @@ -40,13 +40,12 @@ } } - @Override /** * Enables to send update procedure name as a parameter that overrides the default * one. * In case this parameter is null the default procedure is used. */ - public void updateAllInBatch(String procedureName, + protected void updateAllInBatch(String procedureName, Collection<T> paramValues, MapSqlParameterMapper<T> mapper) { getCallsHandler().executeStoredProcAsBatch(procedureName == null ? getProcedureNameForUpdate() : procedureName, @@ -66,4 +65,11 @@ save(entity); } } + + @Override + public void updateAllInBatch(Collection<T> entities) { + updateAllInBatch(getProcedureNameForUpdate(), entities, getBatchMapper()); + } + + public abstract MapSqlParameterMapper<T> getBatchMapper(); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java index 8a68ec0..5840a7a 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java @@ -11,6 +11,7 @@ import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType; import org.ovirt.engine.core.common.businessentities.VmDeviceId; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.utils.SerializationFactory; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -196,4 +197,26 @@ } + @Override + public MapSqlParameterMapper<VmDevice> getBatchMapper() { + return new MapSqlParameterMapper<VmDevice>() { + @Override + public MapSqlParameterSource map(VmDevice entity) { + MapSqlParameterSource paramValue = new MapSqlParameterSource() + .addValue("device_id", entity.getDeviceId()) + .addValue("vm_id", entity.getVmId()) + .addValue("address", entity.getAddress()) + .addValue("alias", entity.getAlias()) + .addValue("type", entity.getType()) + .addValue("is_managed", entity.getIsManaged()) + .addValue("is_plugged", entity.getIsPlugged()) + .addValue("is_readonly", entity.getIsReadOnly()) + .addValue("spec_params", entity.getSpecParams()) + .addValue("boot_order", entity.getBootOrder()) + .addValue("device", entity.getDevice()); + + return paramValue; + } + }; + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java index ee37de2..e3f2207 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAODbFacadeImpl.java @@ -15,6 +15,7 @@ import org.ovirt.engine.core.common.businessentities.VmPauseStatus; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -174,4 +175,50 @@ } }; } + + @Override + public MapSqlParameterMapper<VmDynamic> getBatchMapper() { + return new MapSqlParameterMapper<VmDynamic>() { + @Override + public MapSqlParameterSource map(VmDynamic entity) { + MapSqlParameterSource paramValue = new MapSqlParameterSource() + .addValue("guest_cur_user_name", entity.getGuestCurrentUserName()) + .addValue("console_cur_user_name", entity.getConsoleCurrentUserName()) + .addValue("guest_last_login_time", entity.getGuestLastLoginTime()) + .addValue("guest_last_logout_time", entity.getGuestLastLogoutTime()) + .addValue("console_user_id", entity.getConsoleUserId()) + .addValue("guest_os", entity.getGuestOs()) + .addValue("migrating_to_vds", entity.getMigratingToVds()) + .addValue("run_on_vds", entity.getRunOnVds()) + .addValue("status", entity.getStatus()) + .addValue("vm_guid", entity.getId()) + .addValue("vm_host", entity.getVmHost()) + .addValue("vm_ip", entity.getVmIp()) + .addValue("last_start_time", entity.getLastStartTime()) + .addValue("vm_pid", entity.getVmPid()) + .addValue("display", entity.getDisplay()) + .addValue("acpi_enable", entity.getAcpiEnable()) + .addValue("session", entity.getSession()) + .addValue("display_ip", entity.getDisplayIp()) + .addValue("display_type", entity.getDisplayType()) + .addValue("kvm_enable", entity.getKvmEnable()) + .addValue("boot_sequence", entity.getBootSequence()) + .addValue("display_secure_port", entity.getDisplaySecurePort()) + .addValue("utc_diff", entity.getUtcDiff()) + .addValue("last_vds_run_on", entity.getLastVdsRunOn()) + .addValue("client_ip", entity.getClientIp()) + .addValue("guest_requested_memory", entity.getGuestRequestedMemory()) + .addValue("hibernation_vol_handle", entity.getHibernationVolHandle()) + .addValue("exit_status", entity.getExitStatus()) + .addValue("pause_status", entity.getPauseStatus()) + .addValue("exit_message", entity.getExitMessage()) + .addValue("hash", entity.getHash()) + .addValue("guest_agent_nics_hash", entity.getGuestAgentNicsHash()) + .addValue("last_watchdog_event", entity.getLastWatchdogEvent()) + .addValue("last_watchdog_action", entity.getLastWatchdogAction()); + + return paramValue; + } + }; + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java index e89b626..1c6b31d 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDaoDbFacadeImpl.java @@ -7,6 +7,7 @@ import org.apache.commons.lang.NotImplementedException; import org.ovirt.engine.core.common.businessentities.VmStatistics; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -68,4 +69,23 @@ }; } + @Override + public MapSqlParameterMapper<VmStatistics> getBatchMapper() { + return new MapSqlParameterMapper<VmStatistics>() { + @Override + public MapSqlParameterSource map(VmStatistics entity) { + MapSqlParameterSource paramValue = new MapSqlParameterSource() + .addValue("cpu_sys", entity.getcpu_sys()) + .addValue("cpu_user", entity.getcpu_user()) + .addValue("elapsed_time", entity.getelapsed_time()) + .addValue("usage_cpu_percent", entity.getusage_cpu_percent()) + .addValue("usage_mem_percent", entity.getusage_mem_percent()) + .addValue("usage_network_percent", entity.getusage_network_percent()) + .addValue("disks_usage", entity.getDisksUsage()) + .addValue("vm_guid", entity.getId()); + + return paramValue; + } + }; + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java index d859808..4f076b9 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java @@ -10,6 +10,7 @@ import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; import org.ovirt.engine.core.common.utils.EnumUtils; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -158,4 +159,10 @@ protected RowMapper<GlusterBrickEntity> createEntityRowMapper() { return brickRowMapper; } + + @Override + public MapSqlParameterMapper<GlusterBrickEntity> getBatchMapper() { + // TODO: Implement this + throw new RuntimeException("Unsupported operation"); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java index 60b7027..0f038e6 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterHooksDaoDbFacadeImpl.java @@ -12,6 +12,7 @@ import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook; import org.ovirt.engine.core.common.utils.EnumUtils; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -299,4 +300,9 @@ return getCustomMapSqlParameterSource().addValue("id", id); } + @Override + public MapSqlParameterMapper<GlusterHookEntity> getBatchMapper() { + // TODO: Implement this + throw new RuntimeException("Unsupported operation"); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java index 6399952..c418afd 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java @@ -8,6 +8,7 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -92,4 +93,10 @@ protected RowMapper<GlusterVolumeOptionEntity> createEntityRowMapper() { return optionRowMapper; } + + @Override + public MapSqlParameterMapper<GlusterVolumeOptionEntity> getBatchMapper() { + // TODO: Implement this + throw new RuntimeException("Unsupported operation"); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java index c17aa3c..d3b3525 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterServerServiceDaoDbFacadeImpl.java @@ -9,6 +9,7 @@ import org.ovirt.engine.core.common.businessentities.gluster.ServiceType; import org.ovirt.engine.core.common.utils.EnumUtils; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; @@ -113,4 +114,10 @@ return entity; } } + + @Override + public MapSqlParameterMapper<GlusterServerService> getBatchMapper() { + // TODO: Implement this + throw new RuntimeException("Unsupported operation"); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java index 2fc9f2c..7c17236 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java @@ -20,6 +20,7 @@ import org.ovirt.engine.core.common.job.StepEnum; import org.ovirt.engine.core.common.utils.EnumUtils; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -435,5 +436,9 @@ } } - + @Override + public MapSqlParameterMapper<GlusterVolumeEntity> getBatchMapper() { + // TODO: Implement this + throw new RuntimeException("Unsupported operation"); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java index 6804b92..03b72a8 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDao.java @@ -8,6 +8,7 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.DAO; +//TODO: Split to 2 interfaces - one for statistics and one for interfaces. Both should extend MassOperation public interface InterfaceDao extends DAO { /** * Saves the specified statistics @@ -51,6 +52,14 @@ void updateInterfaceForVds(VdsNetworkInterface iface); /** + * Updates the given collection of vds network interface using a more efficient method to update all of them at + * once, rather than each at a time. + * @param statistics + * The collection of statistics to update. + */ + void massUpdateInterfacesForVds(List<VdsNetworkInterface> dbIfacesToBatch); + + /** * Retrieves all interfaces for the given VDS id. * * @param id @@ -74,11 +83,11 @@ /** * Retrieves the management interface for the given VDS id with optional filtering. - * * @param id * the VDS id * @param userID - * the ID of the user requesting the information + * //TODO: Split to 2 interfaces - one for statistics and one for interfaces. Both should extend MassOp + * eration the ID of the user requesting the information * @param isFiltered * Whether the results should be filtered according to the user's permissions * @return the VDS managed interfaces diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java index 25ff0b8..a85c20a 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java @@ -14,6 +14,7 @@ import org.ovirt.engine.core.common.businessentities.network.VdsNetworkStatistics; import org.ovirt.engine.core.common.businessentities.network.Vlan; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.dao.BaseDAODbFacade; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -34,6 +35,41 @@ } @Override + public void massUpdateInterfacesForVds(List<VdsNetworkInterface> dbIfacesToBatch) { + updateAllInBatch("Updatevds_interface", dbIfacesToBatch, new MapSqlParameterMapper<VdsNetworkInterface>() { + @Override + public MapSqlParameterSource map(VdsNetworkInterface entity) { + MapSqlParameterSource paramValue = new MapSqlParameterSource().addValue("addr", entity.getAddress()) + .addValue("bond_name", entity.getBondName()) + .addValue("bond_type", entity.getBondType()) + .addValue("gateway", entity.getGateway()) + .addValue("id", entity.getId()) + .addValue("is_bond", entity.getBonded()) + .addValue("bond_opts", entity.getBondOptions()) + .addValue("mac_addr", entity.getMacAddress()) + .addValue("name", entity.getName()) + .addValue("network_name", entity.getNetworkName()) + .addValue("speed", entity.getSpeed()) + .addValue("subnet", entity.getSubnet()) + .addValue("boot_protocol", entity.getBootProtocol()) + .addValue("type", entity.getType()) + .addValue("vds_id", entity.getVdsId()) + .addValue("vlan_id", entity.getVlanId()) + .addValue("mtu", entity.getMtu()) + .addValue("bridged", entity.isBridged()); + return paramValue; + } + }); + } + + public void updateAllInBatch(String procedureName, + Collection<VdsNetworkInterface> paramValues, + MapSqlParameterMapper<VdsNetworkInterface> mapper) { + getCallsHandler().executeStoredProcAsBatch(procedureName, + paramValues, mapper); + } + + @Override public void saveInterfaceForVds(VdsNetworkInterface stats) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("addr", stats.getAddress()) diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java index 5b21cdb..bc81b1e 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoDbFacadeImpl.java @@ -8,6 +8,7 @@ import org.ovirt.engine.core.common.businessentities.network.InterfaceStatus; import org.ovirt.engine.core.common.businessentities.network.VmNetworkStatistics; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper; import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -58,4 +59,24 @@ } }; } + + @Override + public MapSqlParameterMapper<VmNetworkStatistics> getBatchMapper() { + return new MapSqlParameterMapper<VmNetworkStatistics>() { + + @Override + public MapSqlParameterSource map(VmNetworkStatistics entity) { + MapSqlParameterSource paramValue = new MapSqlParameterSource() + .addValue("id", entity.getId()) + .addValue("rx_drop", entity.getReceiveDropRate()) + .addValue("rx_rate", entity.getReceiveRate()) + .addValue("tx_drop", entity.getTransmitDropRate()) + .addValue("tx_rate", entity.getTransmitRate()) + .addValue("iface_status", entity.getStatus()) + .addValue("vm_id", entity.getVmId()); + + return paramValue; + } + }; + } } diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java index 130b740..2cb1363 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java @@ -1,8 +1,6 @@ package org.ovirt.engine.core.vdsbroker; -import java.io.Serializable; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -18,7 +16,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.exception.ExceptionUtils; import org.ovirt.engine.core.common.AuditLogType; -import org.ovirt.engine.core.common.businessentities.BusinessEntity; import org.ovirt.engine.core.common.businessentities.Disk; import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType; import org.ovirt.engine.core.common.businessentities.DiskImage; @@ -65,7 +62,6 @@ import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; -import org.ovirt.engine.core.dao.MassOperationsDao; import org.ovirt.engine.core.utils.NetworkUtils; import org.ovirt.engine.core.utils.ObjectIdentityChecker; import org.ovirt.engine.core.utils.log.Log; @@ -159,8 +155,8 @@ } } - updateAllInTransaction(_vmDynamicToSave.values(), getDbFacade().getVmDynamicDao()); - updateAllInTransaction(_vmStatisticsToSave.values(), getDbFacade().getVmStatisticsDao()); + getDbFacade().getVmDynamicDao().updateAllInBatch(_vmDynamicToSave.values()); + getDbFacade().getVmStatisticsDao().updateAllInBatch(_vmStatisticsToSave.values()); final List<VmNetworkStatistics> allVmInterfaceStatistics = new LinkedList<VmNetworkStatistics>(); for (List<VmNetworkInterface> list : _vmInterfaceStatisticsToSave.values()) { @@ -169,8 +165,9 @@ } } - updateAllInTransaction(allVmInterfaceStatistics, getDbFacade().getVmNetworkStatisticsDao()); - updateAllInTransaction(_vmDiskImageDynamicToSave.values(), getDbFacade().getDiskImageDynamicDao()); + getDbFacade().getVmNetworkStatisticsDao().updateAllInBatch(allVmInterfaceStatistics); + + getDbFacade().getDiskImageDynamicDao().updateAllInBatch(_vmDiskImageDynamicToSave.values()); saveVmDevicesToDb(); saveVmGuestAgentNetworkDevices(); ResourceManager.getInstance().getEventListener().addExternallyManagedVms(_externalVmsToAdd); @@ -200,7 +197,7 @@ } private void saveVmDevicesToDb() { - updateAllInTransaction("UpdateVmDeviceRuntimeInfo", vmDeviceToSave.values(), getDbFacade().getVmDeviceDao()); + getDbFacade().getVmDeviceDao().updateAllInBatch(vmDeviceToSave.values()); if (!removedDeviceIds.isEmpty()) { TransactionSupport.executeInScope(TransactionScopeOption.Required, @@ -220,53 +217,6 @@ @Override public Void runInTransaction() { getDbFacade().getVmDeviceDao().saveAll(newVmDevices); - return null; - } - }); - } - } - - /** - * Update all the given entities in a transaction, so that a new connection/transaction won't be opened for each - * entity update. - * - * @param <T> - * The type of entity. - * @param entities - * The entities to update. - * @param dao - * The DAO used for updating. - */ - private static <T extends BusinessEntity<ID> & Comparable<T>, ID extends Serializable & Comparable<? super ID>> void updateAllInTransaction(final Collection<T> entities, - final MassOperationsDao<T, ID> dao) { - updateAllInTransaction(null, entities, dao); - } - - /** - * Update all the given entities in a transaction, so that a new connection/transaction won't be opened for each - * entity update. - * - * @param <T> - * The type of entity. - * @param procedureName - * The name of stored procedure to use for update - * @param entities - * The entities to update. - * @param dao - * The DAO used for updating. - */ - - private static <T extends BusinessEntity<ID> & Comparable<T>, ID extends Serializable & Comparable<? super ID>> void updateAllInTransaction - (final String procedureName, final Collection<T> entities, final MassOperationsDao<T, ID> dao) { - final List<T> sortedList = new ArrayList<T>(entities); - Collections.sort(sortedList); - if (!entities.isEmpty()) { - TransactionSupport.executeInScope(TransactionScopeOption.Required, - new TransactionMethod<Void>() { - - @Override - public Void runInTransaction() { - dao.updateAll(procedureName, sortedList); return null; } }); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java index 44cce51..f2f7e5e 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java @@ -162,6 +162,8 @@ List<VdsNetworkInterface> dbIfaces = interfaceDAO.getAllInterfacesForVds(vds.getId()); List<String> updatedIfaces = new ArrayList<String>(); + List<VdsNetworkInterface> dbIfacesToBatch = new ArrayList<>(); + // First we check what interfaces need to update/delete for (VdsNetworkInterface dbIface : dbIfaces) { boolean found = false; @@ -171,7 +173,7 @@ // we preserve only the ID from the Database // everything else is what we got from getVdsCapabilities vdsIface.setId(dbIface.getId()); - interfaceDAO.updateInterfaceForVds(vdsIface); + dbIfacesToBatch.add(vdsIface); updatedIfaces.add(vdsIface.getName()); found = true; break; @@ -183,6 +185,10 @@ } } + if (!dbIfacesToBatch.isEmpty()) { + interfaceDAO.massUpdateInterfacesForVds(dbIfacesToBatch); + } + // now all that left is add the interfaces that not exists in the Database for (VdsNetworkInterface vdsIface : vds.getInterfaces()) { if (!updatedIfaces.contains(vdsIface.getName())) { -- To view, visit http://gerrit.ovirt.org/19274 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6dea40226cd1f3ec44367a27598b24b59ab49aae Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liran Zelkha <liran.zel...@gmail.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches