Skip to content

Commit

Permalink
FIX metadata modifications are not considered as change (with regards…
Browse files Browse the repository at this point in the history
… to subscription alterationTypes) if notifyOnMetadataChange is false
  • Loading branch information
fgalan committed Sep 11, 2024
1 parent 248e2d7 commit a152cb9
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Fix: $max and $min operators were not supported with DateTime attributes (#4585)
- Fix: wrong date values should not allowed in subscription's expires field (#4541)
- Fix: do not raise DB alarm in case of wrong GeoJSON in client request
- Fix: metadata modifications are not considered as change (with regards to subscription alterationTypes) if notifyOnMetadataChange is false (#4605)
- Upgrade cjexl version from 0.3.0 to 0.4.0 (new transformations: now, getTime and toIsoString)
- Upgrade Debian version from 12.4 to 12.6 in Dockerfile
- Fix: invalid date in expires field of subscription (#2303)
4 changes: 3 additions & 1 deletion src/lib/apiTypesV2/Subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ typedef enum NotificationType
*/
typedef enum SubAltType
{
EntityChangeBothValueAndMetadata, // this is the reference one used by parsing/rendering logic
// EntityChange has been specialized into three sub-types in order to solve #4605
// (EntityChangeBothValueAndMetadata is thre reference one used in parsing/rendering logic)
EntityChangeBothValueAndMetadata,
EntityChangeOnlyValue,
EntityChangeOnlyMetadata,
EntityUpdate,
Expand Down
12 changes: 10 additions & 2 deletions src/lib/cache/subCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ static bool subMatch
return false;
}

// If notifyOnMetadataChange is false and only metadata has been changed, we "downgrade" to ngsiv2::EntityUpdate
if (!cSubP->notifyOnMetadataChange && (targetAltType == ngsiv2::EntityChangeOnlyMetadata))
{
targetAltType = ngsiv2::EntityUpdate;
}

//
// If one of the attribute names in the scope vector
Expand All @@ -509,8 +514,11 @@ static bool subMatch
}
else if ((isChangeAltType(targetAltType)) || (targetAltType == ngsiv2::EntityCreate))
{
if (!attributeMatch(cSubP, attrsWithModifiedValue) &&
!(cSubP->notifyOnMetadataChange && attributeMatch(cSubP, attrsWithModifiedMd)))
// No match if: 1) there is no change in the *value* of attributes listed in conditions.attrs and 2) there is no change
// in the *metadata* of the attributes listed in conditions.attrs (the 2) only if notifyOnMetadataChange is true)
bool b1 = attributeMatch(cSubP, attrsWithModifiedValue);
bool b2 = attributeMatch(cSubP, attrsWithModifiedMd);
if (!b1 && !(cSubP->notifyOnMetadataChange && b2))
{
LM_T(LmtSubCacheMatch, ("No match due to attributes"));
return false;
Expand Down
24 changes: 12 additions & 12 deletions src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,15 +1641,21 @@ static bool addTriggeredSubscriptions_noCache

if (subs.count(subIdStr) == 0)
{
// Early extraction of fiedl from DB document. The rest of fields are got later
bool notifyOnMetadataChange = sub.hasField(CSUB_NOTIFYONMETADATACHANGE)? getBoolFieldF(sub, CSUB_NOTIFYONMETADATACHANGE) : true;

// If notifyOnMetadataChange is false and only metadata has been changed, we "downgrade" to ngsiv2::EntityUpdate
if (!notifyOnMetadataChange && (targetAltType == ngsiv2::EntityChangeOnlyMetadata))
{
targetAltType = ngsiv2::EntityUpdate;
}

// Check alteration type
if (!matchAltType(sub, targetAltType))
{
continue;
}

// Early extraction of fiedl from DB document. The rest of fields are got later
bool notifyOnMetadataChange = sub.hasField(CSUB_NOTIFYONMETADATACHANGE)? getBoolFieldF(sub, CSUB_NOTIFYONMETADATACHANGE) : true;

// Depending of the alteration type, we use the list of attributes in the request or the list
// with effective modifications. Note that EntityDelete doesn't check the list
if (targetAltType == ngsiv2::EntityUpdate)
Expand All @@ -1662,9 +1668,10 @@ static bool addTriggeredSubscriptions_noCache
else if ((isChangeAltType(targetAltType)) || (targetAltType == ngsiv2::EntityCreate))
{
// Skip if: 1) there is no change in the *value* of attributes listed in conditions.attrs and 2) there is no change
// in the *metadata* of the attributes listed in conditions.attrs (the 2) only if notifyOnMetadtaChange is true)
// in the *metadata* of the attributes listed in conditions.attrs (the 2) only if notifyOnMetadataChange is true)
bool b1 = condValueAttrMatch(sub, attrsWithModifiedValue);
bool b2 = condValueAttrMatch(sub, attrsWithModifiedMd);

if (!b1 && !(notifyOnMetadataChange && b2))
{
continue;
Expand Down Expand Up @@ -2795,14 +2802,7 @@ static bool processContextAttributeVector
}
}

attributes.push_back(ca->name);

/* If actual update then targetAltType changes from EntityUpdate (the value used to initialize
* the variable) to EntityChange */
/*if (changeType != NO_CHANGE)
{
targetAltType = ngsiv2::SubAltType::EntityChange;
}*/
attributes.push_back(ca->name);
}

/* Add triggered subscriptions */
Expand Down
Loading

0 comments on commit a152cb9

Please sign in to comment.