- Timestamp:
- 01/27/21 14:10:56 (4 years ago)
- Location:
- branches/3040_VectorBasedGP
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP
- Property svn:mergeinfo changed
-
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Services.Hive.DataAccess (added) merged: 17574
- Property svn:mergeinfo changed
-
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimJobDao.cs
r17180 r17825 44 44 } 45 45 46 public void UpdateExistingDimJobs() { 47 DataContext.ExecuteCommand(UpdateExistingDimJobsQuery); 48 } 49 46 50 #region Compiled queries 47 51 private static readonly Func<DataContext, Guid, DimJob> GetByIdQuery = … … 51 55 select dimJob).SingleOrDefault()); 52 56 #endregion 57 58 #region String queries 59 private const string UpdateExistingDimJobsQuery = @" 60 UPDATE u 61 SET 62 u.JobName = case when x.JobId is null then u.JobName else x.JobName end, 63 u.TotalTasks = x.TotalTasks, 64 u.CompletedTasks = x.CompletedTasks, 65 u.DateCompleted = 66 case when x.totaltasks = x.CompletedTasks 67 then (case when x.JobId is null and x.DateCompleted is null then GETDATE() else x.DateCompleted end) 68 else u.DateCompleted 69 end, 70 u.ProjectId = case when x.JobId is null then u.ProjectId else x.ProjectId end 71 FROM [statistics].dimjob u 72 JOIN ( 73 SELECT 74 dj.JobId as DimJobId, 75 j.JobId as JobId, 76 j.Name as JobName, 77 COUNT(*) as TotalTasks, 78 SUM( 79 CASE 80 WHEN TaskState in ('Finished', 'Aborted', 'Failed') then 1 81 ELSE 0 82 END) as CompletedTasks, 83 MAX(EndTime) as DateCompleted, 84 dp.ProjectId as ProjectId 85 from [statistics].DimJob dj 86 join [statistics].FactTask ft on dj.JobId = ft.JobId 87 left join Job j on j.JobId = dj.JobId 88 left join [statistics].DimProject dp on j.ProjectId = dp.ProjectId 89 where dj.DateCompleted is null and dp.DateExpired is null 90 group by dj.JobId, j.JobId, j.Name, dp.ProjectId 91 ) as x on u.JobId = x.DimJobId"; 92 #endregion 53 93 } 54 94 } -
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/JobDao.cs
r17180 r17825 37 37 } 38 38 39 public int DeleteByState(JobState state, int batchSize) { 40 return DataContext.ExecuteCommand(DeleteTopNByStateQueryString, batchSize, Enum.GetName(typeof(JobState), state)); 41 } 42 39 43 public IEnumerable<Job> GetByProjectId(Guid id) { 40 44 return GetByProjectIdQuery(DataContext, id); … … 43 47 public IEnumerable<Job> GetByProjectIds(IEnumerable<Guid> projectIds) { 44 48 string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x))); 45 if (!string.IsNullOrWhiteSpace(paramProjectIds)) {49 if (!string.IsNullOrWhiteSpace(paramProjectIds)) { 46 50 string queryString = string.Format(GetByProjectIdsQueryString, paramProjectIds); 47 51 return DataContext.ExecuteQuery<Job>(queryString); … … 51 55 52 56 public IEnumerable<Job> GetByState(JobState state) { 53 return GetByStateQuery(DataContext, state );57 return GetByStateQuery(DataContext, state.ToString()); 54 58 } 55 59 56 60 public IEnumerable<Guid> GetJobIdsByState(JobState state) { 57 return GetJobIdsByStateQuery(DataContext, state );61 return GetJobIdsByStateQuery(DataContext, state.ToString()); 58 62 } 59 63 … … 74 78 where job.ProjectId == projectId 75 79 select job)); 76 private static readonly Func<DataContext, JobState, IEnumerable<Job>> GetByStateQuery =77 CompiledQuery.Compile((DataContext db, JobStatejobState) =>80 private static readonly Func<DataContext, string, IEnumerable<Job>> GetByStateQuery = 81 CompiledQuery.Compile((DataContext db, string jobState) => 78 82 (from job in db.GetTable<Job>() 79 where job.State == jobState83 where job.State.ToString() == jobState 80 84 select job)); 81 private static readonly Func<DataContext, JobState, IEnumerable<Guid>> GetJobIdsByStateQuery =82 CompiledQuery.Compile((DataContext db, JobStatejobState) =>85 private static readonly Func<DataContext, string, IEnumerable<Guid>> GetJobIdsByStateQuery = 86 CompiledQuery.Compile((DataContext db, string jobState) => 83 87 (from job in db.GetTable<Job>() 84 where job.State == jobState88 where job.State.ToString() == jobState 85 89 select job.JobId)); 86 90 private static readonly Func<DataContext, IEnumerable<Job>> GetJobsReadyForDeletionQuery = … … 101 105 WHERE JobState = {0} 102 106 "; 107 private const string DeleteTopNByStateQueryString = @" 108 DELETE TOP ({0}) 109 FROM [Job] 110 WHERE JobState = {1} 111 "; 103 112 private const string GetStatisticsPendingJobs = @" 104 113 SELECT DISTINCT j.* -
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/StateLogDao.cs
r17180 r17825 40 40 } 41 41 42 public int DeleteObsolete(int batchSize) { 43 return DataContext.ExecuteCommand(DeleteObsoleteQueryString, batchSize); 44 } 45 42 46 #region Compiled queries 43 47 private static readonly Func<DataContext, Guid, StateLog> GetByIdQuery = … … 54 58 select stateLog).First(x => x.SlaveId != null)); 55 59 #endregion 60 61 #region String queries 62 private const string DeleteObsoleteQueryString = @" 63 delete top ({0}) s 64 from statelog s 65 join task t on t.taskid = s.taskid 66 join job j on j.jobid = t.jobid 67 where j.jobstate = 'deletionpending' 68 "; 69 #endregion 56 70 } 57 71 } -
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
r17180 r17825 50 50 //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated), 51 51 //we skip this step because it's wasted runtime 52 return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString, 53 slave.ResourceId, 54 Enum.GetName(typeof(TaskState), TaskState.Waiting), 55 slave.FreeCores, 52 return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString, 53 slave.ResourceId, 54 Enum.GetName(typeof(TaskState), TaskState.Waiting), 55 slave.FreeCores, 56 56 slave.FreeMemory).ToList(); 57 57 } … … 65 65 /// <returns></returns> 66 66 public IEnumerable<Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished) { 67 var query = from t in Table68 where t.State == TaskState.Waiting69 && t.IsParentTask70 && t.Job.AssignedJobResources.All(x => resourceIds.ToList().Contains(x.ResourceId))71 && t.FinishWhenChildJobsFinished == finished72 && t.ChildJobs.Any()73 && t.ChildJobs.All(x =>74 x.State == TaskState.Finished75 || x.State == TaskState.Aborted76 || x.State == TaskState.Failed)67 var query = from t in Table 68 where t.State == TaskState.Waiting 69 && t.IsParentTask 70 && t.Job.AssignedJobResources.All(x => resourceIds.ToList().Contains(x.ResourceId)) 71 && t.FinishWhenChildJobsFinished == finished 72 && t.ChildJobs.Any() 73 && t.ChildJobs.All(x => 74 x.State == TaskState.Finished 75 || x.State == TaskState.Aborted 76 || x.State == TaskState.Failed) 77 77 orderby t.Priority descending 78 78 select t; … … 82 82 public void UpdateExecutionTime(Guid taskId, double executionTime) { 83 83 DataContext.ExecuteCommand(UpdateExecutionTimeQuery, executionTime, DateTime.Now, taskId); 84 } 85 86 public int DeleteObsolete(int batchSize) { 87 return DataContext.ExecuteCommand(DeleteObsoleteQueryString, batchSize); 84 88 } 85 89 … … 129 133 WHERE TaskId = {2} 130 134 "; 135 136 private const string DeleteObsoleteQueryString = @" 137 delete top ({0}) t1 138 from task t1 139 left join task t2 on t1.taskid = t2.parenttaskid 140 join job j on j.jobid = t1.jobid 141 where j.jobstate = 'deletionpending' and t2.taskid is null 142 "; 131 143 #endregion 132 144 } -
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDataDao.cs
r17180 r17825 32 32 } 33 33 34 public int DeleteObsolete(int batchSize) { 35 return DataContext.ExecuteCommand(DeleteObsoleteQueryString, batchSize); 36 } 37 34 38 #region Compiled queries 35 39 private static readonly Func<DataContext, Guid, TaskData> GetByIdQuery = … … 39 43 select taskData).SingleOrDefault()); 40 44 #endregion 45 46 #region String queries 47 private const string DeleteObsoleteQueryString = @" 48 delete top ({0}) td 49 from taskdata td 50 join task t on t.taskid = td.taskid 51 join job j on j.jobid = t.jobid 52 where j.jobstate = 'deletionpending' 53 "; 54 #endregion 41 55 } 42 56 } -
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IPersistenceManager.cs
r17180 r17825 64 64 #region Transaction management 65 65 void UseTransaction(Action call, bool repeatableRead = false, bool longRunning = false); 66 void UseTransactionAndSubmit(Action call, bool repeatableRead = false, bool longRunning = false); 66 67 T UseTransaction<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false); 68 T UseTransactionAndSubmit<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false); 67 69 #endregion 68 70 -
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs
r17180 r17825 184 184 #region Transaction management 185 185 public void UseTransaction(Action call, bool repeatableRead = false, bool longRunning = false) { 186 UseTransaction<object>(() => { 187 call(); 188 return null; 189 }); 186 UseTransaction<object>(() => { call(); return null; }, repeatableRead, longRunning); 187 } 188 189 public void UseTransactionAndSubmit(Action call, bool repeatableRead = false, bool longRunning = false) { 190 UseTransaction(() => { call(); SubmitChanges(); }, repeatableRead, longRunning); 190 191 } 191 192 … … 211 212 } 212 213 214 public T UseTransactionAndSubmit<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false) { 215 return UseTransaction(() => { var res = call(); SubmitChanges(); return res; }, repeatableRead, longRunning); 216 } 217 213 218 private static TransactionScope CreateTransaction(bool repeatableRead, bool longRunning) { 214 219 var options = new TransactionOptions { -
branches/3040_VectorBasedGP/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Prepare Hive Database.sql
r16565 r17825 141 141 INCLUDE ([TaskId],[ExecutionTimeMs],[LastHeartbeat],[ParentTaskId],[Priority],[Command],[JobId]) 142 142 GO 143 144 145 146 -- OBSOLETE - DO NOT PERFORM (start)147 /****** Object: Trigger [dbo].[tr_JobDeleteCascade] Script Date: 04/19/2011 16:31:53 ******/148 SET ANSI_NULLS ON149 GO150 SET QUOTED_IDENTIFIER ON151 GO152 -- =============================================153 -- Author: cneumuel154 -- Create date: 19.04.2011155 -- Description: (1) Writes the execution times of deleted jobs into DeletedJobStats to ensure correct statistics156 -- (2) Deletes all associated jobs. This cannot be done with cascading delete,157 -- because the job table defines a INSTEAD OF DELETE trigger itself, which158 -- is not compatible with cascading deletes.159 -- =============================================160 CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS161 BEGIN162 DELETE Task FROM deleted, Task WHERE deleted.JobId = Task.JobId163 DELETE Job FROM deleted, Job WHERE deleted.JobId = Job.JobId164 END165 GO166 167 -- =============================================168 -- Author: cneumuel169 -- Create date: 11.11.2010170 -- Description: Recursively deletes all child-jobs of a job when it is deleted. (Source: http://devio.wordpress.com/2008/05/23/recursive-delete-in-sql-server/)171 -- =============================================DeletedJobStatistics172 CREATE TRIGGER [dbo].[tr_TaskDeleteCascade] ON [dbo].[Task] INSTEAD OF DELETE AS173 BEGIN174 -- recursively delete jobs175 CREATE TABLE #Table(176 TaskId uniqueidentifier177 )178 INSERT INTO #Table (TaskId)179 SELECT TaskId FROM deleted180 181 DECLARE @c INT182 SET @c = 0183 184 WHILE @c <> (SELECT COUNT(TaskId) FROM #Table) BEGIN185 SELECT @c = COUNT(TaskId) FROM #Table186 187 INSERT INTO #Table (TaskId)188 SELECT Task.TaskId189 FROM Task190 LEFT OUTER JOIN #Table ON Task.TaskId = #Table.TaskId191 WHERE Task.ParentTaskId IN (SELECT TaskId FROM #Table)192 AND #Table.TaskId IS NULL193 END194 195 DELETE TaskData FROM TaskData INNER JOIN #Table ON TaskData.TaskId = #Table.TaskId196 DELETE Task FROM Task INNER JOIN #Table ON Task.TaskId = #Table.TaskId197 END198 GO199 -- OBSOLETE (end)200
Note: See TracChangeset
for help on using the changeset viewer.