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