File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
runtime/service/src/main/java/org/apache/polaris/service/tracing Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 2222import com .google .common .annotations .VisibleForTesting ;
2323import jakarta .enterprise .context .ApplicationScoped ;
2424import java .util .UUID ;
25- import java .util .concurrent .atomic .AtomicBoolean ;
2625import java .util .concurrent .atomic .AtomicLong ;
2726
2827@ ApplicationScoped
@@ -31,17 +30,18 @@ public class RequestIdGenerator {
3130 static final AtomicLong COUNTER = new AtomicLong ();
3231 static final Long COUNTER_SOFT_MAX = Long .MAX_VALUE / 2 ;
3332
34- private final AtomicBoolean resetInProgress = new AtomicBoolean (false );
35-
3633 public String generateRequestId () {
3734 long currentCounter = COUNTER .incrementAndGet ();
3835 String requestId = baseDefaultUuid + "_" + currentCounter ;
39- if (currentCounter >= COUNTER_SOFT_MAX && resetInProgress .compareAndSet (false , true )) {
40- // If we get anywhere close to danger of overflowing Long (which, theoretically,
41- // would be extremely unlikely) rotate the UUID and start again.
42- baseDefaultUuid = UUID .randomUUID ().toString ();
43- COUNTER .set (0 );
44- resetInProgress .set (false );
36+ if (currentCounter >= COUNTER_SOFT_MAX ) {
37+ synchronized (this ) {
38+ if (COUNTER .get () >= COUNTER_SOFT_MAX ) {
39+ // If we get anywhere close to danger of overflowing Long (which, theoretically,
40+ // would be extremely unlikely) rotate the UUID and start again.
41+ baseDefaultUuid = UUID .randomUUID ().toString ();
42+ COUNTER .set (0 );
43+ }
44+ }
4545 }
4646 return requestId ;
4747 }
You can’t perform that action at this time.
0 commit comments