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