Skip to content

Commit

Permalink
updated redis-proxy to use hash bytes instead of bits
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike authored and Mike committed Nov 8, 2010
1 parent e18f8ec commit 7409b4c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions proxy-node/redis-proxy
Expand Up @@ -21,17 +21,18 @@ var CONIFIG_PORT = 8000
var PROXY_PORT = 8001

var HASHING_SLOTS = 4096
var bitsf = Math.log(HASHING_SLOTS)/Math.log(16)
if( Math.ceil(bitsf) != bitsf ) {
var bytesf = Math.log(HASHING_SLOTS)/Math.log(16)
if( Math.ceil(bytesf) != bytesf ) {
sys.puts( '# of hashing slots must be of the form 16^n where n is an integer')
process.exit(-1)
}
var HASH_BITS = bitsf
var HASH_BYTES = bytesf


//query config server for full list of data nodes and establish connections to each
//prior to accepting connections
var configSvr = new ConfigClient( 'localhost', 8000 )
var dataNodePool = new DataNodeClientPool()

configSvr.getDataNodeInfo( function(err, dataNodeInfos) {
//if there was an error listing data nodes
Expand All @@ -43,11 +44,11 @@ configSvr.getDataNodeInfo( function(err, dataNodeInfos) {
for( var id in dataNodeInfos ) {
var info = dataNodeInfo[id]
sys.puts( 'connecting to data node ' + id + ', ' + info.host + ':' + info.port )

dataNodePool.loadServer( id, info.host, info.port, info.range )
}

//start accepting connections
startServer()
//start accepting connections after all clients are connected
dataNodePool.connectAll( startServer )
})


Expand Down Expand Up @@ -87,8 +88,8 @@ function initialize() {
//get hash of key
var keyhash = hashfunc(key)

//get last HASH_BITS of the hash, this bounds the value between [0,HASHING_SLOTS]
var bits = keyhash.substring( keyhash.length - (HASH_BITS+1), keyhash.length-1 )
//get last HASH_BYTES of the hash, this bounds the value between [0,HASHING_SLOTS]
var bits = keyhash.substring( keyhash.length - (HASH_BYTES+1), keyhash.length-1 )

//convert to a base 10 integer for slot number
var slot = parseInt( bits, 16 )
Expand Down

0 comments on commit 7409b4c

Please sign in to comment.