Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

azure service fabric - What would be the best way to search an IReliableDictionary?

Based on these posts:

Convert IReliableDictionary to IList

What is the most optimal method of querying a reliable dictionary collection

I should be able to use Linq to query an IReliableDictionary, but it would appear that this interface no longer implements IEnumerable and the Linq extensions are not available. At least in version 5.0.0.0 of the Microsoft.ServiceFabric.Data.Interfaces assembly.

If this is true, what would be the best way to search an IReliableDictionary?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, we did remove IEnumerable from Reliable Collections in the GA release. As Allan T mentions, Reliable Collections aren't really the same as regular .NET collections, even though they represent the same fundamental data structures. One of the big differences you've probably noticed is that all operations are asynchronous, because of locking semantics and I/O for replication and disk reads. It's the latter part that drove the decisions to remove IEnumerable, because it is strictly synchronous and we're not. Instead we now use IAsyncEnumerable, which as of yet does not support the full set of LINQ extension methods.

We're working on asynchronous LINQ extension methods, but in the meantime, there are a couple of ways to work with IAsyncEnumerable.

Eli Arbel has async extension methods on Gist that provide a bridge to System.Interactive.Async and also async implementations of Select, SelectMany, and Where.

Or you can wrap IAsyncEnumerable in a regular IEnumerable that simply wraps the asynchronous calls with synchronous methods, and that will give you the full set of LINQ extensions methods again. Then you can use the extension method in a regular LINQ query:

        using (ITransaction tx = this.StateManager.CreateTransaction())
        {
            var x = from item in (await clusterDictionary.CreateEnumerableAsync(tx)).ToEnumerable()
                   where item.Value.Status == ClusterStatus.Ready
                   orderby item.Value.CreatedOn descending
                   select new ClusterView(
                       item.Key,
                       item.Value.AppCount,
                       item.Value.ServiceCount,
                       item.Value.Users.Count(),
                       this.config.MaximumUsersPerCluster,
                       this.config.MaximumClusterUptime - (DateTimeOffset.UtcNow - item.Value.CreatedOn.ToUniversalTime()));

        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...