Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/13 16:35:14 (12 years ago)
Author:
pfleck
Message:

#2030
Activated Delayed Loading for binary data.
Added HiveOperationContext to store HiveDataContext for whole ServiceOperation duration.
Added HiveDao methods to query database objects, not DTOs.
Changed HartbeatManager to use only database objects from new queries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs

    r9304 r9381  
    4343    }
    4444
     45    public Task GetTaskDA(Guid id) {
     46      var db = HiveOperationContext.Current.DataContext;
     47      return db.Tasks.SingleOrDefault(x => x.TaskId == id);
     48    }
     49
    4550    public IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate) {
    4651      using (var db = CreateContext()) {
     
    138143        db.SubmitChanges();
    139144      }
     145    }
     146
     147    public void UpdateTaskDA(Task task) {
     148      var db = HiveOperationContext.Current.DataContext;
     149      db.SubmitChanges();
    140150    }
    141151
     
    195205    }
    196206
     207    public IEnumerable<TaskInfoForScheduler> GetWaitingTasksDA(Slave slave) {
     208      var db = HiveOperationContext.Current.DataContext;
     209      var parentResources = GetParentResourcesDA(slave.ResourceId);
     210      var resourceIds = parentResources.Select(x => x.ResourceId);
     211      //Originally we checked here if there are parent tasks which should be calculated (with GetParentTasks(resourceIds, count, false);).
     212      //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated),
     213      //we skip this step because it's wasted runtime
     214
     215      var query = from ar in db.AssignedResources
     216                  where resourceIds.Contains(ar.ResourceId)
     217                     && !(ar.Task.IsParentTask && ar.Task.FinishWhenChildJobsFinished)
     218                     && ar.Task.State == TaskState.Waiting
     219                     && ar.Task.CoresNeeded <= slave.FreeCores
     220                     && ar.Task.MemoryNeeded <= slave.FreeMemory
     221                  select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority };
     222      var waitingTasks = query.ToArray();
     223      return waitingTasks;
     224    }
     225
    197226    public DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) {
    198227      using (var db = CreateContext()) {
     
    222251        return DT.Convert.ToDto(task);
    223252      }
     253    }
     254
     255    public Task UpdateTaskStateDA(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) {
     256      var db = HiveOperationContext.Current.DataContext;
     257
     258      db.StateLogs.InsertOnSubmit(new StateLog {
     259        TaskId = taskId,
     260        State = taskState,
     261        SlaveId = slaveId,
     262        UserId = userId,
     263        Exception = exception,
     264        DateTime = DateTime.Now
     265      });
     266
     267      var task = db.Tasks.SingleOrDefault(x => x.TaskId == taskId);
     268      task.State = taskState;
     269
     270      db.SubmitChanges();
     271
     272      return task;
    224273    }
    225274    #endregion
     
    516565    }
    517566
     567    public Slave GetSlaveDA(Guid id) {
     568      var db = HiveOperationContext.Current.DataContext;
     569      return db.Resources.OfType<Slave>().SingleOrDefault(x => x.ResourceId == id);
     570    }
     571
    518572    public IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate) {
    519573      using (var db = CreateContext()) {
     
    538592        db.SubmitChanges();
    539593      }
     594    }
     595
     596    public void UpdateSlaveDA(Slave slave) {
     597      var db = HiveOperationContext.Current.DataContext;
     598      db.SubmitChanges();
    540599    }
    541600
     
    664723        return resources.Select(r => DT.Convert.ToDto(r)).ToArray();
    665724      }
     725    }
     726
     727    public IEnumerable<Resource> GetParentResourcesDA(Guid resourceId) {
     728      var db = HiveOperationContext.Current.DataContext;
     729      var resources = new List<Resource>();
     730      CollectParentResources(resources, db.Resources.Where(r => r.ResourceId == resourceId).Single());
     731      return resources;
    666732    }
    667733
Note: See TracChangeset for help on using the changeset viewer.