26 max_jobs: Int = 1, |
26 max_jobs: Int = 1, |
27 fresh_build: Boolean = false, |
27 fresh_build: Boolean = false, |
28 no_build: Boolean = false, |
28 no_build: Boolean = false, |
29 verbose: Boolean = false, |
29 verbose: Boolean = false, |
30 session_setup: (String, Session) => Unit = (_, _) => (), |
30 session_setup: (String, Session) => Unit = (_, _) => (), |
31 instance: String = UUID.random().toString |
31 uuid: String = UUID.random().toString |
32 ): Context = { |
32 ): Context = { |
33 val sessions_structure = build_deps.sessions_structure |
33 val sessions_structure = build_deps.sessions_structure |
34 val build_graph = sessions_structure.build_graph |
34 val build_graph = sessions_structure.build_graph |
35 |
35 |
36 val sessions = |
36 val sessions = |
76 case ord => ord |
76 case ord => ord |
77 } |
77 } |
78 } |
78 } |
79 |
79 |
80 val numa_nodes = NUMA.nodes(enabled = numa_shuffling) |
80 val numa_nodes = NUMA.nodes(enabled = numa_shuffling) |
81 new Context(instance, store, build_deps, sessions, ordering, progress, hostname, numa_nodes, |
81 new Context(uuid, store, build_deps, sessions, ordering, progress, hostname, numa_nodes, |
82 build_heap = build_heap, max_jobs = max_jobs, fresh_build = fresh_build, |
82 build_heap = build_heap, max_jobs = max_jobs, fresh_build = fresh_build, |
83 no_build = no_build, verbose = verbose, session_setup) |
83 no_build = no_build, verbose = verbose, session_setup) |
84 } |
84 } |
85 } |
85 } |
86 |
86 |
87 final class Context private( |
87 final class Context private( |
88 val instance: String, |
88 val uuid: String, |
89 val store: Sessions.Store, |
89 val store: Sessions.Store, |
90 val build_deps: Sessions.Deps, |
90 val build_deps: Sessions.Deps, |
91 val sessions: Map[String, Build_Job.Session_Context], |
91 val sessions: Map[String, Build_Job.Session_Context], |
92 val ordering: Ordering[String], |
92 val ordering: Ordering[String], |
93 val progress: Progress, |
93 val progress: Progress, |
198 |
198 |
199 def make_table(name: String, columns: List[SQL.Column], body: String = ""): SQL.Table = |
199 def make_table(name: String, columns: List[SQL.Column], body: String = ""): SQL.Table = |
200 SQL.Table("isabelle_build" + if_proper(name, "_" + name), columns, body = body) |
200 SQL.Table("isabelle_build" + if_proper(name, "_" + name), columns, body = body) |
201 |
201 |
202 object Generic { |
202 object Generic { |
203 val instance = SQL.Column.string("instance") |
203 val uuid = SQL.Column.string("uuid") |
204 val name = SQL.Column.string("name") |
204 val name = SQL.Column.string("name") |
205 |
205 |
206 def sql_equal(instance: String = "", name: String = ""): SQL.Source = |
206 def sql_equal(uuid: String = "", name: String = ""): SQL.Source = |
207 SQL.and( |
207 SQL.and( |
208 if_proper(instance, Generic.instance.equal(instance)), |
208 if_proper(uuid, Generic.uuid.equal(uuid)), |
209 if_proper(name, Generic.name.equal(name))) |
209 if_proper(name, Generic.name.equal(name))) |
210 |
210 |
211 def sql_member(instance: String = "", names: Iterable[String] = Nil): SQL.Source = |
211 def sql_member(uuid: String = "", names: Iterable[String] = Nil): SQL.Source = |
212 SQL.and( |
212 SQL.and( |
213 if_proper(instance, Generic.instance.equal(instance)), |
213 if_proper(uuid, Generic.uuid.equal(uuid)), |
214 if_proper(names, Generic.name.member(names))) |
214 if_proper(names, Generic.name.member(names))) |
215 } |
215 } |
216 |
216 |
217 object Base { |
217 object Base { |
218 val instance = Generic.instance.make_primary_key |
218 val uuid = Generic.uuid.make_primary_key |
219 val ml_platform = SQL.Column.string("ml_platform") |
219 val ml_platform = SQL.Column.string("ml_platform") |
220 val options = SQL.Column.string("options") |
220 val options = SQL.Column.string("options") |
221 |
221 |
222 val table = make_table("", List(instance, ml_platform, options)) |
222 val table = make_table("", List(uuid, ml_platform, options)) |
223 } |
223 } |
224 |
224 |
225 object Serial { |
225 object Serial { |
226 val serial = SQL.Column.long("serial") |
226 val serial = SQL.Column.long("serial") |
227 |
227 |
439 } |
439 } |
440 |
440 |
441 for (table <- tables) db.using_statement(table.delete())(_.execute()) |
441 for (table <- tables) db.using_statement(table.delete())(_.execute()) |
442 |
442 |
443 db.using_statement(Base.table.insert()) { stmt => |
443 db.using_statement(Base.table.insert()) { stmt => |
444 stmt.string(1) = build_context.instance |
444 stmt.string(1) = build_context.uuid |
445 stmt.string(2) = Isabelle_System.getenv("ML_PLATFORM") |
445 stmt.string(2) = Isabelle_System.getenv("ML_PLATFORM") |
446 stmt.string(3) = build_context.store.options.make_prefs(Options.init(prefs = "")) |
446 stmt.string(3) = build_context.store.options.make_prefs(Options.init(prefs = "")) |
447 stmt.execute() |
447 stmt.execute() |
448 } |
448 } |
449 } |
449 } |
450 |
450 |
451 def update_database( |
451 def update_database( |
452 db: SQL.Database, |
452 db: SQL.Database, |
453 instance: String, |
453 uuid: String, |
454 hostname: String, |
454 hostname: String, |
455 state: State |
455 state: State |
456 ): State = { |
456 ): State = { |
457 val changed = |
457 val changed = |
458 List( |
458 List( |