brpc icon indicating copy to clipboard operation
brpc copied to clipboard

Fix multi FlatMap scale and size

Open chenBright opened this issue 1 year ago • 0 comments

What problem does this PR solve?

Issue Number:

Problem Summary:

  1. Multi模式下,插入数据发生hash冲突的时候,size没有加一。另一方面,插入数据不能自动扩容。
  2. m1 = m2,m1扩容后m1._nbucket不等于m2._nbucket的时候,m1的_buckets上除了插入数据的位置,其他位置没有set_invalid,后续使用会出现内存问题。
  3. 扩容时,_buckets和_thumbnail都是先释放再申请新的内存。如果申请失败了,FlatMap就完全不可用了。

What is changed and the side effects?

Changed:

  1. size++。另外,当FlatMap负载超过阈值,则遍历Bucket链表,当存在不同的key的时候,则扩容。否则,不扩容直接插入。因为key一样,扩容后这些数据还是在同一个链表上。
  2. 扩容后都要初始化_buckets和_thumbnail数组。
  3. 申请内存成功后,再将其复制给_buckets和_thumbnail。一旦出现错误,则先释放已经申请的内存再返回失败。

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性):


Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

chenBright avatar Jun 21 '24 12:06 chenBright