Copilot commented on code in PR #12877:
URL: https://github.com/apache/cloudstack/pull/12877#discussion_r3085431985
##########
server/src/main/java/com/cloud/template/TemplateAdapterBase.java:
##########
@@ -191,19 +189,13 @@ protected boolean isZoneAndImageStoreAvailable(DataStore
imageStore, Long zoneId
return false;
}
- if (zoneSet == null) {
- logger.info(String.format("Zone set is null; therefore, the
ISO/template should be allocated in every secondary storage of zone [%s].",
zone));
- return true;
- }
-
- if (isTemplatePrivate && zoneSet.contains(zoneId)) {
- logger.info(String.format("The template is private and it is
already allocated in a secondary storage in zone [%s]; therefore, image store
[%s] will be skipped.",
- zone, imageStore));
+ int currentCount = zoneCopyCount.getOrDefault(zoneId, 0);
+ if (replicaLimit > 0 && currentCount >= replicaLimit) {
+ logger.info("Replica limit of {} reached for zone [{}]; skipping
image store [{}].", replicaLimit, zone, imageStore);
Review Comment:
`replicaLimit` comes from a configuration key and can be set to negative
values. With the current condition (`replicaLimit > 0`), a negative value
effectively disables limiting and will copy to all stores, which contradicts
the “maximum number of ... pools” meaning. Consider validating/sanitizing the
value (e.g., clamp to >= 0, or log+fallback to default) before applying the
limit.
```suggestion
int sanitizedReplicaLimit = Math.max(0, replicaLimit);
if (sanitizedReplicaLimit != replicaLimit) {
logger.warn("Invalid negative replica limit [{}] for zone [{}];
using [{}] instead.", replicaLimit, zone, sanitizedReplicaLimit);
}
int currentCount = zoneCopyCount.getOrDefault(zoneId, 0);
if (currentCount >= sanitizedReplicaLimit) {
logger.info("Replica limit of {} reached for zone [{}]; skipping
image store [{}].", sanitizedReplicaLimit, zone, imageStore);
```
--
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]