/// <summary>
        /// Gets the specified shardlet mapped to a specific spid.
        /// </summary>
        /// <param name="shardlet">The shardlet.</param>
        /// <param name="spid">The spid.</param>
        /// <returns>AzureShardletConnection.</returns>
        public AzureShardletConnection Get(Shardlet shardlet, int spid)
        {
            var partitionKey = shardlet.DistributionKey.ToString(CultureInfo.InvariantCulture);
            var rowKey       = AzureShardletConnection.GetRowKey(shardlet.Catalog, spid);

            var cacheShardletConnection =
                AzureCache.Get <CacheShardletConnection>(GetCacheKey(_cacheType, partitionKey, rowKey));

            if (cacheShardletConnection != null)
            {
                return(cacheShardletConnection.ToAzureShardletConnection());
            }

            var condition1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey);
            var condition2 = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey);
            var condition  = TableQuery.CombineFilters(condition1, TableOperators.And, condition2);

            var query =
                new TableQuery <AzureShardletConnection>()
                .Where(condition);

            IEnumerable <AzureShardletConnection> result = null;

            RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
            .ExecuteAction(() => result = _table.ExecuteQuery(query));

            var azureShardletConnection = result.FirstOrDefault();

            Cache(azureShardletConnection);

            return(azureShardletConnection);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the shardlet from the specified shard set name and distribution key.
        /// </summary>
        /// <param name="distributionKey">The distribution key.</param>
        /// <returns>AzureShardlet.</returns>
        public AzureShardlet Get(long distributionKey)
        {
            var cachedShardlet = AzureCache.Get <CacheShardlet>(GetCacheKey(_cacheType, _shardSetName, LongBasedRowKeyEntity.MakeRowKeyFromLong(distributionKey)));

            if (cachedShardlet != null)
            {
                return(cachedShardlet.ToAzureShardlet());
            }

            var rowKey = LongBasedRowKeyEntity.MakeRowKeyFromLong(distributionKey);

            var condition1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, _shardSetName);
            var condition2 = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey);
            var condition  = TableQuery.CombineFilters(condition1, TableOperators.And, condition2);

            var query =
                new TableQuery <AzureShardlet>()
                .Where(condition);

            IEnumerable <AzureShardlet> result = null;

            RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
            .ExecuteAction(() => result = _table.ExecuteQuery(query));

            var azureShardlet = result.FirstOrDefault();

            Cache(azureShardlet);

            return(azureShardlet);
        }