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

Method _retry

lib/request-execution.js:408–449  ·  view source on GitHub ↗

* @param {Number|undefined} consistency * @param {Boolean} useCurrentHost * @param {Object} [meta] * @private

(consistency, useCurrentHost, meta)

Source from the content-addressed store, hash-verified

406 * @private
407 */
408 _retry(consistency, useCurrentHost, meta) {
409 if (this._cancelled) {
410 // No point in retrying
411 return;
412 }
413
414 this._parent.log('info', 'Retrying request');
415 this._retryCount++;
416
417 if (meta || (typeof consistency === 'number' && this._request.consistency !== consistency)) {
418 this._request = this._request.clone();
419 if (typeof consistency === 'number') {
420 this._request.consistency = consistency;
421 }
422 // possible that we are retrying because we had to reprepare. In this case it is also possible
423 // that our known metadata had changed, therefore we update it on the request.
424 if (meta) {
425 this._request.meta = meta;
426 }
427 }
428
429 if (useCurrentHost !== false) {
430 // Reusing the existing connection is suitable for the most common scenarios, like server read timeouts that
431 // will be fixed with a new request.
432 // To cover all scenarios (e.g., where a different connection to the same host might mean something different),
433 // we obtain a new connection from the host pool.
434 // When there was a socket error, the connection provided was already removed from the pool earlier.
435 try {
436 this._connection = this._host.borrowConnection(this._connection);
437 } catch (err) {
438 // All connections are busy (`BusyConnectionError`) or there isn't a ready connection in the pool (`Error`)
439 // The retry policy declared the intention to retry on the current host but its not available anymore.
440 // Use the next host
441 return promiseUtils.toBackground(this.restart());
442 }
443
444 return this._sendOnConnection();
445 }
446
447 // Use the next host in the query plan to send the request in the background
448 promiseUtils.toBackground(this.restart());
449 }
450
451 /**
452 * Issues a PREPARE request on the current connection.

Callers 2

_handleErrorMethod · 0.95
_prepareAndRetryMethod · 0.80

Calls 4

restartMethod · 0.95
_sendOnConnectionMethod · 0.95
cloneMethod · 0.45
borrowConnectionMethod · 0.45

Tested by

no test coverage detected