Skip to content

Commit 25c4a01

Browse files
authored
Merge branch '4.19' into 419-changescope
2 parents 11b43b2 + c7f1ba5 commit 25c4a01

12 files changed

Lines changed: 229 additions & 162 deletions

File tree

api/src/main/java/com/cloud/vm/NicProfile.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class NicProfile implements InternalIdentity, Serializable {
6262
String iPv4Dns1;
6363
String iPv4Dns2;
6464
String requestedIPv4;
65+
boolean ipv4AllocationRaceCheck;
6566

6667
// IPv6
6768
String iPv6Address;
@@ -405,6 +406,13 @@ public void setMtu(Integer mtu) {
405406
this.mtu = mtu;
406407
}
407408

409+
public boolean getIpv4AllocationRaceCheck() {
410+
return this.ipv4AllocationRaceCheck;
411+
}
412+
413+
public void setIpv4AllocationRaceCheck(boolean ipv4AllocationRaceCheck) {
414+
this.ipv4AllocationRaceCheck = ipv4AllocationRaceCheck;
415+
}
408416

409417
//
410418
// OTHER METHODS

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,42 +1020,84 @@ public void saveExtraDhcpOptions(final String networkUuid, final Long nicId, fin
10201020
}
10211021
}
10221022

1023-
@DB
1024-
@Override
1025-
public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, int deviceId, final VirtualMachineProfile vm)
1026-
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
1023+
private NicVO persistNicAfterRaceCheck(final NicVO nic, final Long networkId, final NicProfile profile, int deviceId) {
1024+
return Transaction.execute(new TransactionCallback<NicVO>() {
1025+
@Override
1026+
public NicVO doInTransaction(TransactionStatus status) {
1027+
NicVO vo = _nicDao.findByIp4AddressAndNetworkId(profile.getIPv4Address(), networkId);
1028+
if (vo == null) {
1029+
applyProfileToNic(nic, profile, deviceId);
1030+
vo = _nicDao.persist(nic);
1031+
return vo;
1032+
} else {
1033+
return null;
1034+
}
1035+
}
1036+
});
1037+
}
10271038

1039+
private NicVO checkForRaceAndAllocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, int deviceId, final VirtualMachineProfile vm)
1040+
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
10281041
final NetworkVO ntwkVO = _networksDao.findById(network.getId());
10291042
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested);
10301043
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, ntwkVO.getGuruName());
10311044

1032-
if (requested != null && requested.getMode() == null) {
1033-
requested.setMode(network.getMode());
1034-
}
1035-
final NicProfile profile = guru.allocate(network, requested, vm);
1036-
if (profile == null) {
1037-
return null;
1038-
}
1045+
NicVO vo = null;
1046+
boolean retryIpAllocation;
1047+
do {
1048+
retryIpAllocation = false;
1049+
final NicProfile profile = guru.allocate(network, requested, vm);
1050+
if (profile == null) {
1051+
return null;
1052+
}
10391053

1040-
if (isDefaultNic != null) {
1041-
profile.setDefaultNic(isDefaultNic);
1042-
}
1054+
if (isDefaultNic != null) {
1055+
profile.setDefaultNic(isDefaultNic);
1056+
}
10431057

1044-
if (requested != null && requested.getMode() == null) {
1045-
profile.setMode(requested.getMode());
1046-
} else {
1047-
profile.setMode(network.getMode());
1048-
}
1058+
if (requested != null && requested.getMode() == null) {
1059+
profile.setMode(requested.getMode());
1060+
} else {
1061+
profile.setMode(network.getMode());
1062+
}
1063+
1064+
vo = new NicVO(guru.getName(), vm.getId(), network.getId(), vm.getType());
1065+
1066+
DataCenterVO dcVo = _dcDao.findById(network.getDataCenterId());
1067+
if (dcVo.getNetworkType() == NetworkType.Basic) {
1068+
configureNicProfileBasedOnRequestedIp(requested, profile, network);
1069+
}
1070+
1071+
if (profile.getIpv4AllocationRaceCheck()) {
1072+
vo = persistNicAfterRaceCheck(vo, network.getId(), profile, deviceId);
1073+
} else {
1074+
applyProfileToNic(vo, profile, deviceId);
1075+
vo = _nicDao.persist(vo);
1076+
}
1077+
1078+
if (vo == null) {
1079+
if (requested.getRequestedIPv4() != null) {
1080+
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire requested Guest IP address " + requested.getRequestedIPv4() + " for network " + network, DataCenter.class, dcVo.getId());
1081+
} else {
1082+
requested.setIPv4Address(null);
1083+
}
1084+
retryIpAllocation = true;
1085+
}
1086+
} while (retryIpAllocation);
10491087

1050-
NicVO vo = new NicVO(guru.getName(), vm.getId(), network.getId(), vm.getType());
1088+
return vo;
1089+
}
10511090

1052-
DataCenterVO dcVo = _dcDao.findById(network.getDataCenterId());
1053-
if (dcVo.getNetworkType() == NetworkType.Basic) {
1054-
configureNicProfileBasedOnRequestedIp(requested, profile, network);
1091+
@DB
1092+
@Override
1093+
public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, int deviceId, final VirtualMachineProfile vm)
1094+
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
1095+
1096+
if (requested != null && requested.getMode() == null) {
1097+
requested.setMode(network.getMode());
10551098
}
10561099

1057-
deviceId = applyProfileToNic(vo, profile, deviceId);
1058-
vo = _nicDao.persist(vo);
1100+
NicVO vo = checkForRaceAndAllocateNic(requested, network, isDefaultNic, deviceId, vm);
10591101

10601102
final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
10611103
final NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),

engine/schema/src/main/java/com/cloud/storage/dao/VolumeStatsDao.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ public interface VolumeStatsDao extends GenericDao<VolumeStatsVO, Long> {
7575
/**
7676
* Removes (expunges) all Volume stats with {@code timestamp} less than
7777
* a given Date.
78-
* @param limit the maximum date to keep stored. Records that exceed this limit will be removed.
78+
* @param limitDate the maximum date to keep stored. Records that exceed this limit will be removed.
79+
* @param limitPerQuery the maximum amount of rows to be removed in a single query. We loop if there are still rows to be removed after a given query.
80+
* If 0 or negative, no limit is used.
7981
*/
80-
void removeAllByTimestampLessThan(Date limit);
82+
void removeAllByTimestampLessThan(Date limitDate, long limitPerQuery);
8183

8284
}

engine/schema/src/main/java/com/cloud/storage/dao/VolumeStatsDaoImpl.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import javax.annotation.PostConstruct;
2323

24+
import org.apache.log4j.Logger;
2425
import org.springframework.stereotype.Component;
2526

