Exemple #1
0
        /// <summary>
        /// Gets the Shardlet by distribution key from either the pinned Shardlet list or by range lookup.
        /// </summary>
        /// <param name="shardSetName">Name of the shard set.</param>
        /// <param name="distributionKey">The distribution key.</param>
        /// <param name="isNew">if set to <c>true</c> the key is a new key and implementer should not look for existing ShardLet.</param>
        /// <returns>Shardlet.</returns>
        public override Shardlet GetShardletByDistributionKey(string shardSetName, long distributionKey,
                                                              bool isNew = false)
        {
            var repository = new AzureShardletMapRepository(shardSetName);

            if (!isNew)
            {
                var azureShardlet = GetAzureShardlet(shardSetName, distributionKey);

                if (azureShardlet != null)
                {
                    return(azureShardlet.ToFrameworkShardlet());
                }
            }

            var shardlet = new Shardlet();

            //todo: how to set the sharding key?
            var rangeShard = repository.Get(distributionKey);

            if (rangeShard == null)
            {
                return(shardlet);
            }

            shardlet.ServerInstanceName = rangeShard.ServerInstanceName;
            shardlet.Catalog            = rangeShard.Catalog;
            shardlet.ShardSetName       = shardSetName;
            shardlet.DistributionKey    = distributionKey;

            //TODO: Determine if the published shard should have a status and derive it from that for full shard transitions.
            shardlet.Status = ShardletStatus.Active;

            return(shardlet);
        }
Exemple #2
0
        private void DeleteAzureShardlet(string shardSetName, Shardlet shardlet)
        {
            var repository    = new AzureShardletMapRepository(shardSetName);
            var azureShardlet = repository.Get(shardlet.DistributionKey);

            if (azureShardlet != null)
            {
                repository.Delete(azureShardlet);
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the shardlet by sharding key.
        /// </summary>
        /// <param name="shardSetName">Name of the shard set.</param>
        /// <param name="shardingKey">The sharding key.</param>
        /// <param name="distributionKey">The distribution key.</param>
        /// <returns>Shardlet.</returns>
        public override Shardlet GetShardletByShardingKey(string shardSetName, string shardingKey, long distributionKey)
        {
            Shardlet shardlet;

            var repository    = new AzureShardletMapRepository(shardSetName);
            var azureShardlet = repository.Get(distributionKey);

            if (azureShardlet == null)
            {
                var rangeShard = GetAzureRangeShard(shardSetName, distributionKey);

                if (rangeShard == null)
                {
                    // would only arrive here if the shardmap is not yet
                    // published or is published incorrectly

                    return(null);
                }

                // add shardlet
                shardlet =
                    new Shardlet
                {
                    ServerInstanceName = rangeShard.ServerInstanceName,
                    Catalog            = rangeShard.Catalog,
                    ShardSetName       = shardSetName,
                    DistributionKey    = distributionKey,
                    ShardingKey        = shardingKey,
                    Status             = ShardletStatus.Active,
                };

                SaveAzureShardlet(shardlet);
            }
            else
            {
                shardlet = azureShardlet.ToFrameworkShardlet();
            }

            return(shardlet);
        }
Exemple #4
0
        /// <summary>
        /// Saves the azure Shardlet.
        /// </summary>
        /// <param name="shardlet">The shardlet.</param>
        private void SaveAzureShardlet(Shardlet shardlet)
        {
            var shardSetName       = shardlet.ShardSetName;
            var distributionKey    = shardlet.DistributionKey;
            var shardingKey        = shardlet.ShardingKey;
            var status             = shardlet.Status;
            var serverInstanceName = shardlet.ServerInstanceName;
            var catalog            = shardlet.Catalog;
            var pinned             = shardlet.Pinned;

            var repository    = new AzureShardletMapRepository(shardSetName);
            var azureShardlet = repository.Get(distributionKey);

            if (azureShardlet == null)
            {
                azureShardlet =
                    new AzureShardlet
                {
                    ShardSetName       = shardSetName,
                    DistributionKey    = distributionKey,
                    ShardingKey        = shardingKey,
                    ServerInstanceName = serverInstanceName,
                    Catalog            = catalog,
                    Status             = status.ToString(),
                    Pinned             = pinned
                };

                repository.Insert(azureShardlet);
            }
            else
            {
                azureShardlet.Catalog            = catalog;
                azureShardlet.ServerInstanceName = serverInstanceName;
                azureShardlet.Status             = status.ToString();
                azureShardlet.Pinned             = pinned;

                repository.Merge(azureShardlet);
            }
        }
Exemple #5
0
        private AzureShardlet GetAzureShardlet(string shardSetName, long distributionKey)
        {
            var repository = new AzureShardletMapRepository(shardSetName);

            return(repository.Get(distributionKey));
        }
Exemple #6
0
        /// <summary>
        /// Gets the shardlets in the shard set.
        /// </summary>
        /// <param name="shardSetName">Name of the shard set.</param>
        /// <returns>IEnumerable&lt;Shardlet&gt;.</returns>
        public override IEnumerable <Shardlet> GetShardlets(string shardSetName)
        {
            var repository = new AzureShardletMapRepository(shardSetName);

            return(repository.Get().Select(s => s.ToFrameworkShardlet()).AsEnumerable());
        }