Project

General

Profile

Actions

Bug #76059

closed
CZ VS

crash and shutdown hang in hash_into_rank_bucket() when ephemeral pins active and max_mds drops to 0

Bug #76059: crash and shutdown hang in hash_into_rank_bucket() when ephemeral pins active and max_mds drops to 0

Added by chung feng zheng 8 months ago. Updated about 1 month ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Correctness/Safety
Target version:
Due date:
% Done:

0%

Source:
Community (dev)
Backport:
tentacle,squid
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Component(FS):
MDS
Labels (FS):
Pull request ID:
Tags (freeform):
Fixed In:
v21.0.0-2118-gaed8065a54
Released In:
v21.2.0~251
Upkeep Timestamp:
2026-10-28T01:10:01+00:00

Description

Summary

Two related bugs manifest when a CephFS filesystem is paused (max_mds set to 0) while one or more inodes have ephemeral directory pins (distributed or random ephemeral pins) active:

  1. Crash -- the MDS daemon aborts with a failed assertion inside hash_into_rank_bucket().
  2. Shutdown hang -- after the crash is fixed, a secondary issue causes shutdown_pass() to loop indefinitely, preventing the MDS from completing its shutdown sequence.

How to Reproduce

Prerequisites:
  • A multi-MDS CephFS cluster.
  • At least one directory with an ephemeral pin set, e.g.:
setfattr -n ceph.dir.pin.distributed -v 1 /mnt/cephfs/some_dir

Steps to trigger the crash:

  1. With ephemerally-pinned directories present, pause the filesystem (which sets max_mds to 0):
    ceph fs set <fs_name> down true
    
  2. The MDS daemon receives the new MDSMap with max_mds 0, detects the max_mds change, and immediately calls maybe_export_pin() on all ephemerally-pinned inodes to redistribute them. This path reaches hash_into_rank_bucket() with max_mds 0 and aborts.

Steps to trigger the shutdown hang (second bug):

After applying the crash fix alone, hash_into_rank_bucket() now returns MDS_RANK_NONE when max_mds 0. The hang then appears:

  1. As above, pause the filesystem while ephemeral pins are active.
  2. The MDS enters shutdown_pass(), which iterates over auth subtrees to export them to rank 0.
  3. Ephemerally-pinned dirs are unconditionally skipped because shutdown_pass() expects handle_export_pins() to place them.
  4. handle_export_pins() calls hash_into_rank_bucket(), receives MDS_RANK_NONE, and cannot schedule any export.
  5. The ephemerally-pinned dirs are never exported; shutdown_pass() loops forever.

Root cause

Bug 1 -- crash in hash_into_rank_bucket()

hash_into_rank_bucket() implements a jump-consistent hash to map an inode number to an MDS rank in [0, max_mds). The loop condition is j < max_mds, so when max_mds 0 the loop body never runs and b stays at its initial value of -1. The assertion at the end of the function then fails:

// src/mds/MDCache.cc
mds_rank_t MDCache::hash_into_rank_bucket(inodeno_t ino, frag_t fg)
{
  const mds_rank_t max_mds = mds->mdsmap->get_max_mds();
  uint64_t hash = rjhash64(ino);
  ...
  int64_t b = -1, j = 0;
  while (j < max_mds) {   // never executes when max_mds == 0
    b = j;
    ...
  }
  auto result = mds_rank_t(b);
  ceph_assert(result >= 0 && result < max_mds);  // -1 >= 0 is false -> ABORT
  return result;
}

Bug 2 -- shutdown hang in shutdown_pass()

shutdown_pass() intentionally skips ephemerally-pinned dirs, delegating their export to handle_export_pins(). This design assumes handle_export_pins() can always compute a valid target rank. When max_mds == 0, hash_into_rank_bucket() returns MDS_RANK_NONE, so no export is ever queued. The ephemerally-pinned dirs remain in the cache indefinitely and the shutdown loop never drains them:

// src/mds/MDCache.cc -- shutdown_pass()
if (dir->is_frozen() || ... ||
    dir->get_inode()->is_ephemerally_pinned()) {   // always true for pinned dirs
  continue;                                         // dir is never added to ls
}
ls.push_back(dir);   // never reached for ephemerally-pinned dirs

Code Flow

Crash path (Bug 1)

ceph fs set <fs> down true  ->  max_mds set to 0 in MDSMap
  |
  v
