Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frozen features #15610

Merged
merged 90 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
be36dc9
initial commit
gnusi Jan 22, 2022
8e7581f
wip
gnusi Jan 23, 2022
2759bad
wip
gnusi Jan 23, 2022
f38bc68
wip
gnusi Jan 23, 2022
81caa1f
wip
gnusi Jan 23, 2022
de9be3f
wip
gnusi Jan 23, 2022
1b9c99c
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 24, 2022
4ac869e
wip
gnusi Jan 24, 2022
44d4347
wip
gnusi Jan 24, 2022
81f4ddd
wip
gnusi Jan 24, 2022
ada8804
wip
gnusi Jan 24, 2022
01a7ba2
wip
gnusi Jan 24, 2022
e729dbe
wip
gnusi Jan 24, 2022
dab8961
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 24, 2022
0a18808
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 24, 2022
e74d1ac
wip
gnusi Jan 24, 2022
5a0702d
wip
gnusi Jan 25, 2022
485dc2f
wip
gnusi Jan 25, 2022
e228b3d
wip
gnusi Jan 25, 2022
cbf4f17
wip
gnusi Jan 25, 2022
0e82ce6
wip
gnusi Jan 25, 2022
9230c96
wip
gnusi Jan 25, 2022
c02365f
wip
gnusi Jan 25, 2022
9d212ed
wip
gnusi Jan 25, 2022
2a9e9e9
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 25, 2022
e9e7c99
wip
gnusi Jan 25, 2022
0d2da9c
wip
gnusi Jan 26, 2022
1d97e72
wip
gnusi Jan 26, 2022
cc22221
wip
gnusi Jan 26, 2022
f4d4a1d
wip
gnusi Jan 26, 2022
dbb946c
wip
gnusi Jan 26, 2022
ce0a551
wip
gnusi Jan 26, 2022
482ef8f
wip
gnusi Jan 26, 2022
1db5cbf
wip
gnusi Jan 26, 2022
280a2f3
wip
gnusi Jan 26, 2022
5e1bd02
wip
gnusi Jan 26, 2022
871d34b
wip
gnusi Jan 26, 2022
21f15fb
wip
gnusi Jan 26, 2022
bc8b310
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 26, 2022
1f19438
wip
gnusi Jan 26, 2022
f255f99
wip
gnusi Jan 26, 2022
9a1129b
wip
gnusi Jan 26, 2022
6e88128
get rid of virtual inheritance
gnusi Jan 26, 2022
7752ecf
wip
gnusi Jan 26, 2022
7d97ca8
wip
gnusi Jan 26, 2022
0ccbe4c
wip
gnusi Jan 26, 2022
5405acb
wup
gnusi Jan 27, 2022
5b687e9
wip
gnusi Jan 27, 2022
3da6cd8
wip
gnusi Jan 27, 2022
c544aea
wip
gnusi Jan 27, 2022
08e0796
wip
gnusi Jan 27, 2022
c270e77
wip
gnusi Jan 27, 2022
534937f
wip
gnusi Jan 27, 2022
5e57f80
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 27, 2022
b0980e9
wip
gnusi Jan 27, 2022
a9849b1
wip
gnusi Jan 27, 2022
ad9eb7f
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 28, 2022
9e04236
wip
gnusi Jan 28, 2022
23e648c
wip
gnusi Jan 28, 2022
5fb19ff
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 28, 2022
4fc9103
finally made it to compile
gnusi Jan 28, 2022
2056192
wip
gnusi Jan 28, 2022
9494b11
wip
gnusi Jan 28, 2022
c05e8b0
wip
gnusi Jan 29, 2022
27af8bc
wip
gnusi Jan 29, 2022
f88645b
wip
gnusi Jan 29, 2022
f2db307
wip
gnusi Jan 29, 2022
f501bf9
wip
gnusi Jan 29, 2022
ff9127f
fix tests
gnusi Jan 29, 2022
7ed0620
wip
gnusi Jan 29, 2022
c2e1618
fix compilation
gnusi Jan 29, 2022
638c5e4
fix msvc build
gnusi Jan 29, 2022
6f87d04
remove unused code
gnusi Jan 30, 2022
5ee88e2
wip
gnusi Jan 30, 2022
404aeba
wip
gnusi Jan 30, 2022
e5b992e
wip
gnusi Jan 30, 2022
ae94da2
address review comments
gnusi Jan 30, 2022
00ddb31
wip
gnusi Jan 30, 2022
c4bcb4c
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 30, 2022
fd95726
wip
gnusi Jan 30, 2022
79e73d8
wip
gnusi Jan 30, 2022
fc8a867
wip
gnusi Jan 30, 2022
7fee8ce
wip
gnusi Jan 31, 2022
0b0aa28
wip
gnusi Jan 31, 2022
db51706
wip
gnusi Jan 31, 2022
068bcf6
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 31, 2022
a9d6128
wip
gnusi Jan 31, 2022
8f60724
Merge branch 'devel' of https://github.com/arangodb/arangodb into fea…
gnusi Jan 31, 2022
199f11b
wip
gnusi Jan 31, 2022
92ee15b
wip
gnusi Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
gnusi committed Jan 28, 2022
commit 2056192051250c16c9f1d739807b2a146d4d470d
76 changes: 43 additions & 33 deletions lib/ApplicationFeatures/ApplicationServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include <unordered_set>
#include <utility>

#include <boost/core/demangle.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/iterator_range.hpp>

#include <velocypack/Options.h>
#include <velocypack/Slice.h>
Expand Down Expand Up @@ -67,6 +69,15 @@ static void failCallback(std::string const& message) {
<< "error. cannot proceed. reason: " << message;
FATAL_ERROR_EXIT();
}

auto nonEmptyFeatures(
std::span<std::unique_ptr<ApplicationFeature>> features) noexcept {
return boost::make_iterator_range(features) |
gnusi marked this conversation as resolved.
Show resolved Hide resolved
boost::adaptors::filtered([](auto& p) { return nullptr != p; }) |
boost::adaptors::transformed(
[](auto& p) -> ApplicationFeature& { return *p; });
}

} // namespace

std::atomic<bool> ApplicationServer::CTRL_C(false);
Expand All @@ -77,10 +88,8 @@ ApplicationServer::ApplicationServer(
: _state(State::UNINITIALIZED),
_options(options),
_features{features},
_binaryPath(binaryPath) {
// register callback function for failures
fail = failCallback;
}
_fail{failCallback}, // register callback function for failures
_binaryPath{binaryPath} {}

bool ApplicationServer::isPrepared() {
auto tmp = state();
Expand Down Expand Up @@ -302,9 +311,9 @@ VPackBuilder ApplicationServer::options(
// the order in which features are visited is unspecified
void ApplicationServer::apply(std::function<void(ApplicationFeature&)> callback,
bool enabledOnly) {
for (auto& it : _features) {
if (!enabledOnly || it->isEnabled()) {
callback(*it);
for (auto& feature : nonEmptyFeatures(_features)) {
if (!enabledOnly || feature.isEnabled()) {
callback(feature);
}
}
}
Expand Down Expand Up @@ -365,13 +374,13 @@ void ApplicationServer::parseOptions(int argc, char* argv[]) {
std::cout << "digraph dependencies\n"
<< "{\n"
<< " overlap = false;\n";
for (auto& feature : _features) {
for (size_t const before : feature->startsAfter()) {
for (auto& feature : ::nonEmptyFeatures(_features)) {
for (size_t const before : feature.startsAfter()) {
std::string_view depName;
if (hasFeature(before)) {
depName = getFeature(before).name();
}
std::cout << " " << feature->name() << " -> " << depName << ";\n";
std::cout << " " << feature.name() << " -> " << depName << ";\n";
}
}
std::cout << "}\n";
Expand Down Expand Up @@ -444,16 +453,15 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
<< "ApplicationServer::validateDependencies";

// apply all "startsBefore" values
for (auto& it : _features) {
auto& feature = *it;
for (auto& feature : nonEmptyFeatures(_features)) {
for (auto const& other : feature.startsBefore()) {
if (!hasFeature(other)) {
if (failOnMissing) {
fail(std::string{"feature '"}
.append(feature.name())
.append("' depends on unknown feature id '")
.append(std::to_string(other))
.append("'"));
_fail(std::string{"feature '"}
.append(feature.name())
.append("' depends on unknown feature id '")
.append(std::to_string(other))
.append("'"));
}
continue;
}
Expand All @@ -462,8 +470,8 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
}

// calculate ancestors for all features
for (auto& it : _features) {
it->determineAncestors(it->registration());
for (auto& feature : nonEmptyFeatures(_features)) {
feature.determineAncestors(feature.registration());
}

// first check if a feature references an unknown other feature
Expand All @@ -472,18 +480,18 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
[this](ApplicationFeature& feature) {
for (auto& other : feature.dependsOn()) {
if (!hasFeature(other)) {
fail(std::string{"feature '"}
.append(feature.name())
.append("' depends on unknown feature with id '")
.append(std::to_string(other))
.append("'"));
_fail(std::string{"feature '"}
.append(feature.name())
.append("' depends on unknown feature with id '")
.append(std::to_string(other))
.append("'"));
}
if (!getFeature(other).isEnabled()) {
fail(std::string{"enabled feature '"}
.append(feature.name())
.append("' depends on other feature '")
.append(getFeature(other).name())
.append("', which is disabled"));
_fail(std::string{"enabled feature '"}
.append(feature.name())
.append("' depends on other feature '")
.append(getFeature(other).name())
.append("', which is disabled"));
}
}
},
Expand All @@ -492,8 +500,7 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {

// first insert all features, even the inactive ones
std::vector<std::reference_wrapper<ApplicationFeature>> features;
for (auto& it : _features) {
auto& us = *it;
for (auto& us : nonEmptyFeatures(_features)) {
auto insertPosition = features.end();

for (size_t i = features.size(); i > 0; --i) {
Expand All @@ -514,6 +521,7 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
features.insert(insertPosition, us);
}

// if (Logger::isEnabled(LogLevel::TRACE, Logger::STARTUP)) {
LOG_TOPIC("0fafb", TRACE, Logger::STARTUP) << "ordered features:";

int position = 0;
Expand All @@ -524,7 +532,8 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
if (!startsAfter.empty()) {
std::function<std::string(size_t)> cb =
[this](size_t type) -> std::string {
return std::string{getFeature(type).name()};
return hasFeature(type) ? std::string{getFeature(type).name()}
: "unknown";
};
dependencies =
" - depends on: " + StringUtils::join(startsAfter, ", ", cb);
Expand All @@ -533,6 +542,7 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
<< "feature #" << ++position << ": " << feature.name()
<< (feature.isEnabled() ? "" : " (disabled)") << dependencies;
}
// }

// remove all inactive features
for (auto it = features.begin(); it != features.end(); /* no hoisting */) {
Expand Down
15 changes: 9 additions & 6 deletions lib/ApplicationFeatures/ApplicationServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ class ApplicationServer {

void registerFailCallback(
std::function<void(std::string const&)> const& callback) {
fail = callback;
_fail = callback;
}

// setup and validate all feature dependencies, determine feature order
void setupDependencies(bool failOnMissing);

// FIXME(gnusi) rerturn span
std::vector<std::reference_wrapper<ApplicationFeature>> const&
getOrderedFeatures() {
return _orderedFeatures;
Expand All @@ -209,12 +210,14 @@ class ApplicationServer {
void setStateUnsafe(State ss) { _state = ss; }
#endif

// FIXME(gnusi) make private
// checks for the existence of a feature by type. will not throw when used
// for a non-existing feature
bool hasFeature(size_t type) const noexcept {
return type < _features.size() && nullptr != _features[type];
}

// FIXME(gnusi) make private
ApplicationFeature& getFeature(size_t type) const {
if (ADB_LIKELY(hasFeature(type))) {
return *_features[type];
Expand All @@ -224,6 +227,7 @@ class ApplicationServer {
TRI_ERROR_INTERNAL, "unknown feature '" + std::to_string(type) + "'");
}

// FIXME(gnusi) use span
void disableFeatures(std::vector<size_t> const&);
void forceDisableFeatures(std::vector<size_t> const&);

Expand Down Expand Up @@ -299,7 +303,7 @@ class ApplicationServer {
std::string _helpSection;

// fail callback
std::function<void(std::string const&)> fail;
std::function<void(std::string const&)> _fail;

// the install directory of this program:
char const* _binaryPath;
Expand Down Expand Up @@ -413,16 +417,15 @@ class ApplicationServerT : public ApplicationServer {
Impl& getEnabledFeature() const {
auto& feature = getFeature<Type, Impl>();
if (!feature.isEnabled()) {
const auto featureName =
boost::typeindex::ctti_type_index::type_id<Type>().pretty_name();

THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL, "feature '" + featureName + "' is not enabled");
TRI_ERROR_INTERNAL,
"feature '" + std::string{feature.name()} + "' is not enabled");
}
return feature;
}

private:
// FIXME(gnusi) consider tuple
gnusi marked this conversation as resolved.
Show resolved Hide resolved
std::array<std::unique_ptr<ApplicationFeature>, Features::size()> _features;
};

Expand Down