| author | wenzelm |
| Tue, 07 Mar 2023 11:13:36 +0100 | |
| changeset 77555 | d45a01c41fe2 |
| parent 77552 | 080422b3d914 |
| child 77561 | a24d77f2cfe9 |
| 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 = (_, _) => (), |
|
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
|
32 |
build_uuid: String = UUID.random().toString |
| 77246 | 33 |
): Context = {
|
| 77453 | 34 |
val sessions_structure = build_deps.sessions_structure |
| 77247 | 35 |
val build_graph = sessions_structure.build_graph |
36 |
||
| 77246 | 37 |
val sessions = |
38 |
Map.from( |
|
| 77448 | 39 |
for ((name, (info, _)) <- build_graph.iterator) |
|
77249
f3f1b7ad1d0d
clarified data structure: more direct access to timeout;
wenzelm
parents:
77248
diff
changeset
|
40 |
yield {
|
|
77447
566e6e393126
proper deps from build_graph, not imports_graph (amending 0c704aba71e3);
wenzelm
parents:
77446
diff
changeset
|
41 |
val deps = info.parent.toList |
|
566e6e393126
proper deps from build_graph, not imports_graph (amending 0c704aba71e3);
wenzelm
parents:
77446
diff
changeset
|
42 |
val ancestors = sessions_structure.build_requirements(deps) |
| 77458 | 43 |
val sources_shasum = build_deps.sources_shasum(name) |
|
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
44 |
val session_context = |
|
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
45 |
Build_Job.Session_Context.load( |
|
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
|
46 |
build_uuid, name, deps, ancestors, sources_shasum, info.timeout, store, |
| 77496 | 47 |
progress = progress) |
|
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
48 |
name -> session_context |
|
77249
f3f1b7ad1d0d
clarified data structure: more direct access to timeout;
wenzelm
parents:
77248
diff
changeset
|
49 |
}) |
| 77247 | 50 |
|
| 77248 | 51 |
val sessions_time = {
|
52 |
val maximals = build_graph.maximals.toSet |
|
53 |
def descendants_time(name: String): Double = {
|
|
54 |
if (maximals.contains(name)) sessions(name).old_time.seconds |
|
55 |
else {
|
|
56 |
val descendants = build_graph.all_succs(List(name)).toSet |
|
57 |
val g = build_graph.restrict(descendants) |
|
58 |
(0.0 :: g.maximals.flatMap { desc =>
|
|
59 |
val ps = g.all_preds(List(desc)) |
|
60 |
if (ps.exists(p => !sessions.isDefinedAt(p))) None |
|
61 |
else Some(ps.map(p => sessions(p).old_time.seconds).sum) |
|
62 |
}).max |
|
63 |
} |
|
| 77247 | 64 |
} |
| 77248 | 65 |
Map.from( |
66 |
for (name <- sessions.keysIterator) |
|
67 |
yield name -> descendants_time(name)).withDefaultValue(0.0) |
|
| 77247 | 68 |
} |
69 |
||
| 77246 | 70 |
val ordering = |
71 |
new Ordering[String] {
|
|
72 |
def compare(name1: String, name2: String): Int = |
|
| 77248 | 73 |
sessions_time(name2) compare sessions_time(name1) match {
|
| 77246 | 74 |
case 0 => |
|
77249
f3f1b7ad1d0d
clarified data structure: more direct access to timeout;
wenzelm
parents:
77248
diff
changeset
|
75 |
sessions(name2).timeout compare sessions(name1).timeout match {
|
| 77246 | 76 |
case 0 => name1 compare name2 |
77 |
case ord => ord |
|
78 |
} |
|
79 |
case ord => ord |
|
80 |
} |
|
81 |
} |
|
82 |
||
| 77477 | 83 |
val numa_nodes = Host.numa_nodes(enabled = numa_shuffling) |
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
84 |
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
|
85 |
build_heap = build_heap, max_jobs = max_jobs, fresh_build = fresh_build, |
|
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
|
86 |
no_build = no_build, session_setup, build_uuid = build_uuid) |
| 77246 | 87 |
} |
88 |
} |
|
89 |
||
90 |
final class Context private( |
|
| 77257 | 91 |
val store: Sessions.Store, |
| 77453 | 92 |
val build_deps: Sessions.Deps, |
| 77496 | 93 |
val sessions: State.Sessions, |
| 77257 | 94 |
val ordering: Ordering[String], |
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
95 |
val ml_platform: String, |
|
77378
f047804f4860
clarified Build_Process.Context: cover all static information;
wenzelm
parents:
77375
diff
changeset
|
96 |
val hostname: String, |
|
77317
b8ec3c0455db
clarified modules: NUMA is managed by Build_Process;
wenzelm
parents:
77315
diff
changeset
|
97 |
val numa_nodes: List[Int], |
|
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
98 |
val build_heap: Boolean, |
|
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
99 |
val max_jobs: Int, |
|
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
100 |
val fresh_build: Boolean, |
|
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
101 |
val no_build: Boolean, |
|
77378
f047804f4860
clarified Build_Process.Context: cover all static information;
wenzelm
parents:
77375
diff
changeset
|
102 |
val session_setup: (String, Session) => Unit, |
|
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
|
103 |
val build_uuid: String |
| 77246 | 104 |
) {
|
| 77470 | 105 |
def build_options: Options = store.options |
106 |
||
| 77453 | 107 |
def sessions_structure: Sessions.Structure = build_deps.sessions_structure |
| 77257 | 108 |
|
| 77462 | 109 |
def sources_shasum(name: String): SHA1.Shasum = sessions(name).sources_shasum |
| 77458 | 110 |
|
| 77462 | 111 |
def old_command_timings(name: String): List[Properties.T] = |
112 |
sessions.get(name) match {
|
|
|
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
113 |
case Some(session_context) => |
|
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
114 |
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
|
115 |
case None => Nil |
|
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77443
diff
changeset
|
116 |
} |
|
77439
d6bf9ec39d12
avoid premature Properties.uncompress: allow blob to be stored in another database;
wenzelm
parents:
77438
diff
changeset
|
117 |
|
| 77514 | 118 |
def open_database(): Option[SQL.Database] = |
119 |
if (!build_options.bool("build_database_test")) None
|
|
120 |
else if (store.database_server) Some(store.open_database_server()) |
|
121 |
else {
|
|
122 |
val db = SQLite.open_database(Build_Process.Data.database) |
|
123 |
try { Isabelle_System.chmod("600", Build_Process.Data.database) }
|
|
124 |
catch { case exn: Throwable => db.close(); throw exn }
|
|
125 |
Some(db) |
|
126 |
} |
|
127 |
||
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
128 |
def prepare_database(): Unit = {
|
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
129 |
using_option(open_database()) { db =>
|
|
77539
2b996a0df1ce
proper clean_build of old data at start of new process --- allow to inspect remains of the last process;
wenzelm
parents:
77538
diff
changeset
|
130 |
db.transaction {
|
|
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
|
131 |
for (table <- Data.all_tables) db.create_table(table) |
|
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
|
132 |
Data.clean_build(db) |
|
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
|
133 |
} |
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
134 |
db.rebuild() |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
135 |
} |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
136 |
} |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
137 |
|
| 77463 | 138 |
def store_heap(name: String): Boolean = |
| 77462 | 139 |
build_heap || Sessions.is_pure(name) || |
140 |
sessions.valuesIterator.exists(_.ancestors.contains(name)) |
|
| 77246 | 141 |
} |
| 77257 | 142 |
|
143 |
||
| 77436 | 144 |
|
145 |
/** dynamic state **/ |
|
| 77257 | 146 |
|
| 77505 | 147 |
type Progress_Messages = SortedMap[Long, Progress.Message] |
148 |
||
| 77344 | 149 |
case class Entry(name: String, deps: List[String], info: JSON.Object.T = JSON.Object.empty) {
|
|
77313
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
150 |
def is_ready: Boolean = deps.isEmpty |
|
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
151 |
def resolve(dep: String): Entry = |
|
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
152 |
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
|
153 |
} |
|
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
154 |
|
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
155 |
case class Result( |
| 77461 | 156 |
process_result: Process_Result, |
|
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
157 |
output_shasum: SHA1.Shasum, |
| 77475 | 158 |
node_info: Host.Node_Info, |
| 77461 | 159 |
current: Boolean |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
160 |
) {
|
|
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
161 |
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
|
162 |
} |
| 77312 | 163 |
|
| 77496 | 164 |
object State {
|
165 |
type Sessions = Map[String, Build_Job.Session_Context] |
|
166 |
type Pending = List[Entry] |
|
167 |
type Running = Map[String, Build_Job] |
|
168 |
type Results = Map[String, Result] |
|
| 77513 | 169 |
|
170 |
def inc_serial(serial: Long): Long = {
|
|
171 |
require(serial < java.lang.Long.MAX_VALUE, "serial overflow") |
|
172 |
serial + 1 |
|
173 |
} |
|
| 77496 | 174 |
} |
175 |
||
|
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
176 |
sealed case class State( |
| 77372 | 177 |
serial: Long = 0, |
| 77505 | 178 |
progress_seen: Long = 0, |
|
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
179 |
numa_next: Int = 0, |
| 77496 | 180 |
sessions: State.Sessions = Map.empty, // static build targets |
181 |
pending: State.Pending = Nil, // dynamic build "queue" |
|
182 |
running: State.Running = Map.empty, // presently running jobs |
|
183 |
results: State.Results = Map.empty // finished results |
|
|
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
184 |
) {
|
| 77513 | 185 |
require(serial >= 0, "serial underflow") |
186 |
def inc_serial: State = copy(serial = State.inc_serial(serial)) |
|
187 |
def set_serial(i: Long): State = {
|
|
188 |
require(serial <= i, "non-monotonic change of serial") |
|
189 |
copy(serial = i) |
|
190 |
} |
|
191 |
||
|
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
192 |
def progress_serial(message_serial: Long = serial): State = |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
193 |
if (message_serial > progress_seen) copy(progress_seen = message_serial) |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
194 |
else error("Bad serial " + message_serial + " for progress output (already seen)")
|
| 77505 | 195 |
|
|
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
196 |
def numa_next_node(numa_nodes: List[Int]): (Option[Int], State) = |
| 77343 | 197 |
if (numa_nodes.isEmpty) (None, this) |
198 |
else {
|
|
199 |
val available = numa_nodes.zipWithIndex |
|
| 77372 | 200 |
val used = |
201 |
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
|
202 |
|
|
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
203 |
val numa_index = available.collectFirst({ case (n, i) if n == numa_next => i }).getOrElse(0)
|
| 77343 | 204 |
val candidates = available.drop(numa_index) ::: available.take(numa_index) |
205 |
val (n, i) = |
|
206 |
candidates.find({ case (n, i) => i == numa_index && !used(n) }) orElse
|
|
207 |
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
|
208 |
|
|
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
209 |
(Some(n), copy(numa_next = numa_nodes((i + 1) % numa_nodes.length))) |
| 77343 | 210 |
} |
| 77337 | 211 |
|
| 77335 | 212 |
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
|
213 |
|
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
|
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
218 |
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
|
219 |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77477
diff
changeset
|
220 |
def stop_running(): Unit = running.valuesIterator.foreach(_.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
|
221 |
|
|
77398
19e9cafaafc5
clarified signature: works for general Build_Job;
wenzelm
parents:
77396
diff
changeset
|
222 |
def finished_running(): List[Build_Job] = |
|
19e9cafaafc5
clarified signature: works for general Build_Job;
wenzelm
parents:
77396
diff
changeset
|
223 |
List.from(running.valuesIterator.filter(_.is_finished)) |
|
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
224 |
|
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
225 |
def add_running(name: String, job: Build_Job): State = |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
226 |
copy(running = running + (name -> job)) |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
227 |
|
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
228 |
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
|
229 |
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
|
230 |
|
| 77336 | 231 |
def make_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
|
232 |
name: String, |
| 77461 | 233 |
process_result: Process_Result, |
|
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
234 |
output_shasum: SHA1.Shasum, |
| 77475 | 235 |
node_info: Host.Node_Info = Host.Node_Info.none, |
| 77461 | 236 |
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
|
237 |
): State = {
|
| 77461 | 238 |
val entry = name -> Build_Process.Result(process_result, output_shasum, node_info, current) |
239 |
copy(results = results + entry) |
|
|
77334
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
240 |
} |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
241 |
} |
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
242 |
|
|
0231e62956a6
clarified state: more explicit type as plain value, which is also easier to sync with external db;
wenzelm
parents:
77333
diff
changeset
|
243 |
|
| 77436 | 244 |
|
245 |
/** SQL data model **/ |
|
| 77372 | 246 |
|
247 |
object Data {
|
|
248 |
val database = Path.explode("$ISABELLE_HOME_USER/build.db")
|
|
249 |
||
250 |
def make_table(name: String, columns: List[SQL.Column], body: String = ""): SQL.Table = |
|
251 |
SQL.Table("isabelle_build" + if_proper(name, "_" + name), columns, body = body)
|
|
252 |
||
253 |
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
|
254 |
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
|
255 |
val worker_uuid = SQL.Column.string("worker_uuid")
|
| 77372 | 256 |
val name = SQL.Column.string("name")
|
257 |
||
|
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
name: 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
|
262 |
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
|
263 |
): SQL.Source = |
| 77372 | 264 |
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
|
265 |
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
|
266 |
if_proper(worker_uuid, Generic.worker_uuid.equal(worker_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
|
267 |
if_proper(name, Generic.name.equal(name)), |
| 77375 | 268 |
if_proper(names, Generic.name.member(names))) |
| 77372 | 269 |
} |
270 |
||
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
271 |
|
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
272 |
/* base table */ |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
273 |
|
| 77417 | 274 |
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
|
275 |
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
|
276 |
val ml_platform = SQL.Column.string("ml_platform")
|
| 77372 | 277 |
val options = SQL.Column.string("options")
|
|
77536
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
278 |
val start = SQL.Column.date("start")
|
| 77545 | 279 |
val stop = SQL.Column.date("stop")
|
| 77372 | 280 |
|
| 77545 | 281 |
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
|
282 |
} |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
283 |
|
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
284 |
def start_build( |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
285 |
db: SQL.Database, |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
286 |
build_uuid: String, |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
287 |
ml_platform: String, |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
288 |
options: String |
|
7c7f1473e51a
clarified database content and prepare/init stages;
wenzelm
parents:
77534
diff
changeset
|
289 |
): Unit = {
|
| 77541 | 290 |
db.execute_statement(Base.table.insert(), body = |
291 |
{ stmt =>
|
|
292 |
stmt.string(1) = build_uuid |
|
293 |
stmt.string(2) = ml_platform |
|
294 |
stmt.string(3) = options |
|
295 |
stmt.date(4) = db.now() |
|
296 |
stmt.date(5) = None |
|
297 |
}) |
|
| 77372 | 298 |
} |
299 |
||
| 77545 | 300 |
def stop_build(db: SQL.Database, build_uuid: String): Unit = |
| 77541 | 301 |
db.execute_statement( |
| 77545 | 302 |
Base.table.update(List(Base.stop), sql = SQL.where(Generic.sql(build_uuid = build_uuid))), |
| 77541 | 303 |
body = { stmt => stmt.date(1) = db.now() })
|
| 77538 | 304 |
|
|
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
|
305 |
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
|
306 |
val old = |
| 77552 | 307 |
db.execute_query_statement( |
308 |
Base.table.select(List(Base.build_uuid), sql = SQL.where(Base.stop.defined)), |
|
309 |
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
|
310 |
|
|
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
|
311 |
if (old.nonEmpty) {
|
|
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
|
312 |
for (table <- List(Base.table, Sessions.table, Progress.table, Workers.table)) {
|
| 77540 | 313 |
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
|
314 |
} |
|
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
|
315 |
} |
|
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
|
316 |
} |
|
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
|
317 |
|
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
318 |
|
| 77531 | 319 |
/* sessions */ |
| 77505 | 320 |
|
| 77496 | 321 |
object Sessions {
|
322 |
val name = Generic.name.make_primary_key |
|
323 |
val deps = SQL.Column.string("deps")
|
|
324 |
val ancestors = SQL.Column.string("ancestors")
|
|
325 |
val sources = SQL.Column.string("sources")
|
|
326 |
val timeout = SQL.Column.long("timeout")
|
|
327 |
val old_time = SQL.Column.long("old_time")
|
|
328 |
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
|
329 |
val build_uuid = Generic.build_uuid |
| 77496 | 330 |
|
331 |
val table = make_table("sessions",
|
|
|
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
|
332 |
List(name, deps, ancestors, sources, timeout, old_time, old_command_timings, build_uuid)) |
| 77496 | 333 |
} |
334 |
||
335 |
def read_sessions_domain(db: SQL.Database): Set[String] = |
|
| 77552 | 336 |
db.execute_query_statement( |
337 |
Sessions.table.select(List(Sessions.name)), |
|
338 |
Set.from[String], res => res.string(Sessions.name)) |
|
| 77496 | 339 |
|
340 |
def read_sessions(db: SQL.Database, names: Iterable[String] = Nil): State.Sessions = |
|
| 77552 | 341 |
db.execute_query_statement( |
342 |
Sessions.table.select(sql = if_proper(names, Sessions.name.where_member(names))), |
|
343 |
Map.from[String, Build_Job.Session_Context], |
|
344 |
{ res =>
|
|
345 |
val name = res.string(Sessions.name) |
|
346 |
val deps = split_lines(res.string(Sessions.deps)) |
|
347 |
val ancestors = split_lines(res.string(Sessions.ancestors)) |
|
348 |
val sources_shasum = SHA1.fake_shasum(res.string(Sessions.sources)) |
|
349 |
val timeout = Time.ms(res.long(Sessions.timeout)) |
|
350 |
val old_time = Time.ms(res.long(Sessions.old_time)) |
|
351 |
val old_command_timings_blob = res.bytes(Sessions.old_command_timings) |
|
352 |
val build_uuid = res.string(Sessions.build_uuid) |
|
353 |
name -> Build_Job.Session_Context(name, deps, ancestors, sources_shasum, |
|
354 |
timeout, old_time, old_command_timings_blob, build_uuid) |
|
| 77496 | 355 |
} |
| 77552 | 356 |
) |
| 77496 | 357 |
|
358 |
def update_sessions(db:SQL.Database, sessions: State.Sessions): Boolean = {
|
|
359 |
val old_sessions = read_sessions_domain(db) |
|
360 |
val insert = sessions.iterator.filterNot(p => old_sessions.contains(p._1)).toList |
|
361 |
||
362 |
for ((name, session) <- insert) {
|
|
| 77541 | 363 |
db.execute_statement(Sessions.table.insert(), body = |
364 |
{ stmt =>
|
|
365 |
stmt.string(1) = name |
|
366 |
stmt.string(2) = cat_lines(session.deps) |
|
367 |
stmt.string(3) = cat_lines(session.ancestors) |
|
368 |
stmt.string(4) = session.sources_shasum.toString |
|
369 |
stmt.long(5) = session.timeout.ms |
|
370 |
stmt.long(6) = session.old_time.ms |
|
371 |
stmt.bytes(7) = session.old_command_timings_blob |
|
372 |
stmt.string(8) = session.build_uuid |
|
373 |
}) |
|
| 77496 | 374 |
} |
375 |
||
376 |
insert.nonEmpty |
|
377 |
} |
|
378 |
||
| 77531 | 379 |
|
380 |
/* progress */ |
|
381 |
||
382 |
object Progress {
|
|
383 |
val serial = SQL.Column.long("serial").make_primary_key
|
|
384 |
val kind = SQL.Column.int("kind")
|
|
385 |
val text = SQL.Column.string("text")
|
|
386 |
val verbose = SQL.Column.bool("verbose")
|
|
387 |
val build_uuid = Generic.build_uuid |
|
388 |
||
389 |
val table = make_table("progress", List(serial, kind, text, verbose, build_uuid))
|
|
390 |
} |
|
391 |
||
392 |
def read_progress(db: SQL.Database, seen: Long = 0, build_uuid: String = ""): Progress_Messages = |
|
| 77552 | 393 |
db.execute_query_statement( |
| 77531 | 394 |
Progress.table.select( |
395 |
sql = |
|
396 |
SQL.where( |
|
397 |
SQL.and( |
|
398 |
if (seen <= 0) "" else Progress.serial.ident + " > " + seen, |
|
| 77552 | 399 |
Generic.sql(build_uuid = build_uuid)))), |
400 |
SortedMap.from[Long, isabelle.Progress.Message], |
|
401 |
{ res =>
|
|
402 |
val serial = res.long(Progress.serial) |
|
403 |
val kind = isabelle.Progress.Kind(res.int(Progress.kind)) |
|
404 |
val text = res.string(Progress.text) |
|
405 |
val verbose = res.bool(Progress.verbose) |
|
406 |
serial -> isabelle.Progress.Message(kind, text, verbose = verbose) |
|
| 77531 | 407 |
} |
| 77552 | 408 |
) |
| 77531 | 409 |
|
410 |
def write_progress( |
|
411 |
db: SQL.Database, |
|
412 |
message_serial: Long, |
|
413 |
message: isabelle.Progress.Message, |
|
414 |
build_uuid: String |
|
415 |
): Unit = {
|
|
| 77541 | 416 |
db.execute_statement(Progress.table.insert(), body = |
417 |
{ stmt =>
|
|
418 |
stmt.long(1) = message_serial |
|
419 |
stmt.int(2) = message.kind.id |
|
420 |
stmt.string(3) = message.text |
|
421 |
stmt.bool(4) = message.verbose |
|
422 |
stmt.string(5) = build_uuid |
|
423 |
}) |
|
| 77531 | 424 |
} |
425 |
||
426 |
||
427 |
/* workers */ |
|
428 |
||
429 |
object Workers {
|
|
430 |
val worker_uuid = Generic.worker_uuid.make_primary_key |
|
431 |
val build_uuid = Generic.build_uuid |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
432 |
val start = SQL.Column.date("start")
|
| 77531 | 433 |
val stamp = SQL.Column.date("stamp")
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
434 |
val stop = SQL.Column.date("stop")
|
| 77531 | 435 |
val serial = SQL.Column.long("serial")
|
436 |
||
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
437 |
val table = make_table("workers", List(worker_uuid, build_uuid, start, stamp, stop, serial))
|
| 77531 | 438 |
|
439 |
val serial_max = serial.copy(expr = "MAX(" + serial.ident + ")")
|
|
440 |
} |
|
441 |
||
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
442 |
def serial_max(db: SQL.Database): Long = |
| 77552 | 443 |
db.execute_query_statementO[Long]( |
444 |
Workers.table.select(List(Workers.serial_max)), |
|
445 |
res => res.long(Workers.serial) |
|
446 |
).getOrElse(0L) |
|
| 77531 | 447 |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
448 |
def start_worker(db: SQL.Database, worker_uuid: String, build_uuid: String): Long = {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
449 |
def err(msg: String): Nothing = |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
450 |
error("Cannot start worker " + worker_uuid + if_proper(msg, "\n" + msg))
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
451 |
|
| 77552 | 452 |
val build_stop = |
453 |
db.execute_query_statementO( |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
454 |
Base.table.select(List(Base.stop), |
| 77552 | 455 |
sql = SQL.where(Generic.sql(build_uuid = build_uuid))), |
456 |
res => res.get_date(Base.stop)) |
|
457 |
||
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
458 |
build_stop match {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
459 |
case Some(None) => |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
460 |
case Some(Some(_)) => err("for already stopped build process " + build_uuid)
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
461 |
case None => err("for unknown build process " + build_uuid)
|
| 77531 | 462 |
} |
463 |
||
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
464 |
val serial = serial_max(db) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
465 |
db.execute_statement(Workers.table.insert(), body = |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
466 |
{ stmt =>
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
467 |
val now = db.now() |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
468 |
stmt.string(1) = worker_uuid |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
469 |
stmt.string(2) = build_uuid |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
470 |
stmt.date(3) = now |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
471 |
stmt.date(4) = now |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
472 |
stmt.date(5) = None |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
473 |
stmt.long(6) = serial |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
474 |
}) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
475 |
serial |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
476 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
477 |
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
478 |
def stamp_worker( |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
479 |
db: SQL.Database, |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
480 |
worker_uuid: String, |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
481 |
serial: Long, |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
482 |
stop: Boolean = false |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
483 |
): Unit = {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
484 |
val sql = |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
485 |
Workers.table.update(List(Workers.stamp, Workers.stop, Workers.serial), |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
486 |
sql = SQL.where(Generic.sql(worker_uuid = worker_uuid))) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
487 |
db.execute_statement(sql, body = |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
488 |
{ stmt =>
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
489 |
val now = db.now() |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
490 |
stmt.date(1) = now |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
491 |
stmt.date(2) = if (stop) Some(now) else None |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
492 |
stmt.long(3) = serial |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
493 |
}) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
494 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
495 |
|
| 77531 | 496 |
|
497 |
/* pending jobs */ |
|
498 |
||
499 |
object Pending {
|
|
500 |
val name = Generic.name.make_primary_key |
|
501 |
val deps = SQL.Column.string("deps")
|
|
502 |
val info = SQL.Column.string("info")
|
|
503 |
||
504 |
val table = make_table("pending", List(name, deps, info))
|
|
505 |
} |
|
506 |
||
| 77372 | 507 |
def read_pending(db: SQL.Database): List[Entry] = |
| 77552 | 508 |
db.execute_query_statement( |
509 |
Pending.table.select(sql = SQL.order_by(List(Pending.name))), |
|
510 |
List.from[Entry], |
|
511 |
{ res =>
|
|
512 |
val name = res.string(Pending.name) |
|
513 |
val deps = res.string(Pending.deps) |
|
514 |
val info = res.string(Pending.info) |
|
515 |
Entry(name, split_lines(deps), info = JSON.Object.parse(info)) |
|
516 |
}) |
|
| 77372 | 517 |
|
| 77496 | 518 |
def update_pending(db: SQL.Database, pending: State.Pending): Boolean = {
|
| 77372 | 519 |
val old_pending = read_pending(db) |
520 |
val (delete, insert) = Library.symmetric_difference(old_pending, pending) |
|
521 |
||
522 |
if (delete.nonEmpty) {
|
|
| 77540 | 523 |
db.execute_statement( |
524 |
Pending.table.delete(sql = SQL.where(Generic.sql(names = delete.map(_.name))))) |
|
| 77372 | 525 |
} |
526 |
||
527 |
for (entry <- insert) {
|
|
| 77541 | 528 |
db.execute_statement(Pending.table.insert(), body = |
529 |
{ stmt =>
|
|
530 |
stmt.string(1) = entry.name |
|
531 |
stmt.string(2) = cat_lines(entry.deps) |
|
532 |
stmt.string(3) = JSON.Format(entry.info) |
|
533 |
}) |
|
| 77372 | 534 |
} |
535 |
||
536 |
delete.nonEmpty || insert.nonEmpty |
|
537 |
} |
|
538 |
||
| 77531 | 539 |
|
540 |
/* running jobs */ |
|
541 |
||
542 |
object Running {
|
|
543 |
val name = Generic.name.make_primary_key |
|
544 |
val hostname = SQL.Column.string("hostname")
|
|
545 |
val numa_node = SQL.Column.int("numa_node")
|
|
546 |
||
547 |
val table = make_table("running", List(name, hostname, numa_node))
|
|
548 |
} |
|
549 |
||
| 77372 | 550 |
def read_running(db: SQL.Database): List[Build_Job.Abstract] = |
| 77552 | 551 |
db.execute_query_statement( |
552 |
Running.table.select(sql = SQL.order_by(List(Running.name))), |
|
553 |
List.from[Build_Job.Abstract], |
|
554 |
{ res =>
|
|
555 |
val name = res.string(Running.name) |
|
556 |
val hostname = res.string(Running.hostname) |
|
557 |
val numa_node = res.get_int(Running.numa_node) |
|
558 |
Build_Job.Abstract(name, Host.Node_Info(hostname, numa_node)) |
|
559 |
} |
|
560 |
) |
|
| 77372 | 561 |
|
| 77496 | 562 |
def update_running(db: SQL.Database, running: State.Running): Boolean = {
|
| 77372 | 563 |
val old_running = read_running(db) |
564 |
val abs_running = running.valuesIterator.map(_.make_abstract).toList |
|
565 |
||
566 |
val (delete, insert) = Library.symmetric_difference(old_running, abs_running) |
|
567 |
||
568 |
if (delete.nonEmpty) {
|
|
| 77540 | 569 |
db.execute_statement( |
570 |
Running.table.delete(sql = SQL.where(Generic.sql(names = delete.map(_.job_name))))) |
|
| 77372 | 571 |
} |
572 |
||
573 |
for (job <- insert) {
|
|
| 77541 | 574 |
db.execute_statement(Running.table.insert(), body = |
575 |
{ stmt =>
|
|
576 |
stmt.string(1) = job.job_name |
|
577 |
stmt.string(2) = job.node_info.hostname |
|
578 |
stmt.int(3) = job.node_info.numa_node |
|
579 |
}) |
|
| 77372 | 580 |
} |
581 |
||
582 |
delete.nonEmpty || insert.nonEmpty |
|
583 |
} |
|
584 |
||
| 77531 | 585 |
|
586 |
/* job results */ |
|
587 |
||
588 |
object Results {
|
|
589 |
val name = Generic.name.make_primary_key |
|
590 |
val hostname = SQL.Column.string("hostname")
|
|
591 |
val numa_node = SQL.Column.string("numa_node")
|
|
592 |
val rc = SQL.Column.int("rc")
|
|
593 |
val out = SQL.Column.string("out")
|
|
594 |
val err = SQL.Column.string("err")
|
|
595 |
val timing_elapsed = SQL.Column.long("timing_elapsed")
|
|
596 |
val timing_cpu = SQL.Column.long("timing_cpu")
|
|
597 |
val timing_gc = SQL.Column.long("timing_gc")
|
|
598 |
||
599 |
val table = |
|
600 |
make_table("results",
|
|
601 |
List(name, hostname, numa_node, rc, out, err, timing_elapsed, timing_cpu, timing_gc)) |
|
602 |
} |
|
603 |
||
| 77496 | 604 |
def read_results_domain(db: SQL.Database): Set[String] = |
| 77552 | 605 |
db.execute_query_statement( |
606 |
Results.table.select(List(Results.name)), |
|
607 |
Set.from[String], res => res.string(Results.name)) |
|
| 77496 | 608 |
|
| 77372 | 609 |
def read_results(db: SQL.Database, names: List[String] = Nil): Map[String, Build_Job.Result] = |
| 77552 | 610 |
db.execute_query_statement( |
611 |
Results.table.select(sql = if_proper(names, Results.name.where_member(names))), |
|
612 |
Map.from[String, Build_Job.Result], |
|
613 |
{ res =>
|
|
614 |
val name = res.string(Results.name) |
|
615 |
val hostname = res.string(Results.hostname) |
|
616 |
val numa_node = res.get_int(Results.numa_node) |
|
617 |
val rc = res.int(Results.rc) |
|
618 |
val out = res.string(Results.out) |
|
619 |
val err = res.string(Results.err) |
|
620 |
val timing = |
|
621 |
res.timing( |
|
622 |
Results.timing_elapsed, |
|
623 |
Results.timing_cpu, |
|
624 |
Results.timing_gc) |
|
625 |
val node_info = Host.Node_Info(hostname, numa_node) |
|
626 |
val process_result = |
|
627 |
Process_Result(rc, |
|
628 |
out_lines = split_lines(out), |
|
629 |
err_lines = split_lines(err), |
|
630 |
timing = timing) |
|
631 |
name -> Build_Job.Result(node_info, process_result) |
|
| 77496 | 632 |
} |
| 77552 | 633 |
) |
| 77372 | 634 |
|
| 77496 | 635 |
def update_results(db: SQL.Database, results: State.Results): Boolean = {
|
636 |
val old_results = read_results_domain(db) |
|
| 77385 | 637 |
val insert = results.iterator.filterNot(p => old_results.contains(p._1)).toList |
| 77372 | 638 |
|
639 |
for ((name, result) <- insert) {
|
|
640 |
val node_info = result.node_info |
|
641 |
val process_result = result.process_result |
|
| 77541 | 642 |
db.execute_statement(Results.table.insert(), body = |
643 |
{ stmt =>
|
|
644 |
stmt.string(1) = name |
|
645 |
stmt.string(2) = node_info.hostname |
|
646 |
stmt.int(3) = node_info.numa_node |
|
647 |
stmt.int(4) = process_result.rc |
|
648 |
stmt.string(5) = cat_lines(process_result.out_lines) |
|
649 |
stmt.string(6) = cat_lines(process_result.err_lines) |
|
650 |
stmt.long(7) = process_result.timing.elapsed.ms |
|
651 |
stmt.long(8) = process_result.timing.cpu.ms |
|
652 |
stmt.long(9) = process_result.timing.gc.ms |
|
653 |
}) |
|
| 77372 | 654 |
} |
655 |
||
656 |
insert.nonEmpty |
|
657 |
} |
|
658 |
||
| 77531 | 659 |
|
660 |
/* collective operations */ |
|
661 |
||
| 77534 | 662 |
def all_tables: List[SQL.Table] = |
663 |
List( |
|
664 |
Base.table, |
|
665 |
Workers.table, |
|
666 |
Progress.table, |
|
667 |
Sessions.table, |
|
668 |
Pending.table, |
|
669 |
Running.table, |
|
670 |
Results.table, |
|
671 |
Host.Data.Node_Info.table) |
|
672 |
||
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
673 |
def update_database( |
|
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
674 |
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
|
675 |
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
|
676 |
build_uuid: String, |
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
677 |
hostname: String, |
|
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
678 |
state: State |
|
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
679 |
): State = {
|
|
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
680 |
val changed = |
|
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
681 |
List( |
| 77496 | 682 |
update_sessions(db, state.sessions), |
|
77416
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
683 |
update_pending(db, state.pending), |
|
d88c12f22ab0
clarified scope of "serial" and "numa_index" within database;
wenzelm
parents:
77415
diff
changeset
|
684 |
update_running(db, state.running), |
| 77476 | 685 |
update_results(db, state.results), |
|
77525
de6fb423fd4b
clarified database content: store actual value instead of index;
wenzelm
parents:
77522
diff
changeset
|
686 |
Host.Data.update_numa_next(db, hostname, state.numa_next)) |
| 77372 | 687 |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
688 |
val serial0 = serial_max(db) |
| 77513 | 689 |
val serial = if (changed.exists(identity)) State.inc_serial(serial0) else serial0 |
| 77372 | 690 |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
691 |
stamp_worker(db, worker_uuid, serial) |
| 77513 | 692 |
state.set_serial(serial) |
| 77372 | 693 |
} |
694 |
} |
|
| 77396 | 695 |
} |
| 77372 | 696 |
|
697 |
||
| 77436 | 698 |
|
699 |
/** main process **/ |
|
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
700 |
|
| 77505 | 701 |
class Build_Process( |
| 77530 | 702 |
protected final val build_context: Build_Process.Context, |
703 |
protected final val build_progress: Progress |
|
| 77505 | 704 |
) |
| 77436 | 705 |
extends AutoCloseable {
|
706 |
/* context */ |
|
707 |
||
| 77530 | 708 |
protected final val store: Sessions.Store = build_context.store |
709 |
protected final val build_options: Options = store.options |
|
710 |
protected final val build_deps: Sessions.Deps = build_context.build_deps |
|
711 |
protected final val build_uuid: String = build_context.build_uuid |
|
712 |
protected final val worker_uuid: String = UUID.random().toString |
|
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
713 |
|
| 77436 | 714 |
|
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
715 |
/* global state: internal var vs. external database */ |
| 77436 | 716 |
|
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
717 |
private var _state: Build_Process.State = init_state(Build_Process.State()) |
|
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
718 |
|
| 77514 | 719 |
private val _database: Option[SQL.Database] = build_context.open_database() |
| 77372 | 720 |
|
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
721 |
def close(): Unit = synchronized { _database.foreach(_.close()) }
|
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
722 |
|
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
723 |
protected def synchronized_database[A](body: => A): A = |
| 77438 | 724 |
synchronized {
|
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
725 |
_database match {
|
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
726 |
case None => body |
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
727 |
case Some(db) => db.transaction { body }
|
| 77436 | 728 |
} |
729 |
} |
|
730 |
||
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
731 |
private def sync_database(): Unit = |
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
732 |
synchronized_database {
|
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
733 |
for (db <- _database) {
|
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
734 |
_state = |
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
735 |
Build_Process.Data.update_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
|
736 |
db, worker_uuid, build_uuid, build_context.hostname, _state) |
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
737 |
} |
|
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
738 |
} |
| 77436 | 739 |
|
740 |
||
| 77505 | 741 |
/* progress backed by database */ |
742 |
||
| 77533 | 743 |
private def progress_output(message: Progress.Message, build_progress_output: => Unit): Unit = {
|
|
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
744 |
synchronized_database {
|
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
745 |
val state1 = _state.inc_serial.progress_serial() |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
746 |
for (db <- _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
|
747 |
Build_Process.Data.write_progress(db, state1.serial, message, build_uuid) |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
748 |
Build_Process.Data.stamp_worker(db, worker_uuid, state1.serial) |
|
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
749 |
} |
| 77533 | 750 |
build_progress_output |
|
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
751 |
_state = state1 |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
752 |
} |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
753 |
} |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
754 |
|
| 77530 | 755 |
protected object progress extends Progress {
|
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77505
diff
changeset
|
756 |
override def verbose: Boolean = build_progress.verbose |
| 77505 | 757 |
|
|
77509
3bc49507bae5
clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents:
77505
diff
changeset
|
758 |
override def output(message: Progress.Message): Unit = |
|
77522
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
759 |
progress_output(message, if (do_output(message)) build_progress.output(message)) |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
760 |
|
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
761 |
override def theory(theory: Progress.Theory): Unit = |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
762 |
progress_output(theory.message, build_progress.theory(theory)) |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
763 |
|
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
764 |
override def nodes_status(nodes_status: Document_Status.Nodes_Status): Unit = |
|
a1d30297cd61
more complete coverage of non-final Progress methods, notably for Server.Connection_Progress;
wenzelm
parents:
77521
diff
changeset
|
765 |
build_progress.nodes_status(nodes_status) |
| 77505 | 766 |
|
767 |
override def stop(): Unit = build_progress.stop() |
|
768 |
override def stopped: Boolean = build_progress.stopped |
|
769 |
} |
|
770 |
||
| 77530 | 771 |
protected val log: Logger = Logger.make_system_log(progress, build_options) |
| 77505 | 772 |
|
773 |
||
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
774 |
/* policy operations */ |
| 77333 | 775 |
|
|
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
776 |
protected def init_state(state: Build_Process.State): Build_Process.State = {
|
| 77496 | 777 |
val sessions1 = |
778 |
build_context.sessions.foldLeft(state.sessions) { case (map, (name, session)) =>
|
|
779 |
if (state.sessions.isDefinedAt(name)) map |
|
780 |
else map + (name -> session) |
|
781 |
} |
|
782 |
||
|
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
783 |
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
|
784 |
val new_pending = |
|
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
785 |
List.from( |
|
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
786 |
for {
|
| 77449 | 787 |
(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
|
788 |
if !old_pending(name) |
| 77449 | 789 |
} yield Build_Process.Entry(name, session_context.deps)) |
| 77496 | 790 |
val pending1 = new_pending ::: state.pending |
791 |
||
792 |
state.copy(sessions = sessions1, pending = pending1) |
|
|
77415
6b928419f109
clarified signature: allow more general init, e.g. from existing database;
wenzelm
parents:
77414
diff
changeset
|
793 |
} |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
794 |
|
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
795 |
protected def next_job(state: Build_Process.State): Option[String] = |
|
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
796 |
if (state.running.size < (build_context.max_jobs max 1)) {
|
|
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
797 |
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
|
798 |
.sortBy(_.name)(build_context.ordering) |
|
f8aa1647d156
more elementary data structures, to fit better to SQL database;
wenzelm
parents:
77312
diff
changeset
|
799 |
.headOption.map(_.name) |
|
77296
eeaa2872320b
clarified signature: more explicit synchronized operations;
wenzelm
parents:
77295
diff
changeset
|
800 |
} |
|
eeaa2872320b
clarified signature: more explicit synchronized operations;
wenzelm
parents:
77295
diff
changeset
|
801 |
else None |
|
77259
61fc2afe4c8b
clarified signature: prefer stateful object-oriented style, to make it fit better into physical world;
wenzelm
parents:
77258
diff
changeset
|
802 |
|
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
803 |
protected def start_session(state: Build_Process.State, session_name: String): Build_Process.State = {
|
| 77468 | 804 |
val ancestor_results = |
805 |
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
|
806 |
|
|
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
807 |
val input_shasum = |
| 77260 | 808 |
if (ancestor_results.isEmpty) {
|
809 |
SHA1.shasum_meta_info(SHA1.digest(Path.explode("$POLYML_EXE")))
|
|
810 |
} |
|
|
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77459
diff
changeset
|
811 |
else SHA1.flat_shasum(ancestor_results.map(_.output_shasum)) |
| 77257 | 812 |
|
| 77463 | 813 |
val store_heap = build_context.store_heap(session_name) |
| 77469 | 814 |
|
815 |
val (current, output_shasum) = |
|
816 |
store.check_output(session_name, |
|
817 |
sources_shasum = build_context.sources_shasum(session_name), |
|
818 |
input_shasum = input_shasum, |
|
819 |
fresh_build = build_context.fresh_build, |
|
820 |
store_heap = store_heap) |
|
821 |
||
| 77260 | 822 |
val all_current = current && ancestor_results.forall(_.current) |
| 77257 | 823 |
|
| 77260 | 824 |
if (all_current) {
|
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
825 |
state |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
826 |
.remove_pending(session_name) |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
827 |
.make_result(session_name, Process_Result.ok, output_shasum, current = true) |
| 77260 | 828 |
} |
|
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77314
diff
changeset
|
829 |
else if (build_context.no_build) {
|
|
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77514
diff
changeset
|
830 |
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
|
831 |
state. |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
832 |
remove_pending(session_name). |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
833 |
make_result(session_name, Process_Result.error, output_shasum) |
| 77260 | 834 |
} |
| 77452 | 835 |
else if (!ancestor_results.forall(_.ok) || progress.stopped) {
|
836 |
progress.echo(session_name + " CANCELLED") |
|
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
837 |
state |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
838 |
.remove_pending(session_name) |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
839 |
.make_result(session_name, Process_Result.undefined, output_shasum) |
| 77452 | 840 |
} |
841 |
else {
|
|
| 77551 | 842 |
val (numa_node, state1) = state.numa_next_node(build_context.numa_nodes) |
843 |
val node_info = Host.Node_Info(build_context.hostname, numa_node) |
|
844 |
||
845 |
progress.echo( |
|
846 |
(if (store_heap) "Building " else "Running ") + session_name + |
|
847 |
if_proper(node_info.numa_node, " on " + node_info) + " ...") |
|
| 77260 | 848 |
|
| 77472 | 849 |
store.init_output(session_name) |
| 77257 | 850 |
|
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
851 |
val job = |
| 77505 | 852 |
Build_Job.start_session(build_context, progress, log, |
853 |
build_deps.background(session_name), input_shasum, node_info) |
|
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
854 |
state1.add_running(session_name, job) |
| 77260 | 855 |
} |
856 |
} |
|
| 77257 | 857 |
|
| 77436 | 858 |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
859 |
/* build process roles */ |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
860 |
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
861 |
final def start_build(): Unit = synchronized_database {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
862 |
for (db <- _database) {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
863 |
Build_Process.Data.start_build(db, build_uuid, build_context.ml_platform, |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
864 |
store.options.make_prefs(Options.init(prefs = ""))) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
865 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
866 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
867 |
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
868 |
final def stop_build(): Unit = synchronized_database {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
869 |
for (db <- _database) {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
870 |
Build_Process.Data.stop_build(db, build_uuid) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
871 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
872 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
873 |
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
874 |
final def start_worker(): Unit = synchronized_database {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
875 |
for (db <- _database) {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
876 |
val serial = Build_Process.Data.start_worker(db, worker_uuid, build_uuid) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
877 |
_state = _state.set_serial(serial) |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
878 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
879 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
880 |
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
881 |
final def stop_worker(): Unit = synchronized_database {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
882 |
for (db <- _database) {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
883 |
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
|
884 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
885 |
} |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
886 |
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
887 |
|
| 77436 | 888 |
/* run */ |
| 77372 | 889 |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
890 |
def run(master: Boolean = false): Map[String, Process_Result] = {
|
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
891 |
def finished(): Boolean = synchronized_database { _state.finished }
|
|
77400
f3e5b3fe230e
clarified signature: more explicit "synchronized" regions;
wenzelm
parents:
77398
diff
changeset
|
892 |
|
|
77437
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
893 |
def sleep(): Unit = |
|
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
894 |
Isabelle_Thread.interrupt_handler(_ => progress.stop()) {
|
|
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
895 |
build_options.seconds("editor_input_delay").sleep()
|
|
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
896 |
} |
|
dcbf96acae27
clarified signature: do not expose global state to object-oriented variants;
wenzelm
parents:
77436
diff
changeset
|
897 |
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
898 |
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
|
899 |
next_job(_state) match {
|
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
900 |
case Some(name) => |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
901 |
if (Build_Job.is_session_name(name)) {
|
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
902 |
_state = start_session(_state, name) |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
903 |
true |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
904 |
} |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
905 |
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
|
906 |
case None => false |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
907 |
} |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
908 |
} |
|
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
909 |
|
| 77335 | 910 |
if (finished()) {
|
911 |
progress.echo_warning("Nothing to build")
|
|
912 |
Map.empty[String, Process_Result] |
|
913 |
} |
|
914 |
else {
|
|
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
915 |
if (master) start_build() |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
916 |
start_worker() |
| 77538 | 917 |
try {
|
918 |
while (!finished()) {
|
|
919 |
if (progress.stopped) synchronized_database { _state.stop_running() }
|
|
| 77310 | 920 |
|
| 77538 | 921 |
for (job <- synchronized_database { _state.finished_running() }) {
|
922 |
val job_name = job.job_name |
|
923 |
val (process_result, output_shasum) = job.join |
|
924 |
synchronized_database {
|
|
925 |
_state = _state. |
|
926 |
remove_pending(job_name). |
|
927 |
remove_running(job_name). |
|
928 |
make_result(job_name, process_result, output_shasum, node_info = job.node_info) |
|
929 |
} |
|
930 |
} |
|
931 |
||
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
932 |
if (!start_job()) {
|
| 77538 | 933 |
sync_database() |
934 |
sleep() |
|
| 77396 | 935 |
} |
936 |
} |
|
| 77310 | 937 |
} |
|
77546
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
938 |
finally {
|
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
939 |
stop_worker() |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
940 |
if (master) stop_build() |
|
9b9179cda155
clarified build process roles: "worker" vs. "build";
wenzelm
parents:
77545
diff
changeset
|
941 |
} |
|
77467
e27bc7957297
more robust: proper synchronization of transition from next_job to start_session;
wenzelm
parents:
77466
diff
changeset
|
942 |
|
|
77466
94dcf2c3895a
more thorough synchronized_database for internal *and* external state;
wenzelm
parents:
77465
diff
changeset
|
943 |
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
|
944 |
for ((name, result) <- _state.results) yield name -> result.process_result |
| 77257 | 945 |
} |
946 |
} |
|
947 |
} |
|
| 77238 | 948 |
} |