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

feat(schema/appdata)!: efficiency & data model improvements aligned with server/v2 #21305

Merged
merged 7 commits into from
Aug 20, 2024

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Aug 14, 2024

Description

This PR makes the following updates:

  • core StateChanges is structurally typed so we can send the same data to listeners with no copying in server/v2
  • inschema/appdata:
    • added PacketBatch for sending a whole batch of updates to the async listeners all at once
    • KVPairData is aligned with core StateChanges
    • EventData can now take multiple Events
    • Events can lazily produce key-value pairs so that this type could now be used in stf, app manager instead of what's there now for more efficiency
  • in schema/decoding, DecoderResolver was updated to decode []byte actor data into string module names to align with how things are done in storage and server/v2

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a batching mechanism for packet processing, enhancing efficiency and allowing for handling multiple packets simultaneously.
    • Added support for multiple events in EventData, improving data representation.
  • Bug Fixes

    • Simplified the logic in the AsyncListener function, ensuring the Commit function is always defined.
  • Documentation

    • Enhanced comments and documentation for the Packet interface and listener functionalities for clearer guidance.
  • Tests

    • Added comprehensive unit tests for the new batch processing capabilities, validating both synchronous and asynchronous operations.

Copy link
Contributor

coderabbitai bot commented Aug 14, 2024

Walkthrough

Walkthrough

This update introduces significant enhancements across the application, notably improving state change handling, packet processing, and listener functionality. Key features include a new batching mechanism for packets, modifications to data structures for clearer representation, and improved asynchronous processing in listeners. These changes collectively aim to enhance performance, maintainability, and clarity within the codebase.

Changes

Files Change Summary
core/store/changeset.go Changed StateChanges from a struct to a type alias for an unnamed struct, enhancing clarity without affecting functionality.
schema/appdata/async.go Simplified AsyncListener by directly defining res.Commit, improving logic flow; introduced onBatch for batch handling.
schema/appdata/batch.go, batch_test.go Added a batching mechanism for packet processing, introducing BatchablePacket interface and PacketBatch type; comprehensive tests added for both sync and async contexts.
schema/appdata/data.go Enhanced EventData and KVPairData structures; added new fields and types for better event handling and updates.
schema/appdata/listener.go, mux.go Expanded Listener struct with a new onBatch function; improved Commit function documentation for clarity.
schema/appdata/packet.go Added comments clarifying valid implementations of the Packet interface.

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.

@aaronc aaronc marked this pull request as ready for review August 14, 2024 18:17
@aaronc aaronc requested a review from a team as a code owner August 14, 2024 18:17

// Attributes lazily returns the key-value attribute representation of the event.
Attributes ToEventAttributes
}
Copy link
Member Author

@aaronc aaronc Aug 14, 2024

Choose a reason for hiding this comment

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

I would propose we use the above Event structure in STF and app manager instead of what we have now. It can support either key-value events or JSON events lazily and tracks tx, msg and event indexes directly (rather than pushed down into string formatted attributes). This could be mirrored in core/app

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 (4)
schema/appdata/batch.go (2)

3-9: Ensure Interface Documentation Clarity.

The BatchablePacket interface documentation is clear but could benefit from specifying why CommitData should not be batched. This will help future developers understand the design decision.

+// CommitData should not be batched because it forces synchronization of asynchronous listeners, which can negate the efficiency benefits of batching.

17-29: Consider Handling Listener Nil Check Outside Loop.

In the apply method, the check for l.onBatch != nil could be moved outside the loop for clarity and efficiency, although the current implementation is correct.

func (p PacketBatch) apply(l *Listener) error {
	if l.onBatch != nil {
		return l.onBatch(p)
	}

	for _, packet := range p {
		if err := packet.apply(l); err != nil {
			return err
		}
	}

	return nil
}
schema/appdata/batch_test.go (1)

9-19: Test Coverage is Good but Consider Additional Edge Cases.

The TestBatch function effectively tests the batch processing. Consider adding edge cases, such as empty batches or batches with mixed valid and invalid packets, to ensure robustness.

schema/decoding/resolver.go (1)

44-49: EncodeModuleName Implementation is Correct.

The EncodeModuleName method correctly checks for module existence and handles errors appropriately. Consider documenting the expected format of the input string.

+// EncodeModuleName expects a valid module name string that exists in the module set.
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between adf5d1b and 110bb35.

Files selected for processing (11)
  • core/store/changeset.go (1 hunks)
  • schema/appdata/async.go (1 hunks)
  • schema/appdata/batch.go (1 hunks)
  • schema/appdata/batch_test.go (1 hunks)
  • schema/appdata/data.go (3 hunks)
  • schema/appdata/listener.go (1 hunks)
  • schema/appdata/mux.go (1 hunks)
  • schema/appdata/packet.go (1 hunks)
  • schema/decoding/decoding_test.go (1 hunks)
  • schema/decoding/middleware.go (3 hunks)
  • schema/decoding/resolver.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • core/store/changeset.go
  • schema/appdata/packet.go
Additional context used
Path-based instructions (9)
schema/appdata/batch.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/appdata/batch_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

schema/decoding/resolver.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/appdata/listener.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/decoding/middleware.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/appdata/mux.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/appdata/data.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/appdata/async.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

schema/decoding/decoding_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (17)
schema/appdata/batch.go (1)

31-41: Interface Implementation Looks Good.

The implementation of isBatchablePacket for each data type is straightforward and correct. This ensures that only appropriate packet types are batchable.

schema/appdata/batch_test.go (1)

62-80: Async Test Coverage is Adequate.

The TestBatchAsync function tests asynchronous processing well. Ensure that the asynchronous behavior is reliably tested by considering potential race conditions or delays.

schema/decoding/resolver.go (1)

37-42: DecodeModuleName Implementation is Correct.

The DecodeModuleName method correctly checks for module existence and returns an appropriate error if not found. Ensure that all potential byte inputs are considered.

schema/appdata/listener.go (2)

40-44: Expanded documentation for Commit function is clear and helpful.

The expanded documentation provides necessary clarity on the blocking behavior of the Commit function when used with asynchronous listeners. This is a valuable addition for developers to understand the implications of using Commit in different contexts.


47-49: The addition of onBatch function is a valuable enhancement.

The onBatch function facilitates efficient forwarding of packet batches to asynchronous listeners, aligning well with the goal of improving performance. This addition is well-structured and fits seamlessly into the Listener struct.

schema/decoding/middleware.go (3)

26-26: The introduction of moduleNames map enhances robustness.

The moduleNames map effectively improves the handling of module names by dynamically mapping actor identifiers to module names. This change enhances the robustness and efficiency of the middleware's operation.


38-47: Efficient handling of module names using moduleNames map.

The logic for checking and decoding module names using the moduleNames map is efficient. It reduces redundant decoding operations by caching resolved module names, thereby improving performance.


50-76: Streamlined module codec handling is effective.

The updates to module codec handling, facilitated by the moduleNames map, ensure consistent and efficient codec lookup and initialization. This contributes to the overall improvements in the middleware's performance and maintainability.

schema/appdata/mux.go (1)

127-135: The addition of onBatch function enhances ListenerMux.

The onBatch function efficiently processes packet batches for multiple listeners, improving the ListenerMux's capability to manage listeners. The implementation is clean and includes appropriate error handling.

schema/appdata/data.go (6)

44-48: LGTM: Struct EventData updated to include multiple events.

The addition of the Events field enhances the representation of multiple events, aligning with the PR objectives.


Line range hint 50-74: LGTM: New struct Event introduced.

The Event struct provides a detailed representation of events, supporting the new functionality effectively.


76-78: LGTM: Type alias EventAttribute introduced.

The alias simplifies the representation of key-value pairs for event attributes.


86-88: LGTM: Type alias ToEventAttributes introduced.

This alias provides a clear method for retrieving event attributes.


90-91: LGTM: Struct KVPairData updated to use ActorKVPairUpdate.

This change broadens the context of updates, enhancing flexibility.


94-100: LGTM: New struct ActorKVPairUpdate introduced.

This struct effectively represents updates associated with an actor, aligning with the new data model.

schema/appdata/async.go (1)

154-161: LGTM: Simplified Commit assignment and added onBatch function.

The changes simplify the logic and enhance functionality by supporting batch processing.

schema/decoding/decoding_test.go (1)

300-307: LGTM: Updated Set method to use ActorKVPairUpdate.

The change aligns with the updated data model and enhances robustness. Ensure that the tests adequately cover these changes.

To verify test coverage, check for tests that validate the behavior of Set with the new ActorKVPairUpdate structure.

@aaronc aaronc added this pull request to the merge queue Aug 20, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Aug 20, 2024
@aaronc aaronc enabled auto-merge August 20, 2024 13:24
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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 110bb35 and 57f17aa.

Files selected for processing (4)
  • schema/appdata/async.go (1 hunks)
  • schema/appdata/listener.go (1 hunks)
  • schema/appdata/mux.go (1 hunks)
  • schema/appdata/packet.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • schema/appdata/async.go
  • schema/appdata/listener.go
  • schema/appdata/mux.go
  • schema/appdata/packet.go

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 57f17aa and de5c78a.

Files selected for processing (1)
  • schema/appdata/batch_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • schema/appdata/batch_test.go

@aaronc aaronc added this pull request to the merge queue Aug 20, 2024
Merged via the queue into main with commit da27d8b Aug 20, 2024
77 checks passed
@aaronc aaronc deleted the aaronc/appdata-packet-batches branch August 20, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants