Beispiel #1
0
        private async Task <(ClusterVersionEntity Version, List <SiloEntity> Silos)> ReadRecords(string clusterId)
        {
            var query = this._container
                        .GetItemQueryIterator <dynamic>(
                READ_ALL_QUERY,
                requestOptions: new QueryRequestOptions
            {
                PartitionKey = new PartitionKey(clusterId)
            }
                );

            var silos = new List <SiloEntity>();
            ClusterVersionEntity clusterVersion = null;

            do
            {
                var items = await query.ReadNextAsync();

                var version = items.Where(i => i.EntityType == nameof(ClusterVersionEntity)).SingleOrDefault();
                if (version != null)
                {
                    clusterVersion = ClusterVersionEntity.FromDocument(version);
                }

                silos.AddRange(items.Where(i => i.EntityType == nameof(SiloEntity)).Select(d => (SiloEntity)SiloEntity.FromDocument(d)));
            } while (query.HasMoreResults);

            return(clusterVersion, silos);
        }
Beispiel #2
0
        public async Task <MembershipTableData> ReadRow(SiloAddress key)
        {
            var id = ConstructSiloEntityId(key);

            try
            {
                var query = this._container
                            .GetItemQueryIterator <dynamic>(
                    new QueryDefinition(READ_ENTRY_QUERY).WithParameter("@siloId", id),
                    requestOptions: new QueryRequestOptions
                {
                    PartitionKey = new PartitionKey(this._clusterOptions.ClusterId)
                }
                    );

                var docs = await query.ReadNextAsync();

                var versionDoc = docs.Where(i => i.EntityType == nameof(ClusterVersionEntity)).SingleOrDefault();
                ClusterVersionEntity clusterVersionEntity = versionDoc != null?ClusterVersionEntity.FromDocument(versionDoc) : default;

                var siloEntities = docs.Where(i => i.EntityType == nameof(SiloEntity)).Select <dynamic, SiloEntity>(d => SiloEntity.FromDocument(d));

                TableVersion version = null;
                if (clusterVersionEntity != null)
                {
                    version = new TableVersion(clusterVersionEntity.ClusterVersion, clusterVersionEntity.ETag);
                }
                else
                {
                    this._logger.LogError("Initial ClusterVersionEntity entity doesn't exist.");
                }

                var memEntries = new List <Tuple <MembershipEntry, string> >();
                foreach (var entity in siloEntities)
                {
                    try
                    {
                        MembershipEntry membershipEntry = ParseEntity(entity);
                        memEntries.Add(new Tuple <MembershipEntry, string>(membershipEntry, entity.ETag));
                    }
                    catch (Exception exc)
                    {
                        this._logger.LogError(exc, "Failure reading membership row.");
                        throw;
                    }
                }

                var data = new MembershipTableData(memEntries, version);
                return(data);
            }
            catch (Exception exc)
            {
                this._logger.LogWarning($"Failure reading silo entry {id} for cluster id {this._clusterOptions.ClusterId}: {exc}");
                throw;
            }
        }