protected override SystemTaskBase GetTask(ResourceReservationContext context) { MrsSystemTask mrsSystemTask = null; SystemTaskBase result; lock (this.instanceLock) { lock (JobScheduler.staticLock) { if (JobScheduler.RunnableJobs.Count > 0) { List <IJob> list = new List <IJob>(); List <IJob> list2 = new List <IJob>(); foreach (IJob job in JobScheduler.RunnableJobs) { mrsSystemTask = job.GetTask(this, context); if (mrsSystemTask != null) { break; } switch (job.State) { case JobState.Waiting: list2.Add(job); break; case JobState.Finished: list.Add(job); break; } } if (mrsSystemTask != null) { JobScheduler.RunnableJobs.Remove(mrsSystemTask.Job); this.runningJobs.Add(mrsSystemTask.Job); } foreach (IJob job2 in list) { JobScheduler.RunnableJobs.Remove(job2); job2.RevertToPreviousUnthrottledState(); this.OnJobStateChanged(job2, job2.State); } foreach (IJob item in list2) { JobScheduler.RunnableJobs.Remove(item); this.waitingJobs.Add(item); } } result = mrsSystemTask; } } return(result); }
public SystemTaskBase GetTask(LoadBalanceWorkload workload, ResourceReservationContext context) { lock (this.requestQueueLock) { this.BlockedTaskCount = 0; if (this.requests.Count == 0) { return(null); } for (int i = 0; i < this.requests.Count; i++) { IRequest request = this.requests[i]; if (request.IsBlocked) { this.BlockedTaskCount++; } else if (request.ShouldCancel(this.settings.IdleRunDelay)) { request.Abort(); DatabaseRequestLog.Write(request); this.requests.RemoveAt(i); i--; } else { ResourceKey obj2; ResourceReservation reservation = context.GetReservation(workload, request.Resources, out obj2); if (reservation != null) { this.requests.RemoveAt(i); return(new LoadBalanceTask(workload, reservation, request)); } if (ProcessorResourceKey.Local.Equals(obj2)) { this.BlockedTaskCount = this.requests.Count; break; } this.BlockedTaskCount++; } } } return(null); }
protected override SystemTaskBase GetTask(ResourceReservationContext context) { return(this.queue.GetTask(this, context)); }
protected override SystemTaskBase GetTask(ResourceReservationContext context) { List <Guid> list = null; Guid guid = this.lastProcessedDriverGuid; lock (this.instanceLock) { TimeBasedAssistantTask timeBasedAssistantTask = null; List <TimeBasedAssistantTask> list2 = new List <TimeBasedAssistantTask>(); foreach (SystemTaskBase systemTaskBase in this.tasksWaitingExecution) { TimeBasedAssistantTask timeBasedAssistantTask2 = (TimeBasedAssistantTask)systemTaskBase; IEnumerable <ResourceKey> resourceDependencies = timeBasedAssistantTask2.ResourceDependencies; if (resourceDependencies != null) { ResourceReservation reservation = context.GetReservation(this, resourceDependencies); if (reservation != null) { timeBasedAssistantTask2.ResourceReservation = reservation; timeBasedAssistantTask = timeBasedAssistantTask2; break; } } else { list2.Add(timeBasedAssistantTask2); } } foreach (TimeBasedAssistantTask value in list2) { this.tasksWaitingExecution.Remove(value); } if (timeBasedAssistantTask != null) { this.tasksWaitingExecution.Remove(timeBasedAssistantTask); return(timeBasedAssistantTask); } } TimeBasedDatabaseDriver nextDriver; ResourceReservation reservation2; for (;;) { nextDriver = this.Controller.GetNextDriver(guid); if (nextDriver == null) { break; } guid = nextDriver.DatabaseInfo.Guid; if (list != null && list.Contains(guid)) { goto Block_4; } if (!nextDriver.HasTask()) { ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "Skipping database '{0}' for assistant '{1}'. There is no task to execute.", guid, this.Controller.TimeBasedAssistantType.Name); } else { IEnumerable <ResourceKey> resourceDependencies2 = nextDriver.ResourceDependencies; if (resourceDependencies2 != null) { reservation2 = context.GetReservation(this, resourceDependencies2); if (reservation2 != null) { goto IL_1E1; } ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "Skipping database '{0}' for assistant '{1}'. Dependent resources are not currently available for this assistant.", guid, this.Controller.TimeBasedAssistantType.Name); } else { ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "The driver for database {0} assistant {1} did not return any resource dependencies. This is possible only when the driver is not started. Skipping tasks from this driver.", guid, this.Controller.TimeBasedAssistantType.Name); } } if (list == null) { list = new List <Guid>(); } list.Add(guid); } ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <LocalizedString>((long)this.GetHashCode(), "There are no drivers available for the assistant controller '{0}' at this time. No task available for execution.", this.Controller.TimeBasedAssistantType.Name); return(null); Block_4: ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <LocalizedString>((long)this.GetHashCode(), "Could not find any tasks to execute for the assistant controller '{0}'. No task available for execution.", this.Controller.TimeBasedAssistantType.Name); return(null); IL_1E1: ExTraceGlobals.TimeBasedAssistantControllerTracer.TraceDebug <Guid, LocalizedString>((long)this.GetHashCode(), "A task is available for execution on database {0} for assistant {1}. Submitting the task to RUBS for execution", guid, this.Controller.TimeBasedAssistantType.Name); this.lastProcessedDriverGuid = guid; return(new TimeBasedAssistantTask(this, nextDriver, reservation2)); }
private ResourceReservation GetReservation(WorkItem workItem, SystemWorkloadBase systemWorkload, ResourceReservationContext context, IEnumerable <ResourceKey> resources, out ResourceKey throttledResource) { throttledResource = null; ResourceReservation result; if (CommonUtils.ServiceIsStopping || this.IsInFinalization || workItem is UnthrottledWorkItem) { result = context.GetUnthrottledReservation(systemWorkload); } else { result = context.GetReservation(systemWorkload, resources, out throttledResource); } return(result); }
private MrsSystemTask GetTask(SystemWorkloadBase systemWorkload, ResourceReservationContext context) { MrsTracer.ActivityID = this.traceActivityID; base.CheckDisposed(); MrsSystemTask result; using (SettingsContextBase.ActivateContext(this as ISettingsContextProvider)) { lock (this.jobLock) { if (this.IsFinished) { MrsTracer.Service.Debug("Job({0}) is finished.", new object[] { base.GetType().Name }); this.state = JobState.Finished; this.jobDoneEvent.Set(); result = null; } else { WorkItem workItem = null; bool flag2 = true; foreach (WorkItem workItem2 in this.workItemQueue.GetCandidateWorkItems()) { if (workItem2.ScheduledRunTime <= ExDateTime.UtcNow || CommonUtils.ServiceIsStopping) { flag2 = false; if (this.GetWorkloadType(workItem2.WorkloadType) == systemWorkload.WorkloadType) { workItem = workItem2; break; } } } if (workItem == null) { if (flag2) { this.state = JobState.Waiting; } result = null; } else { this.RevertToPreviousUnthrottledState(); IEnumerable <ResourceKey> enumerable = this.ResourceDependencies; if (enumerable == null) { enumerable = Array <ResourceKey> .Empty; } ResourceKey resource = null; ResourceReservation reservation = this.GetReservation(workItem, systemWorkload, context, enumerable, out resource); if (reservation != null) { if (reservation.DelayFactor > 0.0) { this.MoveToThrottledState(resource, true); } this.TraceWorkItem(workItem); this.workItemQueue.Remove(workItem); result = new MrsSystemTask(this, workItem.Callback, systemWorkload, reservation, workItem is JobCheck); } else { this.MoveToThrottledState(resource, false); result = null; } } } } } return(result); }
MrsSystemTask IJob.GetTask(SystemWorkloadBase systemWorkload, ResourceReservationContext context) { return(this.GetTask(systemWorkload, context)); }