Skip to content

Commit

Permalink
Improve updating shadow with large # of values
Browse files Browse the repository at this point in the history
The current implementation of ADD value operation in repo is slow
for large number of values. As a test, let's use REPLACE in that cases.
  • Loading branch information
mederly committed Jul 31, 2019
1 parent 3ed334a commit 5db34df
Showing 1 changed file with 15 additions and 6 deletions.
Expand Up @@ -1901,13 +1901,24 @@ private ObjectDelta<ShadowType> computeShadowDelta(@NotNull ProvisioningContext
}
if (ProvisioningUtil.shouldStoreAttributeInShadow(ocDef, attrDef.getName(), cachingStrategy)) {
if (!currentResourceItem.isIncomplete()) {
MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
MatchingRule<Object> matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
PrismProperty<Object> oldRepoAttributeProperty = oldRepoAttributesContainer.findProperty(currentResourceAttrProperty.getElementName());
if (oldRepoAttributeProperty == null) {
PropertyDelta<Object> attrAddDelta = currentResourceAttrProperty.createDelta();
for (PrismPropertyValue<?> pval : currentResourceAttrProperty.getValues()) {
//noinspection unchecked
attrAddDelta.addRealValuesToAdd(matchingRule.normalize(pval.getValue()));
List<PrismPropertyValue<Object>> currentValues = currentResourceAttrProperty.getValues();
// This is a brutal hack: For extension attributes the ADD operation is slow when using large # of
// values to add. So let's do REPLACE instead (this is OK if there are no existing values).
// TODO Move this logic to repository. Here it is only for PoC purposes.
if (currentValues.size() >= 100) {
Object[] currentValuesNormalized = new Object[currentValues.size()];
for (int i = 0; i < currentValues.size(); i++) {
currentValuesNormalized[i] = matchingRule.normalize(currentValues.get(i));
}
attrAddDelta.setRealValuesToReplace(currentValuesNormalized);
} else {
for (PrismPropertyValue<?> pval : currentValues) {
attrAddDelta.addRealValuesToAdd(matchingRule.normalize(pval.getValue()));
}
}
if (attrAddDelta.getDefinition().getTypeName() == null) {
throw new SchemaException("No definition in " + attrAddDelta);
Expand All @@ -1916,7 +1927,6 @@ private ObjectDelta<ShadowType> computeShadowDelta(@NotNull ProvisioningContext
} else {
if (attrDef.isSingleValue()) {
Object currentResourceRealValue = currentResourceAttrProperty.getRealValue();
//noinspection unchecked
Object currentResourceNormalizedRealValue = matchingRule.normalize(currentResourceRealValue);
if (!Objects.equals(currentResourceNormalizedRealValue, oldRepoAttributeProperty.getRealValue())) {
PropertyDelta delta;
Expand All @@ -1935,7 +1945,6 @@ private ObjectDelta<ShadowType> computeShadowDelta(@NotNull ProvisioningContext
} else {
PrismProperty<Object> normalizedCurrentResourceAttrProperty = currentResourceAttrProperty.clone();
for (PrismPropertyValue pval : normalizedCurrentResourceAttrProperty.getValues()) {
//noinspection unchecked
Object normalizedRealValue = matchingRule.normalize(pval.getValue());
//noinspection unchecked
pval.setValue(normalizedRealValue);
Expand Down

0 comments on commit 5db34df

Please sign in to comment.