[
https://issues.apache.org/jira/browse/ROCKETMQ-98?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15885052#comment-15885052
]
ASF GitHub Bot commented on ROCKETMQ-98:
----------------------------------------
Github user Jaskey commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/61
@lizhanhui
Acutully , if thread numbers are large , the cpu problem should be obvious
without doubt in a spin lock with `while(true)` without `sleep`.
But I also agree that we can create a blog for this, remove the comment for
me is fine , just DO NOT merge that commit.
Actully , my very first advice is that when implementing the spin lock add
`sleep(1)` when continiously fail to abatain the lock say 100 times, which
should solve most of the problems.
@Override
public void lock() {
int tryTimes = 0;
boolean flag;
do {
if (tryTimes++ % 100 ==0 ){
Thread.sleep(1); //fierce race condition
}
flag = this.putMessageSpinLock.compareAndSet(true, false);
}
while (!flag);
}
What's your advice
@zhouxinyu @vongosling @lizhanhui
> Risk of unable to release putMessage Lock forever
> -------------------------------------------------
>
> Key: ROCKETMQ-98
> URL: https://issues.apache.org/jira/browse/ROCKETMQ-98
> Project: Apache RocketMQ
> Issue Type: Bug
> Affects Versions: 4.1.0-incubating
> Reporter: Jaskey Lam
> Assignee: Jaskey Lam
> Fix For: 4.1.0-incubating
>
>
> In current implemenation, there are two kind of locks dev can choose. If I
> choose reentrantLock, and lock it then put message, in this time I change the
> config through admin interface to use spin lock. When trying to unlock,
> rocketmq will try to unlock the spin lock though actually the reentrantlock
> is locked, this will cause the reentrantlock not able to release forever and
> trying to release the wrong spin lock but actully it is not locked!
> /**
> * Spin util acquired the lock.
> */
> private void lockForPutMessage() {
> if
> (this.defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage())
> {
> putMessageNormalLock.lock();
> } else {
> boolean flag;
> do {
> flag = this.putMessageSpinLock.compareAndSet(true, false);
> }
> while (!flag);
> }
> }
> private void releasePutMessageLock() {
> if
> (this.defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage())
> {
> putMessageNormalLock.unlock();
> } else {
> this.putMessageSpinLock.compareAndSet(false, true);
> }
> }
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)