mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-20 13:30:46 +02:00
Every enumeration re-read the whole directory out of the local store and decoded it again, so reopening a folder cost exactly what opening it did. That is most of what a readdir spends: about 90% of the bytes and half the allocations of a 200k walk. A walk that covers a directory from its first child to its last now leaves the decoded entries behind, and the next walk pages through them in memory. Nothing is cached from a walk that stopped early or started partway in, so a client reading one page of a huge directory does not pay for the rest of it. What makes this safe is that it is not a timer. The cache holds only what the meta cache holds, so it is void whenever that is: every write goes through one of four wrappers, each dropping the directory it touched under the same lock that made the write, and a rebuild drops it at begin and complete. A walk publishes only if its build is still the live one for that directory, so a write landing halfway through cannot leave a stale listing behind. Expiry is the one thing that changes with no write at all, so it is applied when serving rather than invalidated for -- a listing must not go stale just because a child aged out while it sat there. Only a listing that leaves out chunk lists is cached or served, since those are the entries the readdir path decodes; an entry from the cache can never reach a caller that wanted chunks.