aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-07-07 14:08:34 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-07-07 15:19:59 +0300
commit37af85f5b084c234a350235690eb944984567e78 (patch)
tree8a63a39711e9831e456ebdc1f783c10053805865
parentb125c5f1ca398d4c912ecfba3bf451bfa63b6293 (diff)
Add odb sections to build_package class
-rw-r--r--libbrep/build-package.hxx47
-rw-r--r--mod/mod-build-result.cxx2
-rw-r--r--mod/mod-build-task.cxx107
-rw-r--r--mod/mod-builds.cxx12
-rw-r--r--monitor/monitor.cxx21
5 files changed, 127 insertions, 62 deletions
diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx
index e9104e0..2e3afe0 100644
--- a/libbrep/build-package.hxx
+++ b/libbrep/build-package.hxx
@@ -5,6 +5,7 @@
#define LIBBREP_BUILD_PACKAGE_HXX
#include <odb/core.hxx>
+#include <odb/section.hxx>
#include <odb/nested-container.hxx>
#include <libbrep/types.hxx>
@@ -119,6 +120,8 @@ namespace brep
requirements_type requirements;
small_vector<build_test_dependency, 1> tests;
+ odb::section requirements_tests_section;
+
lazy_shared_ptr<build_repository> internal_repository;
bool buildable;
@@ -129,6 +132,12 @@ namespace brep
build_constraints constraints;
build_package_configs configs;
+ // Group the builds and constraints members of this object as well as of
+ // the nested configs entries for an explicit load. Note that the configs
+ // top-level members are loaded implicitly.
+ //
+ odb::section constraints_section;
+
bool
internal () const noexcept {return internal_repository != nullptr;}
@@ -145,7 +154,8 @@ namespace brep
// Container of the requirement_alternatives values.
//
- #pragma db member(requirements) id_column("") value_column("")
+ #pragma db member(requirements) id_column("") value_column("") \
+ section(requirements_tests_section)
// Container of the requirement_alternative values.
//
@@ -154,7 +164,8 @@ namespace brep
after(requirements) \
get(odb::nested_get (this.requirements)) \
set(odb::nested_set (this.requirements, std::move (?))) \
- id_column("") key_column("") value_column("")
+ id_column("") key_column("") value_column("") \
+ section(requirements_tests_section)
// Container of the requirement (string) values.
//
@@ -163,13 +174,23 @@ namespace brep
after(requirement_alternatives) \
get(odb::nested2_get (this.requirements)) \
set(odb::nested2_set (this.requirements, std::move (?))) \
- id_column("") key_column("") value_column("id")
+ id_column("") key_column("") value_column("id") \
+ section(requirements_tests_section)
+
+ // tests
+ //
+ #pragma db member(tests) id_column("") value_column("test_") \
+ section(requirements_tests_section)
+
+ #pragma db member(requirements_tests_section) load(lazy) update(always)
- // tests, builds, and constraints
+ // builds and constraints
//
- #pragma db member(tests) id_column("") value_column("test_")
- #pragma db member(builds) id_column("") value_column("")
- #pragma db member(constraints) id_column("") value_column("")
+ #pragma db member(builds) id_column("") value_column("") \
+ section(constraints_section)
+
+ #pragma db member(constraints) id_column("") value_column("") \
+ section(constraints_section)
// configs
//
@@ -187,7 +208,8 @@ namespace brep
set(brep::build_package_config_builds bs; \
odb::nested_set (bs, std::move (?)); \
move (bs).to_configs (this.configs)) \
- id_column("") key_column("") value_column("")
+ id_column("") key_column("") value_column("") \
+ section(constraints_section)
#pragma db member(config_constraints) \
virtual(build_constraints_map) \
@@ -197,7 +219,10 @@ namespace brep
set(brep::build_package_config_constraints cs; \
odb::nested_set (cs, std::move (?)); \
move (cs).to_configs (this.configs)) \
- id_column("") key_column("") value_column("")
+ id_column("") key_column("") value_column("") \
+ section(constraints_section)
+
+ #pragma db member(constraints_section) load(lazy) update(always)
private:
friend class odb::access;
@@ -223,6 +248,10 @@ namespace brep
bool archived; // True if the tenant the package belongs to is archived.
+ // Present if the tenant the package belongs to is interactive.
+ //
+ optional<string> interactive;
+
// Database mapping.
//
#pragma db member(version) set(this.version.init (this.id.version, (?)))
diff --git a/mod/mod-build-result.cxx b/mod/mod-build-result.cxx
index 7806cda..533921b 100644
--- a/mod/mod-build-result.cxx
+++ b/mod/mod-build-result.cxx
@@ -365,6 +365,8 @@ handle (request& rq, response&)
if (const build_package_config* pc = find (b->package_config_name,
p->configs))
{
+ build_db_->load (*p, p->constraints_section);
+
if (!exclude (*pc, p->builds, p->constraints, *tc))
bld = move (b);
}
diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx
index 19907ea..27597cf 100644
--- a/mod/mod-build-task.cxx
+++ b/mod/mod-build-task.cxx
@@ -338,6 +338,8 @@ handle (request& rq, response& rs)
//
small_vector<bpkg::test_dependency, 1> tests;
+ build_db_->load (*p, p->requirements_tests_section);
+
for (const build_test_dependency& td: p->tests)
{
// Don't exclude unresolved external tests.
@@ -366,6 +368,8 @@ handle (request& rq, response& rs)
// the `builds: all` and `builds: -windows` manifest values for
// the primary and external test packages, respectively).
//
+ build_db_->load (*p, p->constraints_section);
+
if (exclude (*pc,
p->builds,
p->constraints,
@@ -1081,14 +1085,17 @@ handle (request& rq, response& rs)
// reason (multiple toolchains, buildtab change, etc). Note that the
// build result will still be accepted for an archived build.
//
- shared_ptr<build_tenant> t (
- build_db_->load<build_tenant> (id.tenant));
-
- if (t->interactive)
+ if (bp.interactive)
{
// Note that the tenant can be archived via some other package on
// some previous iteration. Skip the package if that's the case.
//
+ // Also note that we need to (re-)load the tenant object rather
+ // than to refer to bp.archived.
+ //
+ shared_ptr<build_tenant> t (
+ build_db_->load<build_tenant> (id.tenant));
+
if (t->archived)
continue;
@@ -1112,12 +1119,14 @@ handle (request& rq, response& rs)
// per task request. Given that we archive such tenants
// immediately, as a common case there will be none.
//
- pkg_query pq (pkg_query::build_tenant::id == t->id);
+ pkg_query pq (pkg_query::build_tenant::id == id.tenant);
for (auto& tp: build_db_->query<buildable_package> (pq))
{
shared_ptr<build_package> p (
build_db_->load<build_package> (tp.id));
+ build_db_->load (*p, p->constraints_section);
+
for (build_package_config& pc: p->configs)
{
for (const auto& tc: *target_conf_)
@@ -1219,8 +1228,8 @@ handle (request& rq, response& rs)
for (auto i (pkg_builds.begin ()); i != pkg_builds.end (); ++i)
{
auto j (
- configs.find (build_target_config_id {i->id.target,
- i->id.target_config_name}));
+ configs.find (build_target_config_id {
+ i->id.target, i->id.target_config_name}));
// Outdated configurations are already excluded with the
// database query.
@@ -1245,6 +1254,8 @@ handle (request& rq, response& rs)
auto i (configs.begin ());
auto e (configs.end ());
+ build_db_->load (*p, p->constraints_section);
+
for (;
i != e &&
exclude (pc, p->builds, p->constraints, *i->second.config);
@@ -1459,58 +1470,62 @@ handle (request& rq, response& rs)
p->configs)
: nullptr);
- if (pc != nullptr &&
- p->buildable &&
+ if (pc != nullptr &&
+ p->buildable &&
(imode == interactive_mode::both ||
(t->interactive.has_value () ==
- (imode == interactive_mode::true_))) &&
- !exclude (*pc, p->builds, p->constraints, *cm.config))
+ (imode == interactive_mode::true_))))
{
- assert (b->status);
+ build_db_->load (*p, p->constraints_section);
- b->state = build_state::building;
+ if (!exclude (*pc, p->builds, p->constraints, *cm.config))
+ {
+ assert (b->status);
- // Save the interactive build login information into the build
- // object, if the package to be built interactively.
- //
- // Can't move from, as may need it on the next iteration.
- //
- b->interactive = t->interactive
- ? tqm.interactive_login
- : nullopt;
+ b->state = build_state::building;
- // Can't move from, as may need them on the next iteration.
- //
- b->agent_fingerprint = agent_fp;
- b->agent_challenge = cl;
+ // Save the interactive build login information into the
+ // build object, if the package to be built interactively.
+ //
+ // Can't move from, as may need it on the next iteration.
+ //
+ b->interactive = t->interactive
+ ? tqm.interactive_login
+ : nullopt;
- const machine_header_manifest& mh (*cm.machine);
- b->machine = mh.name;
- b->machine_summary = mh.summary;
+ // Can't move from, as may need them on the next iteration.
+ //
+ b->agent_fingerprint = agent_fp;
+ b->agent_challenge = cl;
- // Issue the hard rebuild if the timeout expired, rebuild is
- // forced, or the configuration or machine has changed.
- //
- // Note that we never reset the build status (see above for
- // the reasoning).
- //
- string ccs (controller_checksum (*cm.config));
- string mcs (machine_checksum (*cm.machine));
+ const machine_header_manifest& mh (*cm.machine);
+ b->machine = mh.name;
+ b->machine_summary = mh.summary;
- if (b->hard_timestamp <= hard_rebuild_expiration ||
- b->force == force_state::forced ||
- b->controller_checksum != ccs ||
- b->machine_checksum != mcs)
- convert_to_hard (b);
+ // Issue the hard rebuild if the timeout expired, rebuild is
+ // forced, or the configuration or machine has changed.
+ //
+ // Note that we never reset the build status (see above for
+ // the reasoning).
+ //
+ string ccs (controller_checksum (*cm.config));
+ string mcs (machine_checksum (*cm.machine));
- b->controller_checksum = move (ccs);
- b->machine_checksum = move (mcs);
+ if (b->hard_timestamp <= hard_rebuild_expiration ||
+ b->force == force_state::forced ||
+ b->controller_checksum != ccs ||
+ b->machine_checksum != mcs)
+ convert_to_hard (b);
+
+ b->controller_checksum = move (ccs);
+ b->machine_checksum = move (mcs);
- b->timestamp = system_clock::now ();
+ b->timestamp = system_clock::now ();
- build_db_->update (b);
+ build_db_->update (b);
- tsm = task (move (b), move (p), move (*pc), move (t), cm);
+ tsm = task (move (b), move (p), move (*pc), move (t), cm);
+ }
}
}
diff --git a/mod/mod-builds.cxx b/mod/mod-builds.cxx
index bad13c1..0c9e57a 100644
--- a/mod/mod-builds.cxx
+++ b/mod/mod-builds.cxx
@@ -624,6 +624,8 @@ handle (request& rq, response& rs)
continue;
}
+ build_db_->load (*p, p->constraints_section);
+
if (!exclude (*pc, p->builds, p->constraints, *i->second))
{
if (skip != 0)
@@ -891,6 +893,8 @@ handle (request& rq, response& rs)
shared_ptr<build_package> p (build_db_->load<build_package> (id));
+ // Note: load the constrains section lazily.
+ //
for (const build_package_config& c: p->configs)
{
// Filter by package config name.
@@ -899,6 +903,9 @@ handle (request& rq, response& rs)
{
for (const auto& tc: target_configs)
{
+ if (!p->constraints_section.loaded ())
+ build_db_->load (*p, p->constraints_section);
+
if (exclude (c, p->builds, p->constraints, *tc))
{
target = tc->target;
@@ -1031,6 +1038,8 @@ handle (request& rq, response& rs)
//
set<config_toolchain> unbuilt_configs;
+ // Load the constrains section lazily.
+ //
for (const build_package_config& pc: bp->configs)
{
// Filter by package config name.
@@ -1045,6 +1054,9 @@ handle (request& rq, response& rs)
assert (i != target_conf_map_->end ());
+ if (!bp->constraints_section.loaded ())
+ build_db_->load (*bp, bp->constraints_section);
+
if (!exclude (pc, bp->builds, bp->constraints, *i->second))
unbuilt_configs.insert (
config_toolchain {ct.target,
diff --git a/monitor/monitor.cxx b/monitor/monitor.cxx
index 7dab2a0..eba6e2b 100644
--- a/monitor/monitor.cxx
+++ b/monitor/monitor.cxx
@@ -601,13 +601,18 @@ namespace brep
p->configs)
: nullptr);
- cleanup = (pc == nullptr ||
- !p->buildable ||
- exclude (*pc,
- p->builds,
- p->constraints,
- *ci->second,
- configs.class_inheritance_map));
+ cleanup = (pc == nullptr || !p->buildable);
+
+ if (!cleanup)
+ {
+ db.load (*p, p->constraints_section);
+
+ cleanup = exclude (*pc,
+ p->builds,
+ p->constraints,
+ *ci->second,
+ configs.class_inheritance_map);
+ }
}
if (cleanup)
@@ -818,6 +823,8 @@ namespace brep
{
shared_ptr<build_package> p (db.load<build_package> (bp.id));
+ db.load (*p, p->constraints_section);
+
for (const build_package_config& pc: p->configs)
{
for (const build_target_config& tc: configs)