示例#1
0
        private Task <BoolResult> RequestScaleAsync(OperationContext context, RedisClusterSize targetClusterSize)
        {
            string extraMessage = $"CurrentClusterSize=[{ClusterSize}] TargetClusterSize=[{targetClusterSize}]";

            return(context.PerformOperationAsync(Tracer, async() =>
            {
                if (ClusterSize.Equals(targetClusterSize))
                {
                    return new BoolResult(errorMessage: $"No-op scale request attempted (`{ClusterSize}` -> `{targetClusterSize}`) on instance `{Name}`");
                }

                if (!RedisScalingUtilities.CanScale(ClusterSize, targetClusterSize))
                {
                    return new BoolResult(errorMessage: $"Scale request `{ClusterSize}` -> `{targetClusterSize}` on instance `{Name}` is disallowed by Azure Cache for Redis");
                }

                if (!IsReadyToScale)
                {
                    return new BoolResult(errorMessage: $"Redis instance `{Name}` is not ready to scale, current provisioning state is `{RedisCache.ProvisioningState}`");
                }

                var instance = RedisCache.Update();

                if (!ClusterSize.Tier.Equals(targetClusterSize.Tier))
                {
                    switch (targetClusterSize.Tier.Plan)
                    {
                    case RedisPlan.Basic:
                        instance = instance.WithBasicSku(targetClusterSize.Tier.Capacity);
                        break;

                    case RedisPlan.Standard:
                        instance = instance.WithStandardSku(targetClusterSize.Tier.Capacity);
                        break;

                    case RedisPlan.Premium:
                        instance = instance.WithPremiumSku(targetClusterSize.Tier.Capacity);
                        break;
                    }
                }

                if (ClusterSize.Shards != targetClusterSize.Shards)
                {
                    instance = instance.WithShardCount(targetClusterSize.Shards);
                }

                await instance.ApplyAsync(context.Token);

                return BoolResult.Success;
            },
                                                 extraStartMessage: extraMessage,
                                                 extraEndMessage: _ => extraMessage,
                                                 pendingOperationTracingInterval: TimeSpan.FromMinutes(1)));
        }
示例#2
0
        private async Task <BoolResult> RequestScaleAsync(RedisClusterSize targetClusterSize, CancellationToken cancellationToken = default)
        {
            if (ClusterSize.Equals(targetClusterSize))
            {
                return(new BoolResult(errorMessage: $"No-op scale request attempted (`{ClusterSize}` -> `{targetClusterSize}`) on instance `{Name}`"));
            }

            if (!RedisScalingUtilities.CanScale(ClusterSize, targetClusterSize))
            {
                return(new BoolResult(errorMessage: $"Scale request `{ClusterSize}` -> `{targetClusterSize}` on instance `{Name}` is disallowed by Azure Cache for Redis"));
            }

            if (!IsReadyToScale)
            {
                return(new BoolResult(errorMessage: $"Redis instance `{Name}` is not ready to scale, current provisioning state is `{RedisCache.ProvisioningState}`"));
            }

            var instance = RedisCache.Update();

            if (!ClusterSize.Tier.Equals(targetClusterSize.Tier))
            {
                switch (targetClusterSize.Tier.Plan)
                {
                case RedisPlan.Basic:
                    instance = instance.WithBasicSku(targetClusterSize.Tier.Capacity);
                    break;

                case RedisPlan.Standard:
                    instance = instance.WithStandardSku(targetClusterSize.Tier.Capacity);
                    break;

                case RedisPlan.Premium:
                    instance = instance.WithPremiumSku(targetClusterSize.Tier.Capacity);
                    break;
                }
            }

            if (ClusterSize.Shards != targetClusterSize.Shards)
            {
                instance = instance.WithShardCount(targetClusterSize.Shards);
            }

            await instance.ApplyAsync(cancellationToken);

            return(BoolResult.Success);
        }
示例#3
0
        private async Task <BoolResult> RequestScaleAsync(RedisClusterSize targetClusterSize, CancellationToken cancellationToken = default)
        {
            if (ClusterSize.Equals(targetClusterSize))
            {
                return(new BoolResult(errorMessage: $"No-op scale request attempted (`{ClusterSize}` -> `{targetClusterSize}`) on instance `{Name}`"));
            }

            if (!RedisScalingUtilities.CanScale(ClusterSize, targetClusterSize))
            {
                return(new BoolResult(errorMessage: $"Scale request `{ClusterSize}` -> `{targetClusterSize}` on instance `{Name}` is disallowed by Azure Cache for Redis"));
            }

            if (!IsReadyToScale)
            {
                return(new BoolResult(errorMessage: $"Redis instance `{Name}` is not ready to scale, current provisioning state is `{RedisCache.ProvisioningState}`"));
            }

            return(await SubmitScaleRequestAsync(targetClusterSize, cancellationToken));
        }
示例#4
0
        public RedisClusterSize(RedisTier tier, int shards)
        {
            Contract.Requires(1 <= shards && shards <= 10, "Number of shards out of bounds, must be between 1 and 10");
            Tier   = tier;
            Shards = shards;

            _scaleEligibleSizes = new Lazy <IReadOnlyList <RedisClusterSize> >(() => Instances.Where(to => RedisScalingUtilities.CanScale(this, to)).ToList(), System.Threading.LazyThreadSafetyMode.PublicationOnly);
        }