MDSDaemon::handle_mds_map()                     [MDSDaemon.cc]
  |
  v
MDSRankDispatcher::handle_mds_map()             [MDSRank.cc]
  |
  v
MDCache::handle_mdsmap(new_map, old_map)        [MDCache.cc]
  |  detects max_mds changed -> iterates export_ephemeral_pins
  v
CInode::maybe_export_pin()                      [CInode.cc]
  |
  v
CInode::queue_export_pin(MDS_RANK_EPHEMERAL_*)  [CInode.cc]
  |
  v
MDCache::hash_into_rank_bucket(ino, fg)         [MDCache.cc]
  |  max_mds == 0, loop never runs, b == -1
  v
ceph_assert(result >= 0 && result < max_mds)    <- ABORT / CRASH

Shutdown hang path (Bug 2, after crash fix applied)

ceph fs set <fs> down true  ->  max_mds == 0
  |
  v
MDCache::shutdown_pass()                        [MDCache.cc]
  |  iterates auth subtrees
  |  for each ephemerally-pinned dir:
  |    is_ephemerally_pinned() == true  ->  skip (continue)
  |    dir never added to export list
  |
  v
mds->balancer->handle_export_pins()
  |  for each queued pin:
  |    hash_into_rank_bucket() returns MDS_RANK_NONE (max_mds == 0)
  |    no export scheduled
  |
  v
shutdown_pass() loops again -- no progress

Related issues 2 (0 open — 2 closed)

Copied to CephFS - Backport #77259: squid: crash and shutdown hang in hash_into_rank_bucket() when ephemeral pins active and max_mds drops to 0ResolvedVenky Shankar

Actions
Copied to CephFS - Backport #77260: tentacle: crash and shutdown hang in hash_into_rank_bucket() when ephemeral pins active and max_mds drops to 0ResolvedVenky Shankar

Actions

CZ Updated by chung feng zheng 8 months ago Actions #1

  • Pull request ID set to 68413

VS Updated by Venky Shankar 8 months ago Actions #2

  • Category set to Correctness/Safety
  • Status changed from New to Fix Under Review
  • Target version set to v21.0.0
  • Source set to Community (dev)
  • Backport set to tentacle,squid

VS Updated by Venky Shankar 7 months ago Actions #3

  • Component(FS) MDS added

VS Updated by Venky Shankar 6 months ago Actions #4

  • Assignee set to Dhairya Parmar

@Dhairya Parmar - please do the relevant backports.

UB Updated by Upkeep Bot 6 months ago Actions #5

  • Status changed from Fix Under Review to Pending Backport
  • Merge Commit set to aed8065a545733548a6b4a22c12a8ec9104c5cf3
  • Fixed In set to v21.0.0-2118-gaed8065a54
  • Upkeep Timestamp set to 2026-06-09T01:33:51+00:00

UB Updated by Upkeep Bot 6 months ago Actions #6

  • Copied to Backport #77259: squid: crash and shutdown hang in hash_into_rank_bucket() when ephemeral pins active and max_mds drops to 0 added

UB Updated by Upkeep Bot 6 months ago Actions #7

  • Copied to Backport #77260: tentacle: crash and shutdown hang in hash_into_rank_bucket() when ephemeral pins active and max_mds drops to 0 added

UB Updated by Upkeep Bot 6 months ago Actions #8

  • Tags (freeform) set to backport_processed

VS Updated by Venky Shankar 6 months ago Actions #9

  • Assignee changed from Dhairya Parmar to Venky Shankar

I am taking this one.

UB Updated by Upkeep Bot 3 months ago Actions #10

  • Status changed from Pending Backport to Backporting
  • Tags (freeform) deleted (backport_processed)
  • Upkeep Timestamp changed from 2026-06-09T01:33:51+00:00 to 2026-08-27T18:33:54+00:00

UB Updated by Upkeep Bot about 1 month ago Actions #11

  • Released In set to v21.2.0~251
  • Upkeep Timestamp changed from 2026-08-27T18:33:54+00:00 to 2026-10-24T01:18:19+00:00

UB Updated by Upkeep Bot about 1 month ago Actions #12

  • Status changed from Backporting to Resolved
  • Upkeep Timestamp changed from 2026-10-24T01:18:19+00:00 to 2026-10-28T01:10:01+00:00
Actions

Also available in: PDF Atom