org.apache.rocketmq.store.index.IndexFile#putKey
begin if (this.indexHeader.getIndexCount() <= 1) { this.indexHeader.setBeginPhyOffset(phyOffset); this.indexHeader.setBeginTimestamp(storeTimestamp); }
this.indexHeader.incHashSlotCount();
this.indexHeader.incIndexCount();
this.indexHeader.setEndPhyOffset(phyOffset);
this.indexHeader.setEndTimestamp(storeTimestamp);
update
if (this.indexHeader.getIndexCount() <= 1) {
this.indexHeader.setBeginPhyOffset(phyOffset);
this.indexHeader.setBeginTimestamp(storeTimestamp);
}
//Hash collision send 2 msg [ method param ] key is equal but HashSlot use 1
// key= topic+ keys hashcode equal
if(slotValue == 0) {
this.indexHeader.incHashSlotCount();
}
this.indexHeader.incIndexCount();
this.indexHeader.setEndPhyOffset(phyOffset);
this.indexHeader.setEndTimestamp(storeTimestamp);
i english not good
@jianglianggithub 可以中文描述一下问题的原因哈:)
该逻辑是发生在 product 发送消息后。 由ReputMessageService 服务线程 派发到 org.apache.rocketmq.store.DefaultMessageStore#doDispatch, org.apache.rocketmq.store.index.IndexService#buildIndex, 来更新索引文件的。 在IndexFile 的属性 indexHeader 的属性 hashSlotCount 是用来记录 在索引文件 hashSlot 的使用个数的
在原来的代码里面 每一个消息 会创建2个索引 一个索引= TopicName + UniqKey 另外一个索引是 TopicName + keys 【由product发送消息的时候指定】
我的意思是 如果发送 2条相同的 消息 如果topic 和 kyes 想同的话 那么 原来的代码记录的 hashSlot 使用个数 =4 但是 其实使用只有3个 hashSlot 因为有一个 hashSlot 在第一次发送消息的时候已经被使用了 出现了 哈希冲突
@jianglianggithub Good one!Nothing bad happened by now because the hashSlotCount has never been accessed. Could you please submit a PR to fix it?
Duplicate issue #1807 . I will close this issue first.