public async Task <IEnumerable <NamedPartitionInformation> > GetNamedPartitions(Uri serviceUri, IPartitionHelperLogger logger) { logger.EnumeratingPartitions(serviceUri); lock (_lock) { if (_namedPartitions.ContainsKey(serviceUri)) { var partitions = _namedPartitions[serviceUri]; logger.EnumeratedExistingPartitions(serviceUri, partitions); return(partitions); } } try { var fabricClient = new FabricClient(); var servicePartitionList = await fabricClient.QueryManager.GetPartitionListAsync(serviceUri); IList <NamedPartitionInformation> partitionKeys = new List <NamedPartitionInformation>(servicePartitionList.Count); foreach (var partition in servicePartitionList) { var partitionInfo = partition.PartitionInformation as NamedPartitionInformation; if (partitionInfo == null) { throw new InvalidOperationException( $"The service {serviceUri} should have a Named partition. Instead: {partition.PartitionInformation.Kind}"); } partitionKeys.Add(partitionInfo); } lock (_lock) { if (!_namedPartitions.ContainsKey(serviceUri)) { _namedPartitions.Add(serviceUri, partitionKeys.ToArray()); } } logger.EnumeratedAndCachedPartitions(serviceUri, partitionKeys); return(partitionKeys); } catch (Exception ex) { logger.FailedToEnumeratePartitions(serviceUri, ex); throw new PartitionEnumerationException(serviceUri, ex); } }
public async Task <IEnumerable <Int64RangePartitionInformation> > GetInt64Partitions(Uri serviceUri) { _logger.EnumeratingPartitions(serviceUri); if (_partitions.ContainsKey(serviceUri)) { var partitions = _partitions[serviceUri]; _logger.EnumeratedExistingPartitions(serviceUri, partitions); } try { var fabricClient = new FabricClient(); var servicePartitionList = await fabricClient.QueryManager.GetPartitionListAsync(serviceUri); // For each partition, build a service partition client used to resolve the low key served by the partition. IList <Int64RangePartitionInformation> partitionKeys = new List <Int64RangePartitionInformation>(servicePartitionList.Count); foreach (var partition in servicePartitionList) { var partitionInfo = partition.PartitionInformation as Int64RangePartitionInformation; if (partitionInfo == null) { throw new InvalidOperationException( $"The service {serviceUri} should have a uniform Int64 partition. Instead: {partition.PartitionInformation.Kind}"); } partitionKeys.Add(partitionInfo); } _partitions.Add(serviceUri, partitionKeys); _logger.EnumeratedAndCachedPartitions(serviceUri, partitionKeys); return(partitionKeys); } catch (Exception ex) { _logger.FailedToEnumeratePartitions(serviceUri, ex); throw ex; } }