コード例 #1
0
        /// <summary>
        /// Merges the specified azure shardlet.
        /// </summary>
        /// <param name="azureShardlet">The azure shardlet.</param>
        public void Merge(AzureShardlet azureShardlet)
        {
            RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
            .ExecuteAction(() => _table.Execute(TableOperation.Merge(azureShardlet)));

            Cache(azureShardlet);
        }
コード例 #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);
        }
        /// <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);
        }
        /// <summary>
        /// Deletes the rows associated with the collection of SPIDs for the specified shardlet.
        /// </summary>
        /// <param name="shardlet">The shardlet.</param>
        /// <param name="spids">The spids.</param>
        public void Delete(Shardlet shardlet, IEnumerable <short> spids)
        {
            var array   = spids.ToArray();
            var batches = Enumerable.Range(0, array.Count()).GroupBy(i => i / BatchSize, i => array[i]);

            var partitionKey = shardlet.DistributionKey.ToString(CultureInfo.InvariantCulture);

            foreach (var batch in batches)
            {
                var batchOperation = new TableBatchOperation();
                foreach (var spid in batch)
                {
                    var rowKey = AzureShardletConnection.GetRowKey(shardlet.Catalog, spid);
                    var entity =
                        new DynamicTableEntity
                    {
                        RowKey       = rowKey,
                        PartitionKey = partitionKey,
                        ETag         = "*"
                    };

                    batchOperation.Delete(entity);
                }

                RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
                .ExecuteAction(() => _table.ExecuteBatch(batchOperation));

                foreach (var spid in batch)
                {
                    AzureCache.Remove(GetCacheKey(_cacheType,
                                                  partitionKey,
                                                  AzureShardletConnection.GetRowKey(shardlet.Catalog, spid)));
                }
            }
        }
        /// <summary>
        /// Deletes the specified azure shardlet connection.
        /// </summary>
        /// <param name="azureShardletConnection">The azure shardlet connection.</param>
        public void Delete(AzureShardletConnection azureShardletConnection)
        {
            RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
            .ExecuteAction(() => _table.Execute(TableOperation.Delete(azureShardletConnection)));

            AzureCache.Remove(GetCacheKey(_cacheType, azureShardletConnection));
        }
コード例 #6
0
        /// <summary>
        /// Gets a list of all shardlets for the shard set.
        /// </summary>
        /// <returns>IEnumerable&lt;AzureShardlet&gt;.</returns>
        public IEnumerable <AzureShardlet> Get()
        {
            var query = new TableQuery <AzureShardlet>();

            IEnumerable <AzureShardlet> result = null;

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

            return(result);
        }
コード例 #7
0
        public void CreatesDefaultAzureStoragePolicyFromConfiguration()
        {
            var retryPolicy   = RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy();
            var retryStrategy = retryPolicy.RetryStrategy as Incremental;

            Assert.AreEqual("Default Azure Storage Retry Strategy", retryStrategy.Name);
            Assert.IsInstanceOfType(retryPolicy.ErrorDetectionStrategy, typeof(StorageTransientErrorDetectionStrategy));
            var storagePolicy1 = RetryPolicyFactory.GetRetryPolicy <StorageTransientErrorDetectionStrategy>();

            Assert.IsInstanceOfType(storagePolicy1.RetryStrategy, typeof(Incremental));
            Assert.IsInstanceOfType(storagePolicy1.ErrorDetectionStrategy, typeof(StorageTransientErrorDetectionStrategy));
        }
コード例 #8
0
        /// <summary>
        /// Gets the range shards using shard set name.
        /// </summary>
        /// <param name="shardSetName">Name of the shard set.</param>
        /// <returns>AzureRangeShard[].</returns>
        private AzureRangeShard[] Get(string shardSetName)
        {
            var condition = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, shardSetName);

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

            IEnumerable <AzureRangeShard> result = null;

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

            return(result.ToArray());
        }
コード例 #9
0
        /// <summary>
        /// Gets the specified range shard using the shard set name and the row key.
        /// </summary>
        /// <param name="shardSetName">Name of the shard set.</param>
        /// <param name="rowKey">The row key.</param>
        /// <returns>AzureRangeShard.</returns>
        public AzureRangeShard Get(string shardSetName, string rowKey)
        {
            var condition1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, shardSetName);
            var condition2 = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, rowKey);
            var condition  = TableQuery.CombineFilters(condition1, TableOperators.And, condition2);

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

            IEnumerable <AzureRangeShard> result = null;

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

            return(result.FirstOrDefault());
        }
コード例 #10
0
        /// <summary>
        /// Gets the actions based on the status.
        /// </summary>
        /// <param name="status">The status.</param>
        /// <returns>IList{TRequest}.</returns>
        public IList <TAction> GetActions(TableActionQueueItemStatus status)
        {
            var condition = TableQuery.GenerateFilterCondition("Status", QueryComparisons.Equal, status.ToString());

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

            var table = TableClient.GetTableReference(TableName);

            IList <TAction> result = null;

            RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
            .ExecuteAction(() => { result = table.ExecuteQuery(query).ToList(); });

            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Gets the next action.
        /// </summary>
        /// <returns>TRequest</returns>
        public TRequest GetNextAction()
        {
            //Get the next message
            var message = Queue.GetMessage();

            if (message == null)
            {
                return(null);
            }

            // Look up the table row for the message
            var request = GetAction(Int64.Parse(message.AsString));

            //Delete the message... If it errors during processing the consumer should make a new queue entry
            RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
            .ExecuteAction(() => Queue.DeleteMessage(message));

            return(request != null?CreateRequest(request) : null);
        }
コード例 #12
0
        /// <summary>
        /// Gets the action.
        /// </summary>
        /// <param name="queueId">The queue identifier.</param>
        /// <returns>TAction.</returns>
        protected TAction GetAction(long queueId)
        {
            var rowKey = LongBasedRowKeyEntity.MakeRowKeyFromLong(queueId);

            var condition = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey);

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

            var table = TableClient.GetTableReference(TableName);

            TAction result = null;

            RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
            .ExecuteAction(() => { result = table.ExecuteQuery(query).FirstOrDefault(); });

            return(result);
        }
        /// <summary>
        /// Gets the SQL Server SPIDs currently connected to a specific shardlet.
        /// </summary>
        /// <param name="shardlet">The shardlet.</param>
        /// <returns>IEnumerable&lt;System.Int32&gt;.</returns>
        public IEnumerable <short> Get(Shardlet shardlet)
        {
            // todo - dynamic parameter
            var condition = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal,
                                                               shardlet.DistributionKey.ToString(CultureInfo.InvariantCulture));

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

            IEnumerable <AzureShardletConnection> result = null;

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

            return
                (result
                 .Select(asc => (short)asc.Spid)
                 .ToArray());
        }
コード例 #14
0
        /// <summary>
        /// Determines whether there is a queued request in process.
        /// </summary>
        /// <returns><c>true</c> if there is a queued request in process; otherwise, <c>false</c>.</returns>
        public bool IsInProcess()
        {
            var condition1 = TableQuery.GenerateFilterCondition("Status", QueryComparisons.Equal,
                                                                TableActionQueueItemStatus.InProcess.ToString());
            var condition2 = TableQuery.GenerateFilterCondition("Status", QueryComparisons.Equal,
                                                                TableActionQueueItemStatus.Queued.ToString());
            var condition = TableQuery.CombineFilters(condition1, TableOperators.Or, condition2);

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

            var table = TableClient.GetTableReference(TableName);

            var result = false;

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

            return(result);
        }
        /// <summary>
        /// Deletes the shardlet connections older than the specified UTC Date and Time.
        /// </summary>
        /// <param name="utcDateTime">The UTC date time.</param>
        public void Delete(DateTime utcDateTime)
        {
            var condition = TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual,
                                                                      utcDateTime);

            var query =
                new TableQuery()
                .Where(condition)
                .Select(new[] { "PartitionKey", "RowKey" });

            var result = _table.ExecuteQuery(query).ToArray();

            var array   = result.ToArray();
            var batches = Enumerable.Range(0, array.Count()).GroupBy(i => i / BatchSize, i => array[i]);

            foreach (var batch in batches)
            {
                var batchOperation = new TableBatchOperation();
                foreach (var connection in batch)
                {
                    var entity =
                        new DynamicTableEntity
                    {
                        RowKey       = connection.RowKey,
                        PartitionKey = connection.PartitionKey,
                        ETag         = "*"
                    };

                    batchOperation.Delete(entity);
                }

                RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
                .ExecuteAction(() => _table.ExecuteBatch(batchOperation));

                foreach (var connection in batch)
                {
                    AzureCache.Remove(GetCacheKey(_cacheType, connection.PartitionKey, connection.RowKey));
                }
            }
        }
コード例 #16
0
 protected override void Act()
 {
     this.retryPolicy = RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy();
 }
コード例 #17
0
 public RetryPolicy GetDefaultAzureStorageRetryPolicy()
 {
     return(RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy());
 }
コード例 #18
0
 protected static void MergeTableAction(CloudTable shardCreationsTable, BaseQueuedActionEntity action)
 {
     RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
     .ExecuteAction(() => shardCreationsTable.Execute(TableOperation.Merge(action)));
 }
コード例 #19
0
 protected void AddQueueMessage(long rowKey)
 {
     RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
     .ExecuteAction(
         () => Queue.AddMessage(new CloudQueueMessage(rowKey.ToString(CultureInfo.InvariantCulture))));
 }
コード例 #20
0
 /// <summary>
 /// Inserts the specified azure rangeShard.
 /// </summary>
 /// <param name="azureRangeShard">The azure rangeShard.</param>
 public void Insert(AzureRangeShard azureRangeShard)
 {
     RetryPolicyFactory.GetDefaultAzureStorageRetryPolicy()
     .ExecuteAction(() => _table.Execute(TableOperation.Insert(azureRangeShard)));
 }