Copilot commented on code in PR #62059:
URL: https://github.com/apache/doris/pull/62059#discussion_r3028451884
##########
fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java:
##########
@@ -264,13 +264,13 @@ private void flushEditLog() {
System.exit(-1);
}
- txId += batch.size();
+ txId.addAndGet(batch.size());
// update statistics, etc. (optional, can be added as needed)
- if (txId >= Config.edit_log_roll_num) {
- LOG.info("txId {} is equal to or larger than edit_log_roll_num {},
will roll edit.", txId,
+ if (txId.get() >= Config.edit_log_roll_num) {
+ LOG.info("txId {} is equal to or larger than edit_log_roll_num {},
will roll edit.", txId.get(),
Review Comment:
`txId.get()` is called multiple times after an increment, which can make
logs harder to interpret under concurrency (the logged value may not match the
value used for the decision). Prefer capturing the post-increment value in a
local `long` (e.g., from `addAndGet(...)`) and using that for both the
threshold check and the log message.
##########
fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java:
##########
@@ -264,13 +264,13 @@ private void flushEditLog() {
System.exit(-1);
}
- txId += batch.size();
+ txId.addAndGet(batch.size());
// update statistics, etc. (optional, can be added as needed)
- if (txId >= Config.edit_log_roll_num) {
- LOG.info("txId {} is equal to or larger than edit_log_roll_num {},
will roll edit.", txId,
+ if (txId.get() >= Config.edit_log_roll_num) {
+ LOG.info("txId {} is equal to or larger than edit_log_roll_num {},
will roll edit.", txId.get(),
Config.edit_log_roll_num);
rollEditLog();
- txId = 0;
+ txId.set(0);
}
Review Comment:
The `get() / rollEditLog() / set(0)` sequence is not atomic with respect to
concurrent increments. Another thread can increment `txId` after the threshold
check (or during `rollEditLog()`), and `set(0)` can then wipe out those
increments, causing missed roll accounting and potentially
delaying/accelerating future rolls. Consider guarding the roll decision/reset
with a CAS pattern (e.g., capture the post-increment value and `compareAndSet`
it back to 0 only if unchanged) or synchronizing the roll/reset with the same
lock used for rolling so increments can’t be lost.
##########
fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java:
##########
@@ -1654,13 +1654,13 @@ private synchronized long logEditDirectly(short op,
Writable writable) {
}
// get a new transactionId
- txId++;
+ long newTxId = txId.incrementAndGet();
- if (txId >= Config.edit_log_roll_num) {
- LOG.info("txId {} is equal to or larger than edit_log_roll_num {},
will roll edit.", txId,
+ if (newTxId >= Config.edit_log_roll_num) {
+ LOG.info("txId {} is equal to or larger than edit_log_roll_num {},
will roll edit.", newTxId,
Config.edit_log_roll_num);
rollEditLog();
- txId = 0;
+ txId.set(0);
}
Review Comment:
Similar to `flushEditLog()`, `incrementAndGet()` followed by `rollEditLog()`
and `set(0)` can lose increments performed by other threads while the roll is
in progress, because the reset is unconditional. If `logEditDirectly()` can run
concurrently with other increment sites, prefer making the reset conditional
(CAS) or performing the roll+reset under a shared lock that also covers all
`txId` increments related to rolling.
--
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]