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