Skip to content
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

fix: Concurrent modification exception during the datasource import flow #34818

Merged
merged 3 commits into from
Jul 10, 2024

Conversation

abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Jul 9, 2024

Description

In the import service, we are trying to import datasources using the combination of Flux and Flatmap to create the reactive chain. This translates to creating multiple threads to accomplish the task in an efficient manner. After we introduced database dry ops, where we are now sharing the map of ops type to the object for which the operation needs to be performed. This caused a concurrentModificationException as datasourceService layer is referring to same object via different threads.

Automation

/ok-to-test tags="@tag.ImportExport, @tag.Sanity, @tag.Git"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9861701410
Commit: cf63fab
Cypress dashboard.
Tags: @tag.ImportExport, @tag.Sanity, @tag.Git
Spec:


Tue, 09 Jul 2024 18:05:03 UTC

Communication

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

  • Yes
  • No

Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

The key change in this update is the adoption of the DBOpsType enum for type safety and improved readability. This entails modifying method signatures and data structures across several files to replace String keys with DBOpsType keys. Additionally, thread safety enhancements and a new test method to validate the changes are introduced.

Changes

File Summary
DatasourceServiceCE.java DatasourceServiceCEImpl.java Added DBOpsType import and changed parameters to use DBOpsType instead of String.
DatasourceImportableServiceCEImpl.java Added @NonNull annotation and modified the method to handle DBOpsType in dryRunOpsMap.
MappedImportableResourcesCE_DTO.java Introduced DBOpsType, modified data structures to use DBOpsType keys, and added synchronization for thread safety.
ImportServiceTests.java Added a new test method importArtifactIntoWorkspace_pageRemovedAndUpdatedDefaultPageNameInBranchApplication_Success().

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ImportService
    participant DatasourceService
    
    User->>ImportService: Import Artifact Request
    ImportService->>DatasourceService: Create Datasource with DryRun
    DatasourceService->>DatasourceStorage: Use DBOpsType in Data Map
    DatasourceService-->>ImportService: Return Datasource Info
    ImportService-->>User: Import Success
Loading

Poem

In the land of code, enums arose,
To replace the strings where confusion grows.
With DBOpsType, clarity came,
Data safer, operations tamed.
Welcome changes, tests anew,
In Appsmith's world, our trust it grew. 🌟🐇


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 Configration 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.

@github-actions github-actions bot added the Bug Something isn't working label Jul 9, 2024
Copy link

github-actions bot commented Jul 9, 2024

Failed server tests

  • com.appsmith.server.imports.internal.ImportServiceTests#discardChange_addNewActionAfterImport_addedActionRemoved

@abhvsn abhvsn requested a review from AnaghHegde July 9, 2024 17:35
@abhvsn abhvsn marked this pull request as ready for review July 9, 2024 17:35
@abhvsn abhvsn requested review from nidhi-nair, sondermanish and a team as code owners July 9, 2024 17:35
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

Outside diff range and nitpick comments (1)
app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (1)

Line range hint 1573-1606: Refactor the test method for readability

The test method can be refactored for better readability by breaking down the setup, import, and validation steps into separate sections or helper methods.

@Test
@WithUserDetails(value = "api_user")
public void importArtifactIntoWorkspace_pageRemovedAndUpdatedDefaultPageNameInBranchApplication_Success() {
    Application application = setupApplication();
    String gitSyncIdBeforeImport = getGitSyncIdBeforeImport(application);
    PageDTO savedPage = createPage(application);
    Set<String> applicationPageIdsBeforeImport = getPageIdsBeforeImport(application);

    ApplicationJson applicationJson = prepareApplicationJson(gitSyncIdBeforeImport);
    Application importedApplication = performImport(application, applicationJson);

    validateImport(applicationPageIdsBeforeImport, savedPage, importedApplication);
}

private Application setupApplication() {
    // Setup application code
}

private String getGitSyncIdBeforeImport(Application application) {
    // Get Git sync ID before import
}

private PageDTO createPage(Application application) {
    // Create page code
}

private Set<String> getPageIdsBeforeImport(Application application) {
    // Get page IDs before import
}

private ApplicationJson prepareApplicationJson(String gitSyncIdBeforeImport) {
    // Prepare application JSON
}

private Application performImport(Application application, ApplicationJson applicationJson) {
    // Perform import
}

private void validateImport(Set<String> applicationPageIdsBeforeImport, PageDTO savedPage, Application importedApplication) {
    // Validate import
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 65bded9 and cf63fab.

Files selected for processing (5)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCE.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCEImpl.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/importable/DatasourceImportableServiceCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/MappedImportableResourcesCE_DTO.java (2 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (1 hunks)
Additional comments not posted (11)
app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/MappedImportableResourcesCE_DTO.java (4)

8-8: Import for DBOpsType looks good.

The import is necessary for the changes made in the file.


54-56: Modification of data structures to use DBOpsType keys is correct.

The changes enhance type safety and correctness.


60-72: Thread safety measures with Collections.synchronizedList() are correctly applied.

The use of Collections.synchronizedList() ensures that individual operations on the list are thread-safe. However, ensure that compound operations are correctly synchronized.


62-69: Block comment explaining Collections.synchronizedList() is clear and informative.

The comment provides valuable context and references for understanding the use of Collections.synchronizedList().

app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCE.java (2)

9-9: Import for DBOpsType looks good.

The import is necessary for the changes made in the file.


71-71: Update to createWithoutPermissions method's parameter type is correct.

The changes are consistent with the rest of the codebase.

Ensure that all method calls to createWithoutPermissions match the new signature.

app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/importable/DatasourceImportableServiceCEImpl.java (2)

28-28: Import for @NonNull looks good.

The import is necessary for the changes made in the file.


412-416: Update to addDryOpsForEntity method's parameter type and addition of @NonNull annotation are correct.

The changes enhance type safety and robustness.

app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCEImpl.java (3)

67-67: Static import for SAVE from DBOpsType looks good.

The import is necessary for the changes made in the file.


151-151: Update to createWithoutPermissions method to employ DBOpsType is correct.

The changes are consistent with the rest of the codebase.

Ensure that all method calls to createWithoutPermissions match the new signature.


Line range hint 164-242: Update to createEx method to handle datasourceStorageDryRunQueries using DBOpsType is correct.

The changes enhance type safety and correctness.

@abhvsn abhvsn added the ok-to-test Required label for CI label Jul 9, 2024
@abhvsn abhvsn merged commit 55b53a7 into release Jul 10, 2024
48 checks passed
@abhvsn abhvsn deleted the fix-concurrent-modification-exception branch July 10, 2024 03:07
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Jul 10, 2024
…low (appsmithorg#34818)

## Description
In the import service, we are trying to import datasources using the
combination of Flux and Flatmap to create the reactive chain. This
translates to creating multiple threads to accomplish the task in an
efficient manner. After we introduced database dry ops, where we are now
sharing the map of ops type to the object for which the operation needs
to be performed. This caused a `concurrentModificationException` as
datasourceService layer is referring to same object via different
threads.

## Automation

/ok-to-test tags="@tag.ImportExport, @tag.Sanity, @tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9861701410>
> Commit: cf63fab
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9861701410&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.ImportExport, @tag.Sanity, @tag.Git`
> Spec:
> <hr>Tue, 09 Jul 2024 18:05:03 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
@coderabbitai coderabbitai bot mentioned this pull request Nov 6, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants