author | wenzelm |
Wed, 14 Jun 2023 12:10:40 +0200 | |
changeset 78154 | 8a7df40375ae |
parent 78153 | 55a6aa77f3d8 |
child 78156 | da5cc332ded3 |
permissions | -rw-r--r-- |
77238 | 1 |
/* Title: Pure/Tools/build_process.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Build process for sessions, with build database, optional heap, and |
|
5 |
optional presentation. |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
||
77505 | 11 |
import scala.collection.immutable.SortedMap |
77246 | 12 |
import scala.math.Ordering |
77257 | 13 |
import scala.annotation.tailrec |
77246 | 14 |
|
15 |
||
77238 | 16 |
object Build_Process { |
77436 | 17 |
/** static context **/ |
77238 | 18 |
|
77246 | 19 |
object Context { |
20 |
def apply( |
|
21 |
store: Sessions.Store, |
|
77453 | 22 |
build_deps: Sessions.Deps, |
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
23 |
progress: Progress = new Progress, |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
24 |
ml_platform: String = Isabelle_System.getenv("ML_PLATFORM"), |
77378
f047804f4860
clarified Build_Process.Context: cover all static information;
wenzelm
parents:
77375
diff
changeset
|
25 |
hostname: String = Isabelle_System.hostname(), |
f047804f4860
clarified Build_Process.Context: cover all static information;
wenzelm
parents:
77375
diff
changeset
|
26 |
numa_shuffling: Boolean = false, |
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
27 |
build_heap: Boolean = false, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
28 |
max_jobs: Int = 1, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
29 |
fresh_build: Boolean = false, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
30 |
no_build: Boolean = false, |
77378
f047804f4860
clarified Build_Process.Context: cover all static information;
wenzelm
parents:
77375
diff
changeset
|
31 |
session_setup: (String, Session) => Unit = (_, _) => (), |
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
32 |
build_uuid: String = UUID.random().toString, |
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
33 |
master: Boolean = false, |
77246 | 34 |
): Context = { |
77453 | 35 |
val sessions_structure = build_deps.sessions_structure |
77247 | 36 |
val build_graph = sessions_structure.build_graph |
37 |
||
77246 | 38 |
val sessions = |
39 |
Map.from( |
|
77448 | 40 |
for ((name, (info, _)) <- build_graph.iterator) |
77249
f3f1b7ad1d0d
clarified data structure: more direct access to timeout;
wenzelm
parents:
77248
diff
changeset
|
41 |
yield { |
77447
566e6e393126
proper deps from build_graph, not imports_graph (amending 0c704aba71e3);
wenzelm
parents:
77446
diff
changeset
|
42 |
val deps = info.parent.toList |
566e6e393126
proper deps from build_graph, not imports_graph (amending 0c704aba71e3);
wenzelm
parents:
77446
diff
changeset
|
43 |
val ancestors = sessions_structure.build_requirements(deps) |
77458 | 44 |
val sources_shasum = build_deps.sources_shasum(name) |
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
45 |
val session_context = |
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
46 |
Build_Job.Session_Context.load( |
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
47 |
build_uuid, name, deps, ancestors, info.session_prefs, sources_shasum, |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
48 |
info.timeout, store, progress = progress) |
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
49 |
name -> session_context |
77249
f3f1b7ad1d0d
clarified data structure: more direct access to timeout;
wenzelm
parents:
77248
diff
changeset
|
50 |
}) |
77247 | 51 |
|
77248 | 52 |
val sessions_time = { |
53 |
val maximals = build_graph.maximals.toSet |
|
54 |
def descendants_time(name: String): Double = { |
|
55 |
if (maximals.contains(name)) sessions(name).old_time.seconds |
|
56 |
else { |
|
57 |
val descendants = build_graph.all_succs(List(name)).toSet |
|
58 |
val g = build_graph.restrict(descendants) |
|
59 |
(0.0 :: g.maximals.flatMap { desc => |
|
60 |
val ps = g.all_preds(List(desc)) |
|
61 |
if (ps.exists(p => !sessions.isDefinedAt(p))) None |
|
62 |
else Some(ps.map(p => sessions(p).old_time.seconds).sum) |
|
63 |
}).max |
|
64 |
} |
|
77247 | 65 |
} |
77248 | 66 |
Map.from( |
67 |
for (name <- sessions.keysIterator) |
|
68 |
yield name -> descendants_time(name)).withDefaultValue(0.0) |
|
77247 | 69 |
} |
70 |
||
77246 | 71 |
val ordering = |
72 |
new Ordering[String] { |
|
73 |
def compare(name1: String, name2: String): Int = |
|
77248 | 74 |
sessions_time(name2) compare sessions_time(name1) match { |
77246 | 75 |
case 0 => |
77249
f3f1b7ad1d0d
clarified data structure: more direct access to timeout;
wenzelm
parents:
77248
diff
changeset
|
76 |
sessions(name2).timeout compare sessions(name1).timeout match { |
77246 | 77 |
case 0 => name1 compare name2 |
78 |
case ord => ord |
|
79 |
} |
|
80 |
case ord => ord |
|
81 |
} |
|
82 |
} |
|
83 |
||
77477 | 84 |
val numa_nodes = Host.numa_nodes(enabled = numa_shuffling) |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
85 |
new Context(store, build_deps, sessions, ordering, ml_platform, hostname, numa_nodes, |
77317
b8ec3c0455db
clarified modules: NUMA is managed by Build_Process;
wenzelm
parents:
77315
diff
changeset
|
86 |
build_heap = build_heap, max_jobs = max_jobs, fresh_build = fresh_build, |
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
87 |
no_build = no_build, session_setup, build_uuid = build_uuid, master = master) |
77246 | 88 |
} |
89 |
} |
|
90 |
||
91 |
final class Context private( |
|
77257 | 92 |
val store: Sessions.Store, |
77453 | 93 |
val build_deps: Sessions.Deps, |
77496 | 94 |
val sessions: State.Sessions, |
77257 | 95 |
val ordering: Ordering[String], |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
96 |
val ml_platform: String, |
77378
f047804f4860
clarified Build_Process.Context: cover all static information;
wenzelm
parents:
77375
diff
changeset
|
97 |
val hostname: String, |
77317
b8ec3c0455db
clarified modules: NUMA is managed by Build_Process;
wenzelm
parents:
77315
diff
changeset
|
98 |
val numa_nodes: List[Int], |
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
99 |
val build_heap: Boolean, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
100 |
val max_jobs: Int, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
101 |
val fresh_build: Boolean, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
102 |
val no_build: Boolean, |
77378
f047804f4860
clarified Build_Process.Context: cover all static information;
wenzelm
parents:
77375
diff
changeset
|
103 |
val session_setup: (String, Session) => Unit, |
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
104 |
val build_uuid: String, |
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
105 |
val master: Boolean |
77246 | 106 |
) { |
77561 | 107 |
override def toString: String = |
77646 | 108 |
"Build_Process.Context(build_uuid = " + quote(build_uuid) + |
109 |
if_proper(master, ", master = true") + ")" |
|
77561 | 110 |
|
77470 | 111 |
def build_options: Options = store.options |
112 |
||
77453 | 113 |
def sessions_structure: Sessions.Structure = build_deps.sessions_structure |
77257 | 114 |
|
77462 | 115 |
def sources_shasum(name: String): SHA1.Shasum = sessions(name).sources_shasum |
77458 | 116 |
|
77462 | 117 |
def old_command_timings(name: String): List[Properties.T] = |
118 |
sessions.get(name) match { |
|
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
119 |
case Some(session_context) => |
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
120 |
Properties.uncompress(session_context.old_command_timings_blob, cache = store.cache) |
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
121 |
case None => Nil |
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
122 |
} |
77439
d6bf9ec39d12
avoid premature Properties.uncompress: allow blob to be stored in another database;
wenzelm
parents:
77438
diff
changeset
|
123 |
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
124 |
def prepare_database(): Unit = { |
77629 | 125 |
using_option(store.open_build_database()) { db => |
77678
e7d8e990d378
proper vacuum of session_info tables: only once per build process;
wenzelm
parents:
77675
diff
changeset
|
126 |
val shared_db = db.is_postgresql |
78154 | 127 |
db.transaction_lock(Data.all_tables, create = true) { |
77539
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
128 |
Data.clean_build(db) |
77678
e7d8e990d378
proper vacuum of session_info tables: only once per build process;
wenzelm
parents:
77675
diff
changeset
|
129 |
if (shared_db) store.all_tables.create_lock(db) |
77539
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
130 |
} |
77678
e7d8e990d378
proper vacuum of session_info tables: only once per build process;
wenzelm
parents:
77675
diff
changeset
|
131 |
db.vacuum(Data.all_tables ::: (if (shared_db) store.all_tables else SQL.Tables.empty)) |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
132 |
} |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
133 |
} |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
134 |
|
77463 | 135 |
def store_heap(name: String): Boolean = |
77462 | 136 |
build_heap || Sessions.is_pure(name) || |
137 |
sessions.valuesIterator.exists(_.ancestors.contains(name)) |
|
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
138 |
|
77594 | 139 |
def worker_active: Boolean = max_jobs > 0 |
77246 | 140 |
} |
77257 | 141 |
|
142 |
||
77436 | 143 |
|
144 |
/** dynamic state **/ |
|
77257 | 145 |
|
77505 | 146 |
type Progress_Messages = SortedMap[Long, Progress.Message] |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
147 |
val progress_messages_empty: Progress_Messages = SortedMap.empty |
77505 | 148 |
|
77660 | 149 |
case class Build( |
150 |
build_uuid: String, |
|
151 |
ml_platform: String, |
|
152 |
options: String, |
|
153 |
start: Date, |
|
154 |
stop: Option[Date], |
|
155 |
progress_stopped: Boolean |
|
156 |
) |
|
157 |
||
77631 | 158 |
case class Worker( |
159 |
worker_uuid: String, |
|
160 |
build_uuid: String, |
|
161 |
hostname: String, |
|
162 |
java_pid: Long, |
|
163 |
java_start: Date, |
|
164 |
start: Date, |
|
165 |
stamp: Date, |
|
166 |
stop: Option[Date], |
|
167 |
serial: Long |
|
168 |
) |
|
169 |
||
170 |
case class Task( |
|
171 |
name: String, |
|
172 |
deps: List[String], |
|
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
173 |
info: JSON.Object.T, |
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
174 |
build_uuid: String |
77631 | 175 |
) { |
77313
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
176 |
def is_ready: Boolean = deps.isEmpty |
77585 | 177 |
def resolve(dep: String): Task = |
77313
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
178 |
if (deps.contains(dep)) copy(deps = deps.filterNot(_ == dep)) else this |
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
179 |
} |
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
180 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
181 |
case class Job( |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
182 |
name: String, |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
183 |
worker_uuid: String, |
77634 | 184 |
build_uuid: String, |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
185 |
node_info: Host.Node_Info, |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
186 |
build: Option[Build_Job] |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
187 |
) extends Library.Named { |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
188 |
def no_build: Job = copy(build = None) |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
189 |
} |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
190 |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
191 |
case class Result( |
77651 | 192 |
name: String, |
193 |
worker_uuid: String, |
|
194 |
build_uuid: String, |
|
195 |
node_info: Host.Node_Info, |
|
77461 | 196 |
process_result: Process_Result, |
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
197 |
output_shasum: SHA1.Shasum, |
77461 | 198 |
current: Boolean |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
199 |
) extends Library.Named { |
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
200 |
def ok: Boolean = process_result.ok |
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
201 |
} |
77312 | 202 |
|
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
203 |
sealed case class Snapshot( |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
204 |
progress_messages: Progress_Messages, |
77660 | 205 |
builds: List[Build], // available build configurations |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
206 |
workers: List[Worker], // available worker processes |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
207 |
sessions: State.Sessions, // static build targets |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
208 |
pending: State.Pending, // dynamic build "queue" |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
209 |
running: State.Running, // presently running jobs |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
210 |
results: State.Results) // finished results |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
211 |
|
77496 | 212 |
object State { |
213 |
type Sessions = Map[String, Build_Job.Session_Context] |
|
77585 | 214 |
type Pending = List[Task] |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
215 |
type Running = Map[String, Job] |
77496 | 216 |
type Results = Map[String, Result] |
77513 | 217 |
|
218 |
def inc_serial(serial: Long): Long = { |
|
219 |
require(serial < java.lang.Long.MAX_VALUE, "serial overflow") |
|
220 |
serial + 1 |
|
221 |
} |
|
77496 | 222 |
} |
223 |
||
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
224 |
sealed case class State( |
77372 | 225 |
serial: Long = 0, |
77505 | 226 |
progress_seen: Long = 0, |
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
227 |
numa_next: Int = 0, |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
228 |
sessions: State.Sessions = Map.empty, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
229 |
pending: State.Pending = Nil, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
230 |
running: State.Running = Map.empty, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
231 |
results: State.Results = Map.empty |
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
232 |
) { |
77513 | 233 |
require(serial >= 0, "serial underflow") |
234 |
def inc_serial: State = copy(serial = State.inc_serial(serial)) |
|
235 |
def set_serial(i: Long): State = { |
|
236 |
require(serial <= i, "non-monotonic change of serial") |
|
237 |
copy(serial = i) |
|
238 |
} |
|
239 |
||
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
240 |
def progress_serial(message_serial: Long = serial): State = |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
241 |
if (message_serial > progress_seen) copy(progress_seen = message_serial) |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
242 |
else error("Bad serial " + message_serial + " for progress output (already seen)") |
77505 | 243 |
|
77632 | 244 |
def next_numa_node(numa_nodes: List[Int]): (Option[Int], State) = |
77343 | 245 |
if (numa_nodes.isEmpty) (None, this) |
246 |
else { |
|
247 |
val available = numa_nodes.zipWithIndex |
|
77372 | 248 |
val used = |
249 |
Set.from(for (job <- running.valuesIterator; i <- job.node_info.numa_node) yield i) |
|
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
250 |
|
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
251 |
val numa_index = available.collectFirst({ case (n, i) if n == numa_next => i }).getOrElse(0) |
77343 | 252 |
val candidates = available.drop(numa_index) ::: available.take(numa_index) |
253 |
val (n, i) = |
|
254 |
candidates.find({ case (n, i) => i == numa_index && !used(n) }) orElse |
|
255 |
candidates.find({ case (n, _) => !used(n) }) getOrElse candidates.head |
|
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
256 |
|
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
257 |
(Some(n), copy(numa_next = numa_nodes((i + 1) % numa_nodes.length))) |
77343 | 258 |
} |
77337 | 259 |
|
77335 | 260 |
def finished: Boolean = pending.isEmpty |
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
261 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
262 |
def remove_pending(name: String): State = |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
263 |
copy(pending = pending.flatMap( |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
264 |
entry => if (entry.name == name) None else Some(entry.resolve(name)))) |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
265 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
266 |
def is_running(name: String): Boolean = running.isDefinedAt(name) |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
267 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
268 |
def stop_running(): Unit = |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
269 |
for (job <- running.valuesIterator; build <- job.build) build.cancel() |
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
270 |
|
77649 | 271 |
def finished_running(): List[Job] = |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
272 |
List.from( |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
273 |
for (job <- running.valuesIterator; build <- job.build if build.is_finished) |
77649 | 274 |
yield job) |
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
275 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
276 |
def add_running(job: Job): State = |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
277 |
copy(running = running + (job.name -> job)) |
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
278 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
279 |
def remove_running(name: String): State = |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
280 |
copy(running = running - name) |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
281 |
|
77336 | 282 |
def make_result( |
77651 | 283 |
result_name: (String, String, String), |
77461 | 284 |
process_result: Process_Result, |
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
285 |
output_shasum: SHA1.Shasum, |
77475 | 286 |
node_info: Host.Node_Info = Host.Node_Info.none, |
77461 | 287 |
current: Boolean = false |
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
288 |
): State = { |
77651 | 289 |
val (name, worker_uuid, build_uuid) = result_name |
290 |
val result = |
|
291 |
Result(name, worker_uuid, build_uuid, node_info, process_result, output_shasum, current) |
|
292 |
copy(results = results + (name -> result)) |
|
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
293 |
} |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
294 |
} |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
295 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
296 |
|
77436 | 297 |
|
298 |
/** SQL data model **/ |
|
77372 | 299 |
|
300 |
object Data { |
|
301 |
def make_table(name: String, columns: List[SQL.Column], body: String = ""): SQL.Table = |
|
302 |
SQL.Table("isabelle_build" + if_proper(name, "_" + name), columns, body = body) |
|
303 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
304 |
def pull_data[A <: Library.Named]( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
305 |
data_domain: Set[String], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
306 |
data_iterator: Set[String] => Iterator[A], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
307 |
old_data: Map[String, A] |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
308 |
): Map[String, A] = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
309 |
val dom = data_domain -- old_data.keysIterator |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
310 |
val data = old_data -- old_data.keysIterator.filterNot(dom) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
311 |
if (dom.isEmpty) data |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
312 |
else data_iterator(dom).foldLeft(data) { case (map, a) => map + (a.name -> a) } |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
313 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
314 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
315 |
def pull0[A <: Library.Named]( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
316 |
new_data: Map[String, A], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
317 |
old_data: Map[String, A] |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
318 |
): Map[String, A] = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
319 |
pull_data(new_data.keySet, dom => new_data.valuesIterator.filter(a => dom(a.name)), old_data) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
320 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
321 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
322 |
def pull1[A <: Library.Named]( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
323 |
data_domain: Set[String], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
324 |
data_base: Set[String] => Map[String, A], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
325 |
old_data: Map[String, A] |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
326 |
): Map[String, A] = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
327 |
pull_data(data_domain, dom => data_base(dom).valuesIterator, old_data) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
328 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
329 |
|
77372 | 330 |
object Generic { |
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
331 |
val build_uuid = SQL.Column.string("build_uuid") |
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
332 |
val worker_uuid = SQL.Column.string("worker_uuid") |
77372 | 333 |
val name = SQL.Column.string("name") |
334 |
||
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
335 |
def sql( |
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
336 |
build_uuid: String = "", |
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
337 |
worker_uuid: String = "", |
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
338 |
names: Iterable[String] = Nil |
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
339 |
): SQL.Source = |
77372 | 340 |
SQL.and( |
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
341 |
if_proper(build_uuid, Generic.build_uuid.equal(build_uuid)), |
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
342 |
if_proper(worker_uuid, Generic.worker_uuid.equal(worker_uuid)), |
77375 | 343 |
if_proper(names, Generic.name.member(names))) |
77662 | 344 |
|
345 |
def sql_where( |
|
346 |
build_uuid: String = "", |
|
347 |
worker_uuid: String = "", |
|
348 |
names: Iterable[String] = Nil |
|
349 |
): SQL.Source = { |
|
77663 | 350 |
SQL.where(sql(build_uuid = build_uuid, worker_uuid = worker_uuid, names = names)) |
77662 | 351 |
} |
77372 | 352 |
} |
353 |
||
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
354 |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
355 |
/* base table */ |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
356 |
|
77417 | 357 |
object Base { |
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
358 |
val build_uuid = Generic.build_uuid.make_primary_key |
77387
cd10b8edfdf5
clarified db content: avoid redundancy of historic ML_IDENTIFIER;
wenzelm
parents:
77385
diff
changeset
|
359 |
val ml_platform = SQL.Column.string("ml_platform") |
77372 | 360 |
val options = SQL.Column.string("options") |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
361 |
val start = SQL.Column.date("start") |
77545 | 362 |
val stop = SQL.Column.date("stop") |
77635 | 363 |
val progress_stopped = SQL.Column.bool("progress_stopped") |
77372 | 364 |
|
77635 | 365 |
val table = |
366 |
make_table("", List(build_uuid, ml_platform, options, start, stop, progress_stopped)) |
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
367 |
} |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
368 |
|
77660 | 369 |
def read_builds(db: SQL.Database, build_uuid: String = ""): List[Build] = |
370 |
db.execute_query_statement( |
|
77662 | 371 |
Base.table.select(sql = Generic.sql_where(build_uuid = build_uuid)), |
77660 | 372 |
List.from[Build], |
373 |
{ res => |
|
374 |
val build_uuid = res.string(Base.build_uuid) |
|
375 |
val ml_platform = res.string(Base.ml_platform) |
|
376 |
val options = res.string(Base.options) |
|
377 |
val start = res.date(Base.start) |
|
378 |
val stop = res.get_date(Base.stop) |
|
379 |
val progress_stopped = res.bool(Base.progress_stopped) |
|
380 |
Build(build_uuid, ml_platform, options, start, stop, progress_stopped) |
|
381 |
}) |
|
382 |
||
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
383 |
def start_build( |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
384 |
db: SQL.Database, |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
385 |
build_uuid: String, |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
386 |
ml_platform: String, |
77635 | 387 |
options: String, |
388 |
progress_stopped: Boolean |
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
389 |
): Unit = { |
77541 | 390 |
db.execute_statement(Base.table.insert(), body = |
391 |
{ stmt => |
|
392 |
stmt.string(1) = build_uuid |
|
393 |
stmt.string(2) = ml_platform |
|
394 |
stmt.string(3) = options |
|
395 |
stmt.date(4) = db.now() |
|
396 |
stmt.date(5) = None |
|
77635 | 397 |
stmt.bool(6) = progress_stopped |
77541 | 398 |
}) |
77372 | 399 |
} |
400 |
||
77545 | 401 |
def stop_build(db: SQL.Database, build_uuid: String): Unit = |
77541 | 402 |
db.execute_statement( |
77636 | 403 |
Base.table.update(List(Base.stop), sql = Base.build_uuid.where_equal(build_uuid)), |
77541 | 404 |
body = { stmt => stmt.date(1) = db.now() }) |
77538 | 405 |
|
77539
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
406 |
def clean_build(db: SQL.Database): Unit = { |
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
407 |
val old = |
77552 | 408 |
db.execute_query_statement( |
409 |
Base.table.select(List(Base.build_uuid), sql = SQL.where(Base.stop.defined)), |
|
410 |
List.from[String], res => res.string(Base.build_uuid)) |
|
77539
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
411 |
|
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
412 |
if (old.nonEmpty) { |
77658 | 413 |
for (table <- build_uuid_tables) { |
77540 | 414 |
db.execute_statement(table.delete(sql = Generic.build_uuid.where_member(old))) |
77539
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
415 |
} |
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
416 |
} |
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
417 |
} |
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
418 |
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
419 |
|
77531 | 420 |
/* sessions */ |
77505 | 421 |
|
77496 | 422 |
object Sessions { |
423 |
val name = Generic.name.make_primary_key |
|
424 |
val deps = SQL.Column.string("deps") |
|
425 |
val ancestors = SQL.Column.string("ancestors") |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
426 |
val options = SQL.Column.string("options") |
77496 | 427 |
val sources = SQL.Column.string("sources") |
428 |
val timeout = SQL.Column.long("timeout") |
|
429 |
val old_time = SQL.Column.long("old_time") |
|
430 |
val old_command_timings = SQL.Column.bytes("old_command_timings") |
|
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
431 |
val build_uuid = Generic.build_uuid |
77496 | 432 |
|
433 |
val table = make_table("sessions", |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
434 |
List(name, deps, ancestors, options, sources, timeout, |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
435 |
old_time, old_command_timings, build_uuid)) |
77496 | 436 |
} |
437 |
||
438 |
def read_sessions_domain(db: SQL.Database): Set[String] = |
|
77552 | 439 |
db.execute_query_statement( |
440 |
Sessions.table.select(List(Sessions.name)), |
|
441 |
Set.from[String], res => res.string(Sessions.name)) |
|
77496 | 442 |
|
443 |
def read_sessions(db: SQL.Database, names: Iterable[String] = Nil): State.Sessions = |
|
77552 | 444 |
db.execute_query_statement( |
445 |
Sessions.table.select(sql = if_proper(names, Sessions.name.where_member(names))), |
|
446 |
Map.from[String, Build_Job.Session_Context], |
|
447 |
{ res => |
|
448 |
val name = res.string(Sessions.name) |
|
449 |
val deps = split_lines(res.string(Sessions.deps)) |
|
450 |
val ancestors = split_lines(res.string(Sessions.ancestors)) |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
451 |
val options = res.string(Sessions.options) |
77552 | 452 |
val sources_shasum = SHA1.fake_shasum(res.string(Sessions.sources)) |
453 |
val timeout = Time.ms(res.long(Sessions.timeout)) |
|
454 |
val old_time = Time.ms(res.long(Sessions.old_time)) |
|
455 |
val old_command_timings_blob = res.bytes(Sessions.old_command_timings) |
|
456 |
val build_uuid = res.string(Sessions.build_uuid) |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
457 |
name -> Build_Job.Session_Context(name, deps, ancestors, options, sources_shasum, |
77552 | 458 |
timeout, old_time, old_command_timings_blob, build_uuid) |
77496 | 459 |
} |
77552 | 460 |
) |
77496 | 461 |
|
462 |
def update_sessions(db:SQL.Database, sessions: State.Sessions): Boolean = { |
|
463 |
val old_sessions = read_sessions_domain(db) |
|
464 |
val insert = sessions.iterator.filterNot(p => old_sessions.contains(p._1)).toList |
|
465 |
||
466 |
for ((name, session) <- insert) { |
|
77541 | 467 |
db.execute_statement(Sessions.table.insert(), body = |
468 |
{ stmt => |
|
469 |
stmt.string(1) = name |
|
470 |
stmt.string(2) = cat_lines(session.deps) |
|
471 |
stmt.string(3) = cat_lines(session.ancestors) |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
472 |
stmt.string(4) = session.session_prefs |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
473 |
stmt.string(5) = session.sources_shasum.toString |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
474 |
stmt.long(6) = session.timeout.ms |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
475 |
stmt.long(7) = session.old_time.ms |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
476 |
stmt.bytes(8) = session.old_command_timings_blob |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
477 |
stmt.string(9) = session.build_uuid |
77541 | 478 |
}) |
77496 | 479 |
} |
480 |
||
481 |
insert.nonEmpty |
|
482 |
} |
|
483 |
||
77531 | 484 |
|
485 |
/* progress */ |
|
486 |
||
487 |
object Progress { |
|
488 |
val serial = SQL.Column.long("serial").make_primary_key |
|
489 |
val kind = SQL.Column.int("kind") |
|
490 |
val text = SQL.Column.string("text") |
|
491 |
val verbose = SQL.Column.bool("verbose") |
|
492 |
val build_uuid = Generic.build_uuid |
|
493 |
||
494 |
val table = make_table("progress", List(serial, kind, text, verbose, build_uuid)) |
|
495 |
} |
|
496 |
||
497 |
def read_progress(db: SQL.Database, seen: Long = 0, build_uuid: String = ""): Progress_Messages = |
|
77552 | 498 |
db.execute_query_statement( |
77531 | 499 |
Progress.table.select( |
500 |
sql = |
|
78153 | 501 |
SQL.where_and( |
502 |
if (seen <= 0) "" else Progress.serial.ident + " > " + seen, |
|
503 |
Generic.sql(build_uuid = build_uuid))), |
|
77552 | 504 |
SortedMap.from[Long, isabelle.Progress.Message], |
505 |
{ res => |
|
506 |
val serial = res.long(Progress.serial) |
|
507 |
val kind = isabelle.Progress.Kind(res.int(Progress.kind)) |
|
508 |
val text = res.string(Progress.text) |
|
509 |
val verbose = res.bool(Progress.verbose) |
|
510 |
serial -> isabelle.Progress.Message(kind, text, verbose = verbose) |
|
77531 | 511 |
} |
77552 | 512 |
) |
77531 | 513 |
|
514 |
def write_progress( |
|
515 |
db: SQL.Database, |
|
516 |
message_serial: Long, |
|
517 |
message: isabelle.Progress.Message, |
|
518 |
build_uuid: String |
|
519 |
): Unit = { |
|
77541 | 520 |
db.execute_statement(Progress.table.insert(), body = |
521 |
{ stmt => |
|
522 |
stmt.long(1) = message_serial |
|
523 |
stmt.int(2) = message.kind.id |
|
524 |
stmt.string(3) = message.text |
|
525 |
stmt.bool(4) = message.verbose |
|
526 |
stmt.string(5) = build_uuid |
|
527 |
}) |
|
77531 | 528 |
} |
529 |
||
77637 | 530 |
def sync_progress( |
531 |
db: SQL.Database, |
|
532 |
seen: Long, |
|
533 |
build_uuid: String, |
|
534 |
build_progress: Progress |
|
535 |
): (Progress_Messages, Boolean) = { |
|
536 |
require(build_uuid.nonEmpty) |
|
537 |
||
538 |
val messages = read_progress(db, seen = seen, build_uuid = build_uuid) |
|
539 |
||
77635 | 540 |
val stopped_db = |
541 |
db.execute_query_statementO[Boolean]( |
|
542 |
Base.table.select(List(Base.progress_stopped), |
|
543 |
sql = SQL.where(Base.build_uuid.equal(build_uuid))), |
|
544 |
res => res.bool(Base.progress_stopped) |
|
545 |
).getOrElse(false) |
|
546 |
||
547 |
def stop_db(): Unit = |
|
548 |
db.execute_statement( |
|
549 |
Base.table.update( |
|
77636 | 550 |
List(Base.progress_stopped), sql = Base.build_uuid.where_equal(build_uuid)), |
77635 | 551 |
body = { stmt => stmt.bool(1) = true }) |
552 |
||
553 |
val stopped = build_progress.stopped |
|
554 |
||
555 |
if (stopped_db && !stopped) build_progress.stop() |
|
556 |
if (stopped && !stopped_db) stop_db() |
|
77637 | 557 |
|
558 |
(messages, messages.isEmpty && stopped_db == stopped) |
|
77635 | 559 |
} |
560 |
||
77531 | 561 |
|
562 |
/* workers */ |
|
563 |
||
564 |
object Workers { |
|
565 |
val worker_uuid = Generic.worker_uuid.make_primary_key |
|
566 |
val build_uuid = Generic.build_uuid |
|
77584 | 567 |
val hostname = SQL.Column.string("hostname") |
568 |
val java_pid = SQL.Column.long("java_pid") |
|
569 |
val java_start = SQL.Column.date("java_start") |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
570 |
val start = SQL.Column.date("start") |
77531 | 571 |
val stamp = SQL.Column.date("stamp") |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
572 |
val stop = SQL.Column.date("stop") |
77531 | 573 |
val serial = SQL.Column.long("serial") |
574 |
||
77584 | 575 |
val table = make_table("workers", |
576 |
List(worker_uuid, build_uuid, hostname, java_pid, java_start, start, stamp, stop, serial)) |
|
77531 | 577 |
} |
578 |
||
77655 | 579 |
def read_serial(db: SQL.Database): Long = |
580 |
db.execute_query_statementO[Long]( |
|
78151 | 581 |
Workers.table.select(List(Workers.serial.max)), _.long(Workers.serial)).getOrElse(0L) |
77655 | 582 |
|
77586 | 583 |
def read_workers( |
584 |
db: SQL.Database, |
|
585 |
build_uuid: String = "", |
|
586 |
worker_uuid: String = "" |
|
77657
a2a4adc268b8
removed redundant State.workers: directly maintained within the database, using with SQL update;
wenzelm
parents:
77656
diff
changeset
|
587 |
): List[Worker] = { |
77586 | 588 |
db.execute_query_statement( |
77662 | 589 |
Workers.table.select( |
590 |
sql = Generic.sql_where(build_uuid = build_uuid, worker_uuid = worker_uuid)), |
|
77586 | 591 |
List.from[Worker], |
592 |
{ res => |
|
593 |
Worker( |
|
594 |
worker_uuid = res.string(Workers.worker_uuid), |
|
595 |
build_uuid = res.string(Workers.build_uuid), |
|
596 |
hostname = res.string(Workers.hostname), |
|
597 |
java_pid = res.long(Workers.java_pid), |
|
77588
066d5df144f0
assume total operation: ProcessHandle.current().info.startInstant appears to work on all platforms;
wenzelm
parents:
77587
diff
changeset
|
598 |
java_start = res.date(Workers.java_start), |
77586 | 599 |
start = res.date(Workers.start), |
600 |
stamp = res.date(Workers.stamp), |
|
601 |
stop = res.get_date(Workers.stop), |
|
602 |
serial = res.long(Workers.serial)) |
|
603 |
}) |
|
604 |
} |
|
605 |
||
77584 | 606 |
def start_worker( |
607 |
db: SQL.Database, |
|
608 |
worker_uuid: String, |
|
609 |
build_uuid: String, |
|
610 |
hostname: String, |
|
611 |
java_pid: Long, |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
612 |
java_start: Date, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
613 |
serial: Long |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
614 |
): Unit = { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
615 |
def err(msg: String): Nothing = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
616 |
error("Cannot start worker " + worker_uuid + if_proper(msg, "\n" + msg)) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
617 |
|
77552 | 618 |
val build_stop = |
619 |
db.execute_query_statementO( |
|
77636 | 620 |
Base.table.select(List(Base.stop), sql = Base.build_uuid.where_equal(build_uuid)), |
77552 | 621 |
res => res.get_date(Base.stop)) |
622 |
||
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
623 |
build_stop match { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
624 |
case Some(None) => |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
625 |
case Some(Some(_)) => err("for already stopped build process " + build_uuid) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
626 |
case None => err("for unknown build process " + build_uuid) |
77531 | 627 |
} |
628 |
||
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
629 |
db.execute_statement(Workers.table.insert(), body = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
630 |
{ stmt => |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
631 |
val now = db.now() |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
632 |
stmt.string(1) = worker_uuid |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
633 |
stmt.string(2) = build_uuid |
77584 | 634 |
stmt.string(3) = hostname |
635 |
stmt.long(4) = java_pid |
|
636 |
stmt.date(5) = java_start |
|
637 |
stmt.date(6) = now |
|
638 |
stmt.date(7) = now |
|
639 |
stmt.date(8) = None |
|
640 |
stmt.long(9) = serial |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
641 |
}) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
642 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
643 |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
644 |
def stamp_worker( |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
645 |
db: SQL.Database, |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
646 |
worker_uuid: String, |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
647 |
serial: Long, |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
648 |
stop: Boolean = false |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
649 |
): Unit = { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
650 |
val sql = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
651 |
Workers.table.update(List(Workers.stamp, Workers.stop, Workers.serial), |
77636 | 652 |
sql = Workers.worker_uuid.where_equal(worker_uuid)) |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
653 |
db.execute_statement(sql, body = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
654 |
{ stmt => |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
655 |
val now = db.now() |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
656 |
stmt.date(1) = now |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
657 |
stmt.date(2) = if (stop) Some(now) else None |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
658 |
stmt.long(3) = serial |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
659 |
}) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
660 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
661 |
|
77531 | 662 |
|
663 |
/* pending jobs */ |
|
664 |
||
665 |
object Pending { |
|
666 |
val name = Generic.name.make_primary_key |
|
667 |
val deps = SQL.Column.string("deps") |
|
668 |
val info = SQL.Column.string("info") |
|
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
669 |
val build_uuid = Generic.build_uuid |
77531 | 670 |
|
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
671 |
val table = make_table("pending", List(name, deps, info, build_uuid)) |
77531 | 672 |
} |
673 |
||
77585 | 674 |
def read_pending(db: SQL.Database): List[Task] = |
77552 | 675 |
db.execute_query_statement( |
676 |
Pending.table.select(sql = SQL.order_by(List(Pending.name))), |
|
77585 | 677 |
List.from[Task], |
77552 | 678 |
{ res => |
679 |
val name = res.string(Pending.name) |
|
680 |
val deps = res.string(Pending.deps) |
|
681 |
val info = res.string(Pending.info) |
|
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
682 |
val build_uuid = res.string(Pending.build_uuid) |
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
683 |
Task(name, split_lines(deps), JSON.Object.parse(info), build_uuid) |
77552 | 684 |
}) |
77372 | 685 |
|
77496 | 686 |
def update_pending(db: SQL.Database, pending: State.Pending): Boolean = { |
77372 | 687 |
val old_pending = read_pending(db) |
688 |
val (delete, insert) = Library.symmetric_difference(old_pending, pending) |
|
689 |
||
690 |
if (delete.nonEmpty) { |
|
77540 | 691 |
db.execute_statement( |
77662 | 692 |
Pending.table.delete(sql = Generic.sql_where(names = delete.map(_.name)))) |
77372 | 693 |
} |
694 |
||
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
695 |
for (task <- insert) { |
77541 | 696 |
db.execute_statement(Pending.table.insert(), body = |
697 |
{ stmt => |
|
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
698 |
stmt.string(1) = task.name |
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
699 |
stmt.string(2) = cat_lines(task.deps) |
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
700 |
stmt.string(3) = JSON.Format(task.info) |
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
701 |
stmt.string(4) = task.build_uuid |
77541 | 702 |
}) |
77372 | 703 |
} |
704 |
||
705 |
delete.nonEmpty || insert.nonEmpty |
|
706 |
} |
|
707 |
||
77531 | 708 |
|
709 |
/* running jobs */ |
|
710 |
||
711 |
object Running { |
|
712 |
val name = Generic.name.make_primary_key |
|
77587 | 713 |
val worker_uuid = Generic.worker_uuid |
77634 | 714 |
val build_uuid = Generic.build_uuid |
77531 | 715 |
val hostname = SQL.Column.string("hostname") |
716 |
val numa_node = SQL.Column.int("numa_node") |
|
717 |
||
77634 | 718 |
val table = make_table("running", List(name, worker_uuid, build_uuid, hostname, numa_node)) |
77531 | 719 |
} |
720 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
721 |
def read_running(db: SQL.Database): State.Running = |
77552 | 722 |
db.execute_query_statement( |
723 |
Running.table.select(sql = SQL.order_by(List(Running.name))), |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
724 |
Map.from[String, Job], |
77552 | 725 |
{ res => |
726 |
val name = res.string(Running.name) |
|
77587 | 727 |
val worker_uuid = res.string(Running.worker_uuid) |
77634 | 728 |
val build_uuid = res.string(Running.build_uuid) |
77552 | 729 |
val hostname = res.string(Running.hostname) |
730 |
val numa_node = res.get_int(Running.numa_node) |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
731 |
name -> Job(name, worker_uuid, build_uuid, Host.Node_Info(hostname, numa_node), None) |
77552 | 732 |
} |
733 |
) |
|
77372 | 734 |
|
77496 | 735 |
def update_running(db: SQL.Database, running: State.Running): Boolean = { |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
736 |
val running0 = read_running(db).valuesIterator.toList |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
737 |
val running1 = running.valuesIterator.map(_.no_build).toList |
77372 | 738 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
739 |
val (delete, insert) = Library.symmetric_difference(running0, running1) |
77372 | 740 |
|
741 |
if (delete.nonEmpty) { |
|
77540 | 742 |
db.execute_statement( |
77662 | 743 |
Running.table.delete(sql = Generic.sql_where(names = delete.map(_.name)))) |
77372 | 744 |
} |
745 |
||
746 |
for (job <- insert) { |
|
77541 | 747 |
db.execute_statement(Running.table.insert(), body = |
748 |
{ stmt => |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
749 |
stmt.string(1) = job.name |
77587 | 750 |
stmt.string(2) = job.worker_uuid |
77634 | 751 |
stmt.string(3) = job.build_uuid |
752 |
stmt.string(4) = job.node_info.hostname |
|
753 |
stmt.int(5) = job.node_info.numa_node |
|
77541 | 754 |
}) |
77372 | 755 |
} |
756 |
||
757 |
delete.nonEmpty || insert.nonEmpty |
|
758 |
} |
|
759 |
||
77531 | 760 |
|
761 |
/* job results */ |
|
762 |
||
763 |
object Results { |
|
764 |
val name = Generic.name.make_primary_key |
|
77651 | 765 |
val worker_uuid = Generic.worker_uuid |
766 |
val build_uuid = Generic.build_uuid |
|
77531 | 767 |
val hostname = SQL.Column.string("hostname") |
768 |
val numa_node = SQL.Column.string("numa_node") |
|
769 |
val rc = SQL.Column.int("rc") |
|
770 |
val out = SQL.Column.string("out") |
|
771 |
val err = SQL.Column.string("err") |
|
772 |
val timing_elapsed = SQL.Column.long("timing_elapsed") |
|
773 |
val timing_cpu = SQL.Column.long("timing_cpu") |
|
774 |
val timing_gc = SQL.Column.long("timing_gc") |
|
77651 | 775 |
val output_shasum = SQL.Column.string("output_shasum") |
776 |
val current = SQL.Column.bool("current") |
|
77531 | 777 |
|
778 |
val table = |
|
779 |
make_table("results", |
|
77651 | 780 |
List(name, worker_uuid, build_uuid, hostname, numa_node, |
781 |
rc, out, err, timing_elapsed, timing_cpu, timing_gc, output_shasum, current)) |
|
77531 | 782 |
} |
783 |
||
77496 | 784 |
def read_results_domain(db: SQL.Database): Set[String] = |
77552 | 785 |
db.execute_query_statement( |
786 |
Results.table.select(List(Results.name)), |
|
787 |
Set.from[String], res => res.string(Results.name)) |
|
77496 | 788 |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
789 |
def read_results(db: SQL.Database, names: Iterable[String] = Nil): State.Results = |
77552 | 790 |
db.execute_query_statement( |
791 |
Results.table.select(sql = if_proper(names, Results.name.where_member(names))), |
|
77651 | 792 |
Map.from[String, Result], |
77552 | 793 |
{ res => |
794 |
val name = res.string(Results.name) |
|
77651 | 795 |
val worker_uuid = res.string(Results.worker_uuid) |
796 |
val build_uuid = res.string(Results.build_uuid) |
|
77552 | 797 |
val hostname = res.string(Results.hostname) |
798 |
val numa_node = res.get_int(Results.numa_node) |
|
77651 | 799 |
val node_info = Host.Node_Info(hostname, numa_node) |
800 |
||
77552 | 801 |
val rc = res.int(Results.rc) |
802 |
val out = res.string(Results.out) |
|
803 |
val err = res.string(Results.err) |
|
804 |
val timing = |
|
805 |
res.timing( |
|
806 |
Results.timing_elapsed, |
|
807 |
Results.timing_cpu, |
|
808 |
Results.timing_gc) |
|
809 |
val process_result = |
|
810 |
Process_Result(rc, |
|
811 |
out_lines = split_lines(out), |
|
812 |
err_lines = split_lines(err), |
|
813 |
timing = timing) |
|
77651 | 814 |
|
815 |
val output_shasum = SHA1.fake_shasum(res.string(Results.output_shasum)) |
|
816 |
val current = res.bool(Results.current) |
|
817 |
||
818 |
name -> |
|
819 |
Result(name, worker_uuid, build_uuid, node_info, process_result, output_shasum, current) |
|
77496 | 820 |
} |
77552 | 821 |
) |
77372 | 822 |
|
77496 | 823 |
def update_results(db: SQL.Database, results: State.Results): Boolean = { |
824 |
val old_results = read_results_domain(db) |
|
77651 | 825 |
val insert = results.valuesIterator.filterNot(res => old_results.contains(res.name)).toList |
77372 | 826 |
|
77651 | 827 |
for (result <- insert) { |
77372 | 828 |
val process_result = result.process_result |
77541 | 829 |
db.execute_statement(Results.table.insert(), body = |
830 |
{ stmt => |
|
77651 | 831 |
stmt.string(1) = result.name |
832 |
stmt.string(2) = result.worker_uuid |
|
833 |
stmt.string(3) = result.build_uuid |
|
834 |
stmt.string(4) = result.node_info.hostname |
|
835 |
stmt.int(5) = result.node_info.numa_node |
|
836 |
stmt.int(6) = process_result.rc |
|
837 |
stmt.string(7) = cat_lines(process_result.out_lines) |
|
838 |
stmt.string(8) = cat_lines(process_result.err_lines) |
|
839 |
stmt.long(9) = process_result.timing.elapsed.ms |
|
840 |
stmt.long(10) = process_result.timing.cpu.ms |
|
841 |
stmt.long(11) = process_result.timing.gc.ms |
|
842 |
stmt.string(12) = result.output_shasum.toString |
|
843 |
stmt.bool(13) = result.current |
|
77541 | 844 |
}) |
77372 | 845 |
} |
846 |
||
847 |
insert.nonEmpty |
|
848 |
} |
|
849 |
||
77531 | 850 |
|
851 |
/* collective operations */ |
|
852 |
||
77596 | 853 |
val all_tables: SQL.Tables = |
854 |
SQL.Tables( |
|
77534 | 855 |
Base.table, |
856 |
Workers.table, |
|
857 |
Progress.table, |
|
858 |
Sessions.table, |
|
859 |
Pending.table, |
|
860 |
Running.table, |
|
861 |
Results.table, |
|
862 |
Host.Data.Node_Info.table) |
|
863 |
||
77658 | 864 |
val build_uuid_tables = |
865 |
all_tables.filter(table => |
|
866 |
table.columns.exists(column => column.name == Generic.build_uuid.name)) |
|
867 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
868 |
def pull_database( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
869 |
db: SQL.Database, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
870 |
worker_uuid: String, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
871 |
hostname: String, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
872 |
state: State |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
873 |
): State = { |
77655 | 874 |
val serial_db = read_serial(db) |
875 |
if (serial_db == state.serial) state |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
876 |
else { |
77655 | 877 |
val serial = serial_db max state.serial |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
878 |
stamp_worker(db, worker_uuid, serial) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
879 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
880 |
val numa_next = Host.Data.read_numa_next(db, hostname) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
881 |
val sessions = pull1(read_sessions_domain(db), read_sessions(db, _), state.sessions) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
882 |
val pending = read_pending(db) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
883 |
val running = pull0(read_running(db), state.running) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
884 |
val results = pull1(read_results_domain(db), read_results(db, _), state.results) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
885 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
886 |
state.copy(serial = serial, numa_next = numa_next, sessions = sessions, |
77657
a2a4adc268b8
removed redundant State.workers: directly maintained within the database, using with SQL update;
wenzelm
parents:
77656
diff
changeset
|
887 |
pending = pending, running = running, results = results) |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
888 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
889 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
890 |
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
891 |
def update_database( |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
892 |
db: SQL.Database, |
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
893 |
worker_uuid: String, |
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77527
diff
changeset
|
894 |
build_uuid: String, |
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
895 |
hostname: String, |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
896 |
state: State |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
897 |
): State = { |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
898 |
val changed = |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
899 |
List( |
77496 | 900 |
update_sessions(db, state.sessions), |
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
901 |
update_pending(db, state.pending), |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
902 |
update_running(db, state.running), |
77476 | 903 |
update_results(db, state.results), |
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
904 |
Host.Data.update_numa_next(db, hostname, state.numa_next)) |
77372 | 905 |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
906 |
val serial0 = state.serial |
77513 | 907 |
val serial = if (changed.exists(identity)) State.inc_serial(serial0) else serial0 |
77372 | 908 |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
909 |
stamp_worker(db, worker_uuid, serial) |
77657
a2a4adc268b8
removed redundant State.workers: directly maintained within the database, using with SQL update;
wenzelm
parents:
77656
diff
changeset
|
910 |
state.set_serial(serial) |
77372 | 911 |
} |
912 |
} |
|
77396 | 913 |
} |
77372 | 914 |
|
915 |
||
77436 | 916 |
|
917 |
/** main process **/ |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
918 |
|
77505 | 919 |
class Build_Process( |
77530 | 920 |
protected final val build_context: Build_Process.Context, |
921 |
protected final val build_progress: Progress |
|
77505 | 922 |
) |
77436 | 923 |
extends AutoCloseable { |
924 |
/* context */ |
|
925 |
||
77530 | 926 |
protected final val store: Sessions.Store = build_context.store |
927 |
protected final val build_options: Options = store.options |
|
928 |
protected final val build_deps: Sessions.Deps = build_context.build_deps |
|
77653 | 929 |
protected final val hostname: String = build_context.hostname |
77530 | 930 |
protected final val build_uuid: String = build_context.build_uuid |
931 |
protected final val worker_uuid: String = UUID.random().toString |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
932 |
|
77638 | 933 |
override def toString: String = |
934 |
"Build_Process(worker_uuid = " + quote(worker_uuid) + ", build_uuid = " + quote(build_uuid) + |
|
935 |
if_proper(build_context.master, ", master = true") + ")" |
|
936 |
||
77436 | 937 |
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
938 |
/* global state: internal var vs. external database */ |
77436 | 939 |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
940 |
private var _state: Build_Process.State = Build_Process.State() |
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
941 |
|
77629 | 942 |
private val _database: Option[SQL.Database] = store.open_build_database() |
77372 | 943 |
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
944 |
def close(): Unit = synchronized { _database.foreach(_.close()) } |
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
945 |
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
946 |
protected def synchronized_database[A](body: => A): A = |
77438 | 947 |
synchronized { |
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
948 |
_database match { |
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
949 |
case None => body |
77635 | 950 |
case Some(db) => |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
951 |
def pull_database(): Unit = { |
77653 | 952 |
_state = Build_Process.Data.pull_database(db, worker_uuid, hostname, _state) |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
953 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
954 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
955 |
def sync_database(): Unit = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
956 |
_state = |
77653 | 957 |
Build_Process.Data.update_database(db, worker_uuid, build_uuid, hostname, _state) |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
958 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
959 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
960 |
def attempt(): Either[A, Build_Process.Progress_Messages] = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
961 |
val (messages, sync) = |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
962 |
Build_Process.Data.sync_progress( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
963 |
db, _state.progress_seen, build_uuid, build_progress) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
964 |
if (sync) Left { pull_database(); val res = body; sync_database(); res } |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
965 |
else Right(messages) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
966 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
967 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
968 |
@tailrec def attempts(): A = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
969 |
db.transaction_lock(Build_Process.Data.all_tables) { attempt() } match { |
77637 | 970 |
case Left(res) => res |
971 |
case Right(messages) => |
|
972 |
for ((message_serial, message) <- messages) { |
|
973 |
_state = _state.progress_serial(message_serial = message_serial) |
|
974 |
if (build_progress.do_output(message)) build_progress.output(message) |
|
975 |
} |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
976 |
attempts() |
77637 | 977 |
} |
77635 | 978 |
} |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
979 |
attempts() |
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
980 |
} |
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
981 |
} |
77436 | 982 |
|
983 |
||
77505 | 984 |
/* progress backed by database */ |
985 |
||
77533 | 986 |
private def progress_output(message: Progress.Message, build_progress_output: => Unit): Unit = { |
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
987 |
synchronized_database { |
77640 | 988 |
_state = _state.inc_serial.progress_serial() |
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
989 |
for (db <- _database) { |
77640 | 990 |
Build_Process.Data.write_progress(db, _state.serial, message, build_uuid) |
991 |
Build_Process.Data.stamp_worker(db, worker_uuid, _state.serial) |
|
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
992 |
} |
77533 | 993 |
build_progress_output |
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
994 |
} |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
995 |
} |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
996 |
|
77530 | 997 |
protected object progress extends Progress { |
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77505
diff
changeset
|
998 |
override def verbose: Boolean = build_progress.verbose |
77505 | 999 |
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77505
diff
changeset
|
1000 |
override def output(message: Progress.Message): Unit = |
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
1001 |
progress_output(message, if (do_output(message)) build_progress.output(message)) |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
1002 |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
1003 |
override def theory(theory: Progress.Theory): Unit = |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
1004 |
progress_output(theory.message, build_progress.theory(theory)) |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
1005 |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
1006 |
override def nodes_status(nodes_status: Document_Status.Nodes_Status): Unit = |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
1007 |
build_progress.nodes_status(nodes_status) |
77505 | 1008 |
|
1009 |
override def stop(): Unit = build_progress.stop() |
|
1010 |
override def stopped: Boolean = build_progress.stopped |
|
1011 |
} |
|
1012 |
||
77530 | 1013 |
protected val log: Logger = Logger.make_system_log(progress, build_options) |
77505 | 1014 |
|
1015 |
||
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1016 |
/* policy operations */ |
77333 | 1017 |
|
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
1018 |
protected def init_state(state: Build_Process.State): Build_Process.State = { |
77496 | 1019 |
val sessions1 = |
1020 |
build_context.sessions.foldLeft(state.sessions) { case (map, (name, session)) => |
|
1021 |
if (state.sessions.isDefinedAt(name)) map |
|
1022 |
else map + (name -> session) |
|
1023 |
} |
|
1024 |
||
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
1025 |
val old_pending = state.pending.iterator.map(_.name).toSet |
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
1026 |
val new_pending = |
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
1027 |
List.from( |
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
1028 |
for { |
77449 | 1029 |
(name, session_context) <- build_context.sessions.iterator |
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
1030 |
if !old_pending(name) |
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
1031 |
} yield Build_Process.Task(name, session_context.deps, JSON.Object.empty, build_uuid)) |
77496 | 1032 |
val pending1 = new_pending ::: state.pending |
1033 |
||
1034 |
state.copy(sessions = sessions1, pending = pending1) |
|
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
1035 |
} |
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
1036 |
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1037 |
protected def next_job(state: Build_Process.State): Option[String] = |
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
1038 |
if (progress.stopped || state.running.size < build_context.max_jobs) { |
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1039 |
state.pending.filter(entry => entry.is_ready && !state.is_running(entry.name)) |
77313
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
1040 |
.sortBy(_.name)(build_context.ordering) |
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
1041 |
.headOption.map(_.name) |
77296
eeaa2872320b
clarified signature: more explicit synchronized operations;
wenzelm
parents:
77295
diff
changeset
|
1042 |
} |
eeaa2872320b
clarified signature: more explicit synchronized operations;
wenzelm
parents:
77295
diff
changeset
|
1043 |
else None |
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
1044 |
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1045 |
protected def start_session(state: Build_Process.State, session_name: String): Build_Process.State = { |
77468 | 1046 |
val ancestor_results = |
1047 |
for (a <- build_context.sessions(session_name).ancestors) yield state.results(a) |
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1048 |
|
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
1049 |
val input_shasum = |
77650 | 1050 |
if (ancestor_results.isEmpty) ML_Process.bootstrap_shasum() |
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
1051 |
else SHA1.flat_shasum(ancestor_results.map(_.output_shasum)) |
77257 | 1052 |
|
77463 | 1053 |
val store_heap = build_context.store_heap(session_name) |
77469 | 1054 |
|
1055 |
val (current, output_shasum) = |
|
1056 |
store.check_output(session_name, |
|
77675
9e5f8f6e58a0
more thorough treatment of build prefs, guarded by system option "build_through": avoid accidental rebuild of HOL etc.;
wenzelm
parents:
77664
diff
changeset
|
1057 |
session_options = build_context.sessions_structure(session_name).options, |
77469 | 1058 |
sources_shasum = build_context.sources_shasum(session_name), |
1059 |
input_shasum = input_shasum, |
|
1060 |
fresh_build = build_context.fresh_build, |
|
1061 |
store_heap = store_heap) |
|
1062 |
||
77260 | 1063 |
val all_current = current && ancestor_results.forall(_.current) |
77257 | 1064 |
|
77651 | 1065 |
val result_name = (session_name, worker_uuid, build_uuid) |
1066 |
||
77260 | 1067 |
if (all_current) { |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1068 |
state |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1069 |
.remove_pending(session_name) |
77651 | 1070 |
.make_result(result_name, Process_Result.ok, output_shasum, current = true) |
77260 | 1071 |
} |
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
1072 |
else if (build_context.no_build) { |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77514
diff
changeset
|
1073 |
progress.echo("Skipping " + session_name + " ...", verbose = true) |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1074 |
state. |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1075 |
remove_pending(session_name). |
77651 | 1076 |
make_result(result_name, Process_Result.error, output_shasum) |
77260 | 1077 |
} |
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
1078 |
else if (progress.stopped || !ancestor_results.forall(_.ok)) { |
77452 | 1079 |
progress.echo(session_name + " CANCELLED") |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1080 |
state |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1081 |
.remove_pending(session_name) |
77651 | 1082 |
.make_result(result_name, Process_Result.undefined, output_shasum) |
77452 | 1083 |
} |
1084 |
else { |
|
77632 | 1085 |
val (numa_node, state1) = state.next_numa_node(build_context.numa_nodes) |
77653 | 1086 |
val node_info = Host.Node_Info(hostname, numa_node) |
77551 | 1087 |
|
1088 |
progress.echo( |
|
1089 |
(if (store_heap) "Building " else "Running ") + session_name + |
|
1090 |
if_proper(node_info.numa_node, " on " + node_info) + " ...") |
|
77260 | 1091 |
|
77472 | 1092 |
store.init_output(session_name) |
77257 | 1093 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
1094 |
val build = |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
1095 |
Build_Job.start_session(build_context, progress, log, |
77505 | 1096 |
build_deps.background(session_name), input_shasum, node_info) |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
1097 |
|
77634 | 1098 |
val job = Build_Process.Job(session_name, worker_uuid, build_uuid, node_info, Some(build)) |
1099 |
||
1100 |
state1.add_running(job) |
|
77260 | 1101 |
} |
1102 |
} |
|
77257 | 1103 |
|
77436 | 1104 |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1105 |
/* build process roles */ |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1106 |
|
77654 | 1107 |
final def is_session_name(job_name: String): Boolean = |
1108 |
!Long_Name.is_qualified(job_name) |
|
77648 | 1109 |
|
77654 | 1110 |
protected final def start_build(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1111 |
for (db <- _database) { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1112 |
Build_Process.Data.start_build(db, build_uuid, build_context.ml_platform, |
77635 | 1113 |
build_context.sessions_structure.session_prefs, progress.stopped) |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1114 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1115 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1116 |
|
77654 | 1117 |
protected final def stop_build(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1118 |
for (db <- _database) { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1119 |
Build_Process.Data.stop_build(db, build_uuid) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1120 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1121 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1122 |
|
77654 | 1123 |
protected final def start_worker(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1124 |
for (db <- _database) { |
77584 | 1125 |
val java = ProcessHandle.current() |
1126 |
val java_pid = java.pid |
|
77588
066d5df144f0
assume total operation: ProcessHandle.current().info.startInstant appears to work on all platforms;
wenzelm
parents:
77587
diff
changeset
|
1127 |
val java_start = Date.instant(java.info.startInstant.get) |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1128 |
_state = _state.inc_serial |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1129 |
Build_Process.Data.start_worker( |
77653 | 1130 |
db, worker_uuid, build_uuid, hostname, java_pid, java_start, _state.serial) |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1131 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1132 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1133 |
|
77654 | 1134 |
protected final def stop_worker(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1135 |
for (db <- _database) { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1136 |
Build_Process.Data.stamp_worker(db, worker_uuid, _state.serial, stop = true) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1137 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1138 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1139 |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1140 |
|
77436 | 1141 |
/* run */ |
77372 | 1142 |
|
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
1143 |
def run(): Map[String, Process_Result] = { |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1144 |
if (build_context.master) synchronized_database { _state = init_state(_state) } |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1145 |
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
1146 |
def finished(): Boolean = synchronized_database { _state.finished } |
77400
f3e5b3fe230e
clarified signature: more explicit "synchronized" regions;
wenzelm
parents:
77398
diff
changeset
|
1147 |
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1148 |
def sleep(): Unit = |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1149 |
Isabelle_Thread.interrupt_handler(_ => progress.stop()) { |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1150 |
build_options.seconds("editor_input_delay").sleep() |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1151 |
} |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1152 |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1153 |
def start_job(): Boolean = synchronized_database { |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1154 |
next_job(_state) match { |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1155 |
case Some(name) => |
77648 | 1156 |
if (is_session_name(name)) { |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1157 |
_state = start_session(_state, name) |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1158 |
true |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1159 |
} |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1160 |
else error("Unsupported build job name " + quote(name)) |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1161 |
case None => false |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1162 |
} |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1163 |
} |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1164 |
|
77335 | 1165 |
if (finished()) { |
1166 |
progress.echo_warning("Nothing to build") |
|
1167 |
Map.empty[String, Process_Result] |
|
1168 |
} |
|
1169 |
else { |
|
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
1170 |
if (build_context.master) start_build() |
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
1171 |
|
77580
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1172 |
start_worker() |
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1173 |
if (build_context.master && !build_context.worker_active) { |
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1174 |
progress.echo("Waiting for external workers ...") |
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1175 |
} |
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
1176 |
|
77538 | 1177 |
try { |
1178 |
while (!finished()) { |
|
77639 | 1179 |
synchronized_database { |
1180 |
if (progress.stopped) _state.stop_running() |
|
77310 | 1181 |
|
77649 | 1182 |
for (job <- _state.finished_running()) { |
77651 | 1183 |
val result_name = (job.name, worker_uuid, build_uuid) |
77649 | 1184 |
val (process_result, output_shasum) = job.build.get.join |
77538 | 1185 |
_state = _state. |
77649 | 1186 |
remove_pending(job.name). |
1187 |
remove_running(job.name). |
|
77651 | 1188 |
make_result(result_name, process_result, output_shasum, node_info = job.node_info) |
77538 | 1189 |
} |
1190 |
} |
|
1191 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1192 |
if (!start_job()) sleep() |
77396 | 1193 |
} |
77310 | 1194 |
} |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1195 |
finally { |
77580
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1196 |
stop_worker() |
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
1197 |
if (build_context.master) stop_build() |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1198 |
} |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1199 |
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
1200 |
synchronized_database { |
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
1201 |
for ((name, result) <- _state.results) yield name -> result.process_result |
77257 | 1202 |
} |
1203 |
} |
|
1204 |
} |
|
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1205 |
|
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1206 |
|
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1207 |
/* snapshot */ |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1208 |
|
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1209 |
def snapshot(): Build_Process.Snapshot = synchronized_database { |
77660 | 1210 |
val (progress_messages, builds, workers) = |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1211 |
_database match { |
77660 | 1212 |
case None => (Build_Process.progress_messages_empty, Nil, Nil) |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1213 |
case Some(db) => |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1214 |
(Build_Process.Data.read_progress(db), |
77660 | 1215 |
Build_Process.Data.read_builds(db), |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1216 |
Build_Process.Data.read_workers(db)) |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1217 |
} |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1218 |
Build_Process.Snapshot( |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1219 |
progress_messages = progress_messages, |
77660 | 1220 |
builds = builds, |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1221 |
workers = workers, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1222 |
sessions = _state.sessions, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1223 |
pending = _state.pending, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1224 |
running = _state.running, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1225 |
results = _state.results) |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1226 |
} |
77238 | 1227 |
} |