Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Problem with GuidGenerator on AsParallel context #28

Closed
Caldas opened this Issue · 3 comments

2 participants

Fábio Caldas Nick Berardi
Fábio Caldas

Hi man, here is the code that I´m testing:

static void Main(string[] args)
{
    List<Int32> list = new List<Int32>();
    for (int i = 0; i < 5; i++)
    {
        list.Add(i);
    }
    list.AsParallel().ForAll(item => X());
}

static void X()
{
Guid rowGuid = GuidGenerator.GenerateTimeBasedGuid();
//Here I get a cassandra client 
//Insert cassandra row column name 'A' just for test
}

Because of parallel I just insert 2 or 3 items instead of 5.

Nick Berardi nberardi was assigned
Nick Berardi
Owner

This is a DateTime precision problem. I haven't looked at the problem that you are stating but, this would happen for one of two reasons.

  1. DateTime.UtcNow isn't updating fast enough resulting in the same DateTime
  2. Because you are using Parallel one or more treads is executing at the same time resulting in the same DateTime

Having the same DateTime would cause the column to overwrite it self if you were using this GUID as a Column Name.

I have looked at integrating DateTimePrecise into the GuidGenerate to give the precision a little boost.

http://code.google.com/p/mikeamundsen/source/browse/trunk/Amundsen.Utilities/DateTimePrecise.cs?r=126

But haven't had time, if this is something you want to explore, I will be happy to accept a pull request.

Fábio Caldas

I implemented DateTimePrecise and used:


new DateTimePrecise(5).UtcNow

It´s worked. I will submit a Pull Request

Nick Berardi nberardi referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Nick Berardi
Owner

Thanks for the pull request.

Nick Berardi nberardi closed this
Nick Berardi nberardi referenced this issue from a commit
Nick Berardi nberardi moved around some code from issues #28 and #30 and used DateTimePreci…
…se in other locations in the project

moved around some methods because they were on the wrong object
f4b065b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.