// **************************************************************************** // *** ~khTask // **************************************************************************** khTask::~khTask(void) throw() { assert(taskid_); if (jobHandler) { // stops the job // removes me from his list // takes ownership of my reservations (until job finished) jobHandler->StopTask(this); } else { theResourceManager.EraseWaitingTask(this); // Reservation destructors will release reservation and // remove the files they represent. This would happen // automatically at the end of this destructor. But I just felt like // being explicit reservations_.clear(); } taskVerrefMap.erase(verref_); // remove my persistence if (!khUnlink(TaskFilename())) { notify(NFY_WARN, "Unable to unlink %s", TaskFilename().c_str()); } // help to see if we're deleting the task twice taskid_ = 0; }
/* * worker_fetch_query_results_file fetches a query results file from the remote * node. The function assumes an upstream compute task depends on this query * results file, and therefore directly fetches the file into the upstream * task's directory. */ Datum worker_fetch_query_results_file(PG_FUNCTION_ARGS) { uint64 jobId = PG_GETARG_INT64(0); uint32 queryTaskId = PG_GETARG_UINT32(1); uint32 upstreamTaskId = PG_GETARG_UINT32(2); text *nodeNameText = PG_GETARG_TEXT_P(3); uint32 nodePort = PG_GETARG_UINT32(4); char *nodeName = NULL; /* remote filename is <jobId>/<queryTaskId> */ StringInfo remoteDirectoryName = JobDirectoryName(jobId); StringInfo remoteFilename = TaskFilename(remoteDirectoryName, queryTaskId); /* local filename is <jobId>/<upstreamTaskId>/<queryTaskId> */ StringInfo taskDirectoryName = TaskDirectoryName(jobId, upstreamTaskId); StringInfo taskFilename = TaskFilename(taskDirectoryName, queryTaskId); /* * If we are the first function to fetch a file for the upstream task, the * task directory does not exist. We then lock and create the directory. */ bool taskDirectoryExists = DirectoryExists(taskDirectoryName); if (!taskDirectoryExists) { InitTaskDirectory(jobId, upstreamTaskId); } nodeName = text_to_cstring(nodeNameText); FetchRegularFile(nodeName, nodePort, remoteFilename, taskFilename); PG_RETURN_VOID(); }
// **************************************************************************** // *** khTask // **************************************************************************** khTask::khTask(const SubmitTaskMsg &msg) : verref_(msg.verref), taskid_(msg.taskid), priority_(msg.priority), taskdef_(msg.taskdef), requirements(taskdef_, taskid_, verref_), // <-- can throw exception submitTime_(time(0)), beginTime_(0), progressTime_(0), progress_(0), jobHandler(0) { // It's assumed that the caller already removed any existing // task for this verref // make our persistent copy (it's just a symlink) if (!khSymlink(verref_, TaskFilename())) { throw khErrnoException(kh::tr("Unable to write ") + TaskFilename()); } // now that we're persistent, add myself to the lists taskVerrefMap.insert(std::make_pair(verref_, this)); theResourceManager.InsertWaitingTask(this); }