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