* 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)
| 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 |
nothing calls this directly
no test coverage detected