apache/hadoop · error · ConcurrentModificationException

FS modified

Error message

FS modified

What it means

While walking the source tree, FSTreeWalk catches a FileNotFoundException from listStatus() of a directory it had just accepted and rethrows it as ConcurrentModificationException('FS modified'). The name is deliberate: fs2img requires a stable, unchanging source tree, and this signals an entry disappeared mid-walk, so the emitted image could not be consistent. Any delete/rename under the walked path during the run can trigger it.

Source

Thrown at hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSTreeWalk.java:87

    }
  }

  @Override
  protected Iterable<TreePath> getChildren(TreePath path, long id,
      TreeIterator i) {
    // TODO symlinks
    if (!path.getFileStatus().isDirectory()) {
      return Collections.emptyList();
    }
    try {
      ArrayList<TreePath> ret = new ArrayList<>();
      for (FileStatus s : fs.listStatus(path.getFileStatus().getPath())) {
        AclStatus aclStatus = getAclStatus(fs, s.getPath());
        ret.add(new TreePath(s, id, i, fs, aclStatus));
      }
      return ret;
    } catch (FileNotFoundException e) {
      throw new ConcurrentModificationException("FS modified");
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  class FSTreeIterator extends TreeIterator {

    private FSTreeIterator() {
    }

    FSTreeIterator(TreePath p) {
      this(p.getFileStatus(), p.getParentId());
    }

    FSTreeIterator(FileStatus fileStatus, long parentId) {
      Path path = fileStatus.getPath();
      AclStatus acls;
      try {

View on GitHub (pinned to 2add963021)

Solutions

  1. Quiesce writers or image a point-in-time copy (rsync/snapshot) of the tree instead of the live one.
  2. Exclude volatile subdirectories from the walked root.
  3. If the churn was one-off, simply re-run fs2img once the tree is stable.

Example fix

# before: imaging a live tree
hadoop fs2img -o file:///img /var/live/data

# after: image a frozen copy
rsync -a --delete /var/live/data/ /tmp/frozen-data/
hadoop fs2img -o file:///img /tmp/frozen-data
Defensive patterns

Strategy: try-catch

Try / catch

try {
  for (TreePath e : new FSTreeWalk(root, conf)) { /* ... */ }
} catch (java.util.ConcurrentModificationException e) {
  if ("FS modified".equals(e.getMessage())) {
    // tree changed mid-walk: stop writers or image a frozen copy, then rerun
  }
}

Prevention

When it happens

Trigger: Between path.getFileStatus() succeeding and fs.listStatus() executing, the directory (or a parent) is deleted or renamed, so listStatus throws FileNotFoundException, which the walk translates into ConcurrentModificationException. Also seen when walking a tree pruned by a concurrent cleanup job.

Common situations: Imaging a live filesystem with active writers (logs, temp scratch dirs, compaction output); two jobs mutating and imaging the same tree; cron overlap between a cleaner and fs2img.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/afd0ba17948f4dad. Report an issue: GitHub.