src/Pure/Build/store.scala
author wenzelm
Wed, 21 Feb 2024 19:59:35 +0100
changeset 79684 0554a32a6ef4
parent 79682 1fa1b32b0379
child 79685 45af93b0370a
permissions -rw-r--r--
clarified signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
79502
c7a98469c0e7 clarified directories;
wenzelm
parents: 78863
diff changeset
     1
/*  Title:      Pure/Build/store.scala
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     3
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     4
Persistent store for session content: within file-system and/or SQL database.
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     5
*/
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     6
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     8
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
     9
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    10
import java.sql.SQLException
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    11
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    12
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    13
object Store {
79676
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
    14
  def apply(
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
    15
    options: Options,
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
    16
    build_cluster: Boolean = false,
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
    17
    cache: Term.Cache = Term.Cache.make()
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
    18
  ): Store = new Store(options, build_cluster, cache)
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    19
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    20
79684
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    21
  /* file names */
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    22
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    23
  def heap(name: String): Path = Path.basic(name)
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    24
  def log(name: String): Path = Path.basic("log") + Path.basic(name)
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    25
  def log_db(name: String): Path = log(name).db
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    26
  def log_gz(name: String): Path = log(name).gz
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    27
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
    28
79662
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    29
  /* session */
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    30
79674
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    31
  final class Session private[Store](
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    32
    val name: String,
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    33
    val heap: Option[Path],
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    34
    val log_db: Option[Path],
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    35
    dirs: List[Path]
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    36
  ) {
79662
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    37
    def defined: Boolean = heap.isDefined || log_db.isDefined
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    38
79674
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    39
    def the_heap: Path =
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    40
      heap getOrElse
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    41
        error("Missing heap image for session " + quote(name) + " -- expected in:\n" +
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    42
          cat_lines(dirs.map(dir => "  " + File.standard_path(dir))))
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
    43
79663
4a299bdb5d61 clarified signature: more comprehensive operations;
wenzelm
parents: 79662
diff changeset
    44
    def heap_digest(): Option[SHA1.Digest] =
4a299bdb5d61 clarified signature: more comprehensive operations;
wenzelm
parents: 79662
diff changeset
    45
      heap.flatMap(ML_Heap.read_file_digest)
4a299bdb5d61 clarified signature: more comprehensive operations;
wenzelm
parents: 79662
diff changeset
    46
79662
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    47
    override def toString: String = name
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    48
  }
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    49
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    50
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
    51
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    52
  /* session build info */
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    53
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    54
  sealed case class Build_Info(
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    55
    sources: SHA1.Shasum,
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    56
    input_heaps: SHA1.Shasum,
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    57
    output_heap: SHA1.Shasum,
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    58
    return_code: Int,
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    59
    uuid: String
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    60
  ) {
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    61
    def ok: Boolean = return_code == 0
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    62
  }
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    63
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    64
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
    65
  /* session sources */
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    66
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    67
  sealed case class Source_File(
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    68
    name: String,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    69
    digest: SHA1.Digest,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    70
    compressed: Boolean,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    71
    body: Bytes,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    72
    cache: Compress.Cache
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    73
  ) {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    74
    override def toString: String = name
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    75
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    76
    def bytes: Bytes = if (compressed) body.uncompress(cache = cache) else body
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    77
  }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    78
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    79
  object Sources {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    80
    def load(session_base: Sessions.Base, cache: Compress.Cache = Compress.Cache.none): Sources =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    81
      new Sources(
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    82
        session_base.session_sources.foldLeft(Map.empty) {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    83
          case (sources, (path, digest)) =>
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    84
            def err(): Nothing = error("Incoherent digest for source file: " + path)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    85
            val name = File.symbolic_path(path)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    86
            sources.get(name) match {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    87
              case Some(source_file) =>
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    88
                if (source_file.digest == digest) sources else err()
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    89
              case None =>
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    90
                val bytes = Bytes.read(path)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    91
                if (bytes.sha1_digest == digest) {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    92
                  val (compressed, body) =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    93
                    bytes.maybe_compress(Compress.Options_Zstd(), cache = cache)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    94
                  val file = Source_File(name, digest, compressed, body, cache)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    95
                  sources + (name -> file)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    96
                }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    97
                else err()
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    98
            }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
    99
        })
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   100
  }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   101
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   102
  class Sources private(rep: Map[String, Source_File]) extends Iterable[Source_File] {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   103
    override def toString: String = rep.values.toList.sortBy(_.name).mkString("Sources(", ", ", ")")
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   104
    override def iterator: Iterator[Source_File] = rep.valuesIterator
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   105
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   106
    def get(name: String): Option[Source_File] = rep.get(name)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   107
    def apply(name: String): Source_File =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   108
      get(name).getOrElse(error("Missing session sources entry " + quote(name)))
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   109
  }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   110
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   111
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   112
  /* SQL data model */
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   113
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   114
  object private_data extends SQL.Data() {
78260
0a7f7abbe4f0 more robust transaction_lock: avoid overlapping data spaces;
wenzelm
parents: 78227
diff changeset
   115
    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
   116
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   117
    object Session_Info {
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   118
      val session_name = SQL.Column.string("session_name").make_primary_key
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   119
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   120
      // Build_Log.Session_Info
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   121
      val session_timing = SQL.Column.bytes("session_timing")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   122
      val command_timings = SQL.Column.bytes("command_timings")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   123
      val theory_timings = SQL.Column.bytes("theory_timings")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   124
      val ml_statistics = SQL.Column.bytes("ml_statistics")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   125
      val task_statistics = SQL.Column.bytes("task_statistics")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   126
      val errors = SQL.Column.bytes("errors")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   127
      val build_log_columns =
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   128
        List(session_name, session_timing, command_timings, theory_timings,
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   129
          ml_statistics, task_statistics, errors)
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   130
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   131
      // Build_Info
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   132
      val sources = SQL.Column.string("sources")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   133
      val input_heaps = SQL.Column.string("input_heaps")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   134
      val output_heap = SQL.Column.string("output_heap")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   135
      val return_code = SQL.Column.int("return_code")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   136
      val uuid = SQL.Column.string("uuid")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   137
      val build_columns = List(sources, input_heaps, output_heap, return_code, uuid)
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   138
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   139
      val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns)
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   140
    }
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   141
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   142
    object Sources {
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   143
      val session_name = SQL.Column.string("session_name").make_primary_key
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   144
      val name = SQL.Column.string("name").make_primary_key
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   145
      val digest = SQL.Column.string("digest")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   146
      val compressed = SQL.Column.bool("compressed")
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   147
      val body = SQL.Column.bytes("body")
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   148
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   149
      val table =
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   150
        SQL.Table("isabelle_sources", List(session_name, name, digest, compressed, body))
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   151
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   152
      def where_equal(session_name: String, name: String = ""): SQL.Source =
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   153
        SQL.where_and(
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   154
          Sources.session_name.equal(session_name),
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   155
          if_proper(name, Sources.name.equal(name)))
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   156
    }
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   157
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   158
    def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   159
      db.execute_query_statementO[Bytes](
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   160
        Session_Info.table.select(List(column), sql = Session_Info.session_name.where_equal(name)),
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   161
        res => res.bytes(column)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   162
      ).getOrElse(Bytes.empty)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   163
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   164
    def read_properties(
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   165
      db: SQL.Database, name: String, column: SQL.Column, cache: Term.Cache
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   166
    ): List[Properties.T] = Properties.uncompress(read_bytes(db, name, column), cache = cache)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   167
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   168
    def read_session_timing(db: SQL.Database, name: String, cache: Term.Cache): Properties.T =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   169
      Properties.decode(read_bytes(db, name, Session_Info.session_timing), cache = cache)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   170
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   171
    def read_command_timings(db: SQL.Database, name: String): Bytes =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   172
      read_bytes(db, name, Session_Info.command_timings)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   173
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   174
    def read_theory_timings(db: SQL.Database, name: String, cache: Term.Cache): List[Properties.T] =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   175
      read_properties(db, name, Session_Info.theory_timings, cache)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   176
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   177
    def read_ml_statistics(db: SQL.Database, name: String, cache: Term.Cache): List[Properties.T] =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   178
      read_properties(db, name, Session_Info.ml_statistics, cache)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   179
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   180
    def read_task_statistics(db: SQL.Database, name: String, cache: Term.Cache): List[Properties.T] =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   181
      read_properties(db, name, Session_Info.task_statistics, cache)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   182
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   183
    def read_errors(db: SQL.Database, name: String, cache: Term.Cache): List[String] =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   184
      Build_Log.uncompress_errors(read_bytes(db, name, Session_Info.errors), cache = cache)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   185
78377
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   186
    def read_build(db: SQL.Database, name: String): Option[Store.Build_Info] =
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   187
      db.execute_query_statementO[Store.Build_Info](
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   188
        Session_Info.table.select(sql = Session_Info.session_name.where_equal(name)),
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   189
        { res =>
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   190
          val uuid =
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   191
            try { Option(res.string(Session_Info.uuid)).getOrElse("") }
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   192
            catch { case _: SQLException => "" }
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   193
          Store.Build_Info(
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   194
            SHA1.fake_shasum(res.string(Session_Info.sources)),
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   195
            SHA1.fake_shasum(res.string(Session_Info.input_heaps)),
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   196
            SHA1.fake_shasum(res.string(Session_Info.output_heap)),
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   197
            res.int(Session_Info.return_code),
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   198
            uuid)
e0155f03c781 clarified check: uniform session_info_exists;
wenzelm
parents: 78376
diff changeset
   199
        })
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   200
79682
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   201
    def read_build_uuid(db: SQL.Database, name: String): String =
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   202
      db.execute_query_statementO[String](
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   203
        Session_Info.table.select(List(Session_Info.uuid),
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   204
          sql = Session_Info.session_name.where_equal(name)),
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   205
        { res =>
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   206
            try { Option(res.string(Session_Info.uuid)).getOrElse("") }
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   207
            catch { case _: SQLException => "" }
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   208
        }).getOrElse("")
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   209
78181
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   210
    def write_session_info(
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   211
      db: SQL.Database,
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   212
      cache: Compress.Cache,
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   213
      session_name: String,
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   214
      build_log: Build_Log.Session_Info,
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   215
      build: Build_Info
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   216
    ): Unit = {
78262
wenzelm
parents: 78260
diff changeset
   217
      db.execute_statement(Session_Info.table.insert(), body =
78181
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   218
        { stmt =>
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   219
          stmt.string(1) = session_name
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   220
          stmt.bytes(2) = Properties.encode(build_log.session_timing)
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   221
          stmt.bytes(3) = Properties.compress(build_log.command_timings, cache = cache)
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   222
          stmt.bytes(4) = Properties.compress(build_log.theory_timings, cache = cache)
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   223
          stmt.bytes(5) = Properties.compress(build_log.ml_statistics, cache = cache)
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   224
          stmt.bytes(6) = Properties.compress(build_log.task_statistics, cache = cache)
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   225
          stmt.bytes(7) = Build_Log.compress_errors(build_log.errors, cache = cache)
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   226
          stmt.string(8) = build.sources.toString
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   227
          stmt.string(9) = build.input_heaps.toString
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   228
          stmt.string(10) = build.output_heap.toString
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   229
          stmt.int(11) = build.return_code
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   230
          stmt.string(12) = build.uuid
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   231
        })
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   232
    }
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   233
78555
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   234
    def write_sources(
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   235
      db: SQL.Database,
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   236
      session_name: String,
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   237
      source_files: Iterable[Source_File]
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   238
    ): Unit = {
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   239
      db.execute_batch_statement(Sources.table.insert(), batch =
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   240
        for (source_file <- source_files) yield { (stmt: SQL.Statement) =>
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   241
          stmt.string(1) = session_name
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   242
          stmt.string(2) = source_file.name
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   243
          stmt.string(3) = source_file.digest.toString
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   244
          stmt.bool(4) = source_file.compressed
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   245
          stmt.bytes(5) = source_file.body
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   246
        })
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   247
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   248
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   249
    def read_sources(
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   250
      db: SQL.Database,
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   251
      session_name: String,
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   252
      name: String,
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   253
      cache: Compress.Cache
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   254
    ): List[Source_File] = {
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   255
      db.execute_query_statement(
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   256
        Sources.table.select(
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   257
          sql = Sources.where_equal(session_name, name = name) + SQL.order_by(List(Sources.name))),
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   258
        List.from[Source_File],
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   259
        { res =>
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   260
          val res_name = res.string(Sources.name)
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   261
          val digest = SHA1.fake_digest(res.string(Sources.digest))
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   262
          val compressed = res.bool(Sources.compressed)
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   263
          val body = res.bytes(Sources.body)
78180
02c5488b8c9c tuned signature;
wenzelm
parents: 78179
diff changeset
   264
          Source_File(res_name, digest, compressed, body, cache)
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   265
        }
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   266
      )
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   267
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   268
  }
79682
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   269
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   270
  def read_build_uuid(path: Path, session: String): String =
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   271
    try { using(SQLite.open_database(path))(private_data.read_build_uuid(_, session)) }
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   272
    catch { case _: SQLException => "" }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   273
}
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   274
79676
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
   275
class Store private(
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
   276
    val options: Options,
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
   277
    val build_cluster: Boolean,
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
   278
    val cache: Term.Cache
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
   279
  ) {
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   280
  store =>
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   281
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   282
  override def toString: String = "Store(output_dir = " + output_dir.absolute + ")"
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   283
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   284
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   285
  /* directories */
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   286
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   287
  val system_output_dir: Path = Path.explode("$ISABELLE_HEAPS_SYSTEM/$ML_IDENTIFIER")
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   288
  val user_output_dir: Path = Path.explode("$ISABELLE_HEAPS/$ML_IDENTIFIER")
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   289
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   290
  def system_heaps: Boolean = options.bool("system_heaps")
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   291
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   292
  val output_dir: Path =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   293
    if (system_heaps) system_output_dir else user_output_dir
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   294
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   295
  val input_dirs: List[Path] =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   296
    if (system_heaps) List(system_output_dir)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   297
    else List(user_output_dir, system_output_dir)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   298
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   299
  def presentation_dir: Path =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   300
    if (system_heaps) Path.explode("$ISABELLE_BROWSER_INFO_SYSTEM")
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   301
    else Path.explode("$ISABELLE_BROWSER_INFO")
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   302
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   303
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   304
  /* file names */
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   305
79684
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   306
  def output_heap(name: String): Path = output_dir + Store.heap(name)
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   307
  def output_log(name: String): Path = output_dir + Store.log(name)
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   308
  def output_log_db(name: String): Path = output_dir + Store.log_db(name)
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   309
  def output_log_gz(name: String): Path = output_dir + Store.log_gz(name)
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   310
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   311
79662
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
   312
  /* session */
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
   313
79663
4a299bdb5d61 clarified signature: more comprehensive operations;
wenzelm
parents: 79662
diff changeset
   314
  def get_session(name: String): Store.Session = {
79684
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   315
    val heap = input_dirs.view.map(_ + Store.heap(name)).find(_.is_file)
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   316
    val log_db = input_dirs.view.map(_ + Store.log_db(name)).find(_.is_file)
79674
215db9299a1a clarified signature;
wenzelm
parents: 79664
diff changeset
   317
    new Store.Session(name, heap, log_db, input_dirs)
79663
4a299bdb5d61 clarified signature: more comprehensive operations;
wenzelm
parents: 79662
diff changeset
   318
  }
79662
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
   319
79682
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   320
  def output_session(name: String, store_heap: Boolean = false): Store.Session = {
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   321
    val heap = if (store_heap) Some(output_heap(name)) else None
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   322
    val log_db = if (!build_database_server) Some(output_log_db(name)) else None
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   323
    new Store.Session(name, heap, log_db, List(output_dir))
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   324
  }
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   325
79662
dca6ea3b7a01 clarified signature: more explicit types;
wenzelm
parents: 79661
diff changeset
   326
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   327
  /* heap */
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   328
78212
dfb172d7e40e tuned signature;
wenzelm
parents: 78208
diff changeset
   329
  def heap_shasum(database_server: Option[SQL.Database], name: String): SHA1.Shasum = {
78510
8f45302a9ff0 more thorough ML_Heap.restore: include ancestors; prefer simultaneous ML_Heap.get_entries: just one database access for heap hierarchy;
wenzelm
parents: 78400
diff changeset
   330
    def get_database: Option[SHA1.Digest] = {
8f45302a9ff0 more thorough ML_Heap.restore: include ancestors; prefer simultaneous ML_Heap.get_entries: just one database access for heap hierarchy;
wenzelm
parents: 78400
diff changeset
   331
      for {
8f45302a9ff0 more thorough ML_Heap.restore: include ancestors; prefer simultaneous ML_Heap.get_entries: just one database access for heap hierarchy;
wenzelm
parents: 78400
diff changeset
   332
        db <- database_server
79677
49370f0f7911 clarified names;
wenzelm
parents: 79676
diff changeset
   333
        digest <- ML_Heap.read_digests(db, List(name)).valuesIterator.nextOption()
78510
8f45302a9ff0 more thorough ML_Heap.restore: include ancestors; prefer simultaneous ML_Heap.get_entries: just one database access for heap hierarchy;
wenzelm
parents: 78400
diff changeset
   334
      } yield digest
8f45302a9ff0 more thorough ML_Heap.restore: include ancestors; prefer simultaneous ML_Heap.get_entries: just one database access for heap hierarchy;
wenzelm
parents: 78400
diff changeset
   335
    }
8f45302a9ff0 more thorough ML_Heap.restore: include ancestors; prefer simultaneous ML_Heap.get_entries: just one database access for heap hierarchy;
wenzelm
parents: 78400
diff changeset
   336
79663
4a299bdb5d61 clarified signature: more comprehensive operations;
wenzelm
parents: 79662
diff changeset
   337
    get_database orElse get_session(name).heap_digest() match {
78196
140a6f2e3728 restore heaps from database, which takes precedence over file-system;
wenzelm
parents: 78190
diff changeset
   338
      case Some(digest) => SHA1.shasum(digest, name)
140a6f2e3728 restore heaps from database, which takes precedence over file-system;
wenzelm
parents: 78190
diff changeset
   339
      case None => SHA1.no_shasum
140a6f2e3728 restore heaps from database, which takes precedence over file-system;
wenzelm
parents: 78190
diff changeset
   340
    }
140a6f2e3728 restore heaps from database, which takes precedence over file-system;
wenzelm
parents: 78190
diff changeset
   341
  }
140a6f2e3728 restore heaps from database, which takes precedence over file-system;
wenzelm
parents: 78190
diff changeset
   342
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   343
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   344
  /* databases for build process and session content */
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   345
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   346
  def build_database_server: Boolean = options.bool("build_database_server")
78511
f5fb5bb2533f clarified option name (see also ff43a524aa5d);
wenzelm
parents: 78510
diff changeset
   347
  def build_database: Boolean = options.bool("build_database")
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   348
78366
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   349
  def open_server(): SSH.Server =
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   350
    PostgreSQL.open_server(options,
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   351
      host = options.string("build_database_host"),
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   352
      port = options.int("build_database_port"),
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   353
      ssh_host = options.string("build_database_ssh_host"),
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   354
      ssh_port = options.int("build_database_ssh_port"),
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   355
      ssh_user = options.string("build_database_ssh_user"))
aa4ea5398ab8 clarified signature: more operations;
wenzelm
parents: 78356
diff changeset
   356
78347
72fc2ff08e07 clarified signature: more operations;
wenzelm
parents: 78272
diff changeset
   357
  def open_database_server(server: SSH.Server = SSH.no_server): PostgreSQL.Database =
72fc2ff08e07 clarified signature: more operations;
wenzelm
parents: 78272
diff changeset
   358
    PostgreSQL.open_database_server(options, server = server,
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   359
      user = options.string("build_database_user"),
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   360
      password = options.string("build_database_password"),
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   361
      database = options.string("build_database_name"),
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   362
      host = options.string("build_database_host"),
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   363
      port = options.int("build_database_port"),
78347
72fc2ff08e07 clarified signature: more operations;
wenzelm
parents: 78272
diff changeset
   364
      ssh_host = options.string("build_database_ssh_host"),
72fc2ff08e07 clarified signature: more operations;
wenzelm
parents: 78272
diff changeset
   365
      ssh_port = options.int("build_database_ssh_port"),
78863
f627ab8c276c discontinued pointless option (reverting 63d55ba90a9f): performance tuning works better via SQL.Database.execute_batch_statement;
wenzelm
parents: 78555
diff changeset
   366
      ssh_user = options.string("build_database_ssh_user"))
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   367
79682
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   368
  def maybe_open_database_server(
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   369
    server: SSH.Server = SSH.no_server,
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   370
    guard: Boolean = build_database_server
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   371
  ): Option[SQL.Database] = {
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   372
    if (guard) Some(open_database_server(server = server)) else None
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   373
  }
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   374
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   375
  def maybe_open_heaps_database(
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   376
    database_server: Option[SQL.Database],
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   377
    server: SSH.Server = SSH.no_server
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   378
  ): Option[SQL.Database] = {
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   379
    if (database_server.isDefined) None
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   380
    else store.maybe_open_database_server(server = server, guard = build_cluster)
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   381
  }
78205
a40ae2df39ad clarified database for heaps: do not depend on build_database_test;
wenzelm
parents: 78198
diff changeset
   382
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   383
  def open_build_database(path: Path, server: SSH.Server = SSH.no_server): SQL.Database =
79676
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79674
diff changeset
   384
    if (build_database_server || build_cluster) open_database_server(server = server)
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   385
    else SQLite.open_database(path, restrict = true)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   386
78223
2d2417a63314 clarified signature: better default;
wenzelm
parents: 78217
diff changeset
   387
  def maybe_open_build_database(
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   388
    path: Path = Path.explode("$ISABELLE_HOME_USER/build.db"),
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   389
    server: SSH.Server = SSH.no_server
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   390
  ): Option[SQL.Database] = {
78511
f5fb5bb2533f clarified option name (see also ff43a524aa5d);
wenzelm
parents: 78510
diff changeset
   391
    if (build_database) Some(open_build_database(path, server = server)) else None
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   392
  }
78184
wenzelm
parents: 78182
diff changeset
   393
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   394
  def try_open_database(
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   395
    name: String,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   396
    output: Boolean = false,
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   397
    server: SSH.Server = SSH.no_server,
78367
4978a158dc4c tuned signature;
wenzelm
parents: 78366
diff changeset
   398
    server_mode: Boolean = build_database_server
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   399
  ): Option[SQL.Database] = {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   400
    def check(db: SQL.Database): Option[SQL.Database] =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   401
      if (output || session_info_exists(db)) Some(db) else { db.close(); None }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   402
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   403
    if (server_mode) check(open_database_server(server = server))
79661
2a9d8c74eb3c clarified signature: emphasize physical db files;
wenzelm
parents: 79502
diff changeset
   404
    else if (output) Some(SQLite.open_database(output_log_db(name)))
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   405
    else {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   406
      (for {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   407
        dir <- input_dirs.view
79684
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   408
        path = dir + Store.log_db(name) if path.is_file
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   409
        db <- check(SQLite.open_database(path))
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   410
      } yield db).headOption
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   411
    }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   412
  }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   413
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   414
  def error_database(name: String): Nothing =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   415
    error("Missing build database for session " + quote(name))
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   416
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   417
  def open_database(
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   418
    name: String,
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   419
    output: Boolean = false,
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   420
    server: SSH.Server = SSH.no_server
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   421
  ): SQL.Database = {
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   422
    try_open_database(name, output = output, server = server) getOrElse error_database(name)
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78369
diff changeset
   423
  }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   424
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78212
diff changeset
   425
  def clean_output(
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78212
diff changeset
   426
    database_server: Option[SQL.Database],
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78212
diff changeset
   427
    name: String,
78217
wenzelm
parents: 78215
diff changeset
   428
    session_init: Boolean = false
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78212
diff changeset
   429
  ): Option[Boolean] = {
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   430
    val relevant_db =
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78212
diff changeset
   431
      database_server match {
79682
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79677
diff changeset
   432
        case Some(db) => clean_session_info(db, name)
78227
1ba48d402005 proper session_init *after* deleting db files (amending af6c493b0441);
wenzelm
parents: 78223
diff changeset
   433
        case None => false
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78212
diff changeset
   434
      }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   435
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   436
    val del =
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   437
      for {
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   438
        dir <-
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   439
          (if (system_heaps) List(user_output_dir, system_output_dir) else List(user_output_dir))
79684
0554a32a6ef4 clarified signature;
wenzelm
parents: 79682
diff changeset
   440
        file <- List(Store.heap(name), Store.log_db(name), Store.log(name), Store.log_gz(name))
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   441
        path = dir + file if path.is_file
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   442
      } yield path.file.delete
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   443
78227
1ba48d402005 proper session_init *after* deleting db files (amending af6c493b0441);
wenzelm
parents: 78223
diff changeset
   444
    if (database_server.isEmpty && session_init) {
1ba48d402005 proper session_init *after* deleting db files (amending af6c493b0441);
wenzelm
parents: 78223
diff changeset
   445
      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
   446
    }
1ba48d402005 proper session_init *after* deleting db files (amending af6c493b0441);
wenzelm
parents: 78223
diff changeset
   447
78185
26b9b40ec1af tuned signature;
wenzelm
parents: 78184
diff changeset
   448
    if (relevant_db || del.nonEmpty) Some(del.forall(identity)) else None
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   449
  }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   450
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   451
  def check_output(
78374
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   452
    database_server: Option[SQL.Database],
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   453
    name: String,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   454
    session_options: Options,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   455
    sources_shasum: SHA1.Shasum,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   456
    input_shasum: SHA1.Shasum,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   457
    fresh_build: Boolean,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   458
    store_heap: Boolean
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   459
  ): (Boolean, SHA1.Shasum) = {
78374
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   460
    def no_check: (Boolean, SHA1.Shasum) = (false, SHA1.no_shasum)
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   461
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   462
    def check(db: SQL.Database): (Boolean, SHA1.Shasum) =
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   463
      read_build(db, name) match {
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   464
        case Some(build) =>
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   465
          val output_shasum = heap_shasum(if (db.is_postgresql) Some(db) else None, name)
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   466
          val current =
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   467
            !fresh_build &&
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   468
              build.ok &&
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   469
              Sessions.eq_sources(session_options, build.sources, sources_shasum) &&
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   470
              build.input_heaps == input_shasum &&
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   471
              build.output_heap == output_shasum &&
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   472
              !(store_heap && output_shasum.is_empty)
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   473
          (current, output_shasum)
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   474
        case None => no_check
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   475
      }
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   476
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   477
    database_server match {
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   478
      case Some(db) => if (session_info_exists(db)) check(db) else no_check
f9f1412ea24e reuse database_server connection;
wenzelm
parents: 78372
diff changeset
   479
      case None => using_option(try_open_database(name))(check) getOrElse no_check
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   480
    }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   481
  }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   482
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   483
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   484
  /* session info */
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   485
78375
234f2ff9afe6 clarified signature: more specific exists_table --- avoid retrieving full list beforehand;
wenzelm
parents: 78374
diff changeset
   486
  def session_info_exists(db: SQL.Database): Boolean =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   487
    Store.private_data.tables.forall(db.exists_table)
78181
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   488
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   489
  def session_info_defined(db: SQL.Database, name: String): Boolean =
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   490
    db.execute_query_statementB(
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   491
      Store.private_data.Session_Info.table.select(List(Store.private_data.Session_Info.session_name),
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   492
        sql = Store.private_data.Session_Info.session_name.where_equal(name)))
78181
c2fbe48e9df4 clarified modules;
wenzelm
parents: 78180
diff changeset
   493
78260
0a7f7abbe4f0 more robust transaction_lock: avoid overlapping data spaces;
wenzelm
parents: 78227
diff changeset
   494
  def clean_session_info(db: SQL.Database, name: String): Boolean = {
0a7f7abbe4f0 more robust transaction_lock: avoid overlapping data spaces;
wenzelm
parents: 78227
diff changeset
   495
    Export.clean_session(db, name)
0a7f7abbe4f0 more robust transaction_lock: avoid overlapping data spaces;
wenzelm
parents: 78227
diff changeset
   496
    Document_Build.clean_session(db, name)
0a7f7abbe4f0 more robust transaction_lock: avoid overlapping data spaces;
wenzelm
parents: 78227
diff changeset
   497
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   498
    Store.private_data.transaction_lock(db, create = true, label = "Store.clean_session_info") {
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   499
      val already_defined = session_info_defined(db, name)
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   500
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   501
      db.execute_statement(
78555
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   502
        SQL.multi(
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   503
          Store.private_data.Session_Info.table.delete(
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   504
            sql = Store.private_data.Session_Info.session_name.where_equal(name)),
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   505
          Store.private_data.Sources.table.delete(
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   506
            sql = Store.private_data.Sources.where_equal(name))))
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   507
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   508
      already_defined
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   509
    }
78260
0a7f7abbe4f0 more robust transaction_lock: avoid overlapping data spaces;
wenzelm
parents: 78227
diff changeset
   510
  }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   511
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   512
  def write_session_info(
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   513
    db: SQL.Database,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   514
    session_name: String,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   515
    sources: Store.Sources,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   516
    build_log: Build_Log.Session_Info,
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   517
    build: Store.Build_Info
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   518
  ): Unit = {
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   519
    Store.private_data.transaction_lock(db, label = "Store.write_session_info") {
78555
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   520
      for (source_files <- sources.iterator.toList.grouped(200)) {
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   521
        Store.private_data.write_sources(db, session_name, source_files)
754bfc558d21 performance tuning: avoid redundant db access;
wenzelm
parents: 78511
diff changeset
   522
      }
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   523
      Store.private_data.write_session_info(db, cache.compress, session_name, build_log, build)
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   524
    }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   525
  }
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   526
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   527
  def read_session_timing(db: SQL.Database, session: String): Properties.T =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   528
    Store.private_data.transaction_lock(db, label = "Store.read_session_timing") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   529
      Store.private_data.read_session_timing(db, session, cache)
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   530
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   531
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   532
  def read_command_timings(db: SQL.Database, session: String): Bytes =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   533
    Store.private_data.transaction_lock(db, label = "Store.read_command_timings") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   534
      Store.private_data.read_command_timings(db, session)
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   535
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   536
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   537
  def read_theory_timings(db: SQL.Database, session: String): List[Properties.T] =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   538
    Store.private_data.transaction_lock(db, label = "Store.read_theory_timings") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   539
      Store.private_data.read_theory_timings(db, session, cache)
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   540
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   541
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   542
  def read_ml_statistics(db: SQL.Database, session: String): List[Properties.T] =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   543
    Store.private_data.transaction_lock(db, label = "Store.read_ml_statistics") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   544
      Store.private_data.read_ml_statistics(db, session, cache)
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   545
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   546
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   547
  def read_task_statistics(db: SQL.Database, session: String): List[Properties.T] =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   548
    Store.private_data.transaction_lock(db, label = "Store.read_task_statistics") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   549
      Store.private_data.read_task_statistics(db, session, cache)
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   550
    }
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   551
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   552
  def read_theories(db: SQL.Database, session: String): List[String] =
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   553
    read_theory_timings(db, session).flatMap(Markup.Name.unapply)
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   554
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   555
  def read_errors(db: SQL.Database, session: String): List[String] =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   556
    Store.private_data.transaction_lock(db, label = "Store.read_errors") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   557
      Store.private_data.read_errors(db, session, cache)
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   558
    }
78265
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   559
03eb7f7bb990 proper transaction_lock;
wenzelm
parents: 78262
diff changeset
   560
  def read_build(db: SQL.Database, session: String): Option[Store.Build_Info] =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   561
    Store.private_data.transaction_lock(db, label = "Store.read_build") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   562
      if (session_info_exists(db)) Store.private_data.read_build(db, session) else None
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   563
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   564
78179
a49ad8d183af clarified modules;
wenzelm
parents: 78178
diff changeset
   565
  def read_sources(db: SQL.Database, session: String, name: String = ""): List[Store.Source_File] =
78396
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   566
    Store.private_data.transaction_lock(db, label = "Store.read_sources") {
7853d9072d1b renamed object Data to private_data, to emphasize its intended scope (but it is publicly accessible in the database);
wenzelm
parents: 78377
diff changeset
   567
      Store.private_data.read_sources(db, session, name, cache.compress)
78356
974dbe256a37 more informative trace;
wenzelm
parents: 78347
diff changeset
   568
    }
78178
a177f71dc79f clarified modules;
wenzelm
parents:
diff changeset
   569
}