Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale cache overwrites entries when table key is not an <int>. See test modified from [PutGetWithoutMaxCap] #5

Closed
rugunda opened this issue Oct 22, 2015 · 3 comments
Assignees
Labels

Comments

@rugunda
Copy link

rugunda commented Oct 22, 2015

[Test]
public void T080_PutGetWithoutMaxCap_key_as_string()
{
using (var cache = makeCache())
{
var tA = cache.GetOrCreateTable("A");

            const int CNT = 80000000;
            for (var i = 0; i < CNT; i++)
            {
                var pr = tA.Put(i.ToString(), "value" + i.ToString(), priority: 10);
                // Console.WriteLine("{0} -> {1}", i, pr);
                Assert.IsTrue(pr == PutResult.Inserted);//fails here even though key values are unique
            }
        }
    }
@itadapter
Copy link
Member

will take a look, thanks

@itadapter
Copy link
Member

@rugunda this is not a bug. The cache is "speculative", that is: it does not GUARANTEE that PUT will ALWAYS insert vs replace. This is because the cache design is purposely done as a linear hash array without secondary rehashings. It is capacity-based and does not handle collisions (for efficiency). When you put a new item in cache, there is always a chance that cache slot will be occupied. To make sure that second item does not over-write the first item you can set the "priority" for the items.
This is done on purpose, as in real world the collisions are pretty rare, however the capacity of the table is auto-adjusting. So this is a probability-based solution, it does not work the same way as Dictionary, and that is why it is faster for all operations (no chaining/rehashing)

@itadapter itadapter removed the bug label Oct 29, 2015
@rugunda
Copy link
Author

rugunda commented Oct 30, 2015

@itadapter Thanks for the clarification. I have been using the serializer, and it blows away anything else I have ever come across. Really cool components in Nfx.

itadapter added a commit that referenced this issue Feb 16, 2016
itadapter added a commit that referenced this issue Feb 16, 2016
Merge pull request #5 from aumcode/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants