mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-13 03:02:49 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
37
node_modules/mongodb-core/lib/topologies/command_result.js
generated
vendored
Normal file
37
node_modules/mongodb-core/lib/topologies/command_result.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
|
||||
var setProperty = require('../connection/utils').setProperty
|
||||
, getProperty = require('../connection/utils').getProperty
|
||||
, getSingleProperty = require('../connection/utils').getSingleProperty;
|
||||
|
||||
/**
|
||||
* Creates a new CommandResult instance
|
||||
* @class
|
||||
* @param {object} result CommandResult object
|
||||
* @param {Connection} connection A connection instance associated with this result
|
||||
* @return {CommandResult} A cursor instance
|
||||
*/
|
||||
var CommandResult = function(result, connection) {
|
||||
this.result = result;
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CommandResult to JSON
|
||||
* @method
|
||||
* @return {object}
|
||||
*/
|
||||
CommandResult.prototype.toJSON = function() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CommandResult to String representation
|
||||
* @method
|
||||
* @return {string}
|
||||
*/
|
||||
CommandResult.prototype.toString = function() {
|
||||
return JSON.stringify(this.toJSON());
|
||||
}
|
||||
|
||||
module.exports = CommandResult;
|
||||
1042
node_modules/mongodb-core/lib/topologies/mongos.js
generated
vendored
Normal file
1042
node_modules/mongodb-core/lib/topologies/mongos.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
106
node_modules/mongodb-core/lib/topologies/read_preference.js
generated
vendored
Normal file
106
node_modules/mongodb-core/lib/topologies/read_preference.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
|
||||
var needSlaveOk = ['primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest'];
|
||||
|
||||
/**
|
||||
* @fileOverview The **ReadPreference** class is a class that represents a MongoDB ReadPreference and is
|
||||
* used to construct connections.
|
||||
*
|
||||
* @example
|
||||
* var ReplSet = require('mongodb-core').ReplSet
|
||||
* , ReadPreference = require('mongodb-core').ReadPreference
|
||||
* , assert = require('assert');
|
||||
*
|
||||
* var server = new ReplSet([{host: 'localhost', port: 30000}], {setName: 'rs'});
|
||||
* // Wait for the connection event
|
||||
* server.on('connect', function(server) {
|
||||
* var cursor = server.cursor('db.test'
|
||||
* , {find: 'db.test', query: {}}
|
||||
* , {readPreference: new ReadPreference('secondary')});
|
||||
* cursor.next(function(err, doc) {
|
||||
* server.destroy();
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* // Start connecting
|
||||
* server.connect();
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new Pool instance
|
||||
* @class
|
||||
* @param {string} preference A string describing the preference (primary|primaryPreferred|secondary|secondaryPreferred|nearest)
|
||||
* @param {object} tags The tags object
|
||||
* @param {object} [options] Additional read preference options
|
||||
* @property {string} preference The preference string (primary|primaryPreferred|secondary|secondaryPreferred|nearest)
|
||||
* @property {object} tags The tags object
|
||||
* @property {object} options Additional read preference options
|
||||
* @return {ReadPreference}
|
||||
*/
|
||||
var ReadPreference = function(preference, tags, options) {
|
||||
this.preference = preference;
|
||||
this.tags = tags;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* This needs slaveOk bit set
|
||||
* @method
|
||||
* @return {boolean}
|
||||
*/
|
||||
ReadPreference.prototype.slaveOk = function() {
|
||||
return needSlaveOk.indexOf(this.preference) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are the two read preference equal
|
||||
* @method
|
||||
* @return {boolean}
|
||||
*/
|
||||
ReadPreference.prototype.equals = function(readPreference) {
|
||||
return readPreference.preference == this.preference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON representation
|
||||
* @method
|
||||
* @return {Object}
|
||||
*/
|
||||
ReadPreference.prototype.toJSON = function() {
|
||||
var readPreference = {mode: this.preference};
|
||||
if(Array.isArray(this.tags)) readPreference.tags = this.tags;
|
||||
return readPreference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Primary read preference
|
||||
* @method
|
||||
* @return {ReadPreference}
|
||||
*/
|
||||
ReadPreference.primary = new ReadPreference('primary');
|
||||
/**
|
||||
* Primary Preferred read preference
|
||||
* @method
|
||||
* @return {ReadPreference}
|
||||
*/
|
||||
ReadPreference.primaryPreferred = new ReadPreference('primaryPreferred');
|
||||
/**
|
||||
* Secondary read preference
|
||||
* @method
|
||||
* @return {ReadPreference}
|
||||
*/
|
||||
ReadPreference.secondary = new ReadPreference('secondary');
|
||||
/**
|
||||
* Secondary Preferred read preference
|
||||
* @method
|
||||
* @return {ReadPreference}
|
||||
*/
|
||||
ReadPreference.secondaryPreferred = new ReadPreference('secondaryPreferred');
|
||||
/**
|
||||
* Nearest read preference
|
||||
* @method
|
||||
* @return {ReadPreference}
|
||||
*/
|
||||
ReadPreference.nearest = new ReadPreference('nearest');
|
||||
|
||||
module.exports = ReadPreference;
|
||||
1487
node_modules/mongodb-core/lib/topologies/replset.js
generated
vendored
Normal file
1487
node_modules/mongodb-core/lib/topologies/replset.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
505
node_modules/mongodb-core/lib/topologies/replset_state.js
generated
vendored
Normal file
505
node_modules/mongodb-core/lib/topologies/replset_state.js
generated
vendored
Normal file
@@ -0,0 +1,505 @@
|
||||
"use strict";
|
||||
|
||||
var Logger = require('../connection/logger')
|
||||
, f = require('util').format
|
||||
, ObjectId = require('bson').ObjectId
|
||||
, MongoError = require('../error');
|
||||
|
||||
var DISCONNECTED = 'disconnected';
|
||||
var CONNECTING = 'connecting';
|
||||
var CONNECTED = 'connected';
|
||||
var DESTROYED = 'destroyed';
|
||||
|
||||
/**
|
||||
* Creates a new Replicaset State object
|
||||
* @class
|
||||
* @property {object} primary Primary property
|
||||
* @property {array} secondaries List of secondaries
|
||||
* @property {array} arbiters List of arbiters
|
||||
* @return {State} A cursor instance
|
||||
*/
|
||||
var State = function(replSet, options) {
|
||||
this.replSet = replSet;
|
||||
this.options = options;
|
||||
this.secondaries = [];
|
||||
this.arbiters = [];
|
||||
this.passives = [];
|
||||
this.primary = null;
|
||||
// Initial state is disconnected
|
||||
this.state = DISCONNECTED;
|
||||
// Current electionId
|
||||
this.electionId = null;
|
||||
// Get a logger instance
|
||||
this.logger = Logger('ReplSet', options);
|
||||
// Unpacked options
|
||||
this.id = options.id;
|
||||
this.setName = options.setName;
|
||||
this.connectingServers = options.connectingServers;
|
||||
this.secondaryOnlyConnectionAllowed = options.secondaryOnlyConnectionAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a secondary connected
|
||||
* @method
|
||||
* @return {boolean}
|
||||
*/
|
||||
State.prototype.isSecondaryConnected = function() {
|
||||
for(var i = 0; i < this.secondaries.length; i++) {
|
||||
if(this.secondaries[i].isConnected()) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a primary connection
|
||||
* @method
|
||||
* @return {boolean}
|
||||
*/
|
||||
State.prototype.isPrimaryConnected = function() {
|
||||
return this.primary != null && this.primary.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given address the primary
|
||||
* @method
|
||||
* @param {string} address Server address
|
||||
* @return {boolean}
|
||||
*/
|
||||
State.prototype.isPrimary = function(address) {
|
||||
if(this.primary == null) return false;
|
||||
return this.primary && this.primary.equals(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given address a secondary
|
||||
* @method
|
||||
* @param {string} address Server address
|
||||
* @return {boolean}
|
||||
*/
|
||||
State.prototype.isSecondary = function(address) {
|
||||
// Check if the server is a secondary at the moment
|
||||
for(var i = 0; i < this.secondaries.length; i++) {
|
||||
if(this.secondaries[i].equals(address)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given address a secondary
|
||||
* @method
|
||||
* @param {string} address Server address
|
||||
* @return {boolean}
|
||||
*/
|
||||
State.prototype.isPassive = function(address) {
|
||||
// Check if the server is a secondary at the moment
|
||||
for(var i = 0; i < this.passives.length; i++) {
|
||||
if(this.passives[i].equals(address)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the replicaset contain this server
|
||||
* @method
|
||||
* @param {string} address Server address
|
||||
* @return {boolean}
|
||||
*/
|
||||
State.prototype.contains = function(address) {
|
||||
if(this.primary && this.primary.equals(address)) return true;
|
||||
for(var i = 0; i < this.secondaries.length; i++) {
|
||||
if(this.secondaries[i].equals(address)) return true;
|
||||
}
|
||||
|
||||
for(var i = 0; i < this.arbiters.length; i++) {
|
||||
if(this.arbiters[i].equals(address)) return true;
|
||||
}
|
||||
|
||||
for(var i = 0; i < this.passives.length; i++) {
|
||||
if(this.passives[i].equals(address)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean out all dead connections
|
||||
* @method
|
||||
*/
|
||||
State.prototype.clean = function() {
|
||||
if(this.primary != null && !this.primary.isConnected()) {
|
||||
this.primary = null;
|
||||
}
|
||||
|
||||
// Filter out disconnected servers
|
||||
this.secondaries = this.secondaries.filter(function(s) {
|
||||
return s.isConnected();
|
||||
});
|
||||
|
||||
// Filter out disconnected servers
|
||||
this.arbiters = this.arbiters.filter(function(s) {
|
||||
return s.isConnected();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy state
|
||||
* @method
|
||||
*/
|
||||
State.prototype.destroy = function() {
|
||||
this.state = DESTROYED;
|
||||
if(this.primary) this.primary.destroy();
|
||||
this.secondaries.forEach(function(s) {
|
||||
s.destroy();
|
||||
});
|
||||
this.arbiters.forEach(function(s) {
|
||||
s.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove server from state
|
||||
* @method
|
||||
* @param {Server} Server to remove
|
||||
* @return {string} Returns type of server removed (primary|secondary)
|
||||
*/
|
||||
State.prototype.remove = function(server) {
|
||||
if(this.primary && this.primary.equals(server)) {
|
||||
this.primary = null;
|
||||
}
|
||||
|
||||
var length = this.arbiters.length;
|
||||
// Filter out the server from the arbiters
|
||||
this.arbiters = this.arbiters.filter(function(s) {
|
||||
return !s.equals(server);
|
||||
});
|
||||
if(this.arbiters.length < length) return 'arbiter';
|
||||
|
||||
var length = this.passives.length;
|
||||
// Filter out the server from the passives
|
||||
this.passives = this.passives.filter(function(s) {
|
||||
return !s.equals(server);
|
||||
});
|
||||
|
||||
// We have removed a passive
|
||||
if(this.passives.length < length) {
|
||||
// Ensure we removed it from the list of secondaries as well if it exists
|
||||
this.secondaries = this.secondaries.filter(function(s) {
|
||||
return !s.equals(server);
|
||||
});
|
||||
}
|
||||
|
||||
// Filter out the server from the secondaries
|
||||
this.secondaries = this.secondaries.filter(function(s) {
|
||||
return !s.equals(server);
|
||||
});
|
||||
|
||||
// Get the isMaster
|
||||
var isMaster = server.lastIsMaster();
|
||||
// Return primary if the server was primary
|
||||
if(isMaster.ismaster) return 'primary';
|
||||
if(isMaster.secondary) return 'secondary';
|
||||
if(isMaster.passive) return 'passive';
|
||||
return 'arbiter';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server by name
|
||||
* @method
|
||||
* @param {string} address Server address
|
||||
* @return {Server}
|
||||
*/
|
||||
State.prototype.get = function(server) {
|
||||
var found = false;
|
||||
// All servers to search
|
||||
var servers = this.primary ? [this.primary] : [];
|
||||
servers = servers.concat(this.secondaries);
|
||||
// Locate the server
|
||||
for(var i = 0; i < servers.length; i++) {
|
||||
if(servers[i].equals(server)) {
|
||||
return servers[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the servers in the set
|
||||
* @method
|
||||
* @param {boolean} [options.includeArbiters] Include Arbiters in returned server list
|
||||
* @return {array}
|
||||
*/
|
||||
State.prototype.getAll = function(options) {
|
||||
options = options || {};
|
||||
var servers = [];
|
||||
if(this.primary) servers.push(this.primary);
|
||||
servers = servers.concat(this.secondaries);
|
||||
|
||||
// Include the arbiters
|
||||
if(options.includeArbiters) {
|
||||
servers = servers.concat(this.arbiters);
|
||||
}
|
||||
|
||||
// return ;
|
||||
return servers;
|
||||
}
|
||||
|
||||
/**
|
||||
* All raw connections
|
||||
* @method
|
||||
* @param {boolean} [options.includeArbiters] Include Arbiters in returned server list
|
||||
* @return {array}
|
||||
*/
|
||||
State.prototype.getAllConnections = function(options) {
|
||||
options = options || {};
|
||||
var connections = [];
|
||||
if(this.primary) connections = connections.concat(this.primary.connections());
|
||||
this.secondaries.forEach(function(s) {
|
||||
connections = connections.concat(s.connections());
|
||||
})
|
||||
|
||||
// Include the arbiters
|
||||
if(options.includeArbiters) {
|
||||
this.arbiters.forEach(function(s) {
|
||||
connections = connections.concat(s.connections());
|
||||
})
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return JSON object
|
||||
* @method
|
||||
* @return {object}
|
||||
*/
|
||||
State.prototype.toJSON = function() {
|
||||
return {
|
||||
primary: this.primary ? this.primary.lastIsMaster().me : null
|
||||
, secondaries: this.secondaries.map(function(s) {
|
||||
return s.lastIsMaster().me
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last known ismaster document for this server
|
||||
* @method
|
||||
* @return {object}
|
||||
*/
|
||||
State.prototype.lastIsMaster = function() {
|
||||
if(this.primary) return this.primary.lastIsMaster();
|
||||
if(this.secondaries.length > 0) return this.secondaries[0].lastIsMaster();
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Promote server to primary
|
||||
* @method
|
||||
* @param {Server} server Server we wish to promote
|
||||
*/
|
||||
State.prototype.promotePrimary = function(server) {
|
||||
var currentServer = this.get(server);
|
||||
// Server does not exist in the state, add it as new primary
|
||||
if(currentServer == null) {
|
||||
this.primary = server;
|
||||
return;
|
||||
}
|
||||
|
||||
// We found a server, make it primary and remove it from the secondaries
|
||||
// Remove the server first
|
||||
this.remove(currentServer);
|
||||
// Set as primary
|
||||
this.primary = currentServer;
|
||||
}
|
||||
|
||||
var add = function(list, server) {
|
||||
// Check if the server is a secondary at the moment
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
if(list[i].equals(server)) return false;
|
||||
}
|
||||
|
||||
list.push(server);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add server to list of secondaries
|
||||
* @method
|
||||
* @param {Server} server Server we wish to add
|
||||
*/
|
||||
State.prototype.addSecondary = function(server) {
|
||||
return add(this.secondaries, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add server to list of arbiters
|
||||
* @method
|
||||
* @param {Server} server Server we wish to add
|
||||
*/
|
||||
State.prototype.addArbiter = function(server) {
|
||||
return add(this.arbiters, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add server to list of passives
|
||||
* @method
|
||||
* @param {Server} server Server we wish to add
|
||||
*/
|
||||
State.prototype.addPassive = function(server) {
|
||||
return add(this.passives, server);
|
||||
}
|
||||
|
||||
var compareObjectIds = function(id1, id2) {
|
||||
var a = new Buffer(id1.toHexString(), 'hex');
|
||||
var b = new Buffer(id2.toHexString(), 'hex');
|
||||
|
||||
if(a === b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(typeof Buffer.compare === 'function') {
|
||||
return Buffer.compare(a, b);
|
||||
}
|
||||
|
||||
var x = a.length;
|
||||
var y = b.length;
|
||||
var len = Math.min(x, y);
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i !== len) {
|
||||
x = a[i];
|
||||
y = b[i];
|
||||
}
|
||||
|
||||
return x < y ? -1 : y < x ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the state given a specific ismaster result
|
||||
* @method
|
||||
* @param {object} ismaster IsMaster result
|
||||
* @param {Server} server IsMaster Server source
|
||||
*/
|
||||
State.prototype.update = function(ismaster, server) {
|
||||
var self = this;
|
||||
// Not in a known connection valid state
|
||||
if((!ismaster.ismaster && !ismaster.secondary && !ismaster.arbiterOnly) || !Array.isArray(ismaster.hosts)) {
|
||||
// Remove the state
|
||||
var result = self.remove(server);
|
||||
if(self.state == CONNECTED) {
|
||||
if(self.logger.isInfo()) self.logger.info(f('[%s] removing %s from set', self.id, ismaster.me));
|
||||
self.replSet.emit('left', self.remove(server), server);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the setName if it's not set from the first server
|
||||
if(self.setName == null && ismaster.setName) {
|
||||
if(self.logger.isInfo()) self.logger.info(f('[%s] setting setName to %s', self.id, ismaster.setName));
|
||||
self.setName = ismaster.setName;
|
||||
}
|
||||
|
||||
// Check if the replicaset name matches the provided one
|
||||
if(ismaster.setName && self.setName != ismaster.setName) {
|
||||
if(self.logger.isError()) self.logger.error(f('[%s] server in replset %s is not part of the specified setName %s', self.id, ismaster.setName, self.setName));
|
||||
self.remove(server);
|
||||
self.replSet.emit('error', new MongoError("provided setName for Replicaset Connection does not match setName found in server seedlist"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Log information
|
||||
if(self.logger.isInfo()) self.logger.info(f('[%s] updating replicaset state %s', self.id, JSON.stringify(this)));
|
||||
|
||||
// It's a master set it
|
||||
if(ismaster.ismaster && self.setName == ismaster.setName && !self.isPrimary(ismaster.me)) {
|
||||
// Check if the electionId is not null
|
||||
if(ismaster.electionId instanceof ObjectId && self.electionId instanceof ObjectId) {
|
||||
if(compareObjectIds(self.electionId, ismaster.electionId) == -1) {
|
||||
self.electionId = ismaster.electionId;
|
||||
} else if(compareObjectIds(self.electionId, ismaster.electionId) == 0) {
|
||||
self.electionId = ismaster.electionId;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Initial electionId
|
||||
if(ismaster.electionId instanceof ObjectId && self.electionId == null) {
|
||||
self.electionId = ismaster.electionId;
|
||||
}
|
||||
|
||||
// Promote to primary
|
||||
self.promotePrimary(server);
|
||||
// Log change of primary
|
||||
if(self.logger.isInfo()) self.logger.info(f('[%s] promoting %s to primary', self.id, ismaster.me));
|
||||
// Emit primary
|
||||
self.replSet.emit('joined', 'primary', this.primary);
|
||||
|
||||
// We are connected
|
||||
if(self.state == CONNECTING) {
|
||||
self.state = CONNECTED;
|
||||
self.replSet.emit('connect', self.replSet);
|
||||
} else {
|
||||
self.state = CONNECTED;
|
||||
self.replSet.emit('reconnect', server);
|
||||
}
|
||||
} else if(!ismaster.ismaster && self.setName == ismaster.setName
|
||||
&& ismaster.arbiterOnly) {
|
||||
if(self.addArbiter(server)) {
|
||||
if(self.logger.isInfo()) self.logger.info(f('[%s] promoting %s to arbiter', self.id, ismaster.me));
|
||||
self.replSet.emit('joined', 'arbiter', server);
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
} else if(!ismaster.ismaster && self.setName == ismaster.setName
|
||||
&& ismaster.secondary && ismaster.passive) {
|
||||
if(self.addPassive(server) && self.addSecondary(server)) {
|
||||
if(self.logger.isInfo()) self.logger.info(f('[%s] promoting %s to passive', self.id, ismaster.me));
|
||||
self.replSet.emit('joined', 'passive', server);
|
||||
|
||||
// If we have secondaryOnlyConnectionAllowed and just a passive it's
|
||||
// still a valid connection
|
||||
if(self.secondaryOnlyConnectionAllowed && self.state == CONNECTING) {
|
||||
self.state = CONNECTED;
|
||||
self.replSet.emit('connect', self.replSet);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
} else if(!ismaster.ismaster && self.setName == ismaster.setName
|
||||
&& ismaster.secondary) {
|
||||
if(self.addSecondary(server)) {
|
||||
if(self.logger.isInfo()) self.logger.info(f('[%s] promoting %s to secondary', self.id, ismaster.me));
|
||||
self.replSet.emit('joined', 'secondary', server);
|
||||
|
||||
if(self.secondaryOnlyConnectionAllowed && self.state == CONNECTING) {
|
||||
self.state = CONNECTED;
|
||||
self.replSet.emit('connect', self.replSet);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return update applied
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = State;
|
||||
1264
node_modules/mongodb-core/lib/topologies/server.js
generated
vendored
Normal file
1264
node_modules/mongodb-core/lib/topologies/server.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
93
node_modules/mongodb-core/lib/topologies/session.js
generated
vendored
Normal file
93
node_modules/mongodb-core/lib/topologies/session.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
|
||||
var inherits = require('util').inherits
|
||||
, f = require('util').format
|
||||
, EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* Creates a new Authentication Session
|
||||
* @class
|
||||
* @param {object} [options] Options for the session
|
||||
* @param {{Server}|{ReplSet}|{Mongos}} topology The topology instance underpinning the session
|
||||
*/
|
||||
var Session = function(options, topology) {
|
||||
this.options = options;
|
||||
this.topology = topology;
|
||||
|
||||
// Add event listener
|
||||
EventEmitter.call(this);
|
||||
}
|
||||
|
||||
inherits(Session, EventEmitter);
|
||||
|
||||
/**
|
||||
* Execute a command
|
||||
* @method
|
||||
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
|
||||
* @param {object} cmd The command hash
|
||||
* @param {object} [options.readPreference] Specify read preference if command supports it
|
||||
* @param {object} [options.connection] Specify connection object to execute command against
|
||||
* @param {opResultCallback} callback A callback function
|
||||
*/
|
||||
Session.prototype.command = function(ns, cmd, options, callback) {
|
||||
this.topology.command(ns, cmd, options, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert one or more documents
|
||||
* @method
|
||||
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
|
||||
* @param {array} ops An array of documents to insert
|
||||
* @param {boolean} [options.ordered=true] Execute in order or out of order
|
||||
* @param {object} [options.writeConcern={}] Write concern for the operation
|
||||
* @param {opResultCallback} callback A callback function
|
||||
*/
|
||||
Session.prototype.insert = function(ns, ops, options, callback) {
|
||||
this.topology.insert(ns, ops, options, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform one or more update operations
|
||||
* @method
|
||||
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
|
||||
* @param {array} ops An array of updates
|
||||
* @param {boolean} [options.ordered=true] Execute in order or out of order
|
||||
* @param {object} [options.writeConcern={}] Write concern for the operation
|
||||
* @param {opResultCallback} callback A callback function
|
||||
*/
|
||||
Session.prototype.update = function(ns, ops, options, callback) {
|
||||
this.topology.update(ns, ops, options, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform one or more remove operations
|
||||
* @method
|
||||
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
|
||||
* @param {array} ops An array of removes
|
||||
* @param {boolean} [options.ordered=true] Execute in order or out of order
|
||||
* @param {object} [options.writeConcern={}] Write concern for the operation
|
||||
* @param {opResultCallback} callback A callback function
|
||||
*/
|
||||
Session.prototype.remove = function(ns, ops, options, callback) {
|
||||
this.topology.remove(ns, ops, options, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform one or more remove operations
|
||||
* @method
|
||||
* @param {string} ns The MongoDB fully qualified namespace (ex: db1.collection1)
|
||||
* @param {{object}|{Long}} cmd Can be either a command returning a cursor or a cursorId
|
||||
* @param {object} [options.batchSize=0] Batchsize for the operation
|
||||
* @param {array} [options.documents=[]] Initial documents list for cursor
|
||||
* @param {boolean} [options.tailable=false] Tailable flag set
|
||||
* @param {boolean} [options.oplogReply=false] oplogReply flag set
|
||||
* @param {boolean} [options.awaitdata=false] awaitdata flag set
|
||||
* @param {boolean} [options.exhaust=false] exhaust flag set
|
||||
* @param {boolean} [options.partial=false] partial flag set
|
||||
* @param {opResultCallback} callback A callback function
|
||||
*/
|
||||
Session.prototype.cursor = function(ns, cmd, options) {
|
||||
return this.topology.cursor(ns, cmd, options);
|
||||
}
|
||||
|
||||
module.exports = Session;
|
||||
276
node_modules/mongodb-core/lib/topologies/strategies/ping.js
generated
vendored
Normal file
276
node_modules/mongodb-core/lib/topologies/strategies/ping.js
generated
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
"use strict";
|
||||
|
||||
var Logger = require('../../connection/logger')
|
||||
, EventEmitter = require('events').EventEmitter
|
||||
, inherits = require('util').inherits
|
||||
, f = require('util').format;
|
||||
|
||||
/**
|
||||
* Creates a new Ping read preference strategy instance
|
||||
* @class
|
||||
* @param {number} [options.pingInterval=5000] Ping interval to check the response time to the different servers
|
||||
* @param {number} [options.acceptableLatency=250] Acceptable latency for selecting a server for reading (in milliseconds)
|
||||
* @return {Ping} A cursor instance
|
||||
*/
|
||||
var Ping = function(options) {
|
||||
// Add event listener
|
||||
EventEmitter.call(this);
|
||||
|
||||
// Contains the ping state
|
||||
this.s = {
|
||||
// Contains all the ping data
|
||||
pings: {}
|
||||
// Set no options if none provided
|
||||
, options: options || {}
|
||||
// Logger
|
||||
, logger: Logger('Ping', options)
|
||||
// Ping interval
|
||||
, pingInterval: options.pingInterval || 10000
|
||||
, acceptableLatency: options.acceptableLatency || 15
|
||||
// Debug options
|
||||
, debug: typeof options.debug == 'boolean' ? options.debug : false
|
||||
// Index
|
||||
, index: 0
|
||||
// Current ping time
|
||||
, lastPing: null
|
||||
|
||||
}
|
||||
|
||||
// Log the options set
|
||||
if(this.s.logger.isDebug()) this.s.logger.debug(f('ping strategy interval [%s], acceptableLatency [%s]', this.s.pingInterval, this.s.acceptableLatency));
|
||||
|
||||
// If we have enabled debug
|
||||
if(this.s.debug) {
|
||||
// Add access to the read Preference Strategies
|
||||
Object.defineProperty(this, 'data', {
|
||||
enumerable: true, get: function() { return this.s.pings; }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Ping, EventEmitter);
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
var filterByTags = function(readPreference, servers) {
|
||||
if(readPreference.tags == null) return servers;
|
||||
var filteredServers = [];
|
||||
var tags = readPreference.tags;
|
||||
|
||||
// Iterate over all the servers
|
||||
for(var i = 0; i < servers.length; i++) {
|
||||
var serverTag = servers[i].lastIsMaster().tags || {};
|
||||
// Did we find the a matching server
|
||||
var found = true;
|
||||
// Check if the server is valid
|
||||
for(var name in tags) {
|
||||
if(serverTag[name] != tags[name]) found = false;
|
||||
}
|
||||
|
||||
// Add to candidate list
|
||||
if(found) filteredServers.push(servers[i]);
|
||||
}
|
||||
|
||||
// Returned filtered servers
|
||||
return filteredServers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick a server
|
||||
* @method
|
||||
* @param {State} set The current replicaset state object
|
||||
* @param {ReadPreference} readPreference The current readPreference object
|
||||
* @param {readPreferenceResultCallback} callback The callback to return the result from the function
|
||||
* @return {object}
|
||||
*/
|
||||
Ping.prototype.pickServer = function(set, readPreference) {
|
||||
var self = this;
|
||||
// Only get primary and secondaries as seeds
|
||||
var seeds = {};
|
||||
var servers = [];
|
||||
if(set.primary) {
|
||||
servers.push(set.primary);
|
||||
}
|
||||
|
||||
for(var i = 0; i < set.secondaries.length; i++) {
|
||||
servers.push(set.secondaries[i]);
|
||||
}
|
||||
|
||||
// Filter by tags
|
||||
servers = filterByTags(readPreference, servers);
|
||||
|
||||
// Transform the list
|
||||
var serverList = [];
|
||||
// for(var name in seeds) {
|
||||
for(var i = 0; i < servers.length; i++) {
|
||||
serverList.push({name: servers[i].name, time: self.s.pings[servers[i].name] || 0});
|
||||
}
|
||||
|
||||
// Sort by time
|
||||
serverList.sort(function(a, b) {
|
||||
return a.time > b.time;
|
||||
});
|
||||
|
||||
// Locate lowest time (picked servers are lowest time + acceptable Latency margin)
|
||||
var lowest = serverList.length > 0 ? serverList[0].time : 0;
|
||||
|
||||
// Filter by latency
|
||||
serverList = serverList.filter(function(s) {
|
||||
return s.time <= lowest + self.s.acceptableLatency;
|
||||
});
|
||||
|
||||
// No servers, default to primary
|
||||
if(serverList.length == 0 && set.primary) {
|
||||
if(self.s.logger.isInfo()) self.s.logger.info(f('picked primary server [%s]', set.primary.name));
|
||||
return set.primary;
|
||||
} else if(serverList.length == 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
// We picked first server
|
||||
if(self.s.logger.isInfo()) self.s.logger.info(f('picked server [%s] with ping latency [%s]', serverList[0].name, serverList[0].time));
|
||||
|
||||
// Add to the index
|
||||
self.s.index = self.s.index + 1;
|
||||
// Select the index
|
||||
self.s.index = self.s.index % serverList.length;
|
||||
// Return the first server of the sorted and filtered list
|
||||
return set.get(serverList[self.s.index].name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start of an operation
|
||||
* @method
|
||||
* @param {Server} server The server the operation is running against
|
||||
* @param {object} query The operation running
|
||||
* @param {Date} date The start time of the operation
|
||||
* @return {object}
|
||||
*/
|
||||
Ping.prototype.startOperation = function(server, query, date) {
|
||||
}
|
||||
|
||||
/**
|
||||
* End of an operation
|
||||
* @method
|
||||
* @param {Server} server The server the operation is running against
|
||||
* @param {error} err An error from the operation
|
||||
* @param {object} result The result from the operation
|
||||
* @param {Date} date The start time of the operation
|
||||
* @return {object}
|
||||
*/
|
||||
Ping.prototype.endOperation = function(server, err, result, date) {
|
||||
}
|
||||
|
||||
/**
|
||||
* High availability process running
|
||||
* @method
|
||||
* @param {State} set The current replicaset state object
|
||||
* @param {resultCallback} callback The callback to return the result from the function
|
||||
* @return {object}
|
||||
*/
|
||||
Ping.prototype.ha = function(topology, state, callback) {
|
||||
var self = this;
|
||||
var servers = state.getAll();
|
||||
var count = servers.length;
|
||||
|
||||
// No servers return
|
||||
if(servers.length == 0) return callback(null, null);
|
||||
|
||||
// Return if we have not yet reached the ping interval
|
||||
if(self.s.lastPing != null) {
|
||||
var diff = new Date().getTime() - self.s.lastPing.getTime();
|
||||
if(diff < self.s.pingInterval) return callback(null, null);
|
||||
}
|
||||
|
||||
// Execute operation
|
||||
var operation = function(_server) {
|
||||
var start = new Date();
|
||||
// Execute ping against server
|
||||
_server.command('system.$cmd', {ismaster:1}, function(err, r) {
|
||||
count = count - 1;
|
||||
var time = new Date().getTime() - start.getTime();
|
||||
self.s.pings[_server.name] = time;
|
||||
// Log info for debug
|
||||
if(self.s.logger.isDebug()) self.s.logger.debug(f('ha latency for server [%s] is [%s] ms', _server.name, time));
|
||||
// We are done with all the servers
|
||||
if(count == 0) {
|
||||
// Emit ping event
|
||||
topology.emit('ping', err, r ? r.result : null);
|
||||
// Update the last ping time
|
||||
self.s.lastPing = new Date();
|
||||
// Return
|
||||
callback(null, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Let's ping all servers
|
||||
while(servers.length > 0) {
|
||||
operation(servers.shift());
|
||||
}
|
||||
}
|
||||
|
||||
var removeServer = function(self, server) {
|
||||
delete self.s.pings[server.name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Server connection closed
|
||||
* @method
|
||||
* @param {Server} server The server that closed
|
||||
*/
|
||||
Ping.prototype.close = function(server) {
|
||||
removeServer(this, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Server connection errored out
|
||||
* @method
|
||||
* @param {Server} server The server that errored out
|
||||
*/
|
||||
Ping.prototype.error = function(server) {
|
||||
removeServer(this, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Server connection timeout
|
||||
* @method
|
||||
* @param {Server} server The server that timed out
|
||||
*/
|
||||
Ping.prototype.timeout = function(server) {
|
||||
removeServer(this, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Server connection happened
|
||||
* @method
|
||||
* @param {Server} server The server that connected
|
||||
* @param {resultCallback} callback The callback to return the result from the function
|
||||
*/
|
||||
Ping.prototype.connect = function(server, callback) {
|
||||
var self = this;
|
||||
// Get the command start date
|
||||
var start = new Date();
|
||||
// Execute ping against server
|
||||
server.command('system.$cmd', {ismaster:1}, function(err, r) {
|
||||
var time = new Date().getTime() - start.getTime();
|
||||
self.s.pings[server.name] = time;
|
||||
// Log info for debug
|
||||
if(self.s.logger.isDebug()) self.s.logger.debug(f('connect latency for server [%s] is [%s] ms', server.name, time));
|
||||
// Set last ping
|
||||
self.s.lastPing = new Date();
|
||||
// Done, return
|
||||
callback(null, null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a result from a readPreference strategy
|
||||
*
|
||||
* @callback readPreferenceResultCallback
|
||||
* @param {error} error An error object. Set to null if no error present
|
||||
* @param {Server} server The server picked by the strategy
|
||||
*/
|
||||
|
||||
module.exports = Ping;
|
||||
Reference in New Issue
Block a user