Skip to content

chore: Add tenant cache eviction for the existing policies to policyMap migration#35614

Merged
abhvsn merged 1 commit intoreleasefrom
fix-tenant-update-issue-for-policies-migration
Aug 12, 2024
Merged

chore: Add tenant cache eviction for the existing policies to policyMap migration#35614
abhvsn merged 1 commit intoreleasefrom
fix-tenant-update-issue-for-policies-migration

Conversation

@abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Aug 12, 2024

Description

Observation: Even after successful execution of the migration where we are replacing policies to policyMap for tenant, we end up in a state where the policies has the required values but policyMap was still end up in a empty state.

{
	policyMap: {},
    policies: [
      {
        permission: 'tenantReadPermissionGroups:tenant',
        permissionGroups: [ '6303edf184daf727dddb003d' ]
      },
      {
        permission: 'tenantManageUserGroups:tenant',
        permissionGroups: [ '6303edf184daf727dddb003d' ]
      },
      {
        permission: 'tenantDeleteUserGroups:tenant',
        permissionGroups: [ '6303edf184daf727dddb003d' ]
      },
	.
	.
	.
}

/test sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10348884858
Commit: 539a767
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Mon, 12 Aug 2024 09:16:31 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Improved tenant management and cache eviction processes during migrations to ensure accurate and up-to-date tenant information.
  • Bug Fixes

    • Enhanced data consistency and integrity by evicting the default tenant from the cache after updates, preventing stale data issues.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Aug 12, 2024
@abhvsn abhvsn requested a review from AnaghHegde August 12, 2024 08:47
@abhvsn abhvsn marked this pull request as ready for review August 12, 2024 08:57
@abhvsn abhvsn requested a review from sharat87 as a code owner August 12, 2024 08:57
@abhvsn abhvsn added the ok-to-test Required label for CI label Aug 12, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

This update enhances the tenant management and cache eviction capabilities within the Migration059PolicySetToPolicyMap class. Key improvements include the addition of new imports and a private field for cache interactions, alongside logic to evict the default tenant from the cache after updates. This ensures that the application maintains accurate and up-to-date tenant information, improving overall data consistency during migrations.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/... Added imports for Tenant and CacheableRepositoryHelper; introduced cache eviction logic for tenants.

Poem

In the realm of code where tenants roam,
A cache refreshed, like waves of foam.
With each migration, data stays bright,
Evicting the stale, embracing the right.
Here’s to the changes, let clarity flow,
In the world of Appsmith, watch progress grow! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

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

Outside diff range, codebase verification and nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java (1)

89-94: Replace assert with proper error handling in production code.

The use of assert in production code, such as in Migration059PolicySetToPolicyMap.java, is risky because assertions can be disabled, leading to potential issues if the condition fails. Consider using exceptions or logging to handle such cases more reliably. Here are some locations to review:

  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java (lines 89-94)

Ensure that all critical checks in production code use robust error handling to maintain application stability.

Analysis chain

Ensure robust error handling for tenant eviction.

The logic for evicting the default tenant from the cache is clear and necessary. However, ensure that the assert statement is appropriate for your production environment, as it can be disabled. Consider using a more robust error handling mechanism if needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of assert statements in the codebase to ensure they are not used inappropriately in production code.

# Test: Search for assert statements. Expect: No inappropriate usage in production code.
rg --type java --word-regexp 'assert '

Length of output: 8670

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d03278a and 539a767.

Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java (4 hunks)
Additional comments not posted (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration059PolicySetToPolicyMap.java (2)

3-4: Good use of imports for cache management.

The addition of Tenant and CacheableRepositoryHelper imports is appropriate for the new cache eviction logic.


41-41: Introduction of cacheableRepositoryHelper is well-placed.

This field is essential for managing cache eviction related to tenant data.

Copy link
Contributor

@AnaghHegde AnaghHegde left a comment

Choose a reason for hiding this comment

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

Minor comment rest look good to me

// Evict the default tenant from the cache to ensure that the updated tenant object is fetched from the database
Query tenantQuery = new Query();
tenantQuery.addCriteria(where(Tenant.Fields.slug).is(DEFAULT));
Tenant defaultTenant = mongoTemplate.findOne(tenantQuery, Tenant.class).block();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a block call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AnaghHegde here the MongoTemplate that is injected is a reactive one, in other cases we inject the non-reactive template. The blocking is required just to make sure the eviction happens after the migration is completed. This can be done using .then but thought it won't make any difference as the earlier call is also blocking in nature.

@abhvsn abhvsn requested a review from AnaghHegde August 12, 2024 09:21
@abhvsn abhvsn enabled auto-merge (squash) August 12, 2024 09:22
@abhvsn abhvsn merged commit 5494e8e into release Aug 12, 2024
@abhvsn abhvsn deleted the fix-tenant-update-issue-for-policies-migration branch August 12, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants