Skip to content

Commit

Permalink
feat: add known, data-bearing filters to TopologyDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst authored and daprahamian committed Aug 13, 2019
1 parent 852e14f commit d0ccb56
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions lib/core/sdam/topology_description.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const ServerType = require('./server_description').ServerType;
const ServerDescription = require('./server_description').ServerDescription;
const ReadPreference = require('../topologies/read_preference');
const WIRE_CONSTANTS = require('../wireprotocol/constants');

// contstants related to compatability checks
Expand Down Expand Up @@ -258,24 +257,17 @@ class TopologyDescription {
}

/**
* Determines if the topology has a readable server available. See the table in the
* following section for behaviour rules.
*
* @param {ReadPreference} [readPreference] An optional read preference for determining if a readable server is present
* @return {Boolean} Whether there is a readable server in this topology
* Determines if the topology description has any known servers
*/
hasReadableServer(/* readPreference */) {
// To be implemented when server selection is implemented
get hasKnownServers() {
return Array.from(this.servers.values()).some(sd => sd.type !== ServerDescription.Unknown);
}

/**
* Determines if the topology has a writable server available. See the table in the
* following section for behaviour rules.
*
* @return {Boolean} Whether there is a writable server in this topology
* Determines if this topology description has a data-bearing server available.
*/
hasWritableServer() {
return this.hasReadableServer(ReadPreference.primary);
get hasDataBearingServers() {
return Array.from(this.servers.values()).some(sd => sd.isDataBearing);
}

/**
Expand Down

0 comments on commit d0ccb56

Please sign in to comment.