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