Segment with more than one language breaks aggregation


Description

The Experience Analytics reports might fail to display the actual data if a Segment item has multiple language versions. The issue occurs if Sitecore XP runs in the Scaled topology (XP1). The following message can be found in the logs of the Processing server:

ERROR Aggregation Error
Exception: System.ArgumentException
Message: An item with the same key has already been added.
Source: mscorlib
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)
   at Sitecore.ExperienceAnalytics.Core.Repositories.MarketingSegmentReaderBase`1.GetAll(CultureInfo cultureInfo, NameValueCollection readingPreferences)
   at Sitecore.ExperienceAnalytics.Aggregation.Pipeline.MarketingSegmentationProcessor.GetSegments()
   at Sitecore.ExperienceAnalytics.Aggregation.Pipeline.MarketingSegmentationProcessor.Process(InteractionAggregationPipelineArgs args)
   at (Object , Object )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   at Sitecore.ExperienceAnalytics.Aggregation.Pipeline.InteractionProcessor.OnProcess(InteractionAggregationPipelineArgs args)
   at Sitecore.Analytics.Aggregation.Pipeline.InteractionAggregationPipelineProcessor.Process(InteractionAggregationPipelineArgs args)

There are two possible scenarios for the issue:

Solution

To resolve the issue:

  1. Make sure that multiple language versions are present by running the following query against the ReferenceData database:
    select dc.*
      from [xdb_refdata].[Definitions] as d
      join [xdb_refdata].[DefinitionCultures] as dc
        on d.ID = dc.DefinitionVersionID
     where d.Moniker in
     (
        'cd0b4c6b-8c41-4eba-bc10-b936b29303e7', -- Computer
        '0df6797e-ee1b-4bfd-9262-0471b1add438', -- Mobile Phone
        'ecd9a3d4-f549-487a-93aa-1ea3cf0477e5'  -- Tablet
     )
       and dc.Culture != 'en';
  2. In the Content Editor, remove the language versions other than the English one for the items in the /sitecore/system/Marketing Control Panel/Segments folder.
  3. Make a backup of the ReferenceData database.
  4. Run the following query against the ReferenceData database:
    DELETE
    FROM [xdb_refdata].[DefinitionCultures]
    where ID in (
    select dc.ID
    from [xdb_refdata].[Definitions] as d
    join [xdb_refdata].[DefinitionCultures] as dc
    on d.ID = dc.DefinitionVersionID
    where d.Moniker in
    (
    'cd0b4c6b-8c41-4eba-bc10-b936b29303e7', -- Computer
    '0df6797e-ee1b-4bfd-9262-0471b1add438', -- Mobile Phone
    'ecd9a3d4-f549-487a-93aa-1ea3cf0477e5' -- Tablet
    )
    and dc.Culture != 'en')