Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Services.Hive/3.3/Scheduler/TaskScheduler.cs @ 17717

Last change on this file since 17717 was 17574, checked in by jkarder, 5 years ago

#3062: overhauled statistics generation and cleanup

  • switched to a single thread for database cleanup and statistics generation (executed sequentially)
  • switched to preemptive deletion of items that are in status DeletionPending (for jobs: statelogs, taskdata, tasks)
  • added code that aborts tasks whose jobs have already been marked for deletion
  • added method UseTransactionAndSubmit in addition to UseTransaction in PersistenceManager
  • updated DAO methods and introduced more bare metal sql
  • introduced DAO methods for batch deletion
  • fixed usage of enum values in DAO sql queries
  • deleted unnecessary triggers tr_JobDeleteCascade and tr_TaskDeleteCascade in Prepare Hive Database.sql
  • changed scheduling for less interference with janitor and other heartbeats
    • increased scheduling patience from 20 to 70 seconds (to wait longer to get the mutex for scheduling)
    • changed signature of ITaskScheduler.Schedule
    • added base class for TaskSchedulers and moved assignment of tasks to slaves into it
    • changed RoundRobinTaskScheduler to use bare metal sql
  • made MessageContainer a storable type (leftover)
  • updated HiveJanitorServiceInstaller.nsi
File size: 1.3 KB
RevLine 
[17574]1using System;
2using System.Collections.Generic;
3using HeuristicLab.Services.Hive.DataAccess;
4using HeuristicLab.Services.Hive.DataAccess.Interfaces;
5
6
7namespace HeuristicLab.Services.Hive {
8  public abstract class TaskScheduler : ITaskScheduler {
9    protected IPersistenceManager PersistenceManager => ServiceLocator.Instance.PersistenceManager;
10
11    public IEnumerable<Guid> Schedule(Slave slave, int count = 1) {
12      return PersistenceManager.UseTransactionAndSubmit(() => {
13        var ids = ScheduleInternal(slave, count);
14        foreach (var id in ids) AssignTask(slave, id);
15        return ids;
16      });
17    }
18
19    protected abstract IReadOnlyList<Guid> ScheduleInternal(Slave slave, int count);
20
21    private void AssignTask(Slave slave, Guid taskId) {
22      const TaskState transferring = TaskState.Transferring;
23      DateTime now = DateTime.Now;
24
25      var pm = PersistenceManager;
26      var taskDao = pm.TaskDao;
27      var stateLogDao = pm.StateLogDao;
28
29      var task = taskDao.GetById(taskId);
30      task.State = transferring;
31      task.LastHeartbeat = now;
32
33      stateLogDao.Save(new StateLog {
34        State = transferring,
35        DateTime = now,
36        TaskId = taskId,
37        SlaveId = slave.ResourceId,
38        UserId = null,
39        Exception = null
40      });
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.