Skip to content

Commit

Permalink
Lock around accesses to deduplicationMap.
Browse files Browse the repository at this point in the history
Now that binlog loading is multi-threaded, we need to ensure safe access to the dictionary.
  • Loading branch information
KirillOsenkov committed Mar 26, 2023
1 parent 8ef7b3e commit d1c4eff
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/StructuredLogger/Serialization/StringCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,25 @@ public string Intern(string text)
text = text.NormalizeLineBreaks();
}

if (deduplicationMap.TryGetValue(text, out string existing))
lock (deduplicationMap)
{
return existing;
}
if (deduplicationMap.TryGetValue(text, out string existing))
{
return existing;
}

deduplicationMap[text] = text;
deduplicationMap[text] = text;
}

return text;
}

public bool Contains(string text)
{
return deduplicationMap.ContainsKey(text);
lock (deduplicationMap)
{
return deduplicationMap.ContainsKey(text);
}
}

public IDictionary<string, string> InternStringDictionary(IDictionary<string, string> inputDictionary)
Expand Down

0 comments on commit d1c4eff

Please sign in to comment.