Skip to content

Redesign the Drive folder-ID cache around parent edges and preserve DVC traversal budgets #413

Backlog

Description

@shcheklein

Current behavior

Drive names are not unique. PyDrive2 resolves path components to Drive IDs and caches folders. In the filesystem stack starting at #408, each filesystem keeps a path-to-folder-IDs index and a reverse ID-to-materialized-path index. A move, removal, or rediscovery evicts the affected paths and copies surviving entries into a replacement cache. Requests that started earlier can finish using their original cache. Traversal uses known folder IDs to batch listings and constructs result paths from the parent links Drive returns.

Why change it

Moving one folder changes the cached path of every descendant. When two folders share a name, a materialized path cannot identify which folder owns a cached child. Invalidation scans and copies unrelated entries. An unrelated invalidation also prevents an in-flight lookup from warming the replacement cache. Depth-limited traversal can scan the full reverse index to select warm descendants. These costs grow with the directory cache even when a user is operating on a small subtree.

DVC workloads to preserve

DVC stores objects below two-character hash prefixes. Its Google Drive adapter sets TRAVERSE_WEIGHT_MULTIPLIER = 1 to favor listing under API quotas. The object database can still use individual existence checks for small queries. The adapter calls makedirs(parent) before streaming an upload, so already resolved parents should stay cheap. PyDrive2’s folder-ID cache is per filesystem instance and serves a different purpose from DVC’s persistent object cache. dvc-gdrive adapter · DVC object database

A real DVC cloud-status traversal with 251 prefix folders failed when all parent IDs were included in one Drive query. Smaller batches worked. Keep pagination and the existing limit of 50 parents per query. That is our tested batch size, not a published Google limit. Original reproduction

Implementation plan

  1. Store directory edges by parent ID and exact name, with all matching child IDs. Maintain a reverse edge index to unlink a known folder when it moves. Keep root aliases, bare IDs, and shared-drive routing explicit. Distinguish a completely resolved name from a partial listing or failed page.
  2. Resolve paths by following edges. Rediscovering a moved ID should relink it without rewriting its descendants. Define path invalidation, full invalidation, and deletion separately. Preserve siblings and same-name folders belonging to other parents.
  3. Capture a generation before resolving the parent. Reject stale cache writes through the final lookup or create. Start with one instance generation and measure the effect on unrelated in-flight reads. Keep network I/O outside the cache lock and coordinate duplicate creates for the same parent and name.
  4. Collect warm parent IDs with a bounded breadth-first walk from the requested folder. Batch the resulting Drive queries across levels where possible. Continue reconstructing output paths from fresh parent links so a moved folder cannot reappear under its old name.
  5. Compare both implementations through public filesystem and DVC object-database operations. Measure CPU, memory and request counts on deep, wide, and duplicate-name trees, including a small subtree in a large warm cache. Include concurrent uploads to the same and different hash prefixes, moves during listing, partial pages, shared drives, trash, and externally replaced mounts.

Acceptance criteria

  • The original deep-path test still needs five cold logical listings and one request for each warm file lookup, listing and recursive traversal in that fixture. Repeated creation/checking of known named directories stays local.
  • The single-page 251-folder fixture stays at seven cold requests and six warm requests. Each parent is queried once per traversal. Retain distinct files and folder IDs even when names repeat.
  • An old in-flight response cannot resurrect an invalidated path. Removing or moving one folder leaves unrelated warm folders usable. A failed or partial lookup cannot record an incomplete set of duplicate matches as complete.
  • Exercise both single-object existence checks and multi-object traversal using dvc-gdrive and dvc-objects. Check the DVC adapter’s upload preflight and confirm that cache lookup costs scale with the touched subtree.

Related work: #232, #349, #393, #408, #409, #411.

Activity

  1. shcheklein commented on Nov 25, 2026

    @shcheklein
    MemberAuthor

    I measured the proposed request budgets through DVC 3.67.1, dvc-gdrive 3.0.1, dvc-objects 5.3.1 and dvc-data 3.18.3 against a simulated Drive transport. The results matched on fsspec 2024.2.0 and 2026.9.0. The fixture has 251 two-character prefix directories with one object each and single-page responses.

    DVC operation Drive requests
    Filesystem traversal of all prefixes 7 cold, 6 warm
    Object database existence check 1 request for 1 object, 7 for 24 objects on the warm filesystem
    Enumerate all 251 object IDs through the object database 7
    Stream directly to an already resolved prefix with upload_fobj 2, the upload session POST and body PUT
    Second consecutive stream via put_file to the same initially warm prefix 3, one parent lookup plus POST and PUT

    The last two rows matter for the redesign. The Google Drive adapter checks makedirs(parent) before uploading. The dvc-objects put_file wrapper also calls invalidate_cache(parent) after a successful upload. Repeating the transfer therefore needs to resolve the prefix again. Benchmark both public entry points and preserve explicit invalidation for callers that have changed a directory externally. DVC filesystem wrapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions