/// each other; each tier has its own BeesCrawl position and Task.
class BeesScanModeExtent : public BeesScanMode {
mutex m_mutex;
+ /// Bytenrs of extents already queued for scanning and not yet
+ /// finished. Successive crawl cycles re-derive overlapping extent
+ /// sets, so without this the same extent is queued again while the
+ /// previous Task is still parked on its Exclusion: the duplicates
+ /// 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);
+ /// Release a claim taken by inflight_insert().
+ void inflight_erase(uint64_t bytenr);
+private:
mutex m_insert_root_mutex;
/// Size range [m_min_size, m_max_size] for one extent size tier.
return cm;
}
+bool
+BeesScanModeExtent::inflight_insert(const uint64_t bytenr)
+{
+ unique_lock<mutex> lock(m_inflight_mutex);
+ return m_inflight.insert(bytenr).second;
+}
+
+void
+BeesScanModeExtent::inflight_erase(const uint64_t bytenr)
+{
+ unique_lock<mutex> lock(m_inflight_mutex);
+ m_inflight.erase(bytenr);
+}
+
shared_ptr<const BeesScanModeExtent::ChunkMap>
BeesScanModeExtent::chunk_map(const bool force)
{
// every scan method, not only the planner path.
const auto incrementer = make_shared<ScannerByteCounters::Incrementer>(counters, created_length);
if (m_method == 1) {
+ // Successive crawl cycles re-derive overlapping extent sets, so
+ // the same extent arrives here again while the Task from a
+ // previous cycle is still parked on its Exclusion. Queueing it
+ // twice cannot make it run any sooner -- the duplicate parks on
+ // the same lock -- but it does hold a second crawl progress
+ // 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)) {
+ BEESCOUNT(crawl_extent_dup);
+ continue;
+ }
+ const auto bsme = m_bsme;
+ const auto inflight = shared_ptr<void>(nullptr, [bsme, this_bytenr](void *) {
+ bsme->inflight_erase(this_bytenr);
+ });
ostringstream oss;
oss << m_name << "_" << hex << this_bytenr << dec << "_" << pretty(this_length);
const auto pstate = make_shared<PlannerState>();
- Task scan_next_task(oss.str(), [sft, bti, hold_state, find_next_task, pstate, incrementer]() {
+ Task scan_next_task(oss.str(), [sft, bti, hold_state, find_next_task, pstate, incrementer, inflight]() {
const bool restart_extent = sft->scan_one_extent_item(bti, pstate);
if (restart_extent) {
Task::current_task().run();