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

Disable doc garbage collection when running in serve-doc mode. #282

Merged
merged 5 commits into from
Sep 18, 2024

Conversation

paulgb
Copy link
Member

@paulgb paulgb commented Sep 18, 2024

When running with serve-doc, if there is no active connection, the doc will be garbage collected and then accessing it will not work. This prevents the doc from being garbage collected in serve-doc mode.

This also renames the Y_SWEET_PORT env var to PORT, which is used by convention by most HTTP container hosts.

Summary by CodeRabbit

  • New Features

    • Standardized environment variable usage for port configuration across the application.
    • Introduced a new option for enabling or disabling document garbage collection in the server.
    • Added a testing framework for the document server, ensuring robust lifecycle management during tests.
  • Bug Fixes

    • Adjusted logic for document garbage collection based on new configuration.
  • Documentation

    • Updated export statements for improved clarity in module interfaces.
  • Tests

    • Implemented new test cases for the document server's functionality.

Copy link

vercel bot commented Sep 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
y-sweet-debugger ⬜️ Ignored (Inspect) Visit Preview Sep 18, 2024 6:23pm
y-sweet-demos ⬜️ Ignored (Inspect) Visit Preview Sep 18, 2024 6:23pm
y-sweet-gendocs ⬜️ Ignored (Inspect) Visit Preview Sep 18, 2024 6:23pm

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The pull request introduces several changes across multiple files in the y-sweet crate and its associated SDK. The ServSubcommand enum's environment variable for the port field has been standardized from Y_SWEET_PORT to PORT. A new boolean parameter has been added to the main function. Additionally, a doc_gc field has been introduced to the Server struct to manage document garbage collection. The SDK's main.ts file has been updated to change export statements, and a new testing framework has been established for the document server.

Changes

Files Change Summary
crates/y-sweet/src/main.rs Updated ServSubcommand enum to use PORT instead of Y_SWEET_PORT; added a new boolean parameter in main.
crates/y-sweet/src/server.rs Introduced doc_gc boolean field in Server struct; modified constructor and garbage collection logic.
js-pkg/sdk/src/main.ts Exported DocConnection directly; removed YSweetError import; maintained exports for other types.
tests/src/doc-server.test.ts Added a new testing framework for the document server; defined DocServer class with lifecycle management and test cases.
tests/src/server.ts Removed import of tmpdir function; no other changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant DocConnection

    User->>Server: Start Document Server
    Server->>Server: Initialize with doc_gc
    Server->>DocConnection: Establish Connection
    DocConnection-->>Server: Connection Established
    User->>DocConnection: Fetch Document
    DocConnection-->>User: Return Document
Loading

🐇 In the code we hop and play,
With ports and docs in a new way.
Garbage collection now takes its stance,
As tests ensure we take a chance.
Hooray for changes, let’s all cheer,
For a brighter code, we hold dear! 🥕✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7b5f4cc and 6c63cee.

Files selected for processing (1)
  • tests/src/doc-server.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/src/doc-server.test.ts

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 generate interesting stats about this repository and render them as a table.
    -- @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.

@paulgb paulgb changed the title Add failing test Disable doc garbage collection when running in single-doc mode. Sep 18, 2024
@paulgb paulgb changed the title Disable doc garbage collection when running in single-doc mode. Disable doc garbage collection when running in serve-doc mode. Sep 18, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request introduces changes to improve the functionality and usability of the y-sweet server, particularly in serve-doc mode. Here's a concise summary of the key changes:

  • Disabled document garbage collection in serve-doc mode to prevent docs from becoming inaccessible when there are no active connections
  • Renamed Y_SWEET_PORT environment variable to PORT for better compatibility with standard HTTP container hosts
  • Added a new doc_gc parameter to Server::new() function to control garbage collection behavior
  • Introduced a new test file doc-server.test.ts to validate the serve-doc mode functionality
  • Refactored the SDK's main module (js-pkg/sdk/src/main.ts) to improve its API and export additional components

These changes address the issue of document inaccessibility in serve-doc mode and enhance the overall flexibility and usability of the y-sweet server.

5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between edf597a and 7b5f4cc.

