Skip to content

[data_storage] implement nfs backend delete and exists - #126

Open
wangxiyu191 wants to merge 1 commit into
mainfrom
fix/nfs-backend-delete
Open

[data_storage] implement nfs backend delete and exists#126
wangxiyu191 wants to merge 1 commit into
mainfrom
fix/nfs-backend-delete

Conversation

@wangxiyu191

Copy link
Copy Markdown
Collaborator

Summary

  • Implement NFS backend file deletion using the URI path.
  • Avoid deleting shared multi-block files except for blkid=0; missing or empty blkid is treated as block 0 for compatibility.
  • Make Exist check the filesystem and keep MightExist cheap by returning true without filesystem IO.
  • Extend NFS backend tests for delete, multi-block delete behavior, invalid blkid, missing/empty blkid, Exist, and MightExist.

Validation

  • git diff --check
  • bazel test --config=py312 --cache_test_results=no //kv_cache_manager/data_storage/test:NfsBackendTest --test_output=errors
  • bazel build --config=py312 //kv_cache_manager:kv_cache_manager_bin

@wangxiyu191
wangxiyu191 force-pushed the fix/nfs-backend-delete branch from 6c7c2a5 to 3f2d6a8 Compare April 25, 2026 15:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c7c2a5d9b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kv_cache_manager/data_storage/nfs_backend.cc
@wangxiyu191 wangxiyu191 changed the title [fix] enable nfs backend delete checks [storage] implement nfs backend delete and exists Apr 25, 2026

@qoderai qoderai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Review Summary

Solid implementation — the ShouldDeleteFile logic is clean, the from_chars parsing is correct and strict, and the overall pattern is consistent with the existing Hf3fsBackend. Good use of non-throwing std::error_code overloads throughout.

🛡️ Key Risks & Issues

No blocking issues found. The core logic is sound:

  • ShouldDeleteFile correctly treats missing/empty blkid as block-0 (delete), rejects non-numeric values with EC_ERROR, and skips deletion for non-zero blocks.
  • std::from_chars with uint64_t naturally rejects negative values and non-numeric input.
  • The std::filesystem::remove call gracefully handles already-deleted files (returns false without error, logged as a warning).

One design note worth considering: The Hf3fsBackend::Delete (lines 98-121 in hf3fs_backend.cc) unconditionally deletes the file for every URI, with no blkid-awareness. If hf3fs is also used with multi-block files (key_count_per_file > 1), it would delete the shared file on every block's Delete call, which could race with reads of other blocks. If that's an intentional difference, a brief comment in hf3fs_backend.cc would help future maintainers. If not, the ShouldDeleteFile guard could be promoted to a shared utility.

🧪 Verification Advice

The tests cover the critical scenarios well (block-0, non-zero, invalid, missing, empty blkid, real filesystem Exist, MightExist always-true). A few minor gaps to consider:

  • Mixed-URI batch Delete: All multi-block tests call Delete with a single URI at a time. A test calling Delete({blkid=0_uri, blkid=1_uri, invalid_uri}) in one batch would verify the loop correctly produces [EC_OK, EC_OK, EC_ERROR] in a single invocation.
  • Null callback: The code guards with if (cb) before invoking, but all tests pass a non-null lambda. One test with a default-constructed std::function<void()>{} would confirm no crash.

These are minor — the current coverage is sufficient for the core behavioral contract.

💡 Thoughts & Suggestions

  • Exist operates at file granularity, not block granularity — for multi-block URIs all blocks sharing the same file will report the same existence status. This is consistent with Hf3fsBackend but worth a brief inline comment for future readers.
  • The MightExist override is a nice touch — keeping it as a cheap always-true avoids unnecessary filesystem I/O for the fast-path check, which aligns well with the base class contract.

🤖 Generated by QoderView workflow run

Comment thread kv_cache_manager/data_storage/nfs_backend.cc
@github-actions github-actions Bot added the ai reviewed AI has reviewed this PR label Apr 25, 2026
@wangxiyu191
wangxiyu191 requested a review from charpty April 27, 2026 00:47
@wangxiyu191 wangxiyu191 changed the title [storage] implement nfs backend delete and exists [data_storage] implement nfs backend delete and exists Apr 28, 2026
std::vector<ErrorCode> result;
result.reserve(storage_uris.size());
for (const auto &storage_uri : storage_uris) {
const auto [decision, should_delete] = ShouldDeleteFile(storage_uri);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里把error code叫成decision有点困惑

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

Labels

ai reviewed AI has reviewed this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants