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