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(sqlite): flush data items using bundle db writer PE-6872 #219

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

djwhitt
Copy link
Collaborator

@djwhitt djwhitt commented Oct 7, 2024

Prior to this commit, data items were flushed via the core DB writer. Under sufficiently heavy bunde import load this lead to contention with data item writes. This change adjusts the flushing logic to use the bundle DB writer. This avoids concurrent bundle DB write attempts and eliminates the contention.

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.81%. Comparing base (6c29438) to head (3d36c69).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #219      +/-   ##
===========================================
+ Coverage    68.72%   68.81%   +0.09%     
===========================================
  Files           32       32              
  Lines         7919     7942      +23     
  Branches       431      434       +3     
===========================================
+ Hits          5442     5465      +23     
  Misses        2476     2476              
  Partials         1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request includes updates to the package.json file, specifically upgrading the @ar.io/sdk dependency from version ^2.0.0 to ^2.2.5. Additionally, modifications were made to the StandaloneSqliteDatabase and StandaloneSqliteDatabaseWorker classes in src/database/standalone-sqlite.ts. A new method, flushStableDataItems, was added to the worker class, and the saveBlockAndTxs method in the database class was updated to handle return values more effectively. Changes also included updates to type declarations and error handling.

Changes

File Change Summary
package.json Updated @ar.io/sdk dependency from ^2.0.0 to ^2.2.5.
src/database/standalone-sqlite.ts - Added method flushStableDataItems in StandaloneSqliteDatabaseWorker.
- Updated saveBlockAndTxs method signature in StandaloneSqliteDatabase.
- Changed WorkerMethodName type to reference StandaloneSqliteDatabaseWorker.
- Adjusted error handling and message passing between threads.

Possibly related PRs

  • feat(sqlite-wal-cleanup): add data database WAL cleanup worker #188: The changes in this PR involve modifications to the StandaloneSqliteDatabase and StandaloneSqliteDatabaseWorker classes in src/database/standalone-sqlite.ts, which are directly related to the main PR's updates to these classes, specifically the addition of new methods and changes to existing method signatures.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 46aa5ac and 3d36c69.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/database/standalone-sqlite.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🔇 Additional comments (5)
src/database/standalone-sqlite.ts (5)

949-954: Ensure consistent return values in saveBlockAndTxs

The saveBlockAndTxs method now returns an object { endHeight, maxStableBlockTimestamp } when certain conditions are met and an empty object {} otherwise. Ensure that all callers of this method, including those not modified in this PR, properly handle the returned values to prevent unexpected behavior.


956-962: Potential issue: Negative values in timestamp subtraction

The calculation maxStableBlockTimestamp - NEW_DATA_ITEM_CLEANUP_WAIT_SECS could result in a negative value if maxStableBlockTimestamp is less than NEW_DATA_ITEM_CLEANUP_WAIT_SECS. This may lead to unintended behavior in deleteBundlesStaleNewDataFn. The issue raised in a previous review comment remains valid.


2381-2381: Type definition updated appropriately

The type WorkerMethodName is now correctly defined as keyof StandaloneSqliteDatabaseWorker, ensuring type safety for worker method names.


2753-2768: Correctly updated saveBlockAndTxs to handle asynchronous operations

The saveBlockAndTxs method is now asynchronous and properly awaits the worker's saveBlockAndTxs call. It also checks for non-undefined endHeight and maxStableBlockTimestamp before invoking flushStableDataItems. This ensures that stable data items are flushed only when appropriate, improving data consistency.


3085-3096: Proper handling of worker messages for new methods

The worker now correctly processes the 'saveBlockAndTxs' and 'flushStableDataItems' messages. Arguments are appropriately extracted, methods are called, and responses are posted back to the parent thread. This facilitates the asynchronous communication between the main thread and worker threads.


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>, please review it.
    • 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 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 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 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 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.

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

🧹 Outside diff range and nitpick comments (1)
src/database/standalone-sqlite.ts (1)

949-951: Specify the return type for saveBlockAndTxs

The saveBlockAndTxs method currently lacks an explicit return type, which can lead to less clarity and potential type safety issues. Consider specifying the return type for better code maintainability.

Apply this diff to specify the return type:

-saveBlockAndTxs(
+saveBlockAndTxs(
   block: PartialJsonBlock,
   txs: PartialJsonTransaction[],
   missingTxIds: string[],
+): { endHeight: number; maxStableBlockTimestamp: number } {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6c29438 and 46aa5ac.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/database/standalone-sqlite.ts (4 hunks)
🧰 Additional context used
🔇 Additional comments (3)
package.json (1)

11-11: Verify compatibility with updated @ar.io/sdk version

The @ar.io/sdk dependency has been updated from ^2.0.0 to ^2.2.5. This minor version update may introduce new features or optimizations that could be relevant to the database operation changes mentioned in the PR objectives.

While keeping dependencies up-to-date is good practice, please ensure:

  1. The new SDK version has been thoroughly tested with your codebase.
  2. Any new features or changes in the SDK from 2.0.0 to 2.2.5 have been reviewed for potential impacts on your implementation.
  3. The changelog or release notes for @ar.io/sdk versions 2.1.0 through 2.2.5 have been checked for any relevant updates or breaking changes.

To help verify the impact of this change, you can run the following script:

src/database/standalone-sqlite.ts (2)

2381-2381: Verify all usages of WorkerMethodName after type change

The WorkerMethodName type has been updated to keyof StandaloneSqliteDatabaseWorker. Ensure that all references and implementations using WorkerMethodName are compatible with this change to prevent type errors.


3085-3096: Confirm the synchronous execution of saveBlockAndTxs in worker

In the worker message handler, worker.saveBlockAndTxs is called synchronously, and the result is immediately posted back. Verify that this method is intended to be synchronous and does not perform long-running operations that could block the worker thread.

src/database/standalone-sqlite.ts Show resolved Hide resolved
src/database/standalone-sqlite.ts Outdated Show resolved Hide resolved
@djwhitt djwhitt requested a review from karlprieb October 7, 2024 18:25
Prior to this commit, data items were flushed via the core DB writer.
Under sufficiently heavy bunde import load this lead to contention with
data item writes. This change adjusts the flushing logic to use the
bundle DB writer. This avoids concurrent bundle DB write attempts and
eliminates the contention.
@djwhitt djwhitt force-pushed the PE-6872-data-item-flush-contention-fix branch from 46aa5ac to 3d36c69 Compare October 7, 2024 19:22
@djwhitt djwhitt merged commit 900e3c4 into develop Oct 7, 2024
5 checks passed
@djwhitt djwhitt deleted the PE-6872-data-item-flush-contention-fix branch October 7, 2024 20:06
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.

2 participants