Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/23/09 11:35:41 (15 years ago)
Author:
svonolfe
Message:

Avoid out of memory exceptions related to job objects (#372)

Location:
trunk/sources/HeuristicLab.Hive.Server.Core/3.2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs

    r2022 r2082  
    371371    /// <returns></returns>
    372372    public ResponseJob SendJob(Guid clientId) {
    373       ResponseJob response = new ResponseJob();
    374 
    375       Job job2Calculate = scheduler.GetNextJobForClient(clientId);
    376       if (job2Calculate != null) {
    377         response.Job = job2Calculate;
    378         response.Success = true;
    379         response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_PULLED;
    380         lock (newAssignedJobs) {
    381           newAssignedJobs.Add(job2Calculate.Id, ApplicationConstants.JOB_TIME_TO_LIVE);
    382         }
    383       } else {
    384         response.Success = false;
    385         response.Job = null;
    386         response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT;
    387       }
    388       return response;
     373       ISession session = factory.GetSessionForCurrentThread();
     374      ITransaction tx = null;
     375
     376      try {
     377        IJobAdapter jobAdapter =
     378          session.GetDataAdapter<Job, IJobAdapter>();
     379
     380        tx = session.BeginTransaction();
     381
     382        ResponseJob response = new ResponseJob();
     383
     384        Job job2Calculate = scheduler.GetNextJobForClient(clientId);
     385        if (job2Calculate != null) {
     386          ComputableJob computableJob =
     387            jobAdapter.GetComputableJob(job2Calculate.Id);
     388
     389          response.Job = computableJob;
     390          response.Success = true;
     391          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_PULLED;
     392          lock (newAssignedJobs) {
     393            newAssignedJobs.Add(job2Calculate.Id, ApplicationConstants.JOB_TIME_TO_LIVE);
     394          }
     395        } else {
     396          response.Success = false;
     397          response.Job = null;
     398          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT;
     399        }
     400
     401        return response;
     402      }
     403      catch (Exception ex) {
     404        if (tx != null)
     405          tx.Rollback();
     406        throw ex;
     407      }
     408      finally {
     409        if (session != null)
     410          session.EndSession();
     411      }
    389412    }
    390413
     
    412435          clientAdapter.GetById(clientId);
    413436
    414         Job job =
    415           jobAdapter.GetById(jobId);
     437        ComputableJob job =
     438          new ComputableJob();
     439
     440        if (job != null) {
     441          job.JobInfo =
     442            jobAdapter.GetById(jobId);
     443        }
    416444       
    417         if (job == null) {
     445        if (job == null && job.JobInfo != null) {
    418446          response.Success = false;
    419447          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID;
     
    421449          return response;
    422450        }
    423         if (job.State == State.abort) {
     451        if (job.JobInfo.State == State.abort) {
    424452          response.Success = false;
    425453          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_WAS_ABORTED;
    426454        }
    427         if (job.Client == null) {
     455        if (job.JobInfo.Client == null) {
    428456          response.Success = false;
    429457          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
     
    431459          return response;
    432460        }
    433         if (job.Client.Id != clientId) {
     461        if (job.JobInfo.Client.Id != clientId) {
    434462          response.Success = false;
    435463          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB;
     
    437465          return response;
    438466        }
    439         if (job.State == State.finished) {
     467        if (job.JobInfo.State == State.finished) {
    440468          response.Success = true;
    441469          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED;
     
    443471          return response;
    444472        }
    445         if (job.State == State.requestSnapshotSent) {
    446           job.State = State.calculating;
    447         }
    448         if (job.State != State.calculating && job.State != State.pending) {
     473        if (job.JobInfo.State == State.requestSnapshotSent) {
     474          job.JobInfo.State = State.calculating;
     475        }
     476        if (job.JobInfo.State != State.calculating &&
     477          job.JobInfo.State != State.pending) {
    449478          response.Success = false;
    450479          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_JOB_STATE;
     
    453482        }
    454483        job.SerializedJob = result;
    455         job.Percentage = percentage;
     484        job.JobInfo.Percentage = percentage;
    456485
    457486        if (finished) {
    458           job.State = State.finished;
    459           jobAdapter.Update(job);
    460         }
    461         List<JobResult> jobResults = new List<JobResult>(jobResultAdapter.GetResultsOf(job));
     487          job.JobInfo.State = State.finished;
     488          job.SerializedJob = result;
     489        }
     490
     491        jobAdapter.UpdateComputableJob(job);
     492
     493        List<JobResult> jobResults = new List<JobResult>(
     494          jobResultAdapter.GetResultsOf(job.JobInfo));
    462495        foreach (JobResult currentResult in jobResults)
    463496          jobResultAdapter.Delete(currentResult);
     
    466499          new JobResult();
    467500        jobResult.ClientId = client.Id;
    468         jobResult.JobId = job.Id;
     501        jobResult.JobId = job.JobInfo.Id;
    469502        jobResult.Result = result;
    470503        jobResult.Percentage = percentage;
     
    473506
    474507        jobResultAdapter.Update(jobResult);
    475         jobAdapter.Update(job);
     508        jobAdapter.Update(job.JobInfo);
    476509
    477510        response.Success = true;
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ExecutionEngineFacade.cs

    r1530 r2082  
    3636    #region IExecutionEngineFacade Members
    3737
    38     public ResponseObject<Job> AddJob(Job job) {
     38    public ResponseObject<Job> AddJob(ComputableJob job) {
    3939      return jobManager.AddNewJob(job);
    4040    }
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/JobManager.cs

    r2005 r2082  
    7373    public void ResetJobsDependingOnResults(Job job) {
    7474      ISession session = factory.GetSessionForCurrentThread();
     75      ITransaction tx = null;
    7576
    7677      try {
     
    7879            session.GetDataAdapter<Job, IJobAdapter>();
    7980
    80         JobResult lastJobResult = GetLastJobResult(job);
    81         if (lastJobResult != null) {
    82           job.Percentage = lastJobResult.Percentage;
    83           job.SerializedJob = lastJobResult.Result;
    84         } else {
    85           job.Percentage = 0;
    86         }
    87 
    88         job.Client = null;
    89         job.State = State.offline;
    90 
    91         jobAdapter.Update(job);
     81        tx = session.BeginTransaction();
     82
     83        if (job != null) {
     84          ComputableJob computableJob =
     85              new ComputableJob();
     86          computableJob.JobInfo =
     87            job;
     88
     89          JobResult lastJobResult = GetLastJobResult(job);
     90          if (lastJobResult != null) {
     91            computableJob.JobInfo.Percentage = lastJobResult.Percentage;
     92            computableJob.SerializedJob = lastJobResult.Result;
     93
     94            jobAdapter.UpdateComputableJob(computableJob);
     95          } else {
     96            computableJob.JobInfo.Percentage = 0;
     97          }
     98
     99          computableJob.JobInfo.Client = null;
     100          computableJob.JobInfo.State = State.offline;
     101
     102          jobAdapter.Update(computableJob.JobInfo);
     103        }
     104
     105        tx.Commit();
     106      }
     107      catch (Exception ex) {
     108        if (tx != null)
     109          tx.Rollback();
     110        throw ex;
    92111      }
    93112      finally {
     
    185204    /// <param name="job"></param>
    186205    /// <returns></returns>
    187     public ResponseObject<Job> AddNewJob(Job job) {
     206    public ResponseObject<Job> AddNewJob(ComputableJob job) {
    188207      ISession session = factory.GetSessionForCurrentThread();
    189208
     
    194213        ResponseObject<Job> response = new ResponseObject<Job>();
    195214
    196         if (job != null) {
    197           if (job.State != State.offline) {
     215        if (job != null && job.JobInfo != null) {
     216          if (job.JobInfo.State != State.offline) {
    198217            response.Success = false;
    199218            response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE;
    200219            return response;
    201220          }
    202           if (job.Id != Guid.Empty) {
     221          if (job.JobInfo.Id != Guid.Empty) {
    203222            response.Success = false;
    204223            response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET;
     
    211230          }
    212231
    213           job.DateCreated = DateTime.Now;
    214           jobAdapter.Update(job);
     232          job.JobInfo.DateCreated = DateTime.Now;
     233          jobAdapter.UpdateComputableJob(job);
    215234          response.Success = true;
    216           response.Obj = job;
     235          response.Obj = job.JobInfo;
    217236          response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED;
    218237        } else {
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs

    r2067 r2082  
    9999    }
    100100
    101     public ResponseObject<Job> AddNewJob(Job job) {
    102       secMan.Authorize("AddJob", sessionID, job.Id);
     101    public ResponseObject<Job> AddNewJob(ComputableJob job) {
     102      secMan.Authorize("AddJob", sessionID, job.JobInfo.Id);
    103103      return jobManager.AddNewJob(job);
    104104    }
Note: See TracChangeset for help on using the changeset viewer.