Skip to content

Commit

Permalink
Add option to ringpop for cross platform mode,
Browse files Browse the repository at this point in the history
In cross platform mode it uses farmhash’s fingerprint32 instead of hash32 to guarantee consistent hashes across different platforms. Currently cross platform mode is disabled by default to be backwards compatible with running installations of ringpop. This might change in the future.
  • Loading branch information
Nils Dijk committed Oct 9, 2015
1 parent ad3111b commit 39908b7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Config.prototype._seed = function _seed(seed) {
// All config names should be camel-cased.
seedOrDefault('TEST_KEY', 100); // never remove, tests and lives depend on it
seedOrDefault('autoGossip', true);
seedOrDefault('isCrossPlatform', false);
seedOrDefault('dampScoringEnabled', true);
seedOrDefault('dampScoringDecayEnabled', true);
seedOrDefault('dampScoringDecayInterval', 1000);
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
var _ = require('underscore');
var EventEmitter = require('events').EventEmitter;
var fs = require('fs');
var farmhash = require('farmhash');
var globalSetTimeout = require('timers').setTimeout;
var hammock = require('uber-hammock');
var metrics = require('metrics');
Expand Down Expand Up @@ -123,14 +124,23 @@ function RingPop(options) {
// and hash ring dependencies.
this.config = new Config(this, options);

// use fingerprint if ringpop needs to function cross different platforms
if (this.config.get('isCrossPlatform')) {
this.hashFunc = farmhash.fingerprint32;
} else {
this.hashFunc = farmhash.hash32;
}

this.requestProxy = new RequestProxy({
ringpop: this,
maxRetries: options.requestProxyMaxRetries,
retrySchedule: options.requestProxyRetrySchedule,
enforceConsistency: options.enforceConsistency
});

this.ring = new this.Ring();
this.ring = new this.Ring({
hashFunc: this.hashFunc
});

this.dissemination = new Dissemination(this);

Expand Down
3 changes: 1 addition & 2 deletions lib/membership/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

var _ = require('underscore');
var EventEmitter = require('events').EventEmitter;
var farmhash = require('farmhash');
var Member = require('./member.js');
var mergeMembershipChangesets = require('./merge.js');
var timers = require('timers');
Expand Down Expand Up @@ -62,7 +61,7 @@ Membership.prototype.computeChecksum = function computeChecksum() {
var start = new Date();

var prevChecksum = this.checksum;
this.checksum = farmhash.fingerprint32(this.generateChecksumString());
this.checksum = this.ringpop.hashFunc(this.generateChecksumString());

this.emit('checksumComputed');
this.ringpop.stat('timing', 'compute-checksum', start);
Expand Down
2 changes: 1 addition & 1 deletion lib/ring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function HashRing(options) {
this.options = options || {};

this.replicaPoints = this.options.replicaPoints || 100;
this.hashFunc = this.options.hashFunc || farmhash.fingerprint32;
this.hashFunc = this.options.hashFunc || farmhash.hash32;

this.rbtree = new RBTree();
this.servers = {};
Expand Down
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function main(args) {
logger: createLogger('ringpop'),
channel: tchannel.makeSubChannel({
serviceName: 'ringpop'
})
}),
isCrossPlatform: true
});

ringpop.setupChannel();
Expand Down

0 comments on commit 39908b7

Please sign in to comment.