提交 cf8b8465 编写于 作者: D dongeforever

Polish the lock and persist for updateTopicQueueMapping

上级 d18d787f
......@@ -343,7 +343,7 @@ public class AdminBrokerProcessor extends AsyncNettyRequestProcessor implements
this.brokerController.registerIncrementBrokerData(topicConfig, this.brokerController.getTopicConfigManager().getDataVersion());
response.setCode(ResponseCode.SUCCESS);
} catch (Exception e) {
log.error("Update static failed for [{}]", request, e);
log.error("Update static topic failed for [{}]", request, e);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark(e.getMessage());
}
......
......@@ -36,6 +36,7 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -57,9 +58,15 @@ public class TopicQueueMappingManager extends ConfigManager {
this.brokerController = brokerController;
}
public void updateTopicQueueMapping(TopicQueueMappingDetail newDetail, boolean force) {
lock.lock();
public void updateTopicQueueMapping(TopicQueueMappingDetail newDetail, boolean force) throws Exception {
boolean locked = false;
boolean updated = false;
try {
if (lock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
locked = true;
} else {
return;
}
if (newDetail == null) {
return;
}
......@@ -70,6 +77,7 @@ public class TopicQueueMappingManager extends ConfigManager {
TopicQueueMappingDetail oldDetail = topicQueueMappingTable.get(newDetail.getTopic());
if (oldDetail == null) {
topicQueueMappingTable.put(newDetail.getTopic(), newDetail);
updated = true;
return;
}
if (force) {
......@@ -77,6 +85,7 @@ public class TopicQueueMappingManager extends ConfigManager {
newDetail.getHostedQueues().putIfAbsent(queueId, items);
});
topicQueueMappingTable.put(newDetail.getTopic(), newDetail);
updated = true;
return;
}
//do more check
......@@ -94,8 +103,14 @@ public class TopicQueueMappingManager extends ConfigManager {
}
}
topicQueueMappingTable.put(newDetail.getTopic(), newDetail);
} finally {
lock.unlock();
updated = true;
} finally {
if (locked) {
this.lock.unlock();
}
if (updated) {
this.persist();
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册