/// <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 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)); }
/// <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> /// Registers the shardlet connection. /// </summary> /// <param name="shardlet">The shardlet.</param> /// <param name="spid">The spid.</param> public override void PublishShardletConnection(Shardlet shardlet, short spid) { var repository = new AzureShardletConnectionRepository(shardlet.ShardSetName); var azureShardletConnection = repository.Get(shardlet, spid); if (azureShardletConnection != null) { // updates the timestamp repository.Merge(azureShardletConnection); return; } azureShardletConnection = new AzureShardletConnection { Catalog = shardlet.Catalog, DistributionKey = shardlet.DistributionKey, ShardingKey = shardlet.ShardingKey, Spid = spid }; repository.Insert(azureShardletConnection); }
private void Cache(AzureShardletConnection azureShardletConnection) { if (azureShardletConnection == null) { return; } AzureCache.Put(GetCacheKey(_cacheType, azureShardletConnection), azureShardletConnection.ToCacheShardletConnection()); }
/// <summary> /// Merges the specified azure shardlet connection. /// </summary> /// <param name="azureShardletConnection">The azure shardlet connection.</param> public void Merge(AzureShardletConnection azureShardletConnection) { _table.Execute(TableOperation.Merge(azureShardletConnection)); Cache(azureShardletConnection); }
/// <summary> /// Inserts the specified azure shardlet connection. /// </summary> /// <param name="azureShardletConnection">The azure shardlet connection.</param> public void Insert(AzureShardletConnection azureShardletConnection) { _table.Execute(TableOperation.Insert(azureShardletConnection)); Cache(azureShardletConnection); }