Skip to content

Commit 6130668

Browse files
committed
Update to include the NMPI details (but also delete them)
1 parent 6f3ba03 commit 6130668

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/allocator/AllocatorTask.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,14 @@ private Stream<HistoricalJob> jobs() {
771771
return jobs.stream().filter(Objects::nonNull);
772772
}
773773

774+
private Stream<Integer> nmpiJobs() {
775+
return jobs().map(j -> j.nmpiJobId).filter(Objects::nonNull);
776+
}
777+
778+
private Stream<Integer> nmpiSessions() {
779+
return jobs().map(j -> j.nmpiSessionId).filter(Objects::nonNull);
780+
}
781+
774782
/**
775783
* @return The number of job records to copy over to the historical
776784
* database.
@@ -850,6 +858,10 @@ private class HistoricalJob {
850858

851859
String groupName;
852860

861+
Integer nmpiJobId;
862+
863+
Integer nmpiSessionId;
864+
853865
HistoricalJob(Row row) {
854866
jobId = row.getInt("job_id");
855867
machineId = row.getInt("machine_id");
@@ -870,6 +882,8 @@ private class HistoricalJob {
870882
userName = row.getString("user_name");
871883
groupId = row.getInt("group_id");
872884
groupName = row.getString("group_name");
885+
nmpiJobId = row.getInteger("nmpi_job_id");
886+
nmpiSessionId = row.getInteger("nmpi_session_id");
873887
}
874888

875889
Object[] args() {
@@ -878,7 +892,7 @@ Object[] args() {
878892
width, height, depth, allocatedRoot, keepaliveInterval,
879893
keepaliveHost, deathReason, deathTimestamp, originalRequest,
880894
allocationTimestamp, allocationSize, machineName, userName,
881-
groupId, groupName
895+
groupId, groupName, nmpiJobId, nmpiSessionId
882896
};
883897
}
884898
}
@@ -903,6 +917,8 @@ private Copied tombstone(Connection conn, Connection histConn) {
903917
var readAllocs = conn.query(READ_HISTORICAL_ALLOCS);
904918
var deleteJobs = conn.update(DELETE_JOB_RECORD);
905919
var deleteAllocs = conn.update(DELETE_ALLOC_RECORD);
920+
var deleteNMPIJob = conn.update(DELETE_NMPI_JOB);
921+
var deleteNMPISession = conn.update(DELETE_NMPI_SESSION);
906922
var writeJobs = histConn.update(WRITE_HISTORICAL_JOBS);
907923
var writeAllocs = histConn.update(WRITE_HISTORICAL_ALLOCS)) {
908924
var grace = historyProps.getGracePeriod();
@@ -914,6 +930,8 @@ private Copied tombstone(Connection conn, Connection histConn) {
914930
copied.jobs().forEach((j) -> writeJobs.call(j.args()));
915931
});
916932
conn.transaction(() -> {
933+
copied.nmpiJobs().forEach(deleteNMPIJob::call);
934+
copied.nmpiSessions().forEach(deleteNMPISession::call);
917935
copied.allocs().forEach((a) -> deleteAllocs.call(a.allocId));
918936
copied.jobs().forEach((j) -> deleteJobs.call(j.jobId));
919937
});

SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/db/SQLQueries.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,21 @@ public abstract class SQLQueries {
18431843
protected static final String DELETE_ALLOC_RECORD =
18441844
"DELETE FROM old_board_allocations WHERE alloc_id = :alloc_id";
18451845

1846+
/**
1847+
* Actually delete an NMPI job record. Only called by the data tombstone-r.
1848+
*/
1849+
@Parameter("job_id")
1850+
protected static final String DELETE_NMPI_JOB =
1851+
"DELETE FROM job_nmpi_job WHERE job_id = :job_id";
1852+
1853+
/**
1854+
* Actually delete an NMPI session record.
1855+
* Only called by the data tombstone-r.
1856+
*/
1857+
@Parameter("job_id")
1858+
protected static final String DELETE_NMPI_SESSION =
1859+
"DELETE FROM job_nmpi_session WHERE job_id = :job_id";
1860+
18461861
/**
18471862
* Read the blacklisted chips for a board.
18481863
*
@@ -2273,17 +2288,23 @@ public abstract class SQLQueries {
22732288
@ResultColumn("user_name")
22742289
@ResultColumn("group_id")
22752290
@ResultColumn("group_name")
2291+
@ResultColumn("nmpi_job_id")
2292+
@ResultColumn("nmpi_session_id")
22762293
protected static final String READ_HISTORICAL_JOBS =
22772294
"SELECT job_id, machine_id, owner, create_timestamp, "
22782295
+ "jobs.width as width, jobs.height as height, jobs.depth as depth,"
22792296
+ "allocated_root, keepalive_interval, keepalive_host, "
22802297
+ "death_reason, death_timestamp, original_request, "
22812298
+ "allocation_timestamp, allocation_size, "
2282-
+ "machine_name, user_name, group_id, group_name "
2299+
+ "machine_name, user_name, group_id, group_name, "
2300+
+ "job_nmpi_job.nmpi_job_id as nmpi_job_id, "
2301+
+ "job_nmpi_session.session_id as nmpi_session_id "
22832302
+ "FROM jobs "
22842303
+ "JOIN user_groups USING (group_id) "
22852304
+ "JOIN machines USING (machine_id) "
22862305
+ "JOIN user_info ON jobs.owner = user_info.user_id "
2306+
+ "LEFT JOIN job_nmpi_job USING (job_id) "
2307+
+ "LEFT JOIN job_nmpi_session USING (job_id) "
22872308
+ "WHERE death_timestamp + :grace_period < UNIX_TIMESTAMP()";
22882309

22892310
/**
@@ -2320,20 +2341,24 @@ public abstract class SQLQueries {
23202341
@Parameter("owner_name")
23212342
@Parameter("group_id")
23222343
@Parameter("group_name")
2344+
@Parameter("nmpi_job_id")
2345+
@Parameter("nmpi_session_id")
23232346
protected static final String WRITE_HISTORICAL_JOBS =
23242347
"INSERT IGNORE INTO jobs( "
23252348
+ "job_id, machine_id, owner, create_timestamp, "
23262349
+ "width, height, depth, root_id, "
23272350
+ "keepalive_interval, keepalive_host, "
23282351
+ "death_reason, death_timestamp, "
23292352
+ "original_request, allocation_timestamp, allocation_size, "
2330-
+ "machine_name, owner_name, group_id, group_name) "
2353+
+ "machine_name, owner_name, group_id, group_name, "
2354+
+ "nmpi_job_id, nmpi_session_id) "
23312355
+ "VALUES(:job_id, :machine_id, :owner, :create_timestamp, "
23322356
+ ":width, :height, :depth, :root_id, "
23332357
+ ":keepalive_interval, :keepalive_host, "
23342358
+ ":death_reason, :death_timestamp, "
23352359
+ ":original_request, :allocation_timestamp, :allocation_size, "
2336-
+ ":machine_name, :owner_name, :group_id, :group_name)";
2360+
+ ":machine_name, :owner_name, :group_id, :group_name, "
2361+
+ ":nmpi_job_id, :nmpi_session_id)";
23372362

23382363
/**
23392364
* Set the NMPI session for a Job.

SpiNNaker-allocserv/src/main/resources/spalloc-tombstone-mysql.sql

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ CREATE TABLE IF NOT EXISTS jobs(
3737
death_timestamp - allocation_timestamp) VIRTUAL,
3838
resources_used INTEGER GENERATED ALWAYS AS ( -- generated column
3939
lifetime_duration * allocation_size) VIRTUAL,
40+
nmpi_job_id INTEGER,
41+
nmpi_session_id INTEGER,
4042
UNIQUE INDEX (job_id ASC)
4143
);
4244

SpiNNaker-allocserv/src/test/java/uk/ac/manchester/spinnaker/alloc/db/DMLTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,8 @@ void readJobsFromHistoricalData() {
758758
"keepalive_host", "death_reason", "death_timestamp",
759759
"original_request", "allocation_timestamp",
760760
"allocation_size", "machine_name", "user_name",
761-
"group_id", "group_name"), q.getColumns());
761+
"group_id", "group_name", "nmpi_job_id",
762+
"nmpi_session_id"), q.getColumns());
762763
assertEquals(empty(), q.call1(Row::toString, A_LONG_TIME));
763764
});
764765
}
@@ -789,11 +790,12 @@ void writeJopsToHistoricalData() {
789790
"keepalive_host", "death_reason", "death_timestamp",
790791
"original_request", "allocation_timestamp",
791792
"allocation_size", "machine_name", "owner_name",
792-
"group_id", "group_name"), q.getParameters());
793+
"group_id", "group_name", "nmpi_job_id",
794+
"nmpi_session_id"), q.getParameters());
793795
assertEquals(1,
794796
q.call(0, 0, "", A_LONG_TIME, 0, 0, 0, 0, A_LONG_TIME,
795797
"", "", A_LONG_TIME, new byte[] {}, A_LONG_TIME,
796-
0, "", "", 0, ""));
798+
0, "", "", 0, "", null, null));
797799
});
798800
}
799801
}

0 commit comments

Comments
 (0)