搜索IReliableDictionary的最佳方法是什么? [英] What would be the best way to search an IReliableDictionary?

查看:104
本文介绍了搜索IReliableDictionary的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于这些帖子:

将IReliableDictionary转换为IList

查询可靠字典集合的最佳方法是什么?

我应该能够使用Linq来查询IReliableDictionary,但看来此接口不再实现IEnumerable,并且Linq扩展不可用.至少在Microsoft.ServiceFabric.Data.Interfaces程序集的版本5.0.0.0中.

如果这是事实,那么搜索IReliableDictionary的最佳方法是什么?

解决方案

是的,我们确实从GA版本的可靠集合"中删除了IEnumerable.正如Allan T所提到的,可靠集合实际上与常规.NET集合并不完全相同,即使它们表示相同的基本数据结构.您可能已经注意到的最大差异之一是,所有操作都是异步的,这是因为锁定了语义以及用于复制和磁盘读取的I/O.这是促使删除IEnumerable的决定的后一部分,因为它严格同步,而我们不是.取而代之的是,我们现在使用IAsyncEnumerable,它到目前为止还不支持整套LINQ扩展方法.

我们正在研究异步LINQ扩展方法,但是与此同时,有两种方法可以使用IAsyncEnumerable.

Eli Arbel在Gist上具有异步扩展方法,它为 System.Interactive.Async 以及Select,SelectMany和Where的异步实现.

或者您可以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?

解决方案

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()));

        }

这篇关于搜索IReliableDictionary的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