Skip to content

ILookupGrain.AddOrUpdate does not what the function name says #8

@flensrocker

Description

@flensrocker

I'm playing around with Orleans and found your repository, because I was looking into managing Identities with Orleans.

I stumble across ILookupGrain.AddOrUpdate. It will never update a value, once it's in the dictionary.
If this is on purpose, shouldn't it be name just Add?

Otherwise, it should maybe do something like:

diff --git a/src/Orleans.IdentityStore/Grains/LookupGrain.cs b/src/Orleans.IdentityStore/Grains/LookupGrain.cs
index 1ef3f77..b094bb8 100644
--- a/src/Orleans.IdentityStore/Grains/LookupGrain.cs
+++ b/src/Orleans.IdentityStore/Grains/LookupGrain.cs
@@ -34,11 +34,11 @@ namespace Orleans.IdentityStore.Grains

         public async Task<bool> AddOrUpdate(string value, Guid grainKey)
         {
-            if (_index.State.Index.ContainsKey(value))
-                return false;
-
-            _index.State.Index[value] = grainKey;
-            await _index.WriteStateAsync();
+            if (!_index.State.Index.TryGetValue(value, out var oldGrainKey) || grainKey != oldGrainKey)
+            {
+                _index.State.Index[value] = grainKey;
+                await _index.WriteStateAsync();
+            }
             return true;
         }

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions