/// cannot run, they hold crawl progress holds while they wait, and
/// they keep the crawler from ever reporting itself idle.
mutex m_inflight_mutex;
- set<uint64_t> m_inflight;
public:
- /// Claim @p bytenr for scanning. False if already queued.
- bool inflight_insert(uint64_t bytenr);
+ /// Identifying detail of an extent claimed for scanning. Kept as
+ /// scalars rather than a BeesExtent so a claim does not pin a node
+ /// in the layer cache for as long as the scan runs.
+ struct InflightExtent {
+ string m_tier;
+ uint64_t m_bytenr = 0;
+ uint64_t m_length = 0;
+ uint64_t m_gen = 0;
+ time_t m_queued = 0;
+ };
+ /// Claim an extent for scanning. On failure @p existing is filled
+ /// in with the claim already held, so the caller can report both.
+ bool inflight_insert(const InflightExtent &e, InflightExtent &existing);
/// Release a claim taken by inflight_insert().
void inflight_erase(uint64_t bytenr);
private:
+ map<uint64_t, InflightExtent> m_inflight;
mutex m_insert_root_mutex;
/// Size range [m_min_size, m_max_size] for one extent size tier.
return cm;
}
+ostream &
+operator<<(ostream &os, const BeesScanModeExtent::InflightExtent &e)
+{
+ return os << "tier " << e.m_tier
+ << " bytenr " << to_hex(e.m_bytenr)
+ << " size " << pretty(e.m_length)
+ << " gen " << e.m_gen
+ << " queued " << (time(NULL) - e.m_queued) << "s ago";
+}
+
bool
-BeesScanModeExtent::inflight_insert(const uint64_t bytenr)
+BeesScanModeExtent::inflight_insert(const InflightExtent &e, InflightExtent &existing)
{
unique_lock<mutex> lock(m_inflight_mutex);
- return m_inflight.insert(bytenr).second;
+ const auto [it, inserted] = m_inflight.insert(make_pair(e.m_bytenr, e));
+ if (!inserted) {
+ existing = it->second;
+ }
+ return inserted;
}
void
// hold, which is what keeps a crawler from ever reporting
// itself idle. Claim the bytenr, and drop the extent if
// someone already has it.
- if (!m_bsme->inflight_insert(this_bytenr)) {
+ const BeesScanModeExtent::InflightExtent this_inflight {
+ .m_tier = m_name,
+ .m_bytenr = this_bytenr,
+ .m_length = this_length,
+ .m_gen = gen,
+ .m_queued = time(NULL),
+ };
+ BeesScanModeExtent::InflightExtent held_inflight;
+ if (!m_bsme->inflight_insert(this_inflight, held_inflight)) {
+ // Report both descriptions. They routinely disagree
+ // about size and generation, which is the interesting
+ // part: two scans built from different views of what
+ // extent lives at this address, not one extent queued
+ // twice from one view.
BEESCOUNT(crawl_extent_dup);
+ BEESLOGWARN("crawl_extent_dup: extent already queued for scanning\n"
+ << "\tin flight: " << held_inflight << "\n"
+ << "\tdropped: " << this_inflight);
continue;
}
const auto bsme = m_bsme;