aboutsummaryrefslogtreecommitdiff
path: root/libbrep
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-03-18 22:17:49 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-03-27 17:28:44 +0300
commit35359f038f571dc46de3d14af72a2bc911fb0a24 (patch)
treede3e89d678e78b9efc4d395274fd7ccc68f4a213 /libbrep
parent8ad672cc7211952716ffe1fbf76c179b4f1149e3 (diff)
Implement brep-monitor
Diffstat (limited to 'libbrep')
-rw-r--r--libbrep/build-package.hxx2
-rw-r--r--libbrep/build.cxx21
-rw-r--r--libbrep/build.hxx82
-rw-r--r--libbrep/build.xml40
-rw-r--r--libbrep/common.hxx30
5 files changed, 171 insertions, 4 deletions
diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx
index 22a8151..702f937 100644
--- a/libbrep/build-package.hxx
+++ b/libbrep/build-package.hxx
@@ -118,6 +118,8 @@ namespace brep
package_id id;
upstream_version version;
+ bool archived; // True if the tenant the package belongs to is archived.
+
// Database mapping.
//
#pragma db member(version) set(this.version.init (this.id.version, (?)))
diff --git a/libbrep/build.cxx b/libbrep/build.cxx
index b6a07c7..db5bda2 100644
--- a/libbrep/build.cxx
+++ b/libbrep/build.cxx
@@ -80,4 +80,25 @@ namespace brep
target (move (trg))
{
}
+
+ // build_delay
+ //
+ build_delay::
+ build_delay (string tnt,
+ package_name_type pnm, version pvr,
+ string cfg,
+ string tnm, version tvr,
+ timestamp ptm)
+ : id (package_id (move (tnt), move (pnm), pvr),
+ move (cfg),
+ move (tnm), tvr),
+ tenant (id.package.tenant),
+ package_name (id.package.name),
+ package_version (move (pvr)),
+ configuration (id.configuration),
+ toolchain_name (id.toolchain_name),
+ toolchain_version (move (tvr)),
+ package_timestamp (ptm)
+ {
+ }
}
diff --git a/libbrep/build.hxx b/libbrep/build.hxx
index 7e548a4..83b30a8 100644
--- a/libbrep/build.hxx
+++ b/libbrep/build.hxx
@@ -25,7 +25,7 @@
//
#define LIBBREP_BUILD_SCHEMA_VERSION_BASE 9
-#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 9, closed)
+#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 10, closed)
// We have to keep these mappings at the global scope instead of inside
// the brep namespace because they need to be also effective in the
@@ -212,6 +212,16 @@ namespace brep
//
optional<result_status> status;
+ // Time of setting the result status that can be considered as the build
+ // task completion (currently all the result_status values). Initialized
+ // with timestamp_nonexistent by default.
+ //
+ // Note that in the future we may not consider abort and abnormal as the
+ // task completion and, for example, proceed with automatic rebuild (the
+ // flake monitor idea).
+ //
+ timestamp_type completion_timestamp;
+
// May be present only for the building state.
//
optional<string> agent_fingerprint;
@@ -244,6 +254,10 @@ namespace brep
//
#pragma db member(timestamp) index
+ // @@ TMP remove when 0.13.0 is released.
+ //
+ #pragma db member(completion_timestamp) default(0)
+
#pragma db member(results) id_column("") value_column("") \
section(results_section)
@@ -259,9 +273,7 @@ namespace brep
: tenant (id.package.tenant),
package_name (id.package.name),
configuration (id.configuration),
- toolchain_name (id.toolchain_name)
- {
- }
+ toolchain_name (id.toolchain_name) {}
};
// Note that ADL can't find the equal operator in join conditions, so we use
@@ -340,6 +352,68 @@ namespace brep
//
#pragma db member(result) column("count(" + build::id.package.name + ")")
};
+
+ // Used to track the package build delays since the last build or, if not
+ // present, since the first opportunity to build the package.
+ //
+ #pragma db object pointer(shared_ptr) session
+ class build_delay
+ {
+ public:
+ using package_name_type = brep::package_name;
+
+ // If toolchain version is empty, then the object represents a minimum
+ // delay across all versions of the toolchain.
+ //
+ build_delay (string tenant,
+ package_name_type, version,
+ string configuration,
+ string toolchain_name, version toolchain_version,
+ timestamp package_timestamp);
+
+ build_id id;
+
+ string& tenant; // Tracks id.package.tenant.
+ package_name_type& package_name; // Tracks id.package.name.
+ upstream_version package_version; // Original of id.package.version.
+ string& configuration; // Tracks id.configuration.
+ string& toolchain_name; // Tracks id.toolchain_name.
+ upstream_version toolchain_version; // Original of id.toolchain_version.
+
+ // Time of the latest delay report. Initialized with timestamp_nonexistent
+ // by default.
+ //
+ timestamp report_timestamp;
+
+ // Time when the package is initially considered as buildable for this
+ // configuration and toolchain. It is used to track the build delay if the
+ // build object is absent (the first build task is not yet issued, the
+ // build is removed by brep-clean, etc).
+ //
+ timestamp package_timestamp;
+
+ // Database mapping.
+ //
+ #pragma db member(id) id column("")
+
+ #pragma db member(tenant) transient
+ #pragma db member(package_name) transient
+ #pragma db member(package_version) \
+ set(this.package_version.init (this.id.package.version, (?)))
+ #pragma db member(configuration) transient
+ #pragma db member(toolchain_name) transient
+ #pragma db member(toolchain_version) \
+ set(this.toolchain_version.init (this.id.toolchain_version, (?)))
+
+ private:
+ friend class odb::access;
+
+ build_delay ()
+ : tenant (id.package.tenant),
+ package_name (id.package.name),
+ configuration (id.configuration),
+ toolchain_name (id.toolchain_name) {}
+ };
}
#endif // LIBBREP_BUILD_HXX
diff --git a/libbrep/build.xml b/libbrep/build.xml
index 3ade7c8..bf8920b 100644
--- a/libbrep/build.xml
+++ b/libbrep/build.xml
@@ -1,4 +1,44 @@
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" schema-name="build" version="1">
+ <changeset version="10">
+ <alter-table name="build">
+ <add-column name="completion_timestamp" type="BIGINT" null="false" default="0"/>
+ </alter-table>
+ <add-table name="build_delay" kind="object">
+ <column name="package_tenant" type="TEXT" null="false"/>
+ <column name="package_name" type="CITEXT" null="false"/>
+ <column name="package_version_epoch" type="INTEGER" null="false"/>
+ <column name="package_version_canonical_upstream" type="TEXT" null="false"/>
+ <column name="package_version_canonical_release" type="TEXT" null="false" options="COLLATE &quot;C&quot;"/>
+ <column name="package_version_revision" type="INTEGER" null="false"/>
+ <column name="configuration" type="TEXT" null="false"/>
+ <column name="toolchain_name" type="TEXT" null="false"/>
+ <column name="toolchain_version_epoch" type="INTEGER" null="false"/>
+ <column name="toolchain_version_canonical_upstream" type="TEXT" null="false"/>
+ <column name="toolchain_version_canonical_release" type="TEXT" null="false" options="COLLATE &quot;C&quot;"/>
+ <column name="toolchain_version_revision" type="INTEGER" null="false"/>
+ <column name="package_version_upstream" type="TEXT" null="false"/>
+ <column name="package_version_release" type="TEXT" null="true"/>
+ <column name="toolchain_version_upstream" type="TEXT" null="false"/>
+ <column name="toolchain_version_release" type="TEXT" null="true"/>
+ <column name="report_timestamp" type="BIGINT" null="false"/>
+ <column name="package_timestamp" type="BIGINT" null="false"/>
+ <primary-key>
+ <column name="package_tenant"/>
+ <column name="package_name"/>
+ <column name="package_version_epoch"/>
+ <column name="package_version_canonical_upstream"/>
+ <column name="package_version_canonical_release"/>
+ <column name="package_version_revision"/>
+ <column name="configuration"/>
+ <column name="toolchain_name"/>
+ <column name="toolchain_version_epoch"/>
+ <column name="toolchain_version_canonical_upstream"/>
+ <column name="toolchain_version_canonical_release"/>
+ <column name="toolchain_version_revision"/>
+ </primary-key>
+ </add-table>
+ </changeset>
+
<model version="9">
<table name="build" kind="object">
<column name="package_tenant" type="TEXT" null="false"/>
diff --git a/libbrep/common.hxx b/libbrep/common.hxx
index 44028df..b7fc2da 100644
--- a/libbrep/common.hxx
+++ b/libbrep/common.hxx
@@ -8,6 +8,8 @@
#include <chrono>
#include <type_traits> // static_assert
+#include <odb/query.hxx>
+
#include <libbpkg/package-name.hxx>
#include <libbrep/types.hxx>
@@ -510,6 +512,34 @@ namespace brep
compare_version_ne (x.version, y.version, true);
}
+ // Allow comparing the query members with the query parameters bound by
+ // reference to variables of the package id type (in particular in the
+ // prepared queries).
+ //
+ // Note that it is not operator==() since the query template parameter type
+ // can not be deduced from the function parameter types and needs to be
+ // specified explicitly.
+ //
+ template <typename T, typename ID>
+ inline auto
+ equal (const ID& x, const package_id& y)
+ -> decltype (x.tenant == odb::query<T>::_ref (y.tenant) &&
+ x.name == odb::query<T>::_ref (y.name) &&
+ x.version.epoch == odb::query<T>::_ref (y.version.epoch))
+ {
+ using query = odb::query<T>;
+
+ const auto& qv (x.version);
+ const canonical_version& v (y.version);
+
+ return x.tenant == query::_ref (y.tenant) &&
+ x.name == query::_ref (y.name) &&
+ qv.epoch == query::_ref (v.epoch) &&
+ qv.canonical_upstream == query::_ref (v.canonical_upstream) &&
+ qv.canonical_release == query::_ref (v.canonical_release) &&
+ qv.revision == query::_ref (v.revision);
+ }
+
// Repository id comparison operators.
//
inline bool