Skip to content

Commit

Permalink
FDB-319 added metadata validation on archival
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Sep 15, 2023
1 parent d79a966 commit b913d9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/fdb5/database/Archiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ void Archiver::archive(const Key &key, BaseArchiveVisitor& visitor) {

dbConfig_.schema().expand(key, visitor);

if (visitor.rule() == nullptr) { // Make sure we did find a rule that matched
const Rule* rule = visitor.rule();
if (rule == nullptr) { // Make sure we did find a rule that matched
std::ostringstream oss;
oss << "FDB: Could not find a rule to archive " << key;
throw eckit::SeriousBug(oss.str());
}
// validate metadata
rule->check(key);
}

void Archiver::flush() {
Expand Down
13 changes: 12 additions & 1 deletion src/fdb5/rules/Rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "fdb5/rules/Schema.h"
#include "fdb5/database/ReadVisitor.h"
#include "fdb5/database/WriteVisitor.h"

#include "fdb5/types/Type.h"

namespace fdb5 {

Expand Down Expand Up @@ -494,6 +494,17 @@ const Schema &Rule::schema() const {
return schema_;
}

void Rule::check(const Key& key) const {
for (const auto& pred : predicates_ ) {
auto k = key.find(pred->keyword());
if (k != key.end()) {
const std::string& value = (*k).second;
const Type& type = registry_.lookupType(pred->keyword());
ASSERT(value == type.tidy(pred->keyword(), value));
}
}
}

std::ostream &operator<<(std::ostream &s, const Rule &x) {
x.print(s);
return s;
Expand Down
2 changes: 2 additions & 0 deletions src/fdb5/rules/Rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Rule : public eckit::NonCopyable {
const Schema &schema() const;
const TypesRegistry &registry() const;

void check(const Key& key) const;

private: // methods

void expand(const metkit::mars::MarsRequest &request,
Expand Down

0 comments on commit b913d9d

Please sign in to comment.