Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,6 +23,7 @@
var _ = require('underscore');
var EventEmitter = require('events').EventEmitter;
var LoggingLevels = require('./lib/logging/levels.js');
var HashingStrategies = require('./lib/hasher/hashing-strategies.js');
var util = require('util');

// This Config class is meant to be a central store
Expand Down Expand Up @@ -151,6 +152,11 @@ Config.prototype._seed = function _seed(seed) {
// Ping a maximum ratio of the pingable members on self eviction
seedOrDefault('selfEvictionMaxPingRatio', 0.4);

// Hashing strategy
// Use consistentHashing for backwards compatibility.
// Use rendezvousHashing for better ring distribution and light-weight bootstrap.
seedOrDefault('hashingStrategy', HashingStrategies.consistentHashing);

function seedOrDefault(name, defaultVal, validator, reason) {
var seedVal = seed[name];
if (typeof seedVal === 'undefined') {
Expand Down
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -50,7 +50,9 @@ var Dissemination = require('./lib/gossip/dissemination.js');
var discoverProviderFactory = require('./discover-providers.js');
var errors = require('./lib/errors.js');
var getTChannelVersion = require('./lib/util.js').getTChannelVersion;
var HashRing = require('./lib/ring');
var HashingStrategies = require('./lib/hasher/hashing-strategies');
var HashRing = require('./lib/hasher/consistent-hashing');
var RendezvousHasher = require('./lib/hasher/rendezvous-hashing');
var initMembership = require('./lib/membership/index.js');
var LoggerFactory = require('./lib/logging/logger_factory.js');
var LagSampler = require('./lib/lag_sampler.js');
Expand Down Expand Up @@ -109,7 +111,6 @@ function RingPop(options) {
}
this.timers = options.timers || timers;
this.setTimeout = options.setTimeout || timers.setTimeout;
this.Ring = options.Ring || HashRing;

this.isReady = false;

Expand Down Expand Up @@ -154,6 +155,13 @@ function RingPop(options) {
enforceKeyConsistency: options.enforceKeyConsistency
});

this.Ring = options.Ring || HashRing;
if (this.config.get('hashingStrategy') === HashingStrategies.rendezvousHashing) {
this.Ring = RendezvousHasher;
}
// HACK (always use rendezvousHasher while testing)
this.Ring = RendezvousHasher;

this.ring = new this.Ring({
hashFunc: this.hashFunc
});
Expand Down
4 changes: 2 additions & 2 deletions lib/ring/index.js → lib/hasher/consistent-hashing/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,7 +22,7 @@ var EventEmitter = require('events').EventEmitter;
var farmhash = require('farmhash');
var util = require('util');
var RBTree = require('./rbtree').RBTree;
var RingEvents = require('./events.js');
var RingEvents = require('../events.js');

function HashRing(options) {
this.options = options || {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion lib/ring/events.js → lib/hasher/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 26 additions & 0 deletions lib/hasher/hashing-strategies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

'use strict';

module.exports = {
consistentHashing: 'consistent-hashing',
rendezvousHashing: 'rendezvous-hashing'
};
Loading