Skip to content

When deleting dataset on disk, clear its caches #8638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

fm3
Copy link
Member

@fm3 fm3 commented May 19, 2025

Steps to test:

  • Delete a dataset via dataset settings page
  • Caches should be cleared (see backend logging)
  • Put a different dataset under the same name
  • Should show the new data only.

Issues:


@fm3 fm3 self-assigned this May 19, 2025
Copy link
Contributor

coderabbitai bot commented May 19, 2025

📝 Walkthrough

Walkthrough

This change introduces a dedicated method to clear all relevant caches when a dataset is deleted, ensuring that any subsequent dataset with the same name does not use stale cached data. Related methods and repository calls are updated to use this cache-clearing logic and to synchronize dataset removal both locally and remotely.

Changes

Files/Paths Change Summary
webknossos-datastore/app/com/scalableminds/webknossos/datastore/controllers/DataSourceController.scala Added clearCachesOfDataSource method; refactored reload and deleteOnDisk to use it; changed cleanup call to removeDataSource
webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataSourceRepository.scala Removed publishRealPaths; renamed and updated cleanUpDataSource to removeDataSource with remote deletion logic
webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/uploading/UploadService.scala Replaced all calls to cleanUpDataSource with removeDataSource
CHANGELOG.unreleased.md Documented the fix for cache clearing on dataset deletion

Assessment against linked issues

Objective Addressed Explanation
Ensure caches are cleared when a dataset is deleted so that recreating with the same name loads new data (#8569)

Poem

A dataset gone, its caches swept,
No ghostly bytes are slyly kept.
When new arrives with the same old name,
Fresh data shines—no tricks, no shame!
The rabbit hops and clears the way,
For data true, both night and day.
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fm3 fm3 marked this pull request as ready for review May 27, 2025 12:57
@fm3 fm3 changed the title WIP: When deleting dataset on disk, clear its caches When deleting dataset on disk, clear its caches May 27, 2025
@fm3 fm3 requested a review from MichaelBuessemeyer May 27, 2025 12:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataSourceRepository.scala (1)

49-54: Good method rename with improved implementation, but consider error handling.

The rename from cleanUpDataSource to removeDataSource provides better semantic clarity. The implementation now properly sequences local and remote operations within the Fox monad.

However, consider the failure scenario: if the remote deletion fails after local removal succeeds, the data source will be removed locally but still exist remotely, potentially causing inconsistency.

Consider adding error recovery or changing the order of operations:

 def removeDataSource(dataSourceId: DataSourceId): Fox[Unit] =
   for {
-    _ <- Fox.successful(remove(dataSourceId))
     _ <- remoteWebknossosClient.deleteDataSource(dataSourceId)
+    _ <- Fox.successful(remove(dataSourceId))
   } yield ()

This would ensure remote deletion succeeds before local cleanup, maintaining consistency.

CHANGELOG.unreleased.md (1)

52-52: Minor style improvement for American English.

The changelog entry accurately describes the cache clearing fix. Consider using "afterward" instead of "afterwards" for consistency with American English conventions.

-When deleting a dataset, its caches are cleared, so that if a new dataset by the same name is uploaded afterwards, only new data is loaded. [#8638](https://github.com/scalableminds/webknossos/pull/8638)
+When deleting a dataset, its caches are cleared, so that if a new dataset by the same name is uploaded afterward, only new data is loaded. [#8638](https://github.com/scalableminds/webknossos/pull/8638)
🧰 Tools
🪛 LanguageTool

[locale-violation] ~52-~52: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...ew dataset by the same name is uploaded afterwards, only new data is loaded. [#8638](https...

(AFTERWARDS_US)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 055c9e2 and 749572f.

📒 Files selected for processing (4)
  • CHANGELOG.unreleased.md (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/controllers/DataSourceController.scala (3 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataSourceRepository.scala (1 hunks)
  • webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/uploading/UploadService.scala (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/uploading/UploadService.scala (2)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/DataSourceRepository.scala (1)
  • removeDataSource (49-54)
app/models/dataset/Dataset.scala (1)
  • dataSourceId (83-83)
🪛 LanguageTool
CHANGELOG.unreleased.md

[locale-violation] ~52-~52: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...ew dataset by the same name is uploaded afterwards, only new data is loaded. [#8638](https...

(AFTERWARDS_US)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-smoketest-push
🔇 Additional comments (7)
webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/uploading/UploadService.scala (2)

455-455: LGTM: Consistent method call update.

The update from cleanUpDataSource to removeDataSource maintains consistency with the method rename in DataSourceRepository.


676-676: LGTM: Consistent method call update.

The update from cleanUpDataSource to removeDataSource maintains consistency with the method rename in DataSourceRepository.

webknossos-datastore/app/com/scalableminds/webknossos/datastore/controllers/DataSourceController.scala (5)

25-25: LGTM: Import added for safe operation wrapper.

The tryo import is appropriately added to support safe cache clearing in the deleteOnDisk method.


471-487: Excellent refactoring: Cache clearing logic consolidated.

The new clearCachesOfDataSource method effectively consolidates cache clearing logic that was previously scattered. Key benefits:

  • Comprehensive cache coverage: Clears binary data service cache, mesh file cache, dataset error logs, and vault cache
  • Detailed logging: Provides clear information about cleared cache entries
  • Reusability: Can be used by both reload and deleteOnDisk actions
  • Data source reloading: Returns a fresh InboxDataSource after cache clearing

The implementation correctly handles different cache types and provides good observability through logging.


494-494: LGTM: Refactored to use consolidated cache clearing.

The reload method is cleanly refactored to use the new clearCachesOfDataSource method, eliminating code duplication and improving maintainability.


505-505: Good defensive programming: Safe cache clearing before deletion.

Using tryo to wrap clearCachesOfDataSource is appropriate here since:

  • Cache clearing failures shouldn't prevent dataset deletion
  • The dataset is about to be deleted anyway, so stale cache entries will become irrelevant
  • It ensures the deletion process is robust against cache-related errors

511-511: LGTM: Consistent with repository method rename.

The update from cleanUpDataSource to removeDataSource maintains consistency with the method rename in DataSourceRepository and ensures both local and remote cleanup occur.

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

Successfully merging this pull request may close these issues.

Deleting And Recreating a Dataset Does Not Clear Caches
1 participant