Commit 8fc36917 authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Avoid a query to QUEUE since the resubmission count is known

parent 7ae0a77f
......@@ -182,8 +182,8 @@ public class JobBroker {
final Long queueId = (Long) matchAnswer.get("queueId");
final String username = (String) matchAnswer.get("User");
int resubmission = -1;
final JobToken jobToken = TaskQueueUtils.insertJobToken(queueId.longValue(), (String) matchAnswer.get("User"));
int resubmission = ((Integer) matchAnswer.getOrDefault("Resubmission", Integer.valueOf(-1))).intValue();
final JobToken jobToken = TaskQueueUtils.insertJobToken(queueId.longValue(), (String) matchAnswer.get("User"), resubmission);
if (jobToken != null) {
resubmission = jobToken.resubmission;
......@@ -238,7 +238,7 @@ public class JobBroker {
db.setQueryTimeout(60);
final String agentId = (String) waiting.get("entryId");
final Integer agentId = Integer.valueOf((String) waiting.get("entryId"));
final String host = (String) waiting.get("Host");
final String ceName = (String) waiting.get("CE");
......@@ -321,12 +321,15 @@ public class JobBroker {
// we got something to run
String jdl, user;
db.query("select origjdl jdl, user from QUEUEJDL join QUEUE using (queueid) join QUEUE_USER using (userId) where queueId=?", false, Long.valueOf(queueId));
db.query("select origjdl jdl, user, resubmission from QUEUEJDL join QUEUE using (queueid) join QUEUE_USER using (userId) where queueId=?", false, Long.valueOf(queueId));
int resubmission = -1;
if (db.moveNext()) {
logger.log(Level.INFO, "Updated and getting fields queueId, jdl, user for queueId " + queueId);
jdl = db.gets(1);
user = db.gets(2);
resubmission = db.geti(3);
}
else {
logger.log(Level.INFO, "Couldn't get the queueId, jdl and user for the agentId: " + agentId);
......@@ -339,11 +342,12 @@ public class JobBroker {
db.query("update SITEQUEUES set ASSIGNED=GREATEST(ASSIGNED,0)+1, WAITING=GREATEST(WAITING-1,0) where siteid=?", false, Integer.valueOf(siteId));
TaskQueueUtils.deleteJobAgent(Long.parseLong(agentId), queueId);
TaskQueueUtils.deleteJobAgent(agentId.longValue(), queueId);
job.put("queueId", Long.valueOf(queueId));
job.put("JDL", jdl);
job.put("User", user);
job.put("Resubmission", Integer.valueOf(resubmission));
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, "Going to return " + queueId + " and " + user + " and " + jdl);
......
......@@ -73,13 +73,15 @@ public class JobToken implements Comparable<JobToken> {
* @param queueId
* @param username
*/
JobToken(final long queueId, final String username) {
JobToken(final long queueId, final String username, final int resubmission) {
this.queueId = queueId;
this.username = username;
this.exists = false;
this.resubmission = resubmission;
this.legacyToken = generateToken();
}
......@@ -162,9 +164,9 @@ public class JobToken implements Comparable<JobToken> {
if (db == null)
return false;
logger.log(Level.INFO, "Replace JobToken for: " + queueId + " and exists: " + exists);
logger.log(Level.INFO, "Replace JobToken for: " + queueId + " and exists: " + exists + ", known resubmission count: " + resubmission);
final int resubmission_queue = TaskQueueUtils.getResubmission(Long.valueOf(queueId));
final int resubmission_queue = resubmission >= 0 ? resubmission : TaskQueueUtils.getResubmission(Long.valueOf(queueId));
if (resubmission_queue < 0) { // problem getting resubmission from QUEUE
logger.info("JobToken updateOrInsert: cannot retrieve resubmision");
......
......@@ -2309,11 +2309,12 @@ public class TaskQueueUtils {
/**
* @param jobId
* @param username
* @param resubmission
* @return the new token
*/
public static JobToken insertJobToken(final long jobId, final String username) {
public static JobToken insertJobToken(final long jobId, final String username, final int resubmission) {
try (DBFunctions db = getQueueDB()) {
final JobToken jb = new JobToken(jobId, username);
final JobToken jb = new JobToken(jobId, username, resubmission);
if (!jb.updateOrInsert(db)) {
logger.info("Cannot insert (or update) token for job: " + jobId);
return null;
......@@ -2505,12 +2506,12 @@ public class TaskQueueUtils {
System.out.println("---------------------------------------------------------------------");
if (insertJobToken(12341234, "me") == null)
if (insertJobToken(12341234, "me", -1) == null)
System.out.println("exists, update refused.");
System.out.println("---------------------------------------------------------------------");
if (insertJobToken(12341234, "me") == null)
if (insertJobToken(12341234, "me", -1) == null)
System.out.println("exists, update refused.");
System.out.println("---------------------------------------------------------------------");
......
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