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

This commit is contained in:
Nick Wong 2021-04-16 07:38:13 +08:00 committed by GitHub
parent b2216f9414
commit bc1043e9b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

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

View File

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