#7507·juicefs

pruneEmptyDirs loses quota metadata when removing empty directories, causing new inodes to miss original quota on recreation

Author: zhengxingmaoCreated Sep 3, 2026Updated Sep 3, 2026

Problem

When gateway's pruneEmptyDirs() function deletes empty directories during deletObj, it also deletes their associated quota records from the metadata service. If the same directory path is recreated later, it gets a new inode, but the original quota information is lost and cannot be recovered.

Root Cause

The pruneEmptyDirs() function in pkg/gateway/gateway.go calls Rmdir() which deletes the directory and triggers cleanup of quota records in the metadata backend (Redis/TiKV/MySQL). Since quotas are stored with inode as the key, when the directory is recreated with a new inode, the quota association is permanently lost.

https://github.com/juicedata/juicefs/blob/4da0beda87e88e0343c5d01ebfb1e01275466c1c/pkg/gateway/gateway.go#L494-L495

pruneEmptyDirs() 递归删除空目录,直到遇到 bucket root、非空目录或 atime=0 的目录 每个被删除的目录的 inode 被释放,其关联的配额元数据也会丢失 如果后续再创建相同路径的目录,会获得新的 inode,无法关联到原来的配额信息