SharedCode/sop

Linq + parallel access.

Closed this issue · 7 comments

Seems like store is getting diposed after each linq query?

I have this query:

PageStore.Where(x => x.Value.Status == Status.InProgress).Count();

After executing this query the File object of the SimpleKeyValue becomes null.

It works after replacing the linq query with this

int count = 0;
PageStore.MoveFirst();
do
{
    if (PageStore.CurrentValue.Status == Status.InProgress)
    {
        count++;
    }
} while (PageStore.MoveNext());

PageStore.MoveFirst();

return count;

And next question: is ISortedDictionary thread safe? Meaning is it safe to run above code while other thread may be updating through same PageStore object? If not what is correct way to handle such situation?

Hi, pardon my late reply. 'been too busy with other things. Anyway, SOP "explicit" LINQ support is very basic so it is not guaranteed to be bullet proof. The work around you did is the recommended approach until SOP "explicit" LINQ feature is worked on.

There is thread-safeness on ISortedDictionary returned by Store Navigator Get. In multi-thread scenario, when a thread updates the Store, next call to "Movexxx" methods will return false to signify the Store record pointer is not valid or equivalent to EOF.

To prevent such condition, code has to lock at the Store level so only Reads occur while there are no Updates coming in, and vice versa.

More enhancements are planned on this area so there will be built in facility for this, client code doesn't have to bother with it, but it is not checked in yet.

Tx

Thanks for the reply. I'll leave this issue open, so that it can be referenced whenever you have time to work on this issue

Sure yes, 'good idea. Thank you.

nripendra: 'did a small fix on IEnumerator, Store should no longer be disposed after LINQ query (nor via foreach that uses IEnumerator).

OTOH, I'm going to complete the SOP's "LINQ to Objects" support, so keywords such as "where", "orderby", "skip-take" etc... in a Store or via Store "joins" will be optimal. 'could help simplify SOP Store usage. :)

Thanks! please feel free to close the issue if you think its appropriate time to close it.

Sure I will, thanks.

Also, pls. feel free to share any of your code, changes, enhancements, samples, etc... using SOP. 'could be good to show 'em to others.

UPDATE: SOP now supports LINQ to Objects, i.e. - it has new extension methods to aid in LINQ queries authorship that are optimized based on SOP Store usage. Also, parallel access (multi-reader, single writer locking model) is now supported as well.

Pls. check out the demo program "ManyClientSimulator" for examples how to use both of above features. This sample can be found under the Samples project in folder "PeopleDirectory".

I'm closing this issue. Pls. feel free to follow up/comment if you find any further issues.