* Gets the next host from the query plan. * @param {Iterator} iterator * @param {ProfileManager} profileManager * @param {Object} [triedHosts] * @return {Host|null}
(iterator, profileManager, triedHosts)
| 171 | * @return {Host|null} |
| 172 | */ |
| 173 | static getNextHost(iterator, profileManager, triedHosts) { |
| 174 | let host; |
| 175 | // Get a host that is UP in a sync loop |
| 176 | while (true) { |
| 177 | const item = iterator.next(); |
| 178 | if (item.done) { |
| 179 | return null; |
| 180 | } |
| 181 | |
| 182 | host = item.value; |
| 183 | |
| 184 | // set the distance relative to the client first |
| 185 | const distance = profileManager.getDistance(host); |
| 186 | if (distance === types.distance.ignored) { |
| 187 | //If its marked as ignore by the load balancing policy, move on. |
| 188 | continue; |
| 189 | } |
| 190 | |
| 191 | if (host.isUp()) { |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | if (triedHosts) { |
| 196 | triedHosts[host.address] = 'Host considered as DOWN'; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | return host; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Prepares all queries on a single host. |
no test coverage detected