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