Copilot commented on code in PR #13078:
URL: https://github.com/apache/cloudstack/pull/13078#discussion_r3158847587
##########
plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java:
##########
@@ -508,9 +508,20 @@ private boolean deRefOrDeleteResource(DevelopersApi api,
String rscName, String
// if there is only one template-for property left for templates,
the template isn't needed anymore
// or if it isn't a template anyway, it will not have this Aux
property
// _cs-template-for- properties work like a ref-count.
- if (rd.getProps().keySet().stream()
+ long remainingTemplateRefs = rd.getProps().keySet().stream()
.filter(key -> key.startsWith("Aux/" +
LinstorUtil.CS_TEMPLATE_FOR_PREFIX))
- .count() == expectedProps) {
+ .count();
+ if (remainingTemplateRefs == expectedProps) {
+ // Surface the case where a resource that LOOKS like a
template (resource name
+ // starts with the requested prefix) has zero
`_cs-template-for-` aux properties
+ // even though we never decremented one — that's a legacy
template predating the
+ // ref-count convention. Logging it before deletion lets
operators audit how
+ // many such orphans existed at upgrade time.
+ if (expectedProps == 0 &&
rd.getName().toLowerCase().startsWith(rscName.toLowerCase())) {
+ logger.info("Linstor: deleting resource {} which has no
_cs-template-for- aux properties " +
+ "(legacy template predating the ref-count
convention, or a stale orphan). " +
+ "Resource group context: {}",
rd.getName(), rscGrpName);
+ }
Review Comment:
The new INFO log for “legacy template predating the ref-count convention”
will currently fire for *all* non-template resource deletions too.
`existingRDs` is already built via `getRDListStartingWith(api, rscName)`, so
`rd.getName().toLowerCase().startsWith(rscName.toLowerCase())` is always true;
whenever `expectedProps == 0` (normal volume/resource with no
`_cs-template-for-` props), this will emit the legacy-template message and add
significant log noise/misleading attribution. Tighten the condition so it only
matches the intended legacy-template-orphan case (e.g., by using a reliable
template discriminator, passing an `isTemplate` flag from the caller, or
checking for a template-specific naming/property convention), and avoid logging
for ordinary resource deletions.
```suggestion
```
--
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]