未验证 提交 bc1043e9 编写于 作者: nickwong_'s avatar nickwong_ 提交者: GitHub

GlobalIdGenerator will produce a negative id when the time shift back (#6729)

上级 b2216f94
...@@ -9,7 +9,7 @@ Release Notes. ...@@ -9,7 +9,7 @@ Release Notes.
#### Java Agent #### Java Agent
* Add `trace_segment_ref_limit_per_span` configuration mechanism to avoid OOM. * Add `trace_segment_ref_limit_per_span` configuration mechanism to avoid OOM.
* Improve `GlobalIdGenerator` performance.
#### OAP-Backend #### OAP-Backend
* BugFix: filter invalid Envoy access logs whose socket address is empty. * BugFix: filter invalid Envoy access logs whose socket address is empty.
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.skywalking.apm.agent.core.context.ids; package org.apache.skywalking.apm.agent.core.context.ids;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.skywalking.apm.util.StringUtil; import org.apache.skywalking.apm.util.StringUtil;
...@@ -57,8 +56,8 @@ public final class GlobalIdGenerator { ...@@ -57,8 +56,8 @@ public final class GlobalIdGenerator {
private short threadSeq; private short threadSeq;
// Just for considering time-shift-back only. // Just for considering time-shift-back only.
private long runRandomTimestamp; private long lastShiftTimestamp;
private int lastRandomValue; private int lastShiftValue;
private IDContext(long lastTimestamp, short threadSeq) { private IDContext(long lastTimestamp, short threadSeq) {
this.lastTimestamp = lastTimestamp; this.lastTimestamp = lastTimestamp;
...@@ -74,11 +73,11 @@ public final class GlobalIdGenerator { ...@@ -74,11 +73,11 @@ public final class GlobalIdGenerator {
if (currentTimeMillis < lastTimestamp) { if (currentTimeMillis < lastTimestamp) {
// Just for considering time-shift-back by Ops or OS. @hanahmily 's suggestion. // Just for considering time-shift-back by Ops or OS. @hanahmily 's suggestion.
if (runRandomTimestamp != currentTimeMillis) { if (lastShiftTimestamp != currentTimeMillis) {
lastRandomValue = ThreadLocalRandom.current().nextInt(); lastShiftValue++;
runRandomTimestamp = currentTimeMillis; lastShiftTimestamp = currentTimeMillis;
} }
return lastRandomValue; return lastShiftValue;
} else { } else {
lastTimestamp = currentTimeMillis; lastTimestamp = currentTimeMillis;
return lastTimestamp; return lastTimestamp;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册