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