说在前面
今天主要介绍DELETE_TOPIC_IN_BROKER的处理逻辑,更多源码解析请关注“天河聊架构”微信公众号
源码解析
进入到这个方法org.apache.rocketmq.broker.processor.AdminBrokerProcessor#deleteTopic
private synchronized RemotingCommand deleteTopic(ChannelHandlerContext ctx,
RemotingCommand request) throws RemotingCommandException {
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
DeleteTopicRequestHeader requestHeader =
(DeleteTopicRequestHeader) request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class);
log.info("deleteTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
// 删除topic=》
this.brokerController.getTopicConfigManager().deleteTopicConfig(requestHeader.getTopic());
// 删除客户端消息队列中的无用的topic=》
this.brokerController.getMessageStore()
.cleanUnusedTopic(this.brokerController.getTopicConfigManager().getTopicConfigTable().keySet());
response.setCode(ResponseCode.SUCCESS);
response.setRemark(null);
return response;
}
进入到这个方法org.apache.rocketmq.broker.topic.TopicConfigManager#deleteTopicConfig 删除内存和持久化的topic
public void deleteTopicConfig(final String topic) {
// 先删除缓存
TopicConfig old = this.topicConfigTable.remove(topic);
if (old != null) {
log.info("delete topic config OK, topic: {}", old);
// 更新数据版本号
this.dataVersion.nextVersion();
// 删除持久化文件中的topic=》