Esempio n. 1
0
        /// <inheritdoc />
        public async Task <EpochValue> GetEpochAsync(string partitionId, CancellationToken cancellationToken)
        {
            EpochValue epochValue = null;

            using (_logger.BeginScope("Get Epoch"))
            {
                _epochReadCounter.Increment();

                _logger.LogInformation("Getting epoch for partition {partitionId}", partitionId);
                CloudBlockBlob epochBlob = _consumerGroupDirectory.GetBlockBlobReference(partitionId);

                string jsonEpoch;

                using (_storagePerformanceSummary.Time())
                {
                    jsonEpoch = await epochBlob.DownloadTextAsync(_leaseEncoding, _defaultAccessCondition, _defaultRequestOptions, _operationContext).ConfigureAwait(false);
                }

                _logger.LogDebug("Retrieved epoch for partition {id} :: {json}", partitionId, jsonEpoch);

                epochValue = JsonConvert.DeserializeObject <EpochValue>(jsonEpoch);
                epochValue.ConcurrencyValue = epochBlob.Properties.ETag;
            }

            return(epochValue);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task <EpochOperationResult> AddOrUpdateEpochAsync(EpochValue value, bool force, CancellationToken cancellationToken)
        {
            EpochOperationResult results;

            using (_logger.BeginScope("Update epoch"))
            {
                _logger.LogInformation("Adding epoch: {partitionId}, forced: {force}", value.PartitionId, force);

                CloudBlockBlob epochBlob = _consumerGroupDirectory.GetBlockBlobReference(value.PartitionId);

                try
                {
                    _epochUpdateCounter.Increment();
                    AccessCondition accessCondition = force ? AccessCondition.GenerateLeaseCondition("*") : AccessCondition.GenerateLeaseCondition(value.ConcurrencyValue);
                    var             content         = JsonConvert.SerializeObject(value);

                    _logger.LogDebug("Writing content to partition {partitionId}, raw: {json}", value.PartitionId, content);

                    using (_storagePerformanceSummary.Time())
                    {
                        await epochBlob.UploadTextAsync(content, _leaseEncoding, accessCondition, _defaultRequestOptions, null).ConfigureAwait(false);
                    }

                    value.ConcurrencyValue = epochBlob.Properties.ETag;
                    _logger.LogDebug("Completed write of epoch to partition {partitionId}", value.PartitionId);

                    results = EpochOperationResult.Success;
                }
                catch (StorageException e) when(e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict)
                {
                    _logger.LogInformation("Epoch content conflict for partition {partitionId}", value.PartitionId);
                    results = EpochOperationResult.Conflict;
                    _epochErrorCounter.Increment();
                }
                catch (Exception e)
                {
                    _epochErrorCounter.Increment();
                    results = EpochOperationResult.Failure;
                    _logger.LogError(e, "Error adding or updating epoch for partition {partitionId}", value.PartitionId);
                }

                return(results);
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public async Task <EpochOperationResult> DeleteEpochAsync(EpochValue value, bool force, CancellationToken cancellationToken)
        {
            using (_logger.BeginScope("Delete Epoch"))
            {
                _epochUpdateCounter.Increment();

                EpochOperationResult results = EpochOperationResult.Unknown;

                _logger.LogDebug("Deleting epoch for partition {partitionId}", value.PartitionId);

                CloudBlockBlob epochBlob = _consumerGroupDirectory.GetBlockBlobReference(value.PartitionId);

                try
                {
                    AccessCondition accessCondition = force ? AccessCondition.GenerateLeaseCondition("*") : AccessCondition.GenerateLeaseCondition(value.ConcurrencyValue);

                    using (_storagePerformanceSummary.Time())
                    {
                        await epochBlob.DeleteIfExistsAsync(DeleteSnapshotsOption.IncludeSnapshots, accessCondition, _defaultRequestOptions, null, cancellationToken);
                    }

                    results = EpochOperationResult.Success;

                    _logger.LogInformation("Deleted epoch for partition {partitionId}", value.PartitionId);
                }
                catch (StorageException e) when(e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict)
                {
                    _epochErrorCounter.Increment();
                    results = EpochOperationResult.Conflict;
                    _logger.LogError(e, "Conflict deleting epoch for partition {partitionId}", value.PartitionId);
                }
                catch (Exception e)
                {
                    _epochErrorCounter.Increment();
                    results = EpochOperationResult.Failure;
                    _logger.LogError(e, "Error deleting epoch for partition {partitionId}", value.PartitionId);
                }

                return(results);
            }
        }
 /// <inheritdoc />
 public Task <EpochOperationResult> DeleteEpochAsync(EpochValue value, bool force, CancellationToken cancellationToken)
 {
     _logger.LogInformation("Deleting epoch for partition {partitionId}", value.PartitionId);
     return(Task.FromResult(EpochOperationResult.Success));
 }