* Gets the host list representing the replicas that contain the given partition key, token or token range. * * It uses the pre-loaded keyspace metadata to retrieve the replicas for a token for a given keyspace. * When the keyspace metadata has not been loaded, it returns null. *
(keyspaceName, token)
| 302 | * @returns {Array} |
| 303 | */ |
| 304 | getReplicas(keyspaceName, token) { |
| 305 | if (!this.ring) { |
| 306 | return null; |
| 307 | } |
| 308 | if (Buffer.isBuffer(token)) { |
| 309 | token = this.tokenizer.hash(token); |
| 310 | } |
| 311 | if (token instanceof TokenRange) { |
| 312 | token = token.end; |
| 313 | } |
| 314 | let keyspace; |
| 315 | if (keyspaceName) { |
| 316 | keyspace = this.keyspaces[keyspaceName]; |
| 317 | if (!keyspace) { |
| 318 | // the keyspace was not found, the metadata should be loaded beforehand |
| 319 | return null; |
| 320 | } |
| 321 | } |
| 322 | let i = utils.binarySearch(this.ring, token, (t1, t2) => t1.compare(t2)); |
| 323 | if (i < 0) { |
| 324 | i = ~i; |
| 325 | } |
| 326 | if (i >= this.ring.length) { |
| 327 | //it circled back |
| 328 | i = i % this.ring.length; |
| 329 | } |
| 330 | const closestToken = this.ringTokensAsStrings[i]; |
| 331 | if (!keyspaceName) { |
| 332 | return [this.primaryReplicas[closestToken]]; |
| 333 | } |
| 334 | const replicas = this._getKeyspaceReplicas(keyspace); |
| 335 | return replicas[closestToken]; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Gets the token ranges that define data distribution in the ring. |
nothing calls this directly
no test coverage detected