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