Exemplo n.º 1
0
        /// <summary>
        /// 加载所有的RaftGroup信息
        /// </summary>
        public async Task <object> GetParts()
        {
            EnsureIsAdmin();

            //先从MetaCF读取所有EntityModel
            var apps = await ModelStore.LoadAllApplicationAsync();

            //TODO:待优化只加载EntityModel
            var models = await ModelStore.LoadAllModelAsync();

            var ms = models.Where(t => t.ModelType == ModelType.Entity).Select(t => (EntityModel)t).ToArray();

            //再从PartCF读取所有RaftGroupId
            var ls = new List <PartitionInfo>();

            await ScanParts((kp, ks, vp, vs) =>
            {
                unsafe
                {
                    ulong *groupIdPtr = (ulong *)vp.ToPointer();
                    var appId         = ((byte *)kp.ToPointer())[0];
                    var app           = apps.Single(t => t.StoreId == appId);

                    int *tableIdPtr = (int *)kp.ToPointer();
                    var tableId     = (uint)(System.Net.IPAddress.NetworkToHostOrder(*tableIdPtr) & 0xFFFFFF);
                    var groupInfo   = new PartitionInfo
                    {
                        Id        = (*groupIdPtr).ToString("X2"),
                        ModelName = app.Name + "." + ms.SingleOrDefault(t => t.AppId == app.Id && t.TableId == tableId)?.Name
                                    //TODO:其他信息
                    };
                    ls.Add(groupInfo);
                }
            });

            return(ls);
        }