hll1213181368 commented on PR #2835:
URL: https://github.com/apache/kvrocks/pull/2835#issuecomment-2736447312

   @mapleFU   When I was solving this problem, I found that it would be better 
to use atomic operations for the bit operations in the InsertHash function. 
What do you think?
   
   void BlockSplitBloomFilter::InsertHash(uint64_t hash) {
     const auto bucket_index = static_cast<uint32_t>(((hash >> 32) * 
(data_.size() / kBytesPerFilterBlock)) >> 32);
     const auto key = static_cast<uint32_t>(hash);
   //  auto* bitset32 = reinterpret_cast<uint32_t*>(data_.data());
     auto* bitset32 = reinterpret_cast<std::atomic<uint32_t>*>(data_.data());  
// 原子操作
   
     for (int i = 0; i < kBitsSetPerBlock; i++) {
       // Calculate mask for key in the given bitset.
       const uint32_t mask = UINT32_C(0x1) << ((key * SALT[i]) >> 27);
   //    bitset32[bucket_index * kBitsSetPerBlock + i] |= mask;
       bitset32[bucket_index * kBitsSetPerBlock + i].fetch_or(mask, 
std::memory_order_release);  // 使用fetch_or原子操作来设置位
     }
   }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to