Пример #1
0
        public override bool OnStart()
        {
            DiagnosticsHelper.TraceInformation("MongoWorkerRole onstart called");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            RoleEnvironment.Changing += RoleEnvironmentChanging;
            RoleEnvironment.Changed  += RoleEnvironmentChanged;

            replicaSetName = RoleEnvironment.GetConfigurationSettingValue(Constants.ReplicaSetNameSetting);
            instanceId     = ConnectionUtilities.ParseNodeInstanceId(RoleEnvironment.CurrentRoleInstance.Id);

            DiagnosticsHelper.TraceInformation("ReplicaSetName={0}, InstanceId={1}",
                                               replicaSetName, instanceId);

            SetHostAndPort();
            DiagnosticsHelper.TraceInformation("Obtained host={0}, port={1}", mongodHost, mongodPort);

            StartMongoD();
            DiagnosticsHelper.TraceInformation("Mongod process started");

            // Need to ensure MongoD is up here
            DatabaseHelper.EnsureMongodIsListening(replicaSetName, instanceId, mongodPort);

            if ((instanceId == 0) && !DatabaseHelper.IsReplicaSetInitialized(mongodPort))
            {
                try
                {
                    DatabaseHelper.RunInitializeCommandLocally(replicaSetName, mongodPort);
                    DiagnosticsHelper.TraceInformation("RSInit issued successfully");
                }
                catch (MongoCommandException e)
                {
                    //Ignore exceptions caught on rs init for now
                    DiagnosticsHelper.TraceWarning(
                        "Exception {0} on RSInit with {1}",
                        e.Message, e.StackTrace);
                }
            }

            DiagnosticsHelper.TraceInformation("Done with OnStart");
            return(true);
        }
Пример #2
0
        private static AvailableNodes GetAvailableNodes(string rsName)
        {
            var nodes = new AvailableNodes();

            foreach (var instance in RoleEnvironment.Roles[Constants.MongoDBWorkerRoleName].Instances)
            {
                nodes.Add(new NodeAlias()
                {
                    Alias     = ConnectionUtilities.GetNodeAlias(rsName, ConnectionUtilities.ParseNodeInstanceId(instance.Id)),
                    IpAddress = instance.InstanceEndpoints[Constants.MongodPortSetting].IPEndpoint.Address.ToString()
                });
            }
            return(nodes);
        }