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

Disruptor event clear #546

Merged
merged 1 commit into from
Oct 8, 2024
Merged

Conversation

ZijieSong
Copy link
Contributor

@ZijieSong ZijieSong commented Oct 8, 2024

Fix the issue of span events escaping to the old generation in low traffic scenarios. Ensure that the Disruptor consumer sets the carried content to null after processing the event, so it can be garbage collected during YGC.

Summary by CodeRabbit

  • New Features

    • Introduced a new interface ObjectEvent to facilitate state clearing for implementing objects.
    • Updated SofaTracerSpanEvent and StringEvent classes to implement the ObjectEvent interface, adding a clear() method to reset their state.
  • Improvements

    • Updated version numbers across multiple projects and plugins to 3.1.8-SNAPSHOT, indicating ongoing development.
  • Bug Fixes

    • Corrected typographical errors in the properties section of the POM files.

Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

The pull request includes updates to multiple pom.xml files across various projects and plugins, primarily changing the version number from 3.1.7 to 3.1.8-SNAPSHOT. This indicates a shift to a snapshot version for ongoing development. Additionally, a new interface ObjectEvent is introduced, and existing classes implement this interface, adding a clear() method to reset their state. Minor typographical errors were corrected, but no significant structural changes were made to dependencies or plugins.

Changes

File/Directory Change Summary
pom.xml (tracer-all-parent) Version updated from 3.1.7 to 3.1.8-SNAPSHOT.
sofa-tracer-plugins/.../pom.xml (various plugins) Parent version updated from 3.1.7 to 3.1.8-SNAPSHOT across all listed plugin POM files.
tracer-all/pom.xml, tracer-core/pom.xml, tracer-extensions/pom.xml, tracer-sofa-boot-starter/pom.xml, tracer-test/.../pom.xml Parent version updated from 3.1.7 to 3.1.8-SNAPSHOT across all listed project POM files.
AsyncCommonAppenderManager.java, AsyncCommonDigestAppenderManager.java Added event.clear() call after appender.flush() in both classes.
ObjectEvent.java New interface ObjectEvent added with method void clear().
SofaTracerSpanEvent.java, StringEvent.java Implemented ObjectEvent interface and added clear() method to both classes.

Possibly related PRs

Suggested labels

bug

🐰 In the meadow, changes bloom,
Version hopping, dispelling gloom.
With clear calls, events reset,
In the code, no room for regret.
A snapshot dance, the plugins sway,
Hooray for updates, hip-hip-hooray! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0d366db and 154d964.

📒 Files selected for processing (31)
  • pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml (1 hunks)
  • tracer-all/pom.xml (1 hunks)
  • tracer-core/pom.xml (1 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java (1 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonDigestAppenderManager.java (1 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ObjectEvent.java (1 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/SofaTracerSpanEvent.java (2 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEvent.java (2 hunks)
  • tracer-extensions/pom.xml (1 hunks)
  • tracer-sofa-boot-starter/pom.xml (1 hunks)
  • tracer-test/core-test/pom.xml (1 hunks)
  • tracer-test/log4j-test/pom.xml (1 hunks)
  • tracer-test/log4j2-test/pom.xml (1 hunks)
  • tracer-test/logback-test/pom.xml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (31)
  • pom.xml
  • sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml
  • sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml
  • tracer-all/pom.xml
  • tracer-core/pom.xml
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonDigestAppenderManager.java
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ObjectEvent.java
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/SofaTracerSpanEvent.java
  • tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEvent.java
  • tracer-extensions/pom.xml
  • tracer-sofa-boot-starter/pom.xml
  • tracer-test/core-test/pom.xml
  • tracer-test/log4j-test/pom.xml
  • tracer-test/log4j2-test/pom.xml
  • tracer-test/logback-test/pom.xml

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

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

Caution

Inline review comments failed to post

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (7)
tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ObjectEvent.java (2)

12-15: LGTM: Interface declaration is correct. Consider adding Javadoc.

The ObjectEvent interface and its clear() method are well-defined. To improve documentation, consider adding a Javadoc comment for the clear() method explaining its purpose and any side effects.

Here's a suggested Javadoc comment:

/**
 * Clears or resets the state of the object implementing this interface.
 * This method should be called after processing the event to facilitate garbage collection.
 */
void clear();

1-15: LGTM: Well-structured interface aligning with PR objectives.

The ObjectEvent interface is well-structured and focused on a single responsibility. Its clear() method directly addresses the PR objective of ensuring that Disruptor consumers can reset event content, facilitating garbage collection during Young Generation Collection (YGC). This implementation should help improve memory management in low traffic scenarios.

To fully realize the benefits of this interface:

  1. Ensure all relevant event classes implement this interface.
  2. Update the Disruptor consumer to call the clear() method after processing each event.
  3. Consider adding unit tests to verify the clear() method's behavior in implementing classes.
tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEvent.java (1)

36-39: LGTM: clear() method implementation

The clear() method implementation is straightforward and effectively addresses the PR objectives by setting the string property to null.

Consider adding a null check before calling setString(null) to avoid unnecessary method calls:

 @Override
 public void clear() {
-    setString(null);
+    if (string != null) {
+        setString(null);
+    }
 }

This change would prevent unnecessary method calls when the string is already null, potentially improving performance in high-frequency scenarios.

tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/SofaTracerSpanEvent.java (2)

24-24: LGTM! Consider adding a comment explaining the purpose of implementing ObjectEvent.

The implementation of the ObjectEvent interface aligns with the PR objectives to address the issue of span events escaping to the old generation. This change enables the class to support the clearing of its state, which can help with garbage collection.

Consider adding a brief comment above the class declaration to explain why SofaTracerSpanEvent implements ObjectEvent. This would help future developers understand the rationale behind this design decision.


45-48: LGTM! Consider adding synchronization for thread safety.

The clear() method implementation effectively sets the sofaTracerSpan to null, which aligns with the PR objectives. This will help facilitate garbage collection of these events during Young Generation Collection (YGC).

For improved thread safety, consider adding synchronization to the clear() method:

 @Override
-public void clear() {
+public synchronized void clear() {
     setSofaTracerSpan(null);
 }

This ensures that the clearing operation is atomic and prevents potential race conditions in multi-threaded scenarios.

tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java (1)

168-168: Approve the addition of event.clear() with a minor suggestion.

The addition of event.clear() after processing the event is a good practice. It helps in resetting the event object, potentially aiding garbage collection and addressing the issue of span events escaping to the old generation in low traffic scenarios.

However, consider moving the clear() call to a finally block to ensure it's always called, even if an exception occurs during appending or flushing. This would guarantee that the event is cleared regardless of the outcome of the log writing process.

Here's a suggested refactoring:

 try {
     appender.append(string);
     appender.flush();
-    event.clear();
 } catch (Exception e) {
     //todo Globally keep a synchronized log for synchronizing print logs at some key points
     if (string != null) {
         SynchronizingSelfLog.error("fail to async write log", e);
     } else {
         SynchronizingSelfLog.error(
             "fail to async write log.And the sofaTracerSpanContext is null", e);
     }
+} finally {
+    event.clear();
 }

This change ensures that event.clear() is always called, improving the robustness of the event handling process.

pom.xml (1)

Line range hint 52-52: Fix typo in maven.gpg.plugin property name.

There's a typo in the property name for the Maven GPG plugin. This should be corrected to ensure proper configuration.

Please apply the following change:

-        <maven.gpg.pluign>1.6</maven.gpg.pluign>
+        <maven.gpg.plugin>1.6</maven.gpg.plugin>
🛑 Comments failed to post (5)
sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml (1)

8-8: 💡 Codebase verification

Issue Found: Inconsistent Version Number in Root pom.xml

The root pom.xml declares the project version as 3.1.0, which is inconsistent with the 3.1.8-SNAPSHOT version used in other modules.

  • Location: pom.xml at the repository root contains <version>3.1.0</version>

Please update the root pom.xml to <version>3.1.8-SNAPSHOT</version> to ensure consistency across all modules.

🔗 Analysis chain

LGTM: Version update to development SNAPSHOT

The parent version has been correctly updated to 3.1.8-SNAPSHOT, which aligns with the PR objectives. This change indicates that development for the next release has begun.

Note: Using a SNAPSHOT version means that this is now a development version and should not be used in production environments.

Let's verify if this version change is consistent across other modules in the project:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistency of version numbers across pom.xml files

# Test: Search for parent version declarations in all pom.xml files
# Expect: All should be 3.1.8-SNAPSHOT or explain any discrepancies
echo "Checking parent version declarations:"
rg --type xml '<version>3\.1\.[0-9]+(-SNAPSHOT)?</version>' -g 'pom.xml'

# Test: Search for project version declarations in all pom.xml files
# Expect: All should be 3.1.8-SNAPSHOT or explain any discrepancies
echo "Checking project version declarations:"
rg --type xml '<version>3\.1\.[0-9]+(-SNAPSHOT)?</version>' -g 'pom.xml' | rg -v '<parent>'

Length of output: 5116

sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml (1)

8-8: 💡 Codebase verification

Duplicate SNAPSHOT Version Entry in tracer-all/pom.xml

The file tracer-all/pom.xml contains multiple instances of <version>3.1.8-SNAPSHOT</version>, which may lead to build or dependency resolution issues.

Action Required:

  • Remove the duplicate <version>3.1.8-SNAPSHOT</version> entry in tracer-all/pom.xml to ensure consistency.
🔗 Analysis chain

LGTM. Verify version consistency across modules.

The update of the parent version to 3.1.8-SNAPSHOT is appropriate for ongoing development. This change aligns with the overall project update.

To ensure consistency across all modules, please run the following script:

If the script produces any output for the first command or if the counts don't match in the second part, please ensure all modules are consistently updated.


Inconsistency Detected in SNAPSHOT Version Updates

The version count for <version>3.1.8-SNAPSHOT</version> exceeds the total number of pom.xml files, indicating an unexpected pom.xml file may still be referencing the old version or an unintended module has been added.

Action Required:

  • Identify the pom.xml file(s) that are not part of the standard modules or are incorrectly referencing the SNAPSHOT version.

Inconsistency Identified in SNAPSHOT Version Updates

A discrepancy exists where 27 pom.xml files reference <version>3.1.8-SNAPSHOT</version>, but only 26 pom.xml files are present in the repository. This suggests that one pom.xml file may contain multiple references or an unintended pom.xml file exists.

Action Required:

  • Identify pom.xml files with multiple <version>3.1.8-SNAPSHOT</version> entries.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all modules have been updated to the new SNAPSHOT version

# Test: Check for any pom.xml files still using the old version
# Expect: No output, indicating all have been updated
rg --type xml '<version>3\.1\.7</version>' -g 'pom.xml'

# Test: Confirm all pom.xml files are using the new SNAPSHOT version
# Expect: Count of occurrences should match the total number of pom.xml files
rg --type xml '<version>3\.1\.8-SNAPSHOT</version>' -g 'pom.xml' | wc -l
fd -g 'pom.xml' | wc -l

Length of output: 158


Script:

#!/bin/bash
# Description: List all pom.xml files containing the SNAPSHOT version to identify discrepancies

rg --type xml '<version>3\.1\.8-SNAPSHOT</version>' -g 'pom.xml' --files-with-matches

Length of output: 1281


Script:

#!/bin/bash
# Description: Identify pom.xml files containing multiple instances of the SNAPSHOT version

# List pom.xml files with more than one occurrence of '<version>3.1.8-SNAPSHOT</version>'
fd -g 'pom.xml' | while read -r file; do
  count=$(rg '<version>3\.1\.8-SNAPSHOT</version>' "$file" | wc -l)
  if [ "$count" -gt 1 ]; then
    echo "$file contains $count instances of the SNAPSHOT version."
  fi
done

Length of output: 3861

sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml (1)

8-8: 💡 Codebase verification

Version inconsistency detected across project pom.xml files

The version update to <version>3.1.8-SNAPSHOT</version> is not consistent across all pom.xml files. Specifically, tracer-all-parent/pom.xml still references version 3.19.1.

Please update the parent pom.xml to 3.1.8-SNAPSHOT and ensure that all child modules inherit this version to maintain consistency throughout the project.

🔗 Analysis chain

LGTM: Version update to 3.1.8-SNAPSHOT

The parent version has been correctly updated to 3.1.8-SNAPSHOT. This change is consistent with the PR objectives and indicates a shift to a development version.

Note: Using a SNAPSHOT version is appropriate for ongoing development, but ensure that a stable release version is used for production deployments.

Let's verify if this version change is consistent across the project:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the version 3.1.8-SNAPSHOT is consistent across all pom.xml files

# Test: Search for any pom.xml files that don't have the new version
# Expect: No output if all files are consistent
rg -t xml '<version>3\.1\.8-SNAPSHOT</version>' -l | xargs -I {} rg -t xml -v '<version>3\.1\.8-SNAPSHOT</version>' {}

Length of output: 77581

sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml (1)

8-8: 💡 Codebase verification

Inconsistent Version Numbers Across Modules

The root pom.xml has a version of 3.1.0, which does not match the 3.1.8-SNAPSHOT versions in other modules. Please update the root pom.xml to 3.1.8-SNAPSHOT to maintain consistency across the project.

🔗 Analysis chain

LGTM: Version update to development SNAPSHOT

The parent version has been correctly updated to 3.1.8-SNAPSHOT, which aligns with the ongoing development to address the span events issue mentioned in the PR objectives.

Let's verify if this version change is consistent across other modules in the project:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistency of version numbers across pom.xml files

# Test: Search for parent version declarations in pom.xml files
# Expect: All should show 3.1.8-SNAPSHOT
rg --type xml '<version>3\.1\.[0-9]+(-SNAPSHOT)?</version>' -g 'pom.xml'

Length of output: 2462

tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java (1)

168-168: 💡 Codebase verification

Implement StringEvent Class with clear() Method

The StringEvent class does not appear to implement the ObjectEvent interface, and the clear() method is missing. This can lead to runtime errors and improper event handling.

  • Ensure that the StringEvent class implements the ObjectEvent interface.
  • Add a clear() method to the StringEvent class that correctly resets all relevant fields.
🔗 Analysis chain

Verify the implementation of StringEvent.clear()

While the addition of event.clear() is a good practice, it's important to ensure that the clear() method in the StringEvent class properly resets all relevant fields of the event object. This is crucial for effective garbage collection and preventing memory leaks.

Please run the following script to check the implementation of the StringEvent class:

Please review the output to ensure that:

  1. The StringEvent class properly implements the ObjectEvent interface.
  2. The clear() method resets all relevant fields of the StringEvent object.

If the implementation is not visible or seems incomplete, consider updating the StringEvent class to ensure proper object resetting.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of StringEvent class and its clear() method

# Search for the StringEvent class definition
echo "StringEvent class definition:"
ast-grep --lang java --pattern $'class StringEvent implements ObjectEvent {
  $$$
}'

# Search for the clear() method implementation in StringEvent
echo "\nclear() method implementation:"
ast-grep --lang java --pattern $'class StringEvent implements ObjectEvent {
  $$$
  public void clear() {
    $$$
  }
  $$$
}'

Length of output: 357

@ZijieSong ZijieSong merged commit e031ae6 into sofastack:master Oct 8, 2024
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant