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

[ISSUE #3136] TraceDataEncoder add SubAfter trace bean timestamp #3137

Merged
merged 2 commits into from
Aug 27, 2021

Conversation

StyleTang
Copy link
Member

Make sure set the target branch to develop

What is the purpose of the change

TraceDataEncoder add SubAfter trace bean timestamp
Mentioned in PR-744 , the timeStamp and consumeGroup have been deleted by this commit.

(It is fine for deleting SubAfter consumeGroup because we can find consume group from SubBefore traceContext by messageId and requestId)

I use subBefore timestamp+costTime instead of subAfter timestamp, but it is not reasonable.

Brief changelog

TraceDataEncoder add SubAfter trace bean timestamp

Verifying this change

Unit Tests succeed

Follow this checklist to help us incorporate your contribution quickly and easily. Notice, it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@coveralls
Copy link

coveralls commented Jul 10, 2021

Coverage Status

Coverage increased (+0.007%) to 54.021% when pulling e8a0152 on StyleTang:trace-ui into 589e87c on apache:develop.

@francisoliverlee francisoliverlee linked an issue Jul 12, 2021 that may be closed by this pull request
@vongosling vongosling added this to the 4.9.1 milestone Jul 13, 2021
@vongosling
Copy link
Member

Very responsible for this issue closed, thanks ~

subAfterContext.setTimeStamp(Long.parseLong(line[7]));
subAfterContext.setGroupName(line[8]);
Copy link
Member

Choose a reason for hiding this comment

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

The code here is used for compatible reason, if the message is produced by old versions of producer, there will be group name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Get it.
I removed it because I thought this value is useless, maybe add the branch line.length >= 9 back is a better way.

        // compatible with the old version
        if (line.length >= 8) {
            subAfterContext.setTimeStamp(Long.parseLong(line[7]));
        }
        if (line.length >= 9) {
            subAfterContext.setGroupName(Long.parseLong(line[8]));
        }

Copy link
Contributor

@duhenglucky duhenglucky left a comment

Choose a reason for hiding this comment

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

It is not recommended to modify this format in the current state. The previous version upgrade brought many compatibility issues.

@StyleTang
Copy link
Member Author

@yuz10 @duhenglucky Thanks for your comment.

For subAfterContext, in the previous version, it was already defined line[7] is TimeStamp and line[8] is GroupName, it means for compatible reason in new revision we should still follow this protocol.

The subAfter GroupName is duplicated with subBeofre, so based on performance considerations(I guess), it was removed it by https://github.com/apache/rocketmq/pull/3005/files

We have several ways to make it compatible.

Option1 ( Prefer )

Just follow the previous version subAfter protocol.

( line[7] is TimeStamp and line[8] is GroupName )

Props
  • The protocol remains consistent, easy to maintain
Cons
  • In the future revision should add line[8] group name back, even if it is useless

Option2

If line[8] GroupName was never used, just remove it as if it not exist.

Props
  • Performance friendly (can remove the duplicated groupName)
Cons
  • The protocol is changed (Not a good way)
  • Compatible logic is complicated, old version line[8] is group name while new revision may be not. (The new revision content length should not be 9, if it is 9, we can’t tell what the value it is)

Do you have any suggestions for this?

@yuz10
Copy link
Member

yuz10 commented Jul 19, 2021

@StyleTang I prefer just add 2 back and keep the same with 4.9.0.

@vongosling
Copy link
Member

Go ahead~ Designed well is what we have advocated. The previous disturbing is the obvious lack of this point.

@vongosling
Copy link
Member

For this problem, Who said before and after must be atomic exit?

@StyleTang
Copy link
Member Author

@yuz10
Already add them back.

@vongosling
You are right. There is a small probability before and after trace not atomic exist.
If consumeMessageBefore has already been executed and the trace message has been sent by localDispatcher, then the system crashed, subAfter trace may be lost.

org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService.ConsumeRequest#run

      if (ConsumeMessageConcurrentlyService.this.defaultMQPushConsumerImpl.hasHook()) {
          consumeMessageContext = new ConsumeMessageContext();
  ConsumeMessageConcurrentlyService.this.defaultMQPushConsumerImpl.executeHookBefore(consumeMessageContext);
      }
     try {
          status = listener.consumeMessage(Collections.unmodifiableList(msgs), context);
      } catch (Throwable e) {
      }
  
      // System crash happen 
      if (ConsumeMessageConcurrentlyService.this.defaultMQPushConsumerImpl.hasHook()) {           ConsumeMessageConcurrentlyService.this.defaultMQPushConsumerImpl.executeHookAfter(consumeMessageContext);
      }

@vongosling
Copy link
Member

vongosling commented Jul 21, 2021

@duhengforever @duhenglucky pls help to look at this issue, especially compatibility backword:-0

@StyleTang
Copy link
Member Author

I think it is necessary for us to add Timestamp and GroupName back.
The reason is that send SubBefore and SubAfter message trace is not a atomic operation, we may only get SubBefore or SubAfter trace, If SubAfter trace don't have GroupName we don't know which subscription group consumed it.

@vongosling
Copy link
Member

vongosling commented Aug 2, 2021

Yes, I would like to hear any compatible issues that resolved from the opinion of the other @duhengforever @zongtanghu I think this pr apache/rocketmq-externals#769 would resolve the problem from the dashboard viewpoint.

@yuz10 yuz10 merged commit 2cac866 into apache:develop Aug 27, 2021
GenerousMan pushed a commit to GenerousMan/rocketmq that referenced this pull request Aug 12, 2022
apache#3137)

* [ISSUE apache#3136] TraceDataEncoder add SubAfter trace bean timestamp

* add SubAfter TraceBean TimeStamp and GroupName back
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.

TraceDataEncoder add SubAfter trace bean timestamp
6 participants