Skip to content

[Bug]: DiskCache DeletePaths leaves stale range entries across object generations #27367

Closed

Description

@XuPeng-SH

Branch Name

main

Commit ID

c6b2ac9c1eaff0db867e845723a8ce1d2102928f

Other Environment Information

  • Source-level deterministic reproduction in pkg/fileservice
  • Linux amd64, Go 1.26.4
  • Reproduced three consecutive times
  • The reproduction uses the public DiskCache update/delete/set/read sequence and does not depend on an external object store

Actual Behavior

DiskCache.DeletePaths removes only the full-object cache file. Range/IOEntry cache files for the same logical object remain in the FIFO index and on disk.

After a write-once object is deleted and the same path is created again with new content, DiskCache.Read checks the exact range cache before the full-object cache. It therefore returns bytes from the deleted object's stale range entry.

The deterministic reproduction cached range [0,3) as old, deleted foo/bar, recreated its full-file cache as new, and then read [0,3). All three runs returned old.

Expected Behavior

Deleting a FileService path must invalidate every DiskCache representation of that logical object—both the full-object file and all range/IOEntry files—before the path can be reused. A subsequent read after delete-and-recreate must never observe bytes from the deleted generation.

Invalidation must coordinate with in-progress range and full-file updates so an older generation cannot publish after deletion.

Steps to Reproduce

Add a temporary white-box test under pkg/fileservice:

cache, _ := NewDiskCache(context.Background(), t.TempDir(),
    fscache.ConstCapacity(1<<20), nil, false, nil, "")
defer cache.Close(context.Background())
ctx := context.Background()

require.NoError(t, cache.Update(ctx, &IOVector{
    FilePath: "foo/bar",
    Entries: []IOEntry{{
        Offset: 0, Size: 3, Data: []byte("old"),
    }},
}, false))

require.NoError(t, cache.DeletePaths(ctx, []string{"foo/bar"}))

require.NoError(t, cache.SetFile(ctx, "foo/bar",
    func(context.Context) (io.ReadCloser, error) {
        return io.NopCloser(strings.NewReader("new")), nil
    }))

vector := &IOVector{
    FilePath: "foo/bar",
    Entries: []IOEntry{{Offset: 0, Size: 3}},
}
defer vector.Release()
require.NoError(t, cache.Read(ctx, vector))
require.Equal(t, []byte("new"), vector.Entries[0].Data)

Run:

GOWORK=off go test -mod=readonly ./pkg/fileservice \
  -run '^TestCodexDiskCacheDeleteThenRewriteMustNotReadStaleRange$' \
  -count=3 -timeout=1m

Observed on every run:

expected: new
actual:   old

Additional information / Code Analysis

  • DiskCache.pathForIOEntry encodes range files separately from pathForFile.
  • DiskCache.Read tries the IOEntry path first and uses the full-file path only as fallback.
  • DiskCache.DeletePaths calls removeOnePath.
  • removeOnePath removes only pathForFile(path) and deletes only that full-file FIFO key.
  • The production source already contains // TODO also delete IOEntry files at this point.
  • FileService writes are write-once while an object exists, but delete followed by reuse of the same path is allowed, so immutability does not protect across object generations.

Impact

  • Silent stale reads after delete-and-recreate of a FileService path.
  • The returned bytes can belong to a logically deleted object generation.
  • A stale range entry takes precedence even when the new full-object cache contains correct data.
  • The failure can persist until FIFO eviction or manual cache cleanup and can differ by CN, producing cross-CN inconsistency.

Regression Coverage

A fix should cover:

  • range cached → delete → recreate same path → exact range read;
  • multiple offsets/sizes and nested paths;
  • concurrent range fill versus delete, proving the old generation cannot publish afterward;
  • cancellation during invalidation;
  • FIFO index and physical-file cleanup, including partial filesystem failures.

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions