/// <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))); } } }