GlobalIdGenerator will produce a negative id when the time shift back (#6729)
This commit is contained in:
parent
b2216f9414
commit
bc1043e9b3
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue