src/Pure/Admin/build_log.scala
changeset 78866 1bd52b048f8e
parent 78863 f627ab8c276c
child 78867 b02f8fb6b1b6
equal deleted inserted replaced
78865:a0199212046a 78866:1bd52b048f8e
  1017       progress: Progress = new Progress,
  1017       progress: Progress = new Progress,
  1018       errors: Multi_Map[String, String] = Multi_Map.empty
  1018       errors: Multi_Map[String, String] = Multi_Map.empty
  1019     ): Multi_Map[String, String] = {
  1019     ): Multi_Map[String, String] = {
  1020       init_database(db)
  1020       init_database(db)
  1021 
  1021 
  1022       var errors1 = errors
  1022       val errors_result = Synchronized(errors)
  1023       def add_error(name: String, exn: Throwable): Unit = {
  1023       def add_error(name: String, exn: Throwable): Unit =
  1024         errors1 = errors1.insert(name, Exn.print(exn))
  1024         errors_result.change(_.insert(name, Exn.print(exn)))
  1025       }
       
  1026 
  1025 
  1027       val files_domain = {
  1026       val files_domain = {
  1028         val names = files.map(Log_File.plain_name).toSet
  1027         val names = files.map(Log_File.plain_name).toSet
  1029         if (names.size > 100) None else Some(names)
  1028         if (names.size > 100) None else Some(names)
  1030       }
  1029       }
  1031 
  1030 
  1032       abstract class Table_Status(table: SQL.Table) {
  1031       abstract class Table_Status(table: SQL.Table) {
  1033         private var known: Set[String] =
  1032         private val known =
  1034           read_domain(db, table, private_data.log_name,
  1033           Synchronized(read_domain(db, table, private_data.log_name, restriction = files_domain))
  1035             restriction = files_domain)
  1034 
  1036 
  1035         def required(file: JFile): Boolean = !(known.value)(Log_File.plain_name(file))
  1037         def required(file: JFile): Boolean = !known(Log_File.plain_name(file))
  1036         def required(log_file: Log_File): Boolean = !(known.value)(log_file.name)
  1038         def required(log_file: Log_File): Boolean = !known(log_file.name)
       
  1039 
  1037 
  1040         def update_db(db: SQL.Database, log_file: Log_File): Unit
  1038         def update_db(db: SQL.Database, log_file: Log_File): Unit
  1041         def update(log_file: Log_File): Unit = {
  1039         def update(log_file: Log_File): Unit = {
  1042           if (required(log_file)) {
  1040           if (required(log_file)) {
  1043             update_db(db, log_file)
  1041             update_db(db, log_file)
  1044             known += log_file.name
  1042             known.change(_ + log_file.name)
  1045           }
  1043           }
  1046         }
  1044         }
  1047       }
  1045       }
  1048 
  1046 
  1049       val ml_statistics_status =
  1047       val ml_statistics_status =
  1070             override def update_db(db: SQL.Database, log_file: Log_File): Unit =
  1068             override def update_db(db: SQL.Database, log_file: Log_File): Unit =
  1071               update_theories(db, log_file.name, log_file.parse_build_info())
  1069               update_theories(db, log_file.name, log_file.parse_build_info())
  1072           }
  1070           }
  1073         ) ::: ml_statistics_status
  1071         ) ::: ml_statistics_status
  1074 
  1072 
  1075       for (file <- files.iterator if status.exists(_.required(file))) {
  1073       val consumer =
  1076         val log_name = Log_File.plain_name(file)
  1074         Consumer_Thread.fork[Log_File]("build_log_database")(
  1077         progress.echo("Log " + quote(log_name), verbose = true)
  1075           consume = { log_file =>
  1078         Exn.result { Log_File(file) } match {
       
  1079           case Exn.Res(log_file) =>
       
  1080             private_data.transaction_lock(db, label = "build_log_database") {
  1076             private_data.transaction_lock(db, label = "build_log_database") {
  1081               try { status.foreach(_.update(log_file)) }
  1077               try { status.foreach(_.update(log_file)) }
  1082               catch { case exn: Throwable => add_error(log_name, exn) }
  1078               catch { case exn: Throwable => add_error(log_file.name, exn) }
  1083             }
  1079             }
  1084           case Exn.Exn(exn) => add_error(log_name, exn)
  1080             true
       
  1081           },
       
  1082           limit = 1
       
  1083         )
       
  1084 
       
  1085       try {
       
  1086         for (file <- files.iterator if status.exists(_.required(file))) {
       
  1087           val log_name = Log_File.plain_name(file)
       
  1088           progress.echo("Log " + quote(log_name), verbose = true)
       
  1089           Exn.result { Log_File(file) } match {
       
  1090             case Exn.Res(log_file) => consumer.send(log_file)
       
  1091             case Exn.Exn(exn) => add_error(log_name, exn)
       
  1092           }
  1085         }
  1093         }
  1086       }
  1094       }
  1087 
  1095       finally { consumer.shutdown() }
  1088       errors1
  1096 
       
  1097       errors_result.value
  1089     }
  1098     }
  1090 
  1099 
  1091     def read_meta_info(db: SQL.Database, log_name: String): Option[Meta_Info] = {
  1100     def read_meta_info(db: SQL.Database, log_name: String): Option[Meta_Info] = {
  1092       val table = private_data.meta_info_table
  1101       val table = private_data.meta_info_table
  1093       val columns = table.columns.tail
  1102       val columns = table.columns.tail