author | wenzelm |
Thu, 15 Jun 2023 22:09:56 +0200 | |
changeset 78168 | 8fbe3b3d665b |
parent 78166 | 70041580b81e |
child 78170 | c85eeff78b33 |
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 = { |
78168 | 125 |
using_option(store.maybe_open_build_database(Data.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) |
78166 | 129 |
if (shared_db) store.all_tables.lock(db, 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
|
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 |
|
77660 | 146 |
case class Build( |
147 |
build_uuid: String, |
|
148 |
ml_platform: String, |
|
149 |
options: String, |
|
150 |
start: Date, |
|
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
151 |
stop: Option[Date] |
77660 | 152 |
) |
153 |
||
77631 | 154 |
case class Worker( |
155 |
worker_uuid: String, |
|
156 |
build_uuid: String, |
|
157 |
hostname: String, |
|
158 |
java_pid: Long, |
|
159 |
java_start: Date, |
|
160 |
start: Date, |
|
161 |
stamp: Date, |
|
162 |
stop: Option[Date], |
|
163 |
serial: Long |
|
164 |
) |
|
165 |
||
166 |
case class Task( |
|
167 |
name: String, |
|
168 |
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
|
169 |
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
|
170 |
build_uuid: String |
77631 | 171 |
) { |
77313
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
172 |
def is_ready: Boolean = deps.isEmpty |
77585 | 173 |
def resolve(dep: String): Task = |
77313
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
174 |
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
|
175 |
} |
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
176 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
177 |
case class Job( |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
178 |
name: String, |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
179 |
worker_uuid: String, |
77634 | 180 |
build_uuid: String, |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
181 |
node_info: Host.Node_Info, |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
182 |
build: Option[Build_Job] |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
183 |
) extends Library.Named { |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
184 |
def no_build: Job = copy(build = None) |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
185 |
} |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
186 |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
187 |
case class Result( |
77651 | 188 |
name: String, |
189 |
worker_uuid: String, |
|
190 |
build_uuid: String, |
|
191 |
node_info: Host.Node_Info, |
|
77461 | 192 |
process_result: Process_Result, |
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
193 |
output_shasum: SHA1.Shasum, |
77461 | 194 |
current: Boolean |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
195 |
) 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
|
196 |
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
|
197 |
} |
77312 | 198 |
|
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
199 |
sealed case class Snapshot( |
77660 | 200 |
builds: List[Build], // available build configurations |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
201 |
workers: List[Worker], // available worker processes |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
202 |
sessions: State.Sessions, // static build targets |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
203 |
pending: State.Pending, // dynamic build "queue" |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
204 |
running: State.Running, // presently running jobs |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
205 |
results: State.Results) // finished results |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
206 |
|
77496 | 207 |
object State { |
208 |
type Sessions = Map[String, Build_Job.Session_Context] |
|
77585 | 209 |
type Pending = List[Task] |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
210 |
type Running = Map[String, Job] |
77496 | 211 |
type Results = Map[String, Result] |
77513 | 212 |
|
213 |
def inc_serial(serial: Long): Long = { |
|
214 |
require(serial < java.lang.Long.MAX_VALUE, "serial overflow") |
|
215 |
serial + 1 |
|
216 |
} |
|
77496 | 217 |
} |
218 |
||
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
219 |
sealed case class State( |
77372 | 220 |
serial: Long = 0, |
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
221 |
numa_next: Int = 0, |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
222 |
sessions: State.Sessions = Map.empty, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
223 |
pending: State.Pending = Nil, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
224 |
running: State.Running = Map.empty, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
225 |
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
|
226 |
) { |
77513 | 227 |
require(serial >= 0, "serial underflow") |
228 |
def inc_serial: State = copy(serial = State.inc_serial(serial)) |
|
229 |
def set_serial(i: Long): State = { |
|
230 |
require(serial <= i, "non-monotonic change of serial") |
|
231 |
copy(serial = i) |
|
232 |
} |
|
233 |
||
77632 | 234 |
def next_numa_node(numa_nodes: List[Int]): (Option[Int], State) = |
77343 | 235 |
if (numa_nodes.isEmpty) (None, this) |
236 |
else { |
|
237 |
val available = numa_nodes.zipWithIndex |
|
77372 | 238 |
val used = |
239 |
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
|
240 |
|
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
241 |
val numa_index = available.collectFirst({ case (n, i) if n == numa_next => i }).getOrElse(0) |
77343 | 242 |
val candidates = available.drop(numa_index) ::: available.take(numa_index) |
243 |
val (n, i) = |
|
244 |
candidates.find({ case (n, i) => i == numa_index && !used(n) }) orElse |
|
245 |
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
|
246 |
|
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
247 |
(Some(n), copy(numa_next = numa_nodes((i + 1) % numa_nodes.length))) |
77343 | 248 |
} |
77337 | 249 |
|
77335 | 250 |
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
|
251 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
256 |
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
|
257 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
258 |
def stop_running(): Unit = |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
259 |
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
|
260 |
|
77649 | 261 |
def finished_running(): List[Job] = |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
262 |
List.from( |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
263 |
for (job <- running.valuesIterator; build <- job.build if build.is_finished) |
77649 | 264 |
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
|
265 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
266 |
def add_running(job: Job): State = |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
267 |
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
|
268 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
|
77336 | 272 |
def make_result( |
77651 | 273 |
result_name: (String, String, String), |
77461 | 274 |
process_result: Process_Result, |
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
275 |
output_shasum: SHA1.Shasum, |
77475 | 276 |
node_info: Host.Node_Info = Host.Node_Info.none, |
77461 | 277 |
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
|
278 |
): State = { |
77651 | 279 |
val (name, worker_uuid, build_uuid) = result_name |
280 |
val result = |
|
281 |
Result(name, worker_uuid, build_uuid, node_info, process_result, output_shasum, current) |
|
282 |
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
|
283 |
} |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
284 |
} |
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
285 |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
286 |
|
77436 | 287 |
|
288 |
/** SQL data model **/ |
|
77372 | 289 |
|
290 |
object Data { |
|
78168 | 291 |
val database: Path = Path.explode("$ISABELLE_HOME_USER/build.db") |
292 |
||
77372 | 293 |
def make_table(name: String, columns: List[SQL.Column], body: String = ""): SQL.Table = |
294 |
SQL.Table("isabelle_build" + if_proper(name, "_" + name), columns, body = body) |
|
295 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
296 |
def pull_data[A <: Library.Named]( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
297 |
data_domain: Set[String], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
298 |
data_iterator: Set[String] => Iterator[A], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
299 |
old_data: Map[String, A] |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
300 |
): Map[String, A] = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
301 |
val dom = data_domain -- old_data.keysIterator |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
302 |
val data = old_data -- old_data.keysIterator.filterNot(dom) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
303 |
if (dom.isEmpty) data |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
304 |
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
|
305 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
306 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
307 |
def pull0[A <: Library.Named]( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
308 |
new_data: Map[String, A], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
309 |
old_data: Map[String, A] |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
310 |
): Map[String, A] = { |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
311 |
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
|
312 |
} |
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 |
def pull1[A <: Library.Named]( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
315 |
data_domain: Set[String], |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
316 |
data_base: Set[String] => 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(data_domain, dom => data_base(dom).valuesIterator, 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 |
|
77372 | 322 |
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
|
323 |
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
|
324 |
val worker_uuid = SQL.Column.string("worker_uuid") |
77372 | 325 |
val name = SQL.Column.string("name") |
326 |
||
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
): SQL.Source = |
77372 | 332 |
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
|
333 |
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
|
334 |
if_proper(worker_uuid, Generic.worker_uuid.equal(worker_uuid)), |
77375 | 335 |
if_proper(names, Generic.name.member(names))) |
77662 | 336 |
|
337 |
def sql_where( |
|
338 |
build_uuid: String = "", |
|
339 |
worker_uuid: String = "", |
|
340 |
names: Iterable[String] = Nil |
|
341 |
): SQL.Source = { |
|
77663 | 342 |
SQL.where(sql(build_uuid = build_uuid, worker_uuid = worker_uuid, names = names)) |
77662 | 343 |
} |
77372 | 344 |
} |
345 |
||
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
346 |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
347 |
/* base table */ |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
348 |
|
77417 | 349 |
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
|
350 |
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
|
351 |
val ml_platform = SQL.Column.string("ml_platform") |
77372 | 352 |
val options = SQL.Column.string("options") |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
353 |
val start = SQL.Column.date("start") |
77545 | 354 |
val stop = SQL.Column.date("stop") |
77372 | 355 |
|
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
356 |
val table = make_table("", List(build_uuid, ml_platform, options, start, stop)) |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
357 |
} |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
358 |
|
77660 | 359 |
def read_builds(db: SQL.Database, build_uuid: String = ""): List[Build] = |
360 |
db.execute_query_statement( |
|
77662 | 361 |
Base.table.select(sql = Generic.sql_where(build_uuid = build_uuid)), |
77660 | 362 |
List.from[Build], |
363 |
{ res => |
|
364 |
val build_uuid = res.string(Base.build_uuid) |
|
365 |
val ml_platform = res.string(Base.ml_platform) |
|
366 |
val options = res.string(Base.options) |
|
367 |
val start = res.date(Base.start) |
|
368 |
val stop = res.get_date(Base.stop) |
|
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
369 |
Build(build_uuid, ml_platform, options, start, stop) |
77660 | 370 |
}) |
371 |
||
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
372 |
def start_build( |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
373 |
db: SQL.Database, |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
374 |
build_uuid: String, |
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
375 |
ml_platform: String, |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
376 |
options: String |
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
377 |
): Unit = { |
77541 | 378 |
db.execute_statement(Base.table.insert(), body = |
379 |
{ stmt => |
|
380 |
stmt.string(1) = build_uuid |
|
381 |
stmt.string(2) = ml_platform |
|
382 |
stmt.string(3) = options |
|
383 |
stmt.date(4) = db.now() |
|
384 |
stmt.date(5) = None |
|
385 |
}) |
|
77372 | 386 |
} |
387 |
||
77545 | 388 |
def stop_build(db: SQL.Database, build_uuid: String): Unit = |
77541 | 389 |
db.execute_statement( |
77636 | 390 |
Base.table.update(List(Base.stop), sql = Base.build_uuid.where_equal(build_uuid)), |
77541 | 391 |
body = { stmt => stmt.date(1) = db.now() }) |
77538 | 392 |
|
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
|
393 |
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
|
394 |
val old = |
77552 | 395 |
db.execute_query_statement( |
396 |
Base.table.select(List(Base.build_uuid), sql = SQL.where(Base.stop.defined)), |
|
397 |
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
|
398 |
|
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
|
399 |
if (old.nonEmpty) { |
77658 | 400 |
for (table <- build_uuid_tables) { |
77540 | 401 |
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
|
402 |
} |
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
|
403 |
} |
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
|
404 |
} |
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
|
405 |
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
406 |
|
77531 | 407 |
/* sessions */ |
77505 | 408 |
|
77496 | 409 |
object Sessions { |
410 |
val name = Generic.name.make_primary_key |
|
411 |
val deps = SQL.Column.string("deps") |
|
412 |
val ancestors = SQL.Column.string("ancestors") |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
413 |
val options = SQL.Column.string("options") |
77496 | 414 |
val sources = SQL.Column.string("sources") |
415 |
val timeout = SQL.Column.long("timeout") |
|
416 |
val old_time = SQL.Column.long("old_time") |
|
417 |
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
|
418 |
val build_uuid = Generic.build_uuid |
77496 | 419 |
|
420 |
val table = make_table("sessions", |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
421 |
List(name, deps, ancestors, options, sources, timeout, |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
422 |
old_time, old_command_timings, build_uuid)) |
77496 | 423 |
} |
424 |
||
425 |
def read_sessions_domain(db: SQL.Database): Set[String] = |
|
77552 | 426 |
db.execute_query_statement( |
427 |
Sessions.table.select(List(Sessions.name)), |
|
428 |
Set.from[String], res => res.string(Sessions.name)) |
|
77496 | 429 |
|
430 |
def read_sessions(db: SQL.Database, names: Iterable[String] = Nil): State.Sessions = |
|
77552 | 431 |
db.execute_query_statement( |
432 |
Sessions.table.select(sql = if_proper(names, Sessions.name.where_member(names))), |
|
433 |
Map.from[String, Build_Job.Session_Context], |
|
434 |
{ res => |
|
435 |
val name = res.string(Sessions.name) |
|
436 |
val deps = split_lines(res.string(Sessions.deps)) |
|
437 |
val ancestors = split_lines(res.string(Sessions.ancestors)) |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
438 |
val options = res.string(Sessions.options) |
77552 | 439 |
val sources_shasum = SHA1.fake_shasum(res.string(Sessions.sources)) |
440 |
val timeout = Time.ms(res.long(Sessions.timeout)) |
|
441 |
val old_time = Time.ms(res.long(Sessions.old_time)) |
|
442 |
val old_command_timings_blob = res.bytes(Sessions.old_command_timings) |
|
443 |
val build_uuid = res.string(Sessions.build_uuid) |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
444 |
name -> Build_Job.Session_Context(name, deps, ancestors, options, sources_shasum, |
77552 | 445 |
timeout, old_time, old_command_timings_blob, build_uuid) |
77496 | 446 |
} |
77552 | 447 |
) |
77496 | 448 |
|
449 |
def update_sessions(db:SQL.Database, sessions: State.Sessions): Boolean = { |
|
450 |
val old_sessions = read_sessions_domain(db) |
|
451 |
val insert = sessions.iterator.filterNot(p => old_sessions.contains(p._1)).toList |
|
452 |
||
453 |
for ((name, session) <- insert) { |
|
77541 | 454 |
db.execute_statement(Sessions.table.insert(), body = |
455 |
{ stmt => |
|
456 |
stmt.string(1) = name |
|
457 |
stmt.string(2) = cat_lines(session.deps) |
|
458 |
stmt.string(3) = cat_lines(session.ancestors) |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
459 |
stmt.string(4) = session.session_prefs |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
460 |
stmt.string(5) = session.sources_shasum.toString |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
461 |
stmt.long(6) = session.timeout.ms |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
462 |
stmt.long(7) = session.old_time.ms |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
463 |
stmt.bytes(8) = session.old_command_timings_blob |
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77609
diff
changeset
|
464 |
stmt.string(9) = session.build_uuid |
77541 | 465 |
}) |
77496 | 466 |
} |
467 |
||
468 |
insert.nonEmpty |
|
469 |
} |
|
470 |
||
77531 | 471 |
|
472 |
/* workers */ |
|
473 |
||
474 |
object Workers { |
|
475 |
val worker_uuid = Generic.worker_uuid.make_primary_key |
|
476 |
val build_uuid = Generic.build_uuid |
|
77584 | 477 |
val hostname = SQL.Column.string("hostname") |
478 |
val java_pid = SQL.Column.long("java_pid") |
|
479 |
val java_start = SQL.Column.date("java_start") |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
480 |
val start = SQL.Column.date("start") |
77531 | 481 |
val stamp = SQL.Column.date("stamp") |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
482 |
val stop = SQL.Column.date("stop") |
77531 | 483 |
val serial = SQL.Column.long("serial") |
484 |
||
77584 | 485 |
val table = make_table("workers", |
486 |
List(worker_uuid, build_uuid, hostname, java_pid, java_start, start, stamp, stop, serial)) |
|
77531 | 487 |
} |
488 |
||
77655 | 489 |
def read_serial(db: SQL.Database): Long = |
490 |
db.execute_query_statementO[Long]( |
|
78151 | 491 |
Workers.table.select(List(Workers.serial.max)), _.long(Workers.serial)).getOrElse(0L) |
77655 | 492 |
|
77586 | 493 |
def read_workers( |
494 |
db: SQL.Database, |
|
495 |
build_uuid: String = "", |
|
496 |
worker_uuid: String = "" |
|
77657
a2a4adc268b8
removed redundant State.workers: directly maintained within the database, using with SQL update;
wenzelm
parents:
77656
diff
changeset
|
497 |
): List[Worker] = { |
77586 | 498 |
db.execute_query_statement( |
77662 | 499 |
Workers.table.select( |
500 |
sql = Generic.sql_where(build_uuid = build_uuid, worker_uuid = worker_uuid)), |
|
77586 | 501 |
List.from[Worker], |
502 |
{ res => |
|
503 |
Worker( |
|
504 |
worker_uuid = res.string(Workers.worker_uuid), |
|
505 |
build_uuid = res.string(Workers.build_uuid), |
|
506 |
hostname = res.string(Workers.hostname), |
|
507 |
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
|
508 |
java_start = res.date(Workers.java_start), |
77586 | 509 |
start = res.date(Workers.start), |
510 |
stamp = res.date(Workers.stamp), |
|
511 |
stop = res.get_date(Workers.stop), |
|
512 |
serial = res.long(Workers.serial)) |
|
513 |
}) |
|
514 |
} |
|
515 |
||
77584 | 516 |
def start_worker( |
517 |
db: SQL.Database, |
|
518 |
worker_uuid: String, |
|
519 |
build_uuid: String, |
|
520 |
hostname: String, |
|
521 |
java_pid: Long, |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
522 |
java_start: Date, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
523 |
serial: Long |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
524 |
): Unit = { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
525 |
def err(msg: String): Nothing = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
526 |
error("Cannot start worker " + worker_uuid + if_proper(msg, "\n" + msg)) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
527 |
|
77552 | 528 |
val build_stop = |
529 |
db.execute_query_statementO( |
|
77636 | 530 |
Base.table.select(List(Base.stop), sql = Base.build_uuid.where_equal(build_uuid)), |
77552 | 531 |
res => res.get_date(Base.stop)) |
532 |
||
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
533 |
build_stop match { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
534 |
case Some(None) => |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
535 |
case Some(Some(_)) => err("for already stopped build process " + build_uuid) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
536 |
case None => err("for unknown build process " + build_uuid) |
77531 | 537 |
} |
538 |
||
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
539 |
db.execute_statement(Workers.table.insert(), body = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
540 |
{ stmt => |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
541 |
val now = db.now() |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
542 |
stmt.string(1) = worker_uuid |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
543 |
stmt.string(2) = build_uuid |
77584 | 544 |
stmt.string(3) = hostname |
545 |
stmt.long(4) = java_pid |
|
546 |
stmt.date(5) = java_start |
|
547 |
stmt.date(6) = now |
|
548 |
stmt.date(7) = now |
|
549 |
stmt.date(8) = None |
|
550 |
stmt.long(9) = serial |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
551 |
}) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
552 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
553 |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
554 |
def stamp_worker( |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
555 |
db: SQL.Database, |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
556 |
worker_uuid: String, |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
557 |
serial: Long, |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
558 |
stop: Boolean = false |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
559 |
): Unit = { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
560 |
val sql = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
561 |
Workers.table.update(List(Workers.stamp, Workers.stop, Workers.serial), |
77636 | 562 |
sql = Workers.worker_uuid.where_equal(worker_uuid)) |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
563 |
db.execute_statement(sql, body = |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
564 |
{ stmt => |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
565 |
val now = db.now() |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
566 |
stmt.date(1) = now |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
567 |
stmt.date(2) = if (stop) Some(now) else None |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
568 |
stmt.long(3) = serial |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
569 |
}) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
570 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
571 |
|
77531 | 572 |
|
573 |
/* pending jobs */ |
|
574 |
||
575 |
object Pending { |
|
576 |
val name = Generic.name.make_primary_key |
|
577 |
val deps = SQL.Column.string("deps") |
|
578 |
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
|
579 |
val build_uuid = Generic.build_uuid |
77531 | 580 |
|
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
581 |
val table = make_table("pending", List(name, deps, info, build_uuid)) |
77531 | 582 |
} |
583 |
||
77585 | 584 |
def read_pending(db: SQL.Database): List[Task] = |
77552 | 585 |
db.execute_query_statement( |
586 |
Pending.table.select(sql = SQL.order_by(List(Pending.name))), |
|
77585 | 587 |
List.from[Task], |
77552 | 588 |
{ res => |
589 |
val name = res.string(Pending.name) |
|
590 |
val deps = res.string(Pending.deps) |
|
591 |
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
|
592 |
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
|
593 |
Task(name, split_lines(deps), JSON.Object.parse(info), build_uuid) |
77552 | 594 |
}) |
77372 | 595 |
|
77496 | 596 |
def update_pending(db: SQL.Database, pending: State.Pending): Boolean = { |
77372 | 597 |
val old_pending = read_pending(db) |
598 |
val (delete, insert) = Library.symmetric_difference(old_pending, pending) |
|
599 |
||
600 |
if (delete.nonEmpty) { |
|
77540 | 601 |
db.execute_statement( |
77662 | 602 |
Pending.table.delete(sql = Generic.sql_where(names = delete.map(_.name)))) |
77372 | 603 |
} |
604 |
||
77661
45bd5c26cbcc
proper build_uuid for Build_Process.Task: thus old entries are removed via prepare_database/clean_build;
wenzelm
parents:
77660
diff
changeset
|
605 |
for (task <- insert) { |
77541 | 606 |
db.execute_statement(Pending.table.insert(), body = |
607 |
{ 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
|
608 |
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
|
609 |
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
|
610 |
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
|
611 |
stmt.string(4) = task.build_uuid |
77541 | 612 |
}) |
77372 | 613 |
} |
614 |
||
615 |
delete.nonEmpty || insert.nonEmpty |
|
616 |
} |
|
617 |
||
77531 | 618 |
|
619 |
/* running jobs */ |
|
620 |
||
621 |
object Running { |
|
622 |
val name = Generic.name.make_primary_key |
|
77587 | 623 |
val worker_uuid = Generic.worker_uuid |
77634 | 624 |
val build_uuid = Generic.build_uuid |
77531 | 625 |
val hostname = SQL.Column.string("hostname") |
626 |
val numa_node = SQL.Column.int("numa_node") |
|
627 |
||
77634 | 628 |
val table = make_table("running", List(name, worker_uuid, build_uuid, hostname, numa_node)) |
77531 | 629 |
} |
630 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
631 |
def read_running(db: SQL.Database): State.Running = |
77552 | 632 |
db.execute_query_statement( |
633 |
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
|
634 |
Map.from[String, Job], |
77552 | 635 |
{ res => |
636 |
val name = res.string(Running.name) |
|
77587 | 637 |
val worker_uuid = res.string(Running.worker_uuid) |
77634 | 638 |
val build_uuid = res.string(Running.build_uuid) |
77552 | 639 |
val hostname = res.string(Running.hostname) |
640 |
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
|
641 |
name -> Job(name, worker_uuid, build_uuid, Host.Node_Info(hostname, numa_node), None) |
77552 | 642 |
} |
643 |
) |
|
77372 | 644 |
|
77496 | 645 |
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
|
646 |
val running0 = read_running(db).valuesIterator.toList |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
647 |
val running1 = running.valuesIterator.map(_.no_build).toList |
77372 | 648 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
649 |
val (delete, insert) = Library.symmetric_difference(running0, running1) |
77372 | 650 |
|
651 |
if (delete.nonEmpty) { |
|
77540 | 652 |
db.execute_statement( |
77662 | 653 |
Running.table.delete(sql = Generic.sql_where(names = delete.map(_.name)))) |
77372 | 654 |
} |
655 |
||
656 |
for (job <- insert) { |
|
77541 | 657 |
db.execute_statement(Running.table.insert(), body = |
658 |
{ stmt => |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
659 |
stmt.string(1) = job.name |
77587 | 660 |
stmt.string(2) = job.worker_uuid |
77634 | 661 |
stmt.string(3) = job.build_uuid |
662 |
stmt.string(4) = job.node_info.hostname |
|
663 |
stmt.int(5) = job.node_info.numa_node |
|
77541 | 664 |
}) |
77372 | 665 |
} |
666 |
||
667 |
delete.nonEmpty || insert.nonEmpty |
|
668 |
} |
|
669 |
||
77531 | 670 |
|
671 |
/* job results */ |
|
672 |
||
673 |
object Results { |
|
674 |
val name = Generic.name.make_primary_key |
|
77651 | 675 |
val worker_uuid = Generic.worker_uuid |
676 |
val build_uuid = Generic.build_uuid |
|
77531 | 677 |
val hostname = SQL.Column.string("hostname") |
678 |
val numa_node = SQL.Column.string("numa_node") |
|
679 |
val rc = SQL.Column.int("rc") |
|
680 |
val out = SQL.Column.string("out") |
|
681 |
val err = SQL.Column.string("err") |
|
682 |
val timing_elapsed = SQL.Column.long("timing_elapsed") |
|
683 |
val timing_cpu = SQL.Column.long("timing_cpu") |
|
684 |
val timing_gc = SQL.Column.long("timing_gc") |
|
77651 | 685 |
val output_shasum = SQL.Column.string("output_shasum") |
686 |
val current = SQL.Column.bool("current") |
|
77531 | 687 |
|
688 |
val table = |
|
689 |
make_table("results", |
|
77651 | 690 |
List(name, worker_uuid, build_uuid, hostname, numa_node, |
691 |
rc, out, err, timing_elapsed, timing_cpu, timing_gc, output_shasum, current)) |
|
77531 | 692 |
} |
693 |
||
77496 | 694 |
def read_results_domain(db: SQL.Database): Set[String] = |
77552 | 695 |
db.execute_query_statement( |
696 |
Results.table.select(List(Results.name)), |
|
697 |
Set.from[String], res => res.string(Results.name)) |
|
77496 | 698 |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
699 |
def read_results(db: SQL.Database, names: Iterable[String] = Nil): State.Results = |
77552 | 700 |
db.execute_query_statement( |
701 |
Results.table.select(sql = if_proper(names, Results.name.where_member(names))), |
|
77651 | 702 |
Map.from[String, Result], |
77552 | 703 |
{ res => |
704 |
val name = res.string(Results.name) |
|
77651 | 705 |
val worker_uuid = res.string(Results.worker_uuid) |
706 |
val build_uuid = res.string(Results.build_uuid) |
|
77552 | 707 |
val hostname = res.string(Results.hostname) |
708 |
val numa_node = res.get_int(Results.numa_node) |
|
77651 | 709 |
val node_info = Host.Node_Info(hostname, numa_node) |
710 |
||
77552 | 711 |
val rc = res.int(Results.rc) |
712 |
val out = res.string(Results.out) |
|
713 |
val err = res.string(Results.err) |
|
714 |
val timing = |
|
715 |
res.timing( |
|
716 |
Results.timing_elapsed, |
|
717 |
Results.timing_cpu, |
|
718 |
Results.timing_gc) |
|
719 |
val process_result = |
|
720 |
Process_Result(rc, |
|
721 |
out_lines = split_lines(out), |
|
722 |
err_lines = split_lines(err), |
|
723 |
timing = timing) |
|
77651 | 724 |
|
725 |
val output_shasum = SHA1.fake_shasum(res.string(Results.output_shasum)) |
|
726 |
val current = res.bool(Results.current) |
|
727 |
||
728 |
name -> |
|
729 |
Result(name, worker_uuid, build_uuid, node_info, process_result, output_shasum, current) |
|
77496 | 730 |
} |
77552 | 731 |
) |
77372 | 732 |
|
77496 | 733 |
def update_results(db: SQL.Database, results: State.Results): Boolean = { |
734 |
val old_results = read_results_domain(db) |
|
77651 | 735 |
val insert = results.valuesIterator.filterNot(res => old_results.contains(res.name)).toList |
77372 | 736 |
|
77651 | 737 |
for (result <- insert) { |
77372 | 738 |
val process_result = result.process_result |
77541 | 739 |
db.execute_statement(Results.table.insert(), body = |
740 |
{ stmt => |
|
77651 | 741 |
stmt.string(1) = result.name |
742 |
stmt.string(2) = result.worker_uuid |
|
743 |
stmt.string(3) = result.build_uuid |
|
744 |
stmt.string(4) = result.node_info.hostname |
|
745 |
stmt.int(5) = result.node_info.numa_node |
|
746 |
stmt.int(6) = process_result.rc |
|
747 |
stmt.string(7) = cat_lines(process_result.out_lines) |
|
748 |
stmt.string(8) = cat_lines(process_result.err_lines) |
|
749 |
stmt.long(9) = process_result.timing.elapsed.ms |
|
750 |
stmt.long(10) = process_result.timing.cpu.ms |
|
751 |
stmt.long(11) = process_result.timing.gc.ms |
|
752 |
stmt.string(12) = result.output_shasum.toString |
|
753 |
stmt.bool(13) = result.current |
|
77541 | 754 |
}) |
77372 | 755 |
} |
756 |
||
757 |
insert.nonEmpty |
|
758 |
} |
|
759 |
||
77531 | 760 |
|
761 |
/* collective operations */ |
|
762 |
||
77596 | 763 |
val all_tables: SQL.Tables = |
764 |
SQL.Tables( |
|
77534 | 765 |
Base.table, |
766 |
Workers.table, |
|
767 |
Sessions.table, |
|
768 |
Pending.table, |
|
769 |
Running.table, |
|
770 |
Results.table, |
|
771 |
Host.Data.Node_Info.table) |
|
772 |
||
77658 | 773 |
val build_uuid_tables = |
774 |
all_tables.filter(table => |
|
775 |
table.columns.exists(column => column.name == Generic.build_uuid.name)) |
|
776 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
777 |
def pull_database( |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
778 |
db: SQL.Database, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
779 |
worker_uuid: String, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
780 |
hostname: String, |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
781 |
state: State |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
782 |
): State = { |
77655 | 783 |
val serial_db = read_serial(db) |
784 |
if (serial_db == state.serial) state |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
785 |
else { |
77655 | 786 |
val serial = serial_db max state.serial |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
787 |
stamp_worker(db, worker_uuid, serial) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
788 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
789 |
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
|
790 |
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
|
791 |
val pending = read_pending(db) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
792 |
val running = pull0(read_running(db), state.running) |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
793 |
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
|
794 |
|
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
795 |
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
|
796 |
pending = pending, running = running, results = results) |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
797 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
798 |
} |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
799 |
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
800 |
def update_database( |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
801 |
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
|
802 |
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
|
803 |
build_uuid: String, |
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
804 |
hostname: String, |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
805 |
state: State |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
806 |
): State = { |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
807 |
val changed = |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
808 |
List( |
77496 | 809 |
update_sessions(db, state.sessions), |
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
810 |
update_pending(db, state.pending), |
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
811 |
update_running(db, state.running), |
77476 | 812 |
update_results(db, state.results), |
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
813 |
Host.Data.update_numa_next(db, hostname, state.numa_next)) |
77372 | 814 |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
815 |
val serial0 = state.serial |
77513 | 816 |
val serial = if (changed.exists(identity)) State.inc_serial(serial0) else serial0 |
77372 | 817 |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
818 |
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
|
819 |
state.set_serial(serial) |
77372 | 820 |
} |
821 |
} |
|
77396 | 822 |
} |
77372 | 823 |
|
824 |
||
77436 | 825 |
|
826 |
/** main process **/ |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
827 |
|
77505 | 828 |
class Build_Process( |
77530 | 829 |
protected final val build_context: Build_Process.Context, |
830 |
protected final val build_progress: Progress |
|
77505 | 831 |
) |
77436 | 832 |
extends AutoCloseable { |
833 |
/* context */ |
|
834 |
||
77530 | 835 |
protected final val store: Sessions.Store = build_context.store |
836 |
protected final val build_options: Options = store.options |
|
837 |
protected final val build_deps: Sessions.Deps = build_context.build_deps |
|
77653 | 838 |
protected final val hostname: String = build_context.hostname |
77530 | 839 |
protected final val build_uuid: String = build_context.build_uuid |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
840 |
|
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
841 |
|
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
842 |
/* progress backed by database */ |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
843 |
|
78168 | 844 |
private val _database: Option[SQL.Database] = |
845 |
store.maybe_open_build_database(Build_Process.Data.database) |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
846 |
|
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
847 |
protected val (progress, worker_uuid) = synchronized { |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
848 |
_database match { |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
849 |
case None => (build_progress, UUID.random().toString) |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
850 |
case Some(db) => |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
851 |
val progress_db = |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
852 |
if (db.is_postgresql) store.open_database_server() |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
853 |
else db |
78157 | 854 |
val progress = |
855 |
new Database_Progress(progress_db, build_progress, |
|
856 |
hostname = hostname, |
|
857 |
context_uuid = build_uuid) |
|
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
858 |
(progress, progress.agent_uuid) |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
859 |
} |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
860 |
} |
77638 | 861 |
|
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
862 |
protected val log: Logger = Logger.make_system_log(progress, build_options) |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
863 |
|
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
864 |
def close(): Unit = synchronized { |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
865 |
_database.foreach(_.close()) |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
866 |
progress match { |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
867 |
case db_progress: Database_Progress => |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
868 |
db_progress.exit() |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
869 |
db_progress.db.close() |
78159 | 870 |
case _ => |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
871 |
} |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
872 |
} |
77436 | 873 |
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
874 |
/* global state: internal var vs. external database */ |
77436 | 875 |
|
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
876 |
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
|
877 |
|
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
878 |
protected def synchronized_database[A](body: => A): A = synchronized { |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
879 |
_database match { |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
880 |
case None => body |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
881 |
case Some(db) => |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
882 |
db.transaction_lock(Build_Process.Data.all_tables) { |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
883 |
progress.asInstanceOf[Database_Progress].sync() |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
884 |
_state = Build_Process.Data.pull_database(db, worker_uuid, hostname, _state) |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
885 |
val res = body |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
886 |
_state = |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
887 |
Build_Process.Data.update_database(db, worker_uuid, build_uuid, hostname, _state) |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
888 |
res |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
889 |
} |
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
890 |
} |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
891 |
} |
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
892 |
|
77505 | 893 |
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
894 |
/* policy operations */ |
77333 | 895 |
|
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
896 |
protected def init_state(state: Build_Process.State): Build_Process.State = { |
77496 | 897 |
val sessions1 = |
898 |
build_context.sessions.foldLeft(state.sessions) { case (map, (name, session)) => |
|
899 |
if (state.sessions.isDefinedAt(name)) map |
|
900 |
else map + (name -> session) |
|
901 |
} |
|
902 |
||
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
903 |
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
|
904 |
val new_pending = |
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
905 |
List.from( |
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
906 |
for { |
77449 | 907 |
(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
|
908 |
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
|
909 |
} yield Build_Process.Task(name, session_context.deps, JSON.Object.empty, build_uuid)) |
77496 | 910 |
val pending1 = new_pending ::: state.pending |
911 |
||
912 |
state.copy(sessions = sessions1, pending = pending1) |
|
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
913 |
} |
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
914 |
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
915 |
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
|
916 |
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
|
917 |
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
|
918 |
.sortBy(_.name)(build_context.ordering) |
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
919 |
.headOption.map(_.name) |
77296
eeaa2872320b
clarified signature: more explicit synchronized operations;
wenzelm
parents:
77295
diff
changeset
|
920 |
} |
eeaa2872320b
clarified signature: more explicit synchronized operations;
wenzelm
parents:
77295
diff
changeset
|
921 |
else None |
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
922 |
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
923 |
protected def start_session(state: Build_Process.State, session_name: String): Build_Process.State = { |
77468 | 924 |
val ancestor_results = |
925 |
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
|
926 |
|
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
927 |
val input_shasum = |
77650 | 928 |
if (ancestor_results.isEmpty) ML_Process.bootstrap_shasum() |
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
929 |
else SHA1.flat_shasum(ancestor_results.map(_.output_shasum)) |
77257 | 930 |
|
77463 | 931 |
val store_heap = build_context.store_heap(session_name) |
77469 | 932 |
|
933 |
val (current, output_shasum) = |
|
934 |
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
|
935 |
session_options = build_context.sessions_structure(session_name).options, |
77469 | 936 |
sources_shasum = build_context.sources_shasum(session_name), |
937 |
input_shasum = input_shasum, |
|
938 |
fresh_build = build_context.fresh_build, |
|
939 |
store_heap = store_heap) |
|
940 |
||
77260 | 941 |
val all_current = current && ancestor_results.forall(_.current) |
77257 | 942 |
|
77651 | 943 |
val result_name = (session_name, worker_uuid, build_uuid) |
944 |
||
77260 | 945 |
if (all_current) { |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
946 |
state |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
947 |
.remove_pending(session_name) |
77651 | 948 |
.make_result(result_name, Process_Result.ok, output_shasum, current = true) |
77260 | 949 |
} |
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
950 |
else if (build_context.no_build) { |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77514
diff
changeset
|
951 |
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
|
952 |
state. |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
953 |
remove_pending(session_name). |
77651 | 954 |
make_result(result_name, Process_Result.error, output_shasum) |
77260 | 955 |
} |
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
956 |
else if (progress.stopped || !ancestor_results.forall(_.ok)) { |
77452 | 957 |
progress.echo(session_name + " CANCELLED") |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
958 |
state |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
959 |
.remove_pending(session_name) |
77651 | 960 |
.make_result(result_name, Process_Result.undefined, output_shasum) |
77452 | 961 |
} |
962 |
else { |
|
77632 | 963 |
val (numa_node, state1) = state.next_numa_node(build_context.numa_nodes) |
77653 | 964 |
val node_info = Host.Node_Info(hostname, numa_node) |
77551 | 965 |
|
966 |
progress.echo( |
|
967 |
(if (store_heap) "Building " else "Running ") + session_name + |
|
968 |
if_proper(node_info.numa_node, " on " + node_info) + " ...") |
|
77260 | 969 |
|
77472 | 970 |
store.init_output(session_name) |
77257 | 971 |
|
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
972 |
val build = |
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
973 |
Build_Job.start_session(build_context, progress, log, |
77505 | 974 |
build_deps.background(session_name), input_shasum, node_info) |
77630
86ef80d13544
clarified signature: avoid confusion due to object-orientation;
wenzelm
parents:
77629
diff
changeset
|
975 |
|
77634 | 976 |
val job = Build_Process.Job(session_name, worker_uuid, build_uuid, node_info, Some(build)) |
977 |
||
978 |
state1.add_running(job) |
|
77260 | 979 |
} |
980 |
} |
|
77257 | 981 |
|
77436 | 982 |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
983 |
/* build process roles */ |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
984 |
|
77654 | 985 |
final def is_session_name(job_name: String): Boolean = |
986 |
!Long_Name.is_qualified(job_name) |
|
77648 | 987 |
|
77654 | 988 |
protected final def start_build(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
989 |
for (db <- _database) { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
990 |
Build_Process.Data.start_build(db, build_uuid, build_context.ml_platform, |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
991 |
build_context.sessions_structure.session_prefs) |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
992 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
993 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
994 |
|
77654 | 995 |
protected final def stop_build(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
996 |
for (db <- _database) { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
997 |
Build_Process.Data.stop_build(db, build_uuid) |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
998 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
999 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1000 |
|
77654 | 1001 |
protected final def start_worker(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1002 |
for (db <- _database) { |
77584 | 1003 |
val java = ProcessHandle.current() |
1004 |
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
|
1005 |
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
|
1006 |
_state = _state.inc_serial |
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1007 |
Build_Process.Data.start_worker( |
77653 | 1008 |
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
|
1009 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1010 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1011 |
|
77654 | 1012 |
protected final def stop_worker(): Unit = synchronized_database { |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1013 |
for (db <- _database) { |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1014 |
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
|
1015 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1016 |
} |
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1017 |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1018 |
|
77436 | 1019 |
/* run */ |
77372 | 1020 |
|
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
1021 |
def run(): Map[String, Process_Result] = { |
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1022 |
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
|
1023 |
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
1024 |
def finished(): Boolean = synchronized_database { _state.finished } |
77400
f3e5b3fe230e
clarified signature: more explicit "synchronized" regions;
wenzelm
parents:
77398
diff
changeset
|
1025 |
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1026 |
def sleep(): Unit = |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1027 |
Isabelle_Thread.interrupt_handler(_ => progress.stop()) { |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1028 |
build_options.seconds("editor_input_delay").sleep() |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1029 |
} |
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
1030 |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1031 |
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
|
1032 |
next_job(_state) match { |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1033 |
case Some(name) => |
77648 | 1034 |
if (is_session_name(name)) { |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1035 |
_state = start_session(_state, name) |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1036 |
true |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1037 |
} |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1038 |
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
|
1039 |
case None => false |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1040 |
} |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1041 |
} |
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1042 |
|
77335 | 1043 |
if (finished()) { |
1044 |
progress.echo_warning("Nothing to build") |
|
1045 |
Map.empty[String, Process_Result] |
|
1046 |
} |
|
1047 |
else { |
|
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
1048 |
if (build_context.master) start_build() |
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
1049 |
|
77580
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1050 |
start_worker() |
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1051 |
if (build_context.master && !build_context.worker_active) { |
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1052 |
progress.echo("Waiting for external workers ...") |
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1053 |
} |
77578
149d48a4801b
support for "isabelle build -j0": require external workers to make progress;
wenzelm
parents:
77561
diff
changeset
|
1054 |
|
77538 | 1055 |
try { |
1056 |
while (!finished()) { |
|
77639 | 1057 |
synchronized_database { |
1058 |
if (progress.stopped) _state.stop_running() |
|
77310 | 1059 |
|
77649 | 1060 |
for (job <- _state.finished_running()) { |
77651 | 1061 |
val result_name = (job.name, worker_uuid, build_uuid) |
77649 | 1062 |
val (process_result, output_shasum) = job.build.get.join |
77538 | 1063 |
_state = _state. |
77649 | 1064 |
remove_pending(job.name). |
1065 |
remove_running(job.name). |
|
77651 | 1066 |
make_result(result_name, process_result, output_shasum, node_info = job.node_info) |
77538 | 1067 |
} |
1068 |
} |
|
1069 |
||
77652
5f706f7c624b
more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents:
77651
diff
changeset
|
1070 |
if (!start_job()) sleep() |
77396 | 1071 |
} |
77310 | 1072 |
} |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1073 |
finally { |
77580
32f9e75c92e9
clarified worker state: always maintain database content via worker_uuid;
wenzelm
parents:
77579
diff
changeset
|
1074 |
stop_worker() |
77579
69d3547206db
clarified signature: prefer Build_Process.Context for parameters;
wenzelm
parents:
77578
diff
changeset
|
1075 |
if (build_context.master) stop_build() |
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
1076 |
} |
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
1077 |
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
1078 |
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
|
1079 |
for ((name, result) <- _state.results) yield name -> result.process_result |
77257 | 1080 |
} |
1081 |
} |
|
1082 |
} |
|
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1083 |
|
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1084 |
|
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1085 |
/* snapshot */ |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1086 |
|
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1087 |
def snapshot(): Build_Process.Snapshot = synchronized_database { |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1088 |
val (builds, workers) = |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1089 |
_database match { |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1090 |
case None => (Nil, Nil) |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1091 |
case Some(db) => |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1092 |
(Build_Process.Data.read_builds(db), |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1093 |
Build_Process.Data.read_workers(db)) |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1094 |
} |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1095 |
Build_Process.Snapshot( |
77660 | 1096 |
builds = builds, |
77659
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1097 |
workers = workers, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1098 |
sessions = _state.sessions, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1099 |
pending = _state.pending, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1100 |
running = _state.running, |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1101 |
results = _state.results) |
d7eb6a4522b8
more explicit snapshot of "_state" and "_database";
wenzelm
parents:
77658
diff
changeset
|
1102 |
} |
78156
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1103 |
|
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1104 |
|
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1105 |
/* toString */ |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1106 |
|
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1107 |
override def toString: String = |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1108 |
"Build_Process(worker_uuid = " + quote(worker_uuid) + ", build_uuid = " + quote(build_uuid) + |
da5cc332ded3
prefer Database_Progress, which is more robust (amending afb1a19307c4);
wenzelm
parents:
78154
diff
changeset
|
1109 |
if_proper(build_context.master, ", master = true") + ")" |
77238 | 1110 |
} |