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

Method _startNewExecution

lib/request-handler.js:152–190  ·  view source on GitHub ↗

* Starts a new execution on the next host of the query plan. * @param {Boolean} [isSpecExec] * @returns {Promise } * @private

(isSpecExec)

Source from the content-addressed store, hash-verified

150 * @private
151 */
152 async _startNewExecution(isSpecExec) {
153 if (isSpecExec) {
154 this.client.metrics.onSpeculativeExecution();
155 }
156
157 let host;
158 let connection;
159
160 try {
161 ({ host, connection } = this.getNextConnection());
162 } catch (err) {
163 return this.handleNoHostAvailable(err, null);
164 }
165
166 if (isSpecExec && this._executions.length >= 0 && this._executions[0].wasCancelled()) {
167 // This method was called on the next tick and could not be cleared, the previous execution was cancelled so
168 // there's no point in launching a new execution.
169 return;
170 }
171
172 if (this.client.keyspace && this.client.keyspace !== connection.keyspace) {
173 try {
174 await connection.changeKeyspace(this.client.keyspace);
175 } catch (err) {
176 this.triedHosts[host.address] = err;
177 // The error occurred asynchronously
178 // We can blindly re-try to obtain a different host/connection.
179 return this._startNewExecution(isSpecExec);
180 }
181 }
182
183 const execution = new RequestExecution(this, host, connection);
184 this._executions.push(execution);
185 execution.start();
186
187 if (this.executionOptions.isIdempotent()) {
188 this._scheduleSpeculativeExecution(host);
189 }
190 }
191
192 /**
193 * Schedules next speculative execution, if any.

Callers 2

sendMethod · 0.95

Calls 9

getNextConnectionMethod · 0.95
handleNoHostAvailableMethod · 0.95
startMethod · 0.95
wasCancelledMethod · 0.80
changeKeyspaceMethod · 0.80
isIdempotentMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected