author | wenzelm |
Tue, 27 Jun 2023 10:24:32 +0200 | |
changeset 78213 | fd0430a7b7a4 |
parent 78212 | dfb172d7e40e |
child 78215 | cfd58705fbaf |
permissions | -rw-r--r-- |
78178 | 1 |
/* Title: Pure/Thy/store.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Persistent store for session content: within file-system and/or SQL database. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
import java.sql.SQLException |
|
11 |
||
12 |
||
13 |
object Store { |
|
14 |
def apply(options: Options, cache: Term.Cache = Term.Cache.make()): Store = |
|
15 |
new Store(options, cache) |
|
16 |
||
17 |
||
78179 | 18 |
/* session build info */ |
19 |
||
20 |
sealed case class Build_Info( |
|
21 |
sources: SHA1.Shasum, |
|
22 |
input_heaps: SHA1.Shasum, |
|
23 |
output_heap: SHA1.Shasum, |
|
24 |
return_code: Int, |
|
25 |
uuid: String |
|
26 |
) { |
|
27 |
def ok: Boolean = return_code == 0 |
|
28 |
} |
|
29 |
||
30 |
||
31 |
/* session sources */ |
|
78178 | 32 |
|
33 |
sealed case class Source_File( |
|
34 |
name: String, |
|
35 |
digest: SHA1.Digest, |
|
36 |
compressed: Boolean, |
|
37 |
body: Bytes, |
|
38 |
cache: Compress.Cache |
|
39 |
) { |
|
40 |
override def toString: String = name |
|
41 |
||
42 |
def bytes: Bytes = if (compressed) body.uncompress(cache = cache) else body |
|
43 |
} |
|
44 |
||
45 |
object Sources { |
|
46 |
def load(session_base: Sessions.Base, cache: Compress.Cache = Compress.Cache.none): Sources = |
|
47 |
new Sources( |
|
48 |
session_base.session_sources.foldLeft(Map.empty) { |
|
49 |
case (sources, (path, digest)) => |
|
50 |
def err(): Nothing = error("Incoherent digest for source file: " + path) |
|
51 |
val name = File.symbolic_path(path) |
|
52 |
sources.get(name) match { |
|
53 |
case Some(source_file) => |
|
54 |
if (source_file.digest == digest) sources else err() |
|
55 |
case None => |
|
56 |
val bytes = Bytes.read(path) |
|
57 |
if (bytes.sha1_digest == digest) { |
|
58 |
val (compressed, body) = |
|
59 |
bytes.maybe_compress(Compress.Options_Zstd(), cache = cache) |
|
60 |
val file = Source_File(name, digest, compressed, body, cache) |
|
61 |
sources + (name -> file) |
|
62 |
} |
|
63 |
else err() |
|
64 |
} |
|
65 |
}) |
|
66 |
} |
|
67 |
||
68 |
class Sources private(rep: Map[String, Source_File]) extends Iterable[Source_File] { |
|
69 |
override def toString: String = rep.values.toList.sortBy(_.name).mkString("Sources(", ", ", ")") |
|
70 |
override def iterator: Iterator[Source_File] = rep.valuesIterator |
|
71 |
||
72 |
def get(name: String): Option[Source_File] = rep.get(name) |
|
73 |
def apply(name: String): Source_File = |
|
74 |
get(name).getOrElse(error("Missing session sources entry " + quote(name))) |
|
75 |
} |
|
76 |
||
77 |
||
78179 | 78 |
/* SQL data model */ |
78178 | 79 |
|
78187
2df0f3604a67
clarified signature: more explicit class SQL.Data;
wenzelm
parents:
78186
diff
changeset
|
80 |
object Data extends SQL.Data() { |
2df0f3604a67
clarified signature: more explicit class SQL.Data;
wenzelm
parents:
78186
diff
changeset
|
81 |
override lazy val tables = |
78208 | 82 |
SQL.Tables(Session_Info.table, Sources.table, |
83 |
Export.Data.Base.table, Document_Build.Data.table) |
|
78187
2df0f3604a67
clarified signature: more explicit class SQL.Data;
wenzelm
parents:
78186
diff
changeset
|
84 |
|
78179 | 85 |
object Session_Info { |
86 |
val session_name = SQL.Column.string("session_name").make_primary_key |
|
87 |
||
88 |
// Build_Log.Session_Info |
|
89 |
val session_timing = SQL.Column.bytes("session_timing") |
|
90 |
val command_timings = SQL.Column.bytes("command_timings") |
|
91 |
val theory_timings = SQL.Column.bytes("theory_timings") |
|
92 |
val ml_statistics = SQL.Column.bytes("ml_statistics") |
|
93 |
val task_statistics = SQL.Column.bytes("task_statistics") |
|
94 |
val errors = SQL.Column.bytes("errors") |
|
95 |
val build_log_columns = |
|
96 |
List(session_name, session_timing, command_timings, theory_timings, |
|
97 |
ml_statistics, task_statistics, errors) |
|
78178 | 98 |
|
78179 | 99 |
// Build_Info |
100 |
val sources = SQL.Column.string("sources") |
|
101 |
val input_heaps = SQL.Column.string("input_heaps") |
|
102 |
val output_heap = SQL.Column.string("output_heap") |
|
103 |
val return_code = SQL.Column.int("return_code") |
|
104 |
val uuid = SQL.Column.string("uuid") |
|
105 |
val build_columns = List(sources, input_heaps, output_heap, return_code, uuid) |
|
106 |
||
107 |
val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns) |
|
78178 | 108 |
|
78179 | 109 |
val augment_table: PostgreSQL.Source = |
110 |
"ALTER TABLE IF EXISTS " + table.ident + |
|
111 |
" ADD COLUMN IF NOT EXISTS " + uuid.decl(SQL.sql_type_postgresql) |
|
112 |
} |
|
113 |
||
114 |
object Sources { |
|
115 |
val session_name = SQL.Column.string("session_name").make_primary_key |
|
116 |
val name = SQL.Column.string("name").make_primary_key |
|
117 |
val digest = SQL.Column.string("digest") |
|
118 |
val compressed = SQL.Column.bool("compressed") |
|
119 |
val body = SQL.Column.bytes("body") |
|
78178 | 120 |
|
78179 | 121 |
val table = |
122 |
SQL.Table("isabelle_sources", List(session_name, name, digest, compressed, body)) |
|
123 |
||
124 |
def where_equal(session_name: String, name: String = ""): SQL.Source = |
|
125 |
SQL.where_and( |
|
126 |
Sources.session_name.equal(session_name), |
|
127 |
if_proper(name, Sources.name.equal(name))) |
|
128 |
} |
|
129 |
||
78181 | 130 |
def write_session_info( |
131 |
db: SQL.Database, |
|
132 |
cache: Compress.Cache, |
|
133 |
session_name: String, |
|
134 |
build_log: Build_Log.Session_Info, |
|
135 |
build: Build_Info |
|
136 |
): Unit = { |
|
137 |
db.execute_statement(Store.Data.Session_Info.table.insert(), body = |
|
138 |
{ stmt => |
|
139 |
stmt.string(1) = session_name |
|
140 |
stmt.bytes(2) = Properties.encode(build_log.session_timing) |
|
141 |
stmt.bytes(3) = Properties.compress(build_log.command_timings, cache = cache) |
|
142 |
stmt.bytes(4) = Properties.compress(build_log.theory_timings, cache = cache) |
|
143 |
stmt.bytes(5) = Properties.compress(build_log.ml_statistics, cache = cache) |
|
144 |
stmt.bytes(6) = Properties.compress(build_log.task_statistics, cache = cache) |
|
145 |
stmt.bytes(7) = Build_Log.compress_errors(build_log.errors, cache = cache) |
|
146 |
stmt.string(8) = build.sources.toString |
|
147 |
stmt.string(9) = build.input_heaps.toString |
|
148 |
stmt.string(10) = build.output_heap.toString |
|
149 |
stmt.int(11) = build.return_code |
|
150 |
stmt.string(12) = build.uuid |
|
151 |
}) |
|
152 |
} |
|
153 |
||
78179 | 154 |
def write_sources(db: SQL.Database, session_name: String, sources: Sources): Unit = |
155 |
for (source_file <- sources) { |
|
156 |
db.execute_statement(Sources.table.insert(), body = |
|
157 |
{ stmt => |
|
158 |
stmt.string(1) = session_name |
|
159 |
stmt.string(2) = source_file.name |
|
160 |
stmt.string(3) = source_file.digest.toString |
|
161 |
stmt.bool(4) = source_file.compressed |
|
162 |
stmt.bytes(5) = source_file.body |
|
163 |
}) |
|
164 |
} |
|
78178 | 165 |
|
78179 | 166 |
def read_sources( |
167 |
db: SQL.Database, |
|
78180 | 168 |
cache: Compress.Cache, |
78179 | 169 |
session_name: String, |
170 |
name: String = "" |
|
171 |
): List[Source_File] = { |
|
172 |
db.execute_query_statement( |
|
173 |
Sources.table.select( |
|
174 |
sql = Sources.where_equal(session_name, name = name) + SQL.order_by(List(Sources.name))), |
|
175 |
List.from[Source_File], |
|
176 |
{ res => |
|
177 |
val res_name = res.string(Sources.name) |
|
178 |
val digest = SHA1.fake_digest(res.string(Sources.digest)) |
|
179 |
val compressed = res.bool(Sources.compressed) |
|
180 |
val body = res.bytes(Sources.body) |
|
78180 | 181 |
Source_File(res_name, digest, compressed, body, cache) |
78179 | 182 |
} |
183 |
) |
|
184 |
} |
|
78178 | 185 |
} |
186 |
} |
|
187 |
||
188 |
class Store private(val options: Options, val cache: Term.Cache) { |
|
189 |
store => |
|
190 |
||
191 |
override def toString: String = "Store(output_dir = " + output_dir.absolute + ")" |
|
192 |
||
193 |
||
194 |
/* directories */ |
|
195 |
||
196 |
val system_output_dir: Path = Path.explode("$ISABELLE_HEAPS_SYSTEM/$ML_IDENTIFIER") |
|
197 |
val user_output_dir: Path = Path.explode("$ISABELLE_HEAPS/$ML_IDENTIFIER") |
|
198 |
||
199 |
def system_heaps: Boolean = options.bool("system_heaps") |
|
200 |
||
201 |
val output_dir: Path = |
|
202 |
if (system_heaps) system_output_dir else user_output_dir |
|
203 |
||
204 |
val input_dirs: List[Path] = |
|
205 |
if (system_heaps) List(system_output_dir) |
|
206 |
else List(user_output_dir, system_output_dir) |
|
207 |
||
208 |
def presentation_dir: Path = |
|
209 |
if (system_heaps) Path.explode("$ISABELLE_BROWSER_INFO_SYSTEM") |
|
210 |
else Path.explode("$ISABELLE_BROWSER_INFO") |
|
211 |
||
212 |
||
213 |
/* file names */ |
|
214 |
||
215 |
def heap(name: String): Path = Path.basic(name) |
|
216 |
def database(name: String): Path = Path.basic("log") + Path.basic(name).db |
|
217 |
def log(name: String): Path = Path.basic("log") + Path.basic(name) |
|
218 |
def log_gz(name: String): Path = log(name).gz |
|
219 |
||
220 |
def output_heap(name: String): Path = output_dir + heap(name) |
|
221 |
def output_database(name: String): Path = output_dir + database(name) |
|
222 |
def output_log(name: String): Path = output_dir + log(name) |
|
223 |
def output_log_gz(name: String): Path = output_dir + log_gz(name) |
|
224 |
||
225 |
||
226 |
/* heap */ |
|
227 |
||
228 |
def find_heap(name: String): Option[Path] = |
|
229 |
input_dirs.map(_ + heap(name)).find(_.is_file) |
|
230 |
||
231 |
def the_heap(name: String): Path = |
|
232 |
find_heap(name) getOrElse |
|
233 |
error("Missing heap image for session " + quote(name) + " -- expected in:\n" + |
|
234 |
cat_lines(input_dirs.map(dir => " " + File.standard_path(dir)))) |
|
235 |
||
78212 | 236 |
def heap_shasum(database_server: Option[SQL.Database], name: String): SHA1.Shasum = { |
237 |
def get_database = database_server.flatMap(ML_Heap.get_entry(_, name)) |
|
78196
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
238 |
def get_file = find_heap(name).flatMap(ML_Heap.read_file_digest) |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
239 |
|
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
240 |
get_database orElse get_file match { |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
241 |
case Some(digest) => SHA1.shasum(digest, name) |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
242 |
case None => SHA1.no_shasum |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
243 |
} |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
244 |
} |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
245 |
|
78178 | 246 |
|
247 |
/* databases for build process and session content */ |
|
248 |
||
249 |
def find_database(name: String): Option[Path] = |
|
250 |
input_dirs.map(_ + database(name)).find(_.is_file) |
|
251 |
||
252 |
def build_database_server: Boolean = options.bool("build_database_server") |
|
253 |
def build_database_test: Boolean = options.bool("build_database_test") |
|
254 |
||
255 |
def open_database_server(): PostgreSQL.Database = |
|
256 |
PostgreSQL.open_database( |
|
257 |
user = options.string("build_database_user"), |
|
258 |
password = options.string("build_database_password"), |
|
259 |
database = options.string("build_database_name"), |
|
260 |
host = options.string("build_database_host"), |
|
261 |
port = options.int("build_database_port"), |
|
262 |
ssh = |
|
263 |
proper_string(options.string("build_database_ssh_host")).map(ssh_host => |
|
264 |
SSH.open_session(options, |
|
265 |
host = ssh_host, |
|
266 |
user = options.string("build_database_ssh_user"), |
|
267 |
port = options.int("build_database_ssh_port"))), |
|
268 |
ssh_close = true) |
|
269 |
||
78205
a40ae2df39ad
clarified database for heaps: do not depend on build_database_test;
wenzelm
parents:
78198
diff
changeset
|
270 |
def maybe_open_database_server(): Option[SQL.Database] = |
a40ae2df39ad
clarified database for heaps: do not depend on build_database_test;
wenzelm
parents:
78198
diff
changeset
|
271 |
if (build_database_server) Some(open_database_server()) else None |
a40ae2df39ad
clarified database for heaps: do not depend on build_database_test;
wenzelm
parents:
78198
diff
changeset
|
272 |
|
78178 | 273 |
def open_build_database(path: Path): SQL.Database = |
274 |
if (build_database_server) open_database_server() |
|
275 |
else SQLite.open_database(path, restrict = true) |
|
276 |
||
277 |
def maybe_open_build_database(path: Path): Option[SQL.Database] = |
|
78184 | 278 |
if (build_database_test) Some(open_build_database(path)) else None |
279 |
||
78178 | 280 |
def try_open_database( |
281 |
name: String, |
|
282 |
output: Boolean = false, |
|
283 |
server: Boolean = build_database_server |
|
284 |
): Option[SQL.Database] = { |
|
285 |
def check(db: SQL.Database): Option[SQL.Database] = |
|
286 |
if (output || session_info_exists(db)) Some(db) else { db.close(); None } |
|
287 |
||
288 |
if (server) check(open_database_server()) |
|
289 |
else if (output) Some(SQLite.open_database(output_database(name))) |
|
290 |
else { |
|
291 |
(for { |
|
292 |
dir <- input_dirs.view |
|
293 |
path = dir + database(name) if path.is_file |
|
294 |
db <- check(SQLite.open_database(path)) |
|
295 |
} yield db).headOption |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
def error_database(name: String): Nothing = |
|
300 |
error("Missing build database for session " + quote(name)) |
|
301 |
||
302 |
def open_database(name: String, output: Boolean = false): SQL.Database = |
|
303 |
try_open_database(name, output = output) getOrElse error_database(name) |
|
304 |
||
305 |
def prepare_output(): Unit = Isabelle_System.make_directory(output_dir + Path.basic("log")) |
|
306 |
||
78213
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
307 |
def clean_output( |
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
308 |
database_server: Option[SQL.Database], |
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
309 |
name: String, |
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
310 |
init: Boolean = false |
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
311 |
): Option[Boolean] = { |
78178 | 312 |
val relevant_db = |
78213
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
313 |
database_server match { |
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
314 |
case Some(db) => clean_session_info(db, name) |
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
315 |
case None => false |
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
316 |
} |
78178 | 317 |
|
318 |
val del = |
|
319 |
for { |
|
320 |
dir <- |
|
321 |
(if (system_heaps) List(user_output_dir, system_output_dir) else List(user_output_dir)) |
|
322 |
file <- List(heap(name), database(name), log(name), log_gz(name)) |
|
323 |
path = dir + file if path.is_file |
|
324 |
} yield path.file.delete |
|
325 |
||
78213
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
326 |
database_server.foreach(ML_Heap.clean_entry(_, name)) |
78190 | 327 |
|
78186 | 328 |
if (init) { |
78212 | 329 |
using(open_database(name, output = true))(clean_session_info(_, name)) |
78186 | 330 |
} |
78178 | 331 |
|
78185 | 332 |
if (relevant_db || del.nonEmpty) Some(del.forall(identity)) else None |
78178 | 333 |
} |
334 |
||
335 |
def check_output( |
|
336 |
name: String, |
|
337 |
session_options: Options, |
|
338 |
sources_shasum: SHA1.Shasum, |
|
339 |
input_shasum: SHA1.Shasum, |
|
340 |
fresh_build: Boolean, |
|
341 |
store_heap: Boolean |
|
342 |
): (Boolean, SHA1.Shasum) = { |
|
343 |
try_open_database(name) match { |
|
344 |
case Some(db) => |
|
78196
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
345 |
using(db) { _ => |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
346 |
read_build(db, name) match { |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
347 |
case Some(build) => |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
348 |
val output_shasum = heap_shasum(if (db.is_postgresql) Some(db) else None, name) |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
349 |
val current = |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
350 |
!fresh_build && |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
351 |
build.ok && |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
352 |
Sessions.eq_sources(session_options, build.sources, sources_shasum) && |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
353 |
build.input_heaps == input_shasum && |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
354 |
build.output_heap == output_shasum && |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
355 |
!(store_heap && output_shasum.is_empty) |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
356 |
(current, output_shasum) |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
357 |
case None => (false, SHA1.no_shasum) |
140a6f2e3728
restore heaps from database, which takes precedence over file-system;
wenzelm
parents:
78190
diff
changeset
|
358 |
} |
78178 | 359 |
} |
360 |
case None => (false, SHA1.no_shasum) |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
||
365 |
/* SQL database content */ |
|
366 |
||
367 |
def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes = |
|
368 |
db.execute_query_statementO[Bytes]( |
|
78179 | 369 |
Store.Data.Session_Info.table.select(List(column), |
370 |
sql = Store.Data.Session_Info.session_name.where_equal(name)), |
|
78178 | 371 |
res => res.bytes(column) |
372 |
).getOrElse(Bytes.empty) |
|
373 |
||
374 |
def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
|
375 |
Properties.uncompress(read_bytes(db, name, column), cache = cache) |
|
376 |
||
377 |
||
378 |
/* session info */ |
|
379 |
||
78181 | 380 |
def session_info_exists(db: SQL.Database): Boolean = { |
381 |
val tables = db.tables |
|
78187
2df0f3604a67
clarified signature: more explicit class SQL.Data;
wenzelm
parents:
78186
diff
changeset
|
382 |
Store.Data.tables.forall(table => tables.contains(table.name)) |
78181 | 383 |
} |
384 |
||
385 |
def session_info_defined(db: SQL.Database, name: String): Boolean = |
|
386 |
db.execute_query_statementB( |
|
387 |
Store.Data.Session_Info.table.select(List(Store.Data.Session_Info.session_name), |
|
388 |
sql = Store.Data.Session_Info.session_name.where_equal(name))) |
|
389 |
||
78212 | 390 |
def clean_session_info(db: SQL.Database, name: String): Boolean = |
78213
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
391 |
Store.Data.transaction_lock(db, create = true, synchronized = true) { |
78178 | 392 |
val already_defined = session_info_defined(db, name) |
393 |
||
394 |
db.execute_statement( |
|
78179 | 395 |
Store.Data.Session_Info.table.delete( |
396 |
sql = Store.Data.Session_Info.session_name.where_equal(name))) |
|
397 |
if (db.is_postgresql) db.execute_statement(Store.Data.Session_Info.augment_table) |
|
78178 | 398 |
|
78179 | 399 |
db.execute_statement(Store.Data.Sources.table.delete( |
400 |
sql = Store.Data.Sources.where_equal(name))) |
|
78178 | 401 |
|
402 |
db.execute_statement( |
|
78208 | 403 |
Export.Data.Base.table.delete(sql = Export.Data.Base.session_name.where_equal(name))) |
78178 | 404 |
|
405 |
db.execute_statement( |
|
406 |
Document_Build.Data.table.delete(sql = Document_Build.Data.session_name.where_equal(name))) |
|
407 |
||
408 |
already_defined |
|
409 |
} |
|
410 |
||
411 |
def write_session_info( |
|
412 |
db: SQL.Database, |
|
413 |
session_name: String, |
|
414 |
sources: Store.Sources, |
|
415 |
build_log: Build_Log.Session_Info, |
|
416 |
build: Store.Build_Info |
|
417 |
): Unit = { |
|
78213
fd0430a7b7a4
avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents:
78212
diff
changeset
|
418 |
Store.Data.transaction_lock(db, synchronized = true) { |
78179 | 419 |
Store.Data.write_sources(db, session_name, sources) |
78181 | 420 |
Store.Data.write_session_info(db, cache.compress, session_name, build_log, build) |
78178 | 421 |
} |
422 |
} |
|
423 |
||
424 |
def read_session_timing(db: SQL.Database, name: String): Properties.T = |
|
78179 | 425 |
Properties.decode(read_bytes(db, name, Store.Data.Session_Info.session_timing), cache = cache) |
78178 | 426 |
|
427 |
def read_command_timings(db: SQL.Database, name: String): Bytes = |
|
78179 | 428 |
read_bytes(db, name, Store.Data.Session_Info.command_timings) |
78178 | 429 |
|
430 |
def read_theory_timings(db: SQL.Database, name: String): List[Properties.T] = |
|
78179 | 431 |
read_properties(db, name, Store.Data.Session_Info.theory_timings) |
78178 | 432 |
|
433 |
def read_ml_statistics(db: SQL.Database, name: String): List[Properties.T] = |
|
78179 | 434 |
read_properties(db, name, Store.Data.Session_Info.ml_statistics) |
78178 | 435 |
|
436 |
def read_task_statistics(db: SQL.Database, name: String): List[Properties.T] = |
|
78179 | 437 |
read_properties(db, name, Store.Data.Session_Info.task_statistics) |
78178 | 438 |
|
439 |
def read_theories(db: SQL.Database, name: String): List[String] = |
|
440 |
read_theory_timings(db, name).flatMap(Markup.Name.unapply) |
|
441 |
||
442 |
def read_errors(db: SQL.Database, name: String): List[String] = |
|
78179 | 443 |
Build_Log.uncompress_errors(read_bytes(db, name, Store.Data.Session_Info.errors), cache = cache) |
78178 | 444 |
|
445 |
def read_build(db: SQL.Database, name: String): Option[Store.Build_Info] = { |
|
78179 | 446 |
if (db.tables.contains(Store.Data.Session_Info.table.name)) { |
78178 | 447 |
db.execute_query_statementO[Store.Build_Info]( |
78179 | 448 |
Store.Data.Session_Info.table.select( |
449 |
sql = Store.Data.Session_Info.session_name.where_equal(name)), |
|
78178 | 450 |
{ res => |
451 |
val uuid = |
|
78179 | 452 |
try { Option(res.string(Store.Data.Session_Info.uuid)).getOrElse("") } |
78178 | 453 |
catch { case _: SQLException => "" } |
454 |
Store.Build_Info( |
|
78179 | 455 |
SHA1.fake_shasum(res.string(Store.Data.Session_Info.sources)), |
456 |
SHA1.fake_shasum(res.string(Store.Data.Session_Info.input_heaps)), |
|
457 |
SHA1.fake_shasum(res.string(Store.Data.Session_Info.output_heap)), |
|
458 |
res.int(Store.Data.Session_Info.return_code), |
|
78178 | 459 |
uuid) |
460 |
} |
|
461 |
) |
|
462 |
} |
|
463 |
else None |
|
464 |
} |
|
465 |
||
78179 | 466 |
def read_sources(db: SQL.Database, session: String, name: String = ""): List[Store.Source_File] = |
78180 | 467 |
Store.Data.read_sources(db, cache.compress, session, name = name) |
78178 | 468 |
} |