2627
import com.cloud.utils.db.Filter;
@@ -33,6 +34,8 @@
3334
@Component
3435
public class VolumeStatsDaoImpl extends GenericDaoBase<VolumeStatsVO, Long> implements VolumeStatsDao {
3536

37+
protected Logger logger = Logger.getLogger(getClass());
38+
3639
protected SearchBuilder<VolumeStatsVO> volumeIdSearch;
3740
protected SearchBuilder<VolumeStatsVO> volumeIdTimestampGreaterThanEqualSearch;
3841
protected SearchBuilder<VolumeStatsVO> volumeIdTimestampLessThanEqualSearch;
@@ -116,9 +119,21 @@ public void removeAllByVolumeId(long volumeId) {
116119
}
117120

118121
@Override
119-
public void removeAllByTimestampLessThan(Date limit) {
122+
public void removeAllByTimestampLessThan(Date limitDate, long limitPerQuery) {
120123
SearchCriteria<VolumeStatsVO> sc = timestampSearch.create();
121-
sc.setParameters(TIMESTAMP, limit);
122-
expunge(sc);
124+
sc.setParameters(TIMESTAMP, limitDate);
125+
126+
logger.debug(String.format("Starting to remove all volume_stats rows older than [%s].", limitDate));
127+
128+
long totalRemoved = 0;
129+
long removed;
130+
131+
do {
132+
removed = expunge(sc, limitPerQuery);
133+
totalRemoved += removed;
134+
logger.trace(String.format("Removed [%s] volume_stats rows on the last update and a sum of [%s] volume_stats rows older than [%s] until now.", removed, totalRemoved, limitDate));
135+
} while (limitPerQuery > 0 && removed >= limitPerQuery);
136+
137+
logger.info(String.format("Removed a total of [%s] volume_stats rows older than [%s].", totalRemoved, limitDate));
123138
}
124139
}

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,7 +4408,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
44084408
Account caller = CallContext.current().getCallingAccount();
44094409
Long parentTemplateId = cmd.getParentTemplateId();
44104410

4411-
boolean listAll = cmd.listAll();
4411+
boolean listAll = false;
44124412
if (templateFilter != null && templateFilter == TemplateFilter.all) {
44134413
if (caller.getType() == Account.Type.NORMAL) {
44144414
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only");
@@ -4858,7 +4858,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
48584858
boolean showRemovedISO = cmd.getShowRemoved();
48594859
Account caller = CallContext.current().getCallingAccount();
48604860

4861-
boolean listAll = cmd.listAll();
4861+
boolean listAll = false;
48624862
if (isoFilter != null && isoFilter == TemplateFilter.all) {
48634863
if (caller.getType() == Account.Type.NORMAL) {
48644864
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only");

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
506506
public static final ConfigKey<Boolean> ALLOW_DOMAIN_ADMINS_TO_CREATE_TAGGED_OFFERINGS = new ConfigKey<>(Boolean.class, "allow.domain.admins.to.create.tagged.offerings", "Advanced",
507507
"false", "Allow domain admins to create offerings with tags.", true, ConfigKey.Scope.Account, null);
508508

509+
public static final ConfigKey<Long> DELETE_QUERY_BATCH_SIZE = new ConfigKey<>("Advanced", Long.class, "delete.query.batch.size", "0",
510+
"Indicates the limit applied while deleting entries in bulk. With this, the delete query will apply the limit as many times as necessary," +
511+
" to delete all the entries. This is advised when retaining several days of records, which can lead to slowness. <= 0 means that no limit will " +
512+
"be applied. Default value is 0. For now, this is used for deletion of vm & volume stats only.", true);
513+
509514
private static final String IOPS_READ_RATE = "IOPS Read";
510515
private static final String IOPS_WRITE_RATE = "IOPS Write";
511516
private static final String BYTES_READ_RATE = "Bytes Read";
@@ -7803,7 +7808,8 @@ public ConfigKey<?>[] getConfigKeys() {
78037808
return new ConfigKey<?>[] {SystemVMUseLocalStorage, IOPS_MAX_READ_LENGTH, IOPS_MAX_WRITE_LENGTH,
78047809
BYTES_MAX_READ_LENGTH, BYTES_MAX_WRITE_LENGTH, ADD_HOST_ON_SERVICE_RESTART_KVM, SET_HOST_DOWN_TO_MAINTENANCE,
78057810
VM_SERVICE_OFFERING_MAX_CPU_CORES, VM_SERVICE_OFFERING_MAX_RAM_SIZE, MIGRATE_VM_ACROSS_CLUSTERS,
7806-
ENABLE_ACCOUNT_SETTINGS_FOR_DOMAIN, ENABLE_DOMAIN_SETTINGS_FOR_CHILD_DOMAIN, ALLOW_DOMAIN_ADMINS_TO_CREATE_TAGGED_OFFERINGS
7811+
ENABLE_ACCOUNT_SETTINGS_FOR_DOMAIN, ENABLE_DOMAIN_SETTINGS_FOR_CHILD_DOMAIN,
7812+
ALLOW_DOMAIN_ADMINS_TO_CREATE_TAGGED_OFFERINGS, DELETE_QUERY_BATCH_SIZE
78077813
};
78087814
}
78097815

0 commit comments

Comments
 (0)