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