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

Method _prepareWithQueryPlan

lib/prepare-handler.js:128–164  ·  view source on GitHub ↗

* Uses the query plan to prepare the query on the first host and optionally on the rest of the hosts. * @param {Object} info * @param {Iterator} iterator * @param {String} query * @param {String} keyspace * @returns {Promise<{queryId, meta}>} * @private

(info, iterator, query, keyspace)

Source from the content-addressed store, hash-verified

126 * @private
127 */
128 async _prepareWithQueryPlan(info, iterator, query, keyspace) {
129 const triedHosts = {};
130
131 while (true) {
132 const host = PrepareHandler.getNextHost(iterator, this._client.profileManager, triedHosts);
133
134 if (host === null) {
135 throw new errors.NoHostAvailableError(triedHosts);
136 }
137
138 try {
139 const connection = await PrepareHandler._borrowWithKeyspace(host, keyspace);
140 const response = await connection.prepareOnceAsync(query, keyspace);
141
142 if (this._client.options.prepareOnAllHosts) {
143 await this._prepareOnAllHosts(iterator, query, keyspace);
144 }
145
146 // Set the prepared metadata
147 info.preparing = false;
148 info.queryId = response.id;
149 info.meta = response.meta;
150 this._client.metadata.setPreparedById(info);
151 info.emit('prepared', null, info);
152
153 return info;
154
155 } catch (err) {
156 triedHosts[host.address] = err;
157
158 if (!err.isSocketError && !(err instanceof errors.OperationTimedOutError)) {
159 // There's no point in retrying syntax errors and other response errors
160 throw err;
161 }
162 }
163 }
164 }
165
166 /**
167 * Gets the next host from the query plan.

Callers 1

_prepareMethod · 0.95

Calls 4

_prepareOnAllHostsMethod · 0.95
getNextHostMethod · 0.80
_borrowWithKeyspaceMethod · 0.80
setPreparedByIdMethod · 0.80

Tested by

no test coverage detected