Skip to content

Commit

Permalink
fix: waitId may be overflow in long running service (#846)
Browse files Browse the repository at this point in the history
* fix: waitId may be overflow in long running service

* comment: valid waitId
  • Loading branch information
killme2008 authored Jun 17, 2022
1 parent a3ed1f7 commit 8dc5c08
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class LogManagerImpl implements LogManager {
private final Lock readLock = this.lock.readLock();
private volatile boolean stopped;
private volatile boolean hasError;
private long nextWaitId;
private long nextWaitId = 1;
private LogId diskId = new LogId(0, 0);
private LogId appliedId = new LogId(0, 0);
private final SegmentList<LogEntry> logsInMemory = new SegmentList<>(true);
Expand Down Expand Up @@ -1102,10 +1102,11 @@ private long notifyOnNewLog(final long expectedLastLogIndex, final WaitMeta wm)
Utils.runInThread(() -> runOnNewLog(wm));
return 0L;
}
if (this.nextWaitId == 0) { //skip 0
++this.nextWaitId;
long waitId = this.nextWaitId++;
if (waitId < 0) {
// Valid waitId starts from 1, skip 0.
waitId = this.nextWaitId = 1;
}
final long waitId = this.nextWaitId++;
this.waitMap.put(waitId, wm);
return waitId;
} finally {
Expand Down

0 comments on commit 8dc5c08

Please sign in to comment.