codelipenghui commented on PR #21181:
URL: https://github.com/apache/pulsar/pull/21181#issuecomment-1723081439
@horizonzy Why you rollback the `lockObj`?
```this
while (true) {
try {
synchronized (this) {
if (leaderElectionState == LeaderElectionState.Leading) {
return;
} else {
wait();
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
```
This one is not correct, right? It will only allow the same thread to call
`notifyAll()` because `handleStateChanges` will acquire the lock ` synchronized
(this)` first.
As you mentioned in the description
```
"AuditorElector-127.0.0.1:58641" #257 prio=5 os_prio=31 cpu=0.22ms
elapsed=69.67s tid=0x000000013bc23800 nid=0x2a20f in Object.wait()
[0x00000004e3302000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait([email protected]/Native Method)
- waiting on <0x0000200006026150> (a
org.apache.pulsar.metadata.bookkeeper.PulsarLedgerAuditorManager)
at java.lang.Object.wait([email protected]/Object.java:338)
at
org.apache.pulsar.metadata.bookkeeper.PulsarLedgerAuditorManager.tryToBecomeAuditor(PulsarLedgerAuditorManager.java:77)
- locked <0x0000200006026150> (a
org.apache.pulsar.metadata.bookkeeper.PulsarLedgerAuditorManager)
at
org.apache.bookkeeper.replication.AuditorElector$3.run(AuditorElector.java:185)
at
java.util.concurrent.Executors$RunnableAdapter.call([email protected]/Executors.java:539)
at
java.util.concurrent.FutureTask.run([email protected]/FutureTask.java:264)
at
java.util.concurrent.ThreadPoolExecutor.runWorker([email protected]/ThreadPoolExecutor.java:1136)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run([email protected]/ThreadPoolExecutor.java:635)
at java.lang.Thread.run([email protected]/Thread.java:833)
```
If there is another thread calling `handleStateChanges`, it will wait for
the lock.
--
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]