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