Copilot commented on code in PR #13325: URL: https://github.com/apache/cloudstack/pull/13325#discussion_r4187010525
########## engine/schema/src/main/java/com/cloud/upgrade/NetworkRateBackfill.java: ########## @@ -0,0 +1,257 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.upgrade; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.framework.config.dao.ConfigurationDaoImpl; +import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao; +import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDaoImpl; + +import com.cloud.dc.DataCenterDetailVO; +import com.cloud.dc.dao.DataCenterDetailsDaoImpl; +import com.cloud.network.Networks.TrafficType; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkDaoImpl; +import com.cloud.network.dao.NetworkDetailsDao; +import com.cloud.network.dao.NetworkDetailsDaoImpl; +import com.cloud.network.dao.NetworkVO; +import com.cloud.service.ServiceOfferingVO; +import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.service.dao.ServiceOfferingDaoImpl; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.dao.VMInstanceDao; +import com.cloud.vm.dao.VMInstanceDaoImpl; + +/** + * Backfills {@code nics.network_rate} and the {@code network_details} "networkrate" entry for + * pre-existing NICs/networks, deliberately frozen to the pre-feature precedence of + * {@link com.cloud.network.NetworkModelImpl#getNetworkRate} - do not redirect this to call the + * live method, whose precedence will keep evolving. Also backfills the {@code vpc_details} + * "publicnetworkrate" entry for pre-existing VPCs with a fixed "unlimited" value, since both + * {@code vpc_offerings.public_nw_rate} and the "vpc.public.network.throttling.rate" config are + * introduced by this same release and can't yet hold a pre-existing value. + */ +public class NetworkRateBackfill { + protected static Logger LOGGER = LogManager.getLogger(NetworkRateBackfill.class); + + private static final String CONFIG_NETWORK_THROTTLING_RATE = "network.throttling.rate"; + private static final String CONFIG_VM_NETWORK_THROTTLING_RATE = "vm.network.throttling.rate"; + private static final String NETWORKRATE_DETAIL_NAME = "networkrate"; + private static final String PUBLIC_NETWORK_RATE_DETAIL_NAME = "publicnetworkrate"; + private static final int DEFAULT_THROTTLING_RATE = 200; + private static final int UNLIMITED_RATE = -1; + + private final Connection conn; + + private final VMInstanceDao vmInstanceDao = new VMInstanceDaoImpl(); + private final NetworkDao networkDao = new NetworkDaoImpl(); + private final NetworkDetailsDao networkDetailsDao = new NetworkDetailsDaoImpl(); + private final VpcDetailsDao vpcDetailsDao = new VpcDetailsDaoImpl(); + private final ServiceOfferingDao serviceOfferingDao = new ServiceOfferingDaoImpl(); + private final DataCenterDetailsDaoImpl dataCenterDetailsDao = new DataCenterDetailsDaoImpl(); + private final ConfigurationDao configurationDao = new ConfigurationDaoImpl(); + + public NetworkRateBackfill(Connection conn) { + this.conn = conn; + } + Review Comment: This upgrade backfill mixes the provided JDBC `Connection` (raw SQL) with DAO implementations that will typically acquire their own connections/transactions. During schema/data migration this can lead to inconsistent reads, lock contention, and non-repeatable behavior (e.g., DAO reads not seeing changes made through `conn`). A safer approach is to perform all reads/writes for the backfill using the same provided `conn` (prepared statements) and avoid Spring-managed DAOs in upgrade code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
