MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / getTokenRangesForHost

Method getTokenRangesForHost

lib/metadata/index.js:355–381  ·  view source on GitHub ↗

* Gets the token ranges that are replicated on the given host, for * the given keyspace. * * @param {String} keyspaceName The name of the keyspace to get ranges for. * @param {Host} host The host. * @returns {Set |null} Ranges for the keyspace on this host or null if keyspa

(keyspaceName, host)

Source from the content-addressed store, hash-verified

353 * @returns {Set<TokenRange>|null} Ranges for the keyspace on this host or null if keyspace isn't found or hasn't been loaded.
354 */
355 getTokenRangesForHost(keyspaceName, host) {
356 if (!this.ring) {
357 return null;
358 }
359 let keyspace;
360 if (keyspaceName) {
361 keyspace = this.keyspaces[keyspaceName];
362 if (!keyspace) {
363 // the keyspace was not found, the metadata should be loaded beforehand
364 return null;
365 }
366 }
367 // If the ring has only 1 token, just return the ranges as we should only have a single node cluster.
368 if (this.ring.length === 1) {
369 return this.getTokenRanges();
370 }
371 const replicas = this._getKeyspaceReplicas(keyspace);
372 const ranges = new Set();
373 // for each range, find replicas for end token, if replicas include host, add range.
374 this.tokenRanges.forEach((tokenRange) => {
375 const replicasForToken = replicas[this.tokenizer.stringify(tokenRange.end)];
376 if (replicasForToken.indexOf(host) !== -1) {
377 ranges.add(tokenRange);
378 }
379 });
380 return ranges;
381 }
382
383 /**
384 * Constructs a Token from the input buffer(s) or string input. If a string is passed in

Callers

nothing calls this directly

Calls 5

getTokenRangesMethod · 0.95
_getKeyspaceReplicasMethod · 0.95
forEachMethod · 0.65
addMethod · 0.65
stringifyMethod · 0.45

Tested by

no test coverage detected