Commit d7b8badb authored by Alessio Netti's avatar Alessio Netti

libdcdb: improvements to JobDataStore

- Reduced code duplication
- Handling some uncommon error conditions
- Preventing error tangling
- Adding methods to fetch pending and finished jobs
parent 9571e416
......@@ -181,10 +181,28 @@ namespace DCDB {
TimeStamp intervalStart,
TimeStamp intervalEnd);
/**
* @brief Retrieve an inclusive list of jobs which were run in the given
* time interval.
*
* @details INCLUSIVE version; all jobs whose start OR end time lays
* within the interval are returned. See also
* getJobsInIntervalExcl().
*
* @param jobs Reference to a list of JobData that will be
* populated with the jobs.
* @param intervalStart Start time of the interval.
* @param intervalEnd End time of the interval.
* @return See JDError.
*/
JDError getJobsInIntervalIncl(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
/**
* @brief Retrieve a list of jobs which were run in the given time interval.
*
* @details Find all entries in the data store corresponding to jobs that were running in
* the queried time interval, i.e., their start time is less than the queried intervalEnd,
* and their end time is 0 or greater than startInterval.
......@@ -196,16 +214,32 @@ namespace DCDB {
* @return See JDError.
*/
JDError getJobsInIntervalRunning(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
TimeStamp intervalStart,
TimeStamp intervalEnd);
/**
* @brief Retrieve an inclusive list of jobs which were run in the given
* @brief Retrieve a list of jobs which terminated in the given time interval.
*
* @details Find all entries in the data store corresponding to jobs that terminated in
* the queried time interval, i.e., their end time is within the queried interval.
*
* @param jobs Reference to a list of JobData that will be
* populated with the jobs.
* @param intervalStart Start time of the interval.
* @param intervalEnd End time of the interval.
* @return See JDError.
*/
JDError getJobsInIntervalFinished(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
/**
* @brief Retrieve an inclusive list of jobs which were in pending state in the given
* time interval.
*
* @details INCLUSIVE version; all jobs whose start OR end time lays
* within the interval are returned. See also
* getJobsInIntervalExcl().
* @details Find all entries in the data store corresponding to jobs that were in pending state in
* the queried time interval, i.e., their start time is greater than the queried intervalStart,
* and the writing time of the corresponding record in the DB is lower than intervalEnd.
*
* @param jobs Reference to a list of JobData that will be
* populated with the jobs.
......@@ -213,9 +247,9 @@ namespace DCDB {
* @param intervalEnd End time of the interval.
* @return See JDError.
*/
JDError getJobsInIntervalIncl(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
JDError getJobsInIntervalPending(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
/**
* @brief Retrieve the list of nodes which were used by a job.
......
......@@ -75,12 +75,18 @@ namespace DCDB {
JDError getJobsInIntervalExcl(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
JDError getJobsInIntervalRunning(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
JDError getJobsInIntervalIncl(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
JDError getJobsInIntervalRunning(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
JDError getJobsInIntervalFinished(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
JDError getJobsInIntervalPending(std::list<JobData>& jobs,
TimeStamp intervalStart,
TimeStamp intervalEnd);
JDError getNodeList(NodeList& nodes, JobId jid, TimeStamp startTs);
JobDataStoreImpl(Connection* conn);
......@@ -89,7 +95,9 @@ namespace DCDB {
private:
// Private utility method to avoid code duplication
JDError parseJobs(CassIterator* rowIt, std::list<JobData>& jobs, std::unordered_set<JobId>* jobIds);
JDError parseJobs(CassIterator* rowIt, std::list<JobData>& jobs, std::unordered_set<JobId>* jobIds, uint64_t filterWriteTime=0);
// Private utility method to run statements (and avoid duplication)
JDError runStatement(CassStatement* statement, std::list<JobData>& jobs, std::unordered_set<JobId>* jobIds, uint64_t filterWriteTime=0);
};
} /* End of namespace DCDB */
......
This diff is collapsed.
......@@ -112,6 +112,9 @@ void JobAction::doShow(std::string jobId) {
switch (err) {
case DCDB::JD_OK:
case DCDB::JD_PARSINGERROR:
if(err == DCDB::JD_PARSINGERROR)
std::cout << "Parsing error. Some fields may not be populated." << std::endl;
jobData.startTime.convertToLocal();
jobData.endTime.convertToLocal();
std::cout << "Job ID: " << jobId << std::endl;
......@@ -157,7 +160,10 @@ void JobAction::doList() {
DCDB::JDError err = jobDataStore.getJobsInIntervalIncl(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
printList(jobList);
case DCDB::JD_PARSINGERROR:
if(err == DCDB::JD_PARSINGERROR)
std::cout << "Parsing error. Some fields may not be populated." << std::endl;
printList(jobList);
break;
default:
std::cout << "Internal error." << std::endl;
......@@ -166,15 +172,17 @@ void JobAction::doList() {
void JobAction::doPending() {
DCDB::JobDataStore jobDataStore(connection);
DCDB::TimeStamp tsNow;
DCDB::TimeStamp tsEnd((uint64_t)LLONG_MAX);
DCDB::TimeStamp tsStart((uint64_t)0);
DCDB::TimeStamp tsEnd;
DCDB::TimeStamp tsStart(tsEnd.getRaw() - JOB_ACTION_OFFSET);
std::list<DCDB::JobData> jobList;
DCDB::JDError err = jobDataStore.getJobsInIntervalIncl(jobList, tsStart, tsEnd);
DCDB::JDError err = jobDataStore.getJobsInIntervalPending(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
printList(jobList);
break;
case DCDB::JD_PARSINGERROR:
if(err == DCDB::JD_PARSINGERROR)
std::cout << "Parsing error. Some fields may not be populated." << std::endl;
printList(jobList);
break;
default:
std::cout << "Internal error." << std::endl;
}
......@@ -188,8 +196,11 @@ void JobAction::doRunning() {
DCDB::JDError err = jobDataStore.getJobsInIntervalRunning(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
printList(jobList);
break;
case DCDB::JD_PARSINGERROR:
if(err == DCDB::JD_PARSINGERROR)
std::cout << "Parsing error. Some fields may not be populated." << std::endl;
printList(jobList);
break;
default:
std::cout << "Internal error." << std::endl;
}
......@@ -197,15 +208,17 @@ void JobAction::doRunning() {
void JobAction::doFinished() {
DCDB::JobDataStore jobDataStore(connection);
DCDB::TimeStamp tsNow;
DCDB::TimeStamp tsEnd(tsNow.getRaw() - JOB_ACTION_OFFSET);
DCDB::TimeStamp tsEnd;
DCDB::TimeStamp tsStart((uint64_t)0);
std::list<DCDB::JobData> jobList;
DCDB::JDError err = jobDataStore.getJobsInIntervalExcl(jobList, tsStart, tsEnd);
DCDB::JDError err = jobDataStore.getJobsInIntervalFinished(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
printList(jobList);
break;
case DCDB::JD_PARSINGERROR:
if(err == DCDB::JD_PARSINGERROR)
std::cout << "Parsing error. Some fields may not be populated." << std::endl;
printList(jobList);
break;
default:
std::cout << "Internal error." << std::endl;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment