Skip to content

Commit

Permalink
admin: expose time point for last completed scrub
Browse files Browse the repository at this point in the history
When a full scrub of the log finishes, via one or more scrubs, persist
the timestamp at which this happened. This timestamp is then exposed via
the admin API. We will use this in our ducktape tests for end of test
scrubbing.
  • Loading branch information
Vlad Lazar committed Oct 24, 2023
1 parent 11638cc commit 2dc6e19
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/v/cloud_storage/partition_manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,10 @@ void partition_manifest::process_anomalies(
_last_partition_scrub = scrub_timestamp;
_last_scrubbed_offset = last_scrubbed_offset;

if (!_last_scrubbed_offset) {
_detected_anomalies.last_complete_scrub = scrub_timestamp;
}

vlog(
cst_log.debug,
"[{}] Anomalies processed: {{ detected: {}, last_partition_scrub: {}, "
Expand Down
13 changes: 13 additions & 0 deletions src/v/cloud_storage/tests/anomalies_detector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
#include <boost/test/tools/old/interface.hpp>
#include <boost/test/unit_test.hpp>

namespace cloud_storage {

bool operator==(const anomalies& lhs, const anomalies& rhs) {
return lhs.missing_partition_manifest == rhs.missing_partition_manifest
&& lhs.missing_spillover_manifests == rhs.missing_spillover_manifests
&& lhs.missing_segments == rhs.missing_segments
&& lhs.segment_metadata_anomalies == rhs.segment_metadata_anomalies;

// anomalies::last_complete_scrub is intentionally omitted
}

} // namespace cloud_storage

namespace {

ss::logger test_logger{"anomaly_detection_test"};
Expand Down
3 changes: 3 additions & 0 deletions src/v/cloud_storage/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ anomalies& anomalies::operator+=(anomalies&& other) {
std::make_move_iterator(other.segment_metadata_anomalies.begin()),
std::make_move_iterator(other.segment_metadata_anomalies.end()));

last_complete_scrub = std::max(
last_complete_scrub, other.last_complete_scrub);

return *this;
}

Expand Down
8 changes: 6 additions & 2 deletions src/v/cloud_storage/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,24 @@ struct anomalies
absl::node_hash_set<segment_meta> missing_segments;
// Segments that have metadata anomalies (e.g. gaps or overlaps)
segment_meta_anomalies segment_metadata_anomalies;
// Optional timestamp indicating the last time point at which
// the scrub of the full log completed.
std::optional<model::timestamp> last_complete_scrub;

auto serde_fields() {
return std::tie(
missing_partition_manifest,
missing_spillover_manifests,
missing_segments,
segment_metadata_anomalies);
segment_metadata_anomalies,
last_complete_scrub);
}

bool has_value() const;

anomalies& operator+=(anomalies&&);

bool operator==(anomalies const&) const = default;
friend bool operator==(const anomalies& lhs, const anomalies& rhs);
};

std::ostream& operator<<(std::ostream& o, const anomalies& a);
Expand Down
4 changes: 4 additions & 0 deletions src/v/redpanda/admin/api-doc/shadow_indexing.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@
"type": "array",
"items": {"type": "metadata_anomaly"},
"nullable": true
},
"last_complete_scrub_at": {
"type": "long",
"nullable": true
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/v/redpanda/admin_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5304,6 +5304,10 @@ map_anomalies_to_json(
json.partition = ntp.tp.partition();
json.revision_id = initial_rev();

if (detected.last_complete_scrub) {
json.last_complete_scrub_at = detected.last_complete_scrub->value();
}

if (detected.missing_partition_manifest) {
json.missing_partition_manifest = true;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/rptest/tests/cloud_storage_scrubber_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def _collect_anomalies(self):
topic=self.topic,
partition=pid)

anomalies.pop("last_complete_scrub_at", None)

ntpr = NTPR(ns=anomalies["ns"],
topic=anomalies["topic"],
partition=anomalies["partition"],
Expand Down

0 comments on commit 2dc6e19

Please sign in to comment.