Exemple #1
0
        public static IIndexWorkflowQueue GetIndexWorkflowQueueFromGrainHashCode(SiloIndexManager siloIndexManager, Type grainInterfaceType, int grainHashCode, SiloAddress siloAddress)
        {
            int queueSeqNum    = StorageProviderUtils.PositiveHash(grainHashCode, siloIndexManager.NumWorkflowQueuesPerInterface);
            var grainReference = CreateGrainServiceGrainReference(siloIndexManager, grainInterfaceType, queueSeqNum, siloAddress);

            return(siloIndexManager.GetGrainService <IIndexWorkflowQueue>(grainReference));
        }
 internal IndexWorkflowQueueGrainService(SiloIndexManager siloIndexManager, Type grainInterfaceType, int queueSequenceNumber, bool isDefinedAsFaultTolerantGrain)
     : base(IndexWorkflowQueueBase.CreateIndexWorkflowQueueGrainReference(siloIndexManager, grainInterfaceType, queueSequenceNumber, siloIndexManager.SiloAddress).GrainIdentity,
            siloIndexManager.Silo, siloIndexManager.LoggerFactory)
 {
     _base = new IndexWorkflowQueueBase(siloIndexManager, grainInterfaceType, queueSequenceNumber, siloIndexManager.SiloAddress, isDefinedAsFaultTolerantGrain,
                                        () => base.GetGrainReference()); // lazy is needed because the runtime isn't attached until Registered
 }
        internal static async Task RegisterIndexWorkflowQueues(SiloIndexManager sim, Type grainInterfaceType, Type grainClassType, bool isFaultTolerant)
        {
            for (int i = 0; i < sim.NumWorkflowQueuesPerInterface; ++i)
            {
                await sim.Silo.AddGrainService(new IndexWorkflowQueueGrainService(sim, grainInterfaceType, i, isFaultTolerant));

                await sim.Silo.AddGrainService(new IndexWorkflowQueueHandlerGrainService(sim, grainInterfaceType, i, isFaultTolerant));
            }
        }
        internal static async Task RegisterIndexWorkflowQueues(SiloIndexManager siloIndexManager, Type iGrainType, Type grainImplType)
        {
            for (int i = 0; i < IndexWorkflowQueueBase.NUM_AVAILABLE_INDEX_WORKFLOW_QUEUES; ++i)
            {
                bool isAssignable = typeof(IIndexableGrainFaultTolerant).IsAssignableFrom(grainImplType);
                await siloIndexManager.Silo.AddGrainService(new IndexWorkflowQueueGrainService(siloIndexManager, iGrainType, i, isAssignable));

                await siloIndexManager.Silo.AddGrainService(new IndexWorkflowQueueHandlerGrainService(siloIndexManager, iGrainType, i, isAssignable));
            }
        }
Exemple #5
0
        public ActiveHashIndexPartitionedPerSiloBucketImplGrainService(SiloIndexManager siloIndexManager, Type grainInterfaceType, string parentIndexName)
            : base(GetGrainIdentity(siloIndexManager, grainInterfaceType, parentIndexName), siloIndexManager.Silo, siloIndexManager.LoggerFactory)
        {
            this.state = new HashIndexBucketState <K, V>
            {
                IndexMap    = new Dictionary <K, HashIndexSingleBucketEntry <V> >(),
                IndexStatus = IndexStatus.Available
            };

            _parentIndexName      = parentIndexName;
            this.siloIndexManager = siloIndexManager;
            this.logger           = siloIndexManager.LoggerFactory.CreateLoggerWithFullCategoryName <ActiveHashIndexPartitionedPerSiloBucketImplGrainService>();
        }
Exemple #6
0
 internal IndexWorkflowQueueHandlerBase(SiloIndexManager siloIndexManager, Type grainInterfaceType, int queueSeqNum, SiloAddress silo,
                                        bool isDefinedAsFaultTolerantGrain, Func <GrainReference> parentFunc)
 {
     _grainInterfaceType            = grainInterfaceType;
     _queueSeqNum                   = queueSeqNum;
     _isDefinedAsFaultTolerantGrain = isDefinedAsFaultTolerantGrain;
     _hasAnyTotalIndex              = false;
     __grainIndexes                 = null;
     __workflowQueue                = null;
     _silo             = silo;
     _siloIndexManager = siloIndexManager;
     _lazyParent       = new Lazy <GrainReference>(parentFunc, true);
 }
        public ActiveHashIndexPartitionedPerSiloBucketImplGrainService(SiloIndexManager siloIndexManager, string parentIndexName, GrainReference grainReference)
            : base(grainReference.GrainIdentity, siloIndexManager.Silo, siloIndexManager.LoggerFactory)
        {
            state = new HashIndexBucketState <K, V>
            {
                IndexMap    = new Dictionary <K, HashIndexSingleBucketEntry <V> >(),
                IndexStatus = IndexStatus.Available
                              //, IsUnique = false; //a per-silo index cannot check for uniqueness
            };

            _parentIndexName      = parentIndexName;
            this.siloIndexManager = siloIndexManager;
            this.logger           = siloIndexManager.LoggerFactory.CreateLoggerWithFullCategoryName <ActiveHashIndexPartitionedPerSiloBucketImplGrainService>();
        }
 /// <summary>
 /// An extension method to intercept the calls to DirectApplyIndexUpdate on an Index,
 /// so that for a PerSilo index, it can obtain the GrainService of that index on the silo of the indexed grain.
 /// </summary>
 internal static Task <bool> ApplyIndexUpdate(this IIndexInterface index, SiloIndexManager siloIndexManager,
                                              IIndexableGrain updatedGrain, Immutable <IMemberUpdate> update,
                                              IndexMetaData idxMetaData, SiloAddress siloAddress = null)
 {
     if (index is IActiveHashIndexPartitionedPerSilo)
     {
         var bucketInCurrentSilo = siloIndexManager.GetGrainService <IActiveHashIndexPartitionedPerSiloBucket>(
             GetAHashIndexPartitionedPerSiloGrainReference(siloIndexManager,
                                                           IndexUtils.GetIndexNameFromIndexGrain((IAddressable)index), index.GetType().GetGenericArguments()[1],
                                                           siloAddress
                                                           ));
         return(bucketInCurrentSilo.DirectApplyIndexUpdate(updatedGrain, update, idxMetaData.IsUniqueIndex, idxMetaData /*, siloAddress*/));
     }
     return(index.DirectApplyIndexUpdate(updatedGrain, update, idxMetaData.IsUniqueIndex, idxMetaData, siloAddress));
 }
