Skip to content

add tenant cleanup methods for in-memory structs on tenant deletion#1591

Open
nikhilsinhaparseable wants to merge 2 commits intoparseablehq:mainfrom
nikhilsinhaparseable:clear-on-delete-tenant
Open

add tenant cleanup methods for in-memory structs on tenant deletion#1591
nikhilsinhaparseable wants to merge 2 commits intoparseablehq:mainfrom
nikhilsinhaparseable:clear-on-delete-tenant

Conversation

@nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Mar 20, 2026

  1. deregister the schema for a tenant on deletion
  2. remove in-memory dashboards for a tenant
  3. remove in-memory filters for a tenant
  4. remove in-memory alerts for a tenant

Summary by CodeRabbit

  • New Features
    • Tenant cleanup: deleting a tenant now removes all alerts for that tenant.
    • Removes tenant-specific in-memory database schemas.
    • Deletes tenant dashboards stored in memory.
    • Removes tenant-specific saved filters.
    • Ensures comprehensive cleanup of tenant-related runtime state to prevent orphaned data.

1. deregister the schema for a tenant on deletion
2. remove in-memory dashboards for a tenant
3. remove in-memory filters for a tenant
4. remove in-memory alerts for a tenant
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b43e30e3-8716-46b4-8c8e-a6a5d75af0f2

📥 Commits

Reviewing files that changed from the base of the PR and between 539737a and 7729e66.

📒 Files selected for processing (1)
  • src/alerts/mod.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/alerts/mod.rs

Walkthrough

Added tenant-cleanup APIs: an alert manager method to delete all alerts for a tenant, a query context method to remove a tenant schema, and tenant-delete methods for in-memory dashboards and filters; each acquires appropriate locks and removes tenant entries.

Changes

Cohort / File(s) Summary
Alert Management
src/alerts/alert_traits.rs, src/alerts/mod.rs
Added async fn delete_all_for_tenant(&self, tenant_id: &str) to the AlertManagerTrait and implemented it on Alerts. Normalizes empty tenant to DEFAULT_TENANT, collects alert IDs under read lock, sends AlertTask::Delete for each, then removes the tenant entry under write lock.
Query Schema Management
src/query/mod.rs
Added pub fn remove_schema(&self, tenant_id: &str) on InMemorySessionContext that takes a write lock on the inner SessionContext, fetches the datafusion catalog if present, and calls deregister_schema(tenant_id, true).
User Data Management
src/users/dashboards.rs, src/users/filters.rs
Added pub async fn delete_tenant(&self, tenant_id: &str) to both Dashboards and Filters. Each acquires a write lock and removes the tenant's entire entry from the internal HashMap.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Modularize Alerts #1390: Adds delete_all_for_tenant(&self, tenant_id: &str) to the alert manager trait and related alert modularization changes.

🐇 I hop through maps and locks with glee,
Clearing tenants tidy as can be.
Alerts and dashboards waved goodbye,
Schemas unregistered — up they fly! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete and does not follow the required template. It lacks the structured sections (Fixes, Description with goal/solutions/key changes), testing checklist, documentation notes, and proper formatting. Restructure the description to match the template: add 'Fixes #XXXX' section, expand Description with goal/rationale/key changes, and complete the checklist items with actual status.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding tenant cleanup methods for in-memory data structures during tenant deletion.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/alerts/mod.rs`:
- Around line 1488-1490: delete_all_for_tenant only removes the in-memory map
entry and doesn't stop any scheduled alert tasks; update delete_all_for_tenant
to first normalize tenant_id using the same normalization as
object_store_metastore::get_alerts() (map empty -> DEFAULT_TENANT), then acquire
the alerts write lock and cancel/stop any scheduled task handles associated with
that tenant (abort/stop task handles or remove them from whatever
scheduler/handle map you maintain), remove those handles from the internal
structures, and finally remove the tenant entry from self.alerts (currently
referenced as self.alerts.write().await.remove(tenant_id)); ensure you reference
DEFAULT_TENANT and the existing alerts/scheduler handle collections when
locating and cancelling tasks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9d8152fc-1563-47ae-b655-82e566339386

📥 Commits

Reviewing files that changed from the base of the PR and between ed85a1a and 539737a.

📒 Files selected for processing (5)
  • src/alerts/alert_traits.rs
  • src/alerts/mod.rs
  • src/query/mod.rs
  • src/users/dashboards.rs
  • src/users/filters.rs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant