Beispiel #1
0
        public async static Task <StoreInfo> GetHashStoreInfo(IStoreInfoResolveService storeInfoResolveService, IHashGroupRepositoryCacheProxy hashGroupRepositoryCacheProxy, string hashGroupName, params string[] keys)
        {
            //var helper = HashGroupRepositoryHelperFactory.Create(hashGroupRepository);
            var group = await hashGroupRepositoryCacheProxy.QueryByName(hashGroupName);

            if (group == null)
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundHashGroupByName,
                    DefaultFormatting = "没有找到名称为{0}的一致性哈希组",
                    ReplaceParameters = new List <object>()
                    {
                        hashGroupName
                    }
                };

                throw new UtilityException((int)Errors.NotFoundHashGroupByName, fragment);
            }

            //获取前缀的哈希节点关键字,
            var strKey = await group.GetHashNodeKey(string.Join(".", keys), 1, 2, 3);

            //解析关键字为服务器信息和数据表信息
            var storeResult = await storeInfoResolveService.Execute(strKey);

            return(storeResult);
        }
Beispiel #2
0
        public async static Task <List <StoreInfo> > GetHashStoreInfos(IStoreInfoResolveService storeInfoResolveService, IHashGroupRepositoryCacheProxy hashGroupRepositoryCacheProxy, string hashGroupName)
        {
            List <StoreInfo> result = new List <StoreInfo>();
            var group = await hashGroupRepositoryCacheProxy.QueryByName(hashGroupName);

            if (group == null)
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundHashGroupByName,
                    DefaultFormatting = "没有找到名称为{0}的一致性哈希组",
                    ReplaceParameters = new List <object>()
                    {
                        hashGroupName
                    }
                };

                throw new UtilityException((int)Errors.NotFoundHashGroupByName, fragment);
            }

            //获取组下面的所有节点
            await group.GetHashRealNode(async (node) =>
            {
                var strKey = node.NodeKey;
                //解析关键字为服务器信息和数据表信息
                var storeResult = await storeInfoResolveService.Execute(strKey);
                result.Add(storeResult);
            });

            return(result);
        }
Beispiel #3
0
        public async Task <StoreGroupMember> ChooseMember(StoreGroup group, params string[] keys)
        {
            //需要在HashGroup中存在名称为StoreFroup-{group.Name}的哈希组
            string hashGroupName = $"StoreFroup-{group.Name}";
            var    hashGroup     = await _hashGroupRepositoryCacheProxy.QueryByName(hashGroupName);

            if (group == null)
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundHashGroupByName,
                    DefaultFormatting = "没有找到名称为{0}的一致性哈希组",
                    ReplaceParameters = new List <object>()
                    {
                        hashGroupName
                    }
                };

                throw new UtilityException((int)Errors.NotFoundHashGroupByName, fragment);
            }
            //从哈希组获取实际节点信息,节点信息为MemberName
            var memberName = await hashGroup.GetHashNodeKey(string.Join(".", keys), 1, 2, 3);

            var member = await getMember(group.ID, memberName);

            if (member == null)
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFounStoreGroupMemberByName,
                    DefaultFormatting = "在id为{0}的存储组中找不到名称为{1}的组成员",
                    ReplaceParameters = new List <object>()
                    {
                        group.ID.ToString(), memberName
                    }
                };

                throw new UtilityException((int)Errors.NotFounStoreGroupMemberByName, fragment);
            }
            return(member);
        }