Exemple #9
0
        internal IndexWorkflowQueueBase(SiloIndexManager siloIndexManager, Type grainInterfaceType, int queueSequenceNumber, SiloAddress silo,
                                        bool isDefinedAsFaultTolerantGrain, Func <GrainReference> parentFunc)
        {
            queueState          = new IndexWorkflowQueueState(silo);
            _grainInterfaceType = grainInterfaceType;
            _queueSeqNum        = queueSequenceNumber;

            _workflowRecordsTail = null;
            __grainStorage       = null;
            __handler            = null;
            _isHandlerWorkerIdle = 1;

            _isDefinedAsFaultTolerantGrain = isDefinedAsFaultTolerantGrain;

            _writeLock            = new AsyncLock();
            _writeRequestIdGen    = 0;
            _pendingWriteRequests = new HashSet <int>();

            _silo            = silo;
            SiloIndexManager = siloIndexManager;
            _lazyParent      = new Lazy <GrainReference>(parentFunc, true);
        }
        internal IndexWorkflowQueueBase(SiloIndexManager siloIndexManager, Type grainInterfaceType, int queueSequenceNumber, SiloAddress silo,
                                        bool isDefinedAsFaultTolerantGrain, Func <GrainReference> parentFunc, GrainReference recoveryGrainReference = null)
        {
            queueState          = new IndexWorkflowQueueState();
            _grainInterfaceType = grainInterfaceType;
            _queueSeqNum        = queueSequenceNumber;
            _grainTypeName      = "Orleans.Indexing.IndexWorkflowQueue-" + IndexUtils.GetFullTypeName(_grainInterfaceType);

            _workflowRecordsTail = null;
            __handler            = null;
            _isHandlerWorkerIdle = 1;

            _isDefinedAsFaultTolerantGrain = isDefinedAsFaultTolerantGrain;
            this._recoveryGrainReference   = recoveryGrainReference;

            _writeLock            = new AsyncLock();
            _writeRequestIdGen    = 0;
            _pendingWriteRequests = new HashSet <int>();

            _silo            = silo;
            SiloIndexManager = siloIndexManager;
            _lazyParent      = new Lazy <GrainReference>(parentFunc, true);
        }
 private static GrainReference GetAHashIndexPartitionedPerSiloGrainReference(SiloIndexManager siloIndexManager, string indexName, Type grainInterfaceType, SiloAddress siloAddress)
 => siloIndexManager.MakeGrainServiceGrainReference(IndexingConstants.HASH_INDEX_PARTITIONED_PER_SILO_BUCKET_GRAIN_SERVICE_TYPE_CODE,
                                                    IndexUtils.GetIndexGrainPrimaryKey(grainInterfaceType, indexName), siloAddress);
 private static GrainReference GetGrainReference(SiloIndexManager siloIndexManager, string indexName, SiloAddress siloAddress = null)
 => ActiveHashIndexPartitionedPerSiloBucketImplGrainService.GetGrainReference(siloIndexManager, typeof(V), indexName, siloAddress);
 internal static SiloIndexManager GetSiloIndexManager(ref SiloIndexManager siloIndexManager, IServiceProvider serviceProvider)
 => siloIndexManager ?? (siloIndexManager = GetSiloIndexManager(serviceProvider));
 /// <summary>
 /// This method extends GrainFactory by adding a new GetGrain method to it that can get the runtime type of the grain interface along
 /// with its primary key, and return the grain casted to an interface that the given grainInterfaceType extends it.
 ///
 /// The main use-case is when you want to get a grain whose type is unknown at compile time, and also SuperOutputGrainInterfaceType
 /// is non-generic, while outputGrainInterfaceType is a generic type.
 /// </summary>
 /// <param name="siloIndexManager">the Index manager for this silo</param>
 /// <param name="grainPrimaryKey">the primary key of the grain</param>
 /// <param name="grainInterfaceType">the runtime type of the grain interface</param>
 /// <param name="outputGrainInterfaceType">the type of grain interface that should be returned</param>
 /// <returns></returns>
 public static IGrain GetGrain(this SiloIndexManager siloIndexManager, string grainPrimaryKey, Type grainInterfaceType, Type outputGrainInterfaceType)
 => siloIndexManager.GetGrain(grainPrimaryKey, grainInterfaceType, outputGrainInterfaceType);
 /// <summary>
 /// Converts this grain to the grain interface identified by grainInterfaceType.
 ///
 /// Finally, it casts it to the type provided as TGrainInterface. The caller should make sure that grainInterfaceType extends TGrainInterface.
 /// </summary>
 /// <typeparam name="TGrainInterface">output grain interface type, which grainInterfaceType extends it</typeparam>
 /// <param name="grain">the target grain to be casted</param>
 /// <param name="siloIndexManager">the Index manager for this silo</param>
 /// <param name="grainInterfaceType">the grain implementation type</param>
 /// <returns>A strongly typed <c>GrainReference</c> of grain interface type <paramref name="grainInterfaceType"/> cast to TGrainInterface.</returns>
 /// <returns></returns>
 internal static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain, SiloIndexManager siloIndexManager, Type grainInterfaceType) where TGrainInterface : IGrain
 => (grain != null)
         ? (TGrainInterface)siloIndexManager.GrainReferenceRuntime.Convert(grain.AsWeaklyTypedReference(), grainInterfaceType)
 : throw new ArgumentNullException("grain", "Cannot pass null as an argument to AsReference");
Exemple #16
0
 internal ApplicationPartsIndexableGrainLoader(IndexManager indexManager)
 {
     this.indexManager     = indexManager;
     this.siloIndexManager = indexManager as SiloIndexManager;
     this.logger           = this.indexManager.LoggerFactory.CreateLoggerWithFullCategoryName <ApplicationPartsIndexableGrainLoader>();
 }
Exemple #17
0
 public static GrainReference CreateIndexWorkflowQueueGrainReference(SiloIndexManager siloIndexManager, Type grainInterfaceType, int queueSeqNum, SiloAddress siloAddress)
 => CreateGrainServiceGrainReference(siloIndexManager, grainInterfaceType, queueSeqNum, siloAddress);
Exemple #18
0
 public IndexFactory(IndexManager im, IGrainFactory gf)
 {
     this.indexManager     = im;
     this.siloIndexManager = im as SiloIndexManager;
     this.grainFactory     = gf;
 }
Exemple #19
0
 public static GrainReference CreateIndexWorkflowQueueHandlerGrainReference(SiloIndexManager siloIndexManager, Type grainInterfaceType, int queueSeqNum, SiloAddress siloAddress)
 => siloIndexManager.MakeGrainServiceGrainReference(IndexingConstants.INDEX_WORKFLOW_QUEUE_HANDLER_GRAIN_SERVICE_TYPE_CODE,
                                                    IndexWorkflowQueueBase.CreateIndexWorkflowQueuePrimaryKey(grainInterfaceType, queueSeqNum), siloAddress);
Exemple #20
0
 private static IGrainIdentity GetGrainIdentity(SiloIndexManager siloIndexManager, Type grainInterfaceType, string indexName)
 => GetGrainReference(siloIndexManager, grainInterfaceType, indexName).GrainIdentity;
 /// <summary>
 /// Converts this grain to a specific grain interface.
 /// </summary>
 /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam>
 /// <param name="grain">The grain to convert.</param>
 /// <param name="siloIndexManager">the Index manager for this silo</param>
 /// <returns>A strongly typed <c>GrainReference</c> of grain interface type TGrainInterface.</returns>
 internal static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain, SiloIndexManager siloIndexManager) where TGrainInterface : IGrain
 => (grain != null)
         ? grain.Cast <TGrainInterface>()
 : throw new ArgumentNullException("grain", "Cannot pass null as an argument to AsReference");
 internal static Task InitPerSilo(SiloIndexManager siloIndexManager, string indexName, bool isUnique)
 => siloIndexManager.Silo.AddGrainService(new ActiveHashIndexPartitionedPerSiloBucketImplGrainService(siloIndexManager, indexName, GetGrainReference(siloIndexManager, indexName)));
 private static GrainReference GetGrainReference(SiloIndexManager siloIndexManager, string indexName, SiloAddress siloAddress = null)
 => siloIndexManager.MakeGrainServiceGrainReference(IndexingConstants.HASH_INDEX_PARTITIONED_PER_SILO_BUCKET_GRAIN_SERVICE_TYPE_CODE,
                                                    IndexUtils.GetIndexGrainPrimaryKey(typeof(V), indexName), siloAddress ?? siloIndexManager.SiloAddress);
 /// <summary>
 /// This method extends GrainFactory by adding a new GetGrain method to it that can get the runtime type of the grain interface along
 /// with its primary key, and return the grain casted to an interface that the given grainInterfaceType extends it.
 ///
 /// The main use-case is when you want to get a grain whose type is unknown at compile time.
 /// </summary>
 /// <typeparam name="OutputGrainInterfaceType">The output type of the grain</typeparam>
 /// <param name="siloIndexManager">the Index manager for this silo</param>
 /// <param name="grainPrimaryKey">the primary key of the grain</param>
 /// <param name="grainInterfaceType">the runtime type of the grain interface</param>
 /// <returns>the requested grain with the given grainID and grainInterfaceType</returns>
 public static OutputGrainInterfaceType GetGrain <OutputGrainInterfaceType>(this SiloIndexManager siloIndexManager, Guid grainPrimaryKey, Type grainInterfaceType)
     where OutputGrainInterfaceType : IGrain
 => siloIndexManager.GetGrain <OutputGrainInterfaceType>(grainPrimaryKey, grainInterfaceType);