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