SonarQube Server - Data Center Edition v10.8.1 (101195)
Startup the server with our custom plugin
what have you tried so far to achieve this: analyzed log file, analyzed Sonar source code, reproduced in local Sonar
The log file shows: Violation of PRIMARY KEY constraint 'pk_rule_tags'. Cannot insert duplicate key in object 'dbo.rule_tags'
The scenario is as follows:
A tag named ‘x’ is added to rule Y in the Sonar UI (non-system tag);
The rule definition of Y is extended with the tag ‘x’ in our plugin (system tag);
The new plugin is loaded in SonarQube;
Startup fails with the above error.
In the source code we find to be suspicious (but it may not be related):
RulesRegistrant.java
private void removeRule(DbSession session, RulesRegistrationContext recorder, RuleDto rule) {
LOG.info(format("Disable rule %s", rule.getKey()));
rule.setStatus(RuleStatus.REMOVED);
rule.setSystemTags(emptySet());
update(session, rule);
// FIXME resetting the tags for all organizations must be handled a different way
// rule.setTags(Collections.emptySet());
// update(session, rule.getMetadata());
recorder.removed(rule);
if (recorder.getRemoved().count() % 100 == 0) {
session.commit();
}
}
This issue seems to be a bug to us. Do you agree?
Besides the bug fix, we want to have a quick fix.
In our local test, we removed the error-generating row in rule_tags: delete from rule_tags where value='X' and rule_uuid='UUID-Y';
and this seems to work. Startup succeeds again.
Can you confirm this as a quick fix?
Sorry for the delay. Since you have access to commercial support and your colleague raised a ticket in the support system, there was a bit of confusion since we don’t typically “compete” over topics between the two channels.
Not… really. I’d more call it a design oversight. And since this is the sole complaint I’ve ever seen about it, not one that’s likely to be addressed.
Thanks for your reply, Ann. I understand your confusion, no problem. Since I have no access to the commercial support (yet), I chose direct communication, usually better than by proxy.
Well, I understand your hesitation, however, for starters, there are more reports on this issue, see the link above. Furthermore, I think the scenario to get Sonar failure is not very strange:
a (custom) rule is found to lack a tag, sustainability-medium in our case
it is added by hand/UI: a non-system tag
the next ruleset plugin version has the tag correctly defined in the rule: system tag
Boom! Sonar startup failure with duplicate key violation
IMHO If I would develop a product with this defect in it, I would want to fix it, the sooner the better. I care about quality
Fortunately, we found a work-around:
use a ruleset where the rule does not have the system tag
startup Sonar succeeds, that rule is available again
remove the non-system tag by hand/UI
now we can start using the ruleset plugin with the proper system tag on the rule
This is how we are going to try to fix production this week.