MCPcopy
hub / github.com/mongodb/node-mongodb-native / latencyWindowReducer

Function latencyWindowReducer

src/sdam/server_selection.ts:243–254  ·  view source on GitHub ↗

* Reduces a list of servers to ensure they fall within an acceptable latency window. This is * further specified in the "Server Selection" specification, found here: * * @see https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.md * * @param topologyDes

(
  topologyDescription: TopologyDescription,
  servers: ServerDescription[]
)

Source from the content-addressed store, hash-verified

241 * @returns The servers which fall within an acceptable latency window
242 */
243function latencyWindowReducer(
244 topologyDescription: TopologyDescription,
245 servers: ServerDescription[]
246): ServerDescription[] {
247 const low = servers.reduce(
248 (min: number, server: ServerDescription) => Math.min(server.roundTripTime, min),
249 Infinity
250 );
251
252 const high = low + topologyDescription.localThresholdMS;
253 return servers.filter(server => server.roundTripTime <= high && server.roundTripTime >= low);
254}
255
256// filters
257function primaryFilter(server: ServerDescription): boolean {

Callers 3

writableServerSelectorFunction · 0.85
secondarySelectorFunction · 0.85

Calls 2

minMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected