Skip to content

Commit 6d3ce76

Browse files
fix: Replace built-in hash method with MurmurHash3 for consistent lock index calculation
1 parent 22dfd71 commit 6d3ce76

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/optimizely/cmab/cmab_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require 'digest'
2121
require 'json'
2222
require 'securerandom'
23+
require 'murmurhash3'
2324

2425
module Optimizely
2526
CmabDecision = Struct.new(:variation_id, :cmab_uuid, keyword_init: true)
@@ -58,8 +59,7 @@ def get_decision(project_config, user_context, rule_id, options)
5859
def get_lock_index(user_id, rule_id)
5960
# Create a hash of user_id + rule_id for consistent lock selection
6061
hash_input = "#{user_id}#{rule_id}"
61-
# Use Ruby's built-in hash method and ensure positive result
62-
hash_value = hash_input.hash.abs
62+
hash_value = MurmurHash3::V32.str_hash(hash_input, 1) & 0xFFFFFFFF # Convert to unsigned 32-bit equivalent
6363
hash_value % NUM_LOCK_STRIPES
6464
end
6565

0 commit comments

Comments
 (0)