Copilot commented on code in PR #59320:
URL: https://github.com/apache/doris/pull/59320#discussion_r2644914113
##########
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.java:
##########
@@ -67,7 +67,7 @@ public class CloudReplica extends Replica {
@SerializedName(value = "idx")
private long idx = -1;
- private Random rand = new Random();
+ private static final Random rand = new Random();
Review Comment:
Using a shared static `Random` object introduces a concurrency issue.
`java.util.Random` is not thread-safe, and since `getBackendId()` is called
from many multi-threaded contexts (query planning, tablet scheduling,
transactions), multiple threads will contend on this single Random instance.
This can lead to incorrect random number generation and performance degradation.
The recommended solution is to use `ThreadLocalRandom.current().nextInt()`
instead, which is already used in several other places in this codebase (e.g.,
ResettableRandomizedIterator, RemoteDorisSource, HttpDialectUtils). Replace
line 308-309 with:
- `int indexRand =
ThreadLocalRandom.current().nextInt(Config.cloud_replica_num);`
- `int coldReadRand = ThreadLocalRandom.current().nextInt(100);`
This approach is both thread-safe and more memory-efficient than the
original per-instance Random objects.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]