Files selected for processing (5)
  • crates/y-sweet/src/main.rs (4 hunks)
  • crates/y-sweet/src/server.rs (6 hunks)
  • js-pkg/sdk/src/main.ts (1 hunks)
  • tests/src/doc-server.test.ts (1 hunks)
  • tests/src/server.ts (0 hunks)
Files not reviewed due to no reviewable changes (1)
  • tests/src/server.ts
Additional context used
Biome
tests/src/doc-server.test.ts

[error] 5-6: Do not export from a test file.

(lint/suspicious/noExportsInTest)

Additional comments not posted (11)
tests/src/doc-server.test.ts (1)

1-95: Great work on setting up the testing framework!

The DocServer class provides a clean and robust way to manage the lifecycle of the document server during tests. The test cases cover important scenarios like fetching documents as updates.

The use of beforeAll and afterAll hooks ensures proper setup and teardown of the server.

Overall, the implementation looks solid and well-structured.

Tools
Biome

[error] 5-6: Do not export from a test file.

(lint/suspicious/noExportsInTest)

js-pkg/sdk/src/main.ts (2)

2-2: LGTM!

Exporting the DocConnection class directly from the connection module improves clarity and streamlines the module's interface.


Line range hint 6-6: Verify the removal of YSweetError import.

Removing the import statement for an unused class helps keep the code clean and maintainable. However, please ensure that the removal of this import does not break any functionality in this module or other parts of the codebase that may still rely on it.

Run the following script to verify if YSweetError is used anywhere in the codebase:

crates/y-sweet/src/main.rs (3)

40-40: Standardizing the environment variable name for the port is a good practice.

Changing the environment variable from Y_SWEET_PORT to PORT aligns with the common practice used by most HTTP container hosts. This enhances compatibility and allows for greater flexibility in deployment scenarios where the environment variable name is standardized across different applications.


76-76: Consistent change to standardize the environment variable name for the port.

This change is consistent with the previous modification in the Serve variant. Standardizing the environment variable name to PORT aligns with the common practice used by most HTTP container hosts, enhancing compatibility and allowing for greater flexibility in deployment scenarios.


182-182: Please provide more context about the new boolean parameter.

The Server::new function has been updated to include a new boolean parameter, which is set to true in the Serve subcommand and false in the ServeDoc subcommand. Could you please provide more information about the purpose and implications of this parameter?

Understanding the reasoning behind this change and how it influences the application's behavior would be helpful for a thorough review.

Also applies to: 266-266

crates/y-sweet/src/server.rs (5)

80-82: LGTM!

The new doc_gc field is well-named, typed, and documented. Disabling doc GC for single-doc mode is a sensible design choice.


92-92: Looks good!

The doc_gc parameter is correctly added to the constructor to initialize the new field.


102-102: LGTM!

The doc_gc field is correctly initialized using the constructor parameter.


159-170: Conditional spawning of doc_gc_worker looks good!

The code correctly spawns the doc_gc_worker only when doc_gc is enabled. The worker is spawned with the right parameters and instrumented with a tracing span.


Line range hint 664-701: Test cases updated correctly!

The test cases now pass true for the doc_gc parameter when creating the Server instance. This ensures that the document garbage collection functionality is covered in the tests.

tests/src/doc-server.test.ts Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This pull request introduces significant changes to the y-sweet server implementation, focusing on improving document management in serve-doc mode. Here's a concise summary of the key modifications:

  • Modified Server struct in crates/y-sweet/src/server.rs to include doc_gc parameter, controlling garbage collection behavior
  • Updated Server::new() function to incorporate the new doc_gc parameter
  • Adjusted garbage collection logic in doc_gc_worker function to respect the doc_gc flag
  • Implemented serve_doc method in Server struct for single-document mode operation
  • Added single_doc_routes method to Server for routing in single-document mode

These changes effectively prevent document garbage collection in serve-doc mode, addressing the issue of document inaccessibility when there are no active connections.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@paulgb paulgb merged commit 4a92e4a into main Sep 18, 2024
12 checks passed
@paulgb paulgb deleted the paul/dis-2688-y-sweet-serve-doc-gcs-doc branch September 18, 2024 19:14
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