private Task ApplyIndexUpdatesEagerly(Type iGrainType,
                                              IIndexableGrain updatedGrain,
                                              IDictionary <string, IMemberUpdate> updates,
                                              UpdateIndexType updateIndexTypes,
                                              bool updateIndexesTentatively)
        {
            IList <Task <bool> > updateIndexTasks = new List <Task <bool> >();

            foreach (KeyValuePair <string, IMemberUpdate> updt in updates.Where(updt => updt.Value.OperationType != IndexOperationType.None))
            {
                var idxInfo = this._grainIndexes[updt.Key];

                if (updateIndexTypes.HasFlag(idxInfo.MetaData.IsUniqueIndex ? UpdateIndexType.Unique : UpdateIndexType.NonUnique))
                {
                    // If the caller asks for the update to be tentative, then it will be wrapped inside a MemberUpdateTentative
                    IMemberUpdate updateToIndex = updateIndexesTentatively ? new MemberUpdateTentative(updt.Value) : updt.Value;

                    // The update task is added to the list of update tasks
                    updateIndexTasks.Add(idxInfo.IndexInterface.ApplyIndexUpdate(this.SiloIndexManager,
                                                                                 updatedGrain, updateToIndex.AsImmutable(), idxInfo.MetaData, BaseSiloAddress));
                }
            }

            // At the end, because the index update should be eager, we wait for all index update tasks to finish
            return(Task.WhenAll(updateIndexTasks));
        }
        protected async Task ApplyIndexUpdatesEagerly(IList <Type> iGrainTypes,
                                                      IIndexableGrain updatedGrain,
                                                      IDictionary <string, IMemberUpdate> updates,
                                                      UpdateIndexType updateIndexTypes,
                                                      bool updateIndexesTentatively = false)
        {
            Task applyUpdate(Type iGrainType) => ApplyIndexUpdatesEagerly(iGrainType, updatedGrain, updates, updateIndexTypes, updateIndexesTentatively);

            await(iGrainTypes.Count() == 1
                ? applyUpdate(iGrainTypes[0])
                : Task.WhenAll(iGrainTypes.Select(iGrainType => applyUpdate(iGrainType))));
        }
コード例 #3
0
        /// <summary>
        /// Eagerly Applies updates to the indexes defined on this grain for a single grain interface type implemented by this grain
        /// </summary>
        /// <param name="grainInterfaceType">a single indexable grain interface type implemented by this grain</param>
        /// <param name="updates">the dictionary of updates for each index</param>
        /// <param name="updateIndexTypes">indicates whether unique and/or non-unique indexes should be updated</param>
        /// <param name="isTentative">indicates whether updates to indexes should be tentatively done. That is, the update
        ///     won't be visible to readers, but prevents writers from overwriting them and violating constraints</param>
        /// <returns></returns>
        private protected Task ApplyIndexUpdatesEagerly(Type grainInterfaceType, IReadOnlyDictionary <string, IMemberUpdate> updates,
                                                        UpdateIndexType updateIndexTypes, bool isTentative)
        {
            var indexInterfaces = this._grainIndexes[grainInterfaceType];

            IEnumerable <Task <bool> > getUpdateTasks()
            {
                foreach (var(indexName, mu) in updates.Where(kvp => kvp.Value.OperationType != IndexOperationType.None))
                {
                    var indexInfo = indexInterfaces.NamedIndexes[indexName];
                    if (updateIndexTypes.HasFlag(indexInfo.MetaData.IsUniqueIndex ? UpdateIndexType.Unique : UpdateIndexType.NonUnique))
                    {
                        // If the caller asks for the update to be tentative, then it will be wrapped inside a MemberUpdateTentative
                        var updateToIndex = isTentative ? new MemberUpdateOverriddenMode(mu, IndexUpdateMode.Tentative) : mu;
                        yield return(indexInfo.IndexInterface.ApplyIndexUpdate(this.SiloIndexManager,
                                                                               this.iIndexableGrain, updateToIndex.AsImmutable(), indexInfo.MetaData, this.BaseSiloAddress));
                    }
                }
            }

            // At the end, because the index update should be eager, we wait for all index update tasks to finish
            return(Task.WhenAll(getUpdateTasks()));
        }
コード例 #4
0
 private protected Task ApplyIndexUpdatesEagerly(InterfaceToUpdatesMap interfaceToUpdatesMap,
                                                 UpdateIndexType updateIndexTypes, bool isTentative = false)
 => Task.WhenAll(interfaceToUpdatesMap.Select(kvp => this.ApplyIndexUpdatesEagerly(kvp.Key, kvp.Value, updateIndexTypes, isTentative)));