internal NodeGroup(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig) { GroupDefinition = groupDefinition; Activated = groupDefinition.Activated; _clusterByRange = groupDefinition.UseIdRanges; _forwardingConfig = forwardingConfig; RelayNodeClusterDefinition myClusterDefinition = NodeManager.Instance.GetMyNodeClusterDefinition(); foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters) { NodeCluster nodeCluster = new NodeCluster(clusterDefintion, nodeConfig, this, forwardingConfig); if (clusterDefintion == myClusterDefinition) { MyCluster = nodeCluster; } Clusters.Add(nodeCluster); } _nodeReselectTimerCallback = new System.Threading.TimerCallback(NodeReselectTimer_Elapsed); if (_nodeReselectTimer == null) { _nodeReselectTimer = new System.Threading.Timer(_nodeReselectTimerCallback); } _nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds); QueueTimerCallback = new System.Threading.TimerCallback(QueueTimer_Elapsed); if (QueueTimer == null) { QueueTimer = new System.Threading.Timer(QueueTimerCallback); } QueueTimer.Change(DequeueIntervalMilliseconds, DequeueIntervalMilliseconds); }
/// <summary> /// Initializes the component for use using the supplied configuration. /// </summary> /// <param name="config">The config.</param> /// <exception cref="ArgumentNullException">Thrown if the config parameter is null.</exception> /// <exception cref="InvalidOperationException">Thrown if the RelayNode passes in a configuration with a missing section for this component.</exception> private void LoadConfig(RelayNodeConfig config) { if (config == null) { return; } if (config.RelayComponents == null) { throw new InvalidOperationException("No component configurations were found in the RelayNodeConfig passed to this component."); } var flexForwarderConfig = config.RelayComponents.GetConfigFor(GetComponentName()) as FlexForwarderConfig; var groupName = (flexForwarderConfig != null) ? flexForwarderConfig.GroupName : null; var flexCacheClient = new FlexCacheClient(groupName); if (_flexCacheClient == null || flexCacheClient.GroupName != _flexCacheClient.GroupName) { _flexCacheClient = flexCacheClient; Log.InfoFormat("FlexCache will use group: \"{0}\".", _flexCacheClient.GroupName); if (_counters != null) { _counters.RemoveInstance(); } _counters = Counters.GetInstance(_flexCacheClient.GroupName); } }
internal NodeGroupCollection(RelayNodeGroupDefinitionCollection groupDefinitions, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig) : base() { foreach (RelayNodeGroupDefinition groupDefinition in groupDefinitions) { Add(new NodeGroup(groupDefinition, nodeConfig, forwardingConfig)); } }
/// <summary> /// Called when a configuration object needs to be applied. /// </summary> /// <param name="updatedConfig">The updated config.</param> public void UpdateConfig(RelayNodeConfig updatedConfig) { var newMaps = new Dictionary <string, ModuloHashMap <RelayEndPoint> >(); var relayNodeMapping = updatedConfig.RelayNodeMapping; if (relayNodeMapping != null) { if (relayNodeMapping.Validate()) { var groups = relayNodeMapping.RelayNodeGroups; foreach (var group in groups) { newMaps.Add(group.Name, new ModuloHashMap <RelayEndPoint>()); for (int clusterIndex = 0; clusterIndex < group.RelayNodeClusters.Length; ++clusterIndex) { foreach (var node in group.RelayNodeClusters[clusterIndex].RelayNodes) { newMaps[group.Name].Add(clusterIndex, new RelayEndPoint(node, group)); } } newMaps[group.Name].Modulo = group.RelayNodeClusters.Length; newMaps[group.Name].Shuffle(); } } } Thread.MemoryBarrier(); _hashMaps = newMaps; }
internal NodeGroup(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig) { GroupDefinition = groupDefinition; Activated = groupDefinition.Activated; _clusterByRange = groupDefinition.UseIdRanges; _forwardingConfig = forwardingConfig; NodeSelectionHopWindowSize = groupDefinition.NodeSelectionHopWindowSize; RelayNodeClusterDefinition myClusterDefinition = NodeManager.Instance.GetMyNodeClusterDefinition(); foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters) { NodeCluster nodeCluster = new NodeCluster(clusterDefintion, nodeConfig, this, forwardingConfig); if (clusterDefintion == myClusterDefinition) { MyCluster = nodeCluster; } Clusters.Add(nodeCluster); } _nodeReselectTimerCallback = new System.Threading.TimerCallback(NodeReselectTimer_Elapsed); if (_nodeReselectTimer == null) { _nodeReselectTimer = new System.Threading.Timer(_nodeReselectTimerCallback); } _nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds); QueueTimerCallback = new System.Threading.TimerCallback(QueueTimer_Elapsed); if (QueueTimer == null) { QueueTimer = new System.Threading.Timer(QueueTimerCallback); } QueueTimer.Change(DequeueIntervalMilliseconds, DequeueIntervalMilliseconds); }
private void GetConfig() { EventHandler reloadEventHandler = ReloadConfig; configuration = RelayNodeConfig.GetRelayNodeConfig(reloadEventHandler); if (configuration != null) { if (configuration.GetMyNode() != null) { MyZone = configuration.GetMyNode().Zone; } instanceName = configuration.InstanceName; if (configuration.TransportSettings != null) { portNumber = configuration.TransportSettings.ListenPort; httpPortNumber = configuration.TransportSettings.HttpListenPort; } } else { if (log.IsErrorEnabled) { log.Error("NO CONFIG SECTION FOUND, SERVICE NOT STARTING."); } } }
private void SetClusterAddresses(RelayNodeConfig config) { HashSet <IPAddress> localClusterAddresses = null; if (config != null) { var cluster = config.GetMyCluster(); if (cluster != null) { localClusterAddresses = new HashSet <IPAddress>(); foreach (var clusterNode in cluster.RelayNodes) { if (clusterNode.Activated) { var addr = clusterNode.IPAddress; if (!localClusterAddresses.Contains(addr)) { localClusterAddresses.Add(addr); } } } } } clusterAddresses = localClusterAddresses; }
private void InitializeInstance(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary <string, Dictionary <string, MessageQueue> > errorQueues) { Counters = new ForwardingCounters(); if (config != null) { //without this we'll get a null ref exception if (forwardingConfig == null) { throw new ArgumentNullException("forwardingConfig", "Requires a forwardingConfig to initialize"); } Config = config; ForwardingConfig = forwardingConfig; _zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions; Counters.Initialize(Config.InstanceName); if (InMessageDispatcher != null) { if (_log.IsInfoEnabled) { _log.Info("Relay Forwarder Node Manager Initialized with non-null Dispatcher."); } } else { InMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder"); } if (OutMessageDispatcher == null) { OutMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwader Out Messages"); } NodeGroup.MaximumQueuedItems = forwardingConfig.MaximumTaskQueueDepth; BuildNodeGroups(config, errorQueues); if (config.MyAddresses != null && config.MyAddresses.Count > 0) { for (int i = 0; i < config.MyAddresses.Count; i++) { AddressFamily family = config.MyAddresses[i].AddressFamily; if (family == AddressFamily.InterNetwork && !IPAddress.Loopback.Equals(config.MyAddresses[i]) ) { MyIpAddress = config.MyAddresses[i]; break; } } } _queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000); _aggregateCounterTickTimer = new Timer(AggregateCounterTicker, null, 500, 500); _myNodeDefinition = GetMyNodeDefinition(); } }
/// <summary> /// Updates the configuration used for type settings. /// </summary> /// <param name="updatedConfig">The updated config.</param> public void UpdateConfig(RelayNodeConfig updatedConfig) { if (updatedConfig != null && updatedConfig.TypeSettings != null) { RelayMessage.SetCompressionImplementation(updatedConfig.TypeSettings.Compressor); _configuration = updatedConfig; } }
internal void ReloadMapping(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig newConfig, ForwardingConfig newForwardingConfig) { RelayNodeClusterDefinition myClusterDefinition = newConfig.GetMyCluster(); Activated = groupDefinition.Activated; GroupDefinition = groupDefinition; _clusterByRange = groupDefinition.UseIdRanges; _forwardingConfig = newForwardingConfig; if (groupDefinition.RelayNodeClusters.Length == Clusters.Count) { //same number of clusters, just let the clusters rebuild themselves. the clusters will entirely rebuild, so shuffinling around servers should be okay if (_log.IsDebugEnabled) { _log.DebugFormat("Rebuilding existing clusters in group {0}.", groupDefinition.Name); } for (int i = 0; i < groupDefinition.RelayNodeClusters.Length; i++) { Clusters[i].ReloadMapping(groupDefinition.RelayNodeClusters[i], newConfig, newForwardingConfig); if (groupDefinition.RelayNodeClusters[i] == myClusterDefinition) { MyCluster = Clusters[i]; } } if (myClusterDefinition == null && MyCluster != null) { if (_log.IsInfoEnabled) { _log.InfoFormat("Group {0} no longer contains this server. Removing.", GroupName); } //this group no longer contains "me". If it DID contain "me", it would've been set above. MyCluster = null; } } else { //build new clusters and replace the existing ones with them if (_log.IsInfoEnabled) { _log.InfoFormat("Number of clusters in group {0} changed, rebuilding.", groupDefinition.Name); } NodeCluster myCluster = null; List <NodeCluster> newClusters = new List <NodeCluster>(); foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters) { NodeCluster nodeCluster = new NodeCluster(clusterDefintion, newConfig, this, newForwardingConfig); if (clusterDefintion == myClusterDefinition) { myCluster = nodeCluster; } newClusters.Add(nodeCluster); } Clusters = newClusters; MyCluster = myCluster; } _nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds); }
internal NodeCluster(RelayNodeClusterDefinition clusterDefinition, RelayNodeConfig nodeConfig, NodeGroup nodeGroup, ForwardingConfig forwardingConfig) { _nodeGroup = nodeGroup; _clusterDefinition = clusterDefinition; _minimumId = clusterDefinition.MinId; _maximumId = clusterDefinition.MaxId; RelayNodeDefinition meDefinition = nodeConfig.GetMyNode(); _meInThisCluster = false; _localZone = nodeConfig.GetLocalZone(); _zoneDefinitions = nodeConfig.RelayNodeMapping.ZoneDefinitions; foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes) { if (meDefinition == nodeDefinition) { _meInThisCluster = true; } } DispatcherQueue nodeInQueue, nodeOutQueue; if (_meInThisCluster) { GetMessageQueuesFor(GetMessageQueueNameFor(meDefinition), clusterDefinition, NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher, out nodeInQueue, out nodeOutQueue); Me = new Node(meDefinition, nodeGroup, this, forwardingConfig, nodeInQueue, nodeOutQueue); } ushort maxDetectedZone = _localZone; foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes) { if (nodeDefinition != meDefinition) { GetMessageQueuesFor(GetMessageQueueNameFor(nodeDefinition), clusterDefinition, NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher, out nodeInQueue, out nodeOutQueue); Node node = new Node(nodeDefinition, nodeGroup, this, forwardingConfig, nodeInQueue, nodeOutQueue); Nodes.Add(node); if (node.Zone > maxDetectedZone) { maxDetectedZone = node.Zone; } } } _nodesByZone = CalculateNodesByZone(Nodes, maxDetectedZone); }
/// <summary> /// Initializes the Index Cache config. /// </summary> /// <param name="config">The config.</param> /// <returns>Index Cache Configuration</returns> private static CacheIndexV3StorageConfiguration InitializeConfig(RelayNodeConfig config) { CacheIndexV3StorageConfiguration configObj = config.RelayComponents.GetConfigFor(COMPONENT_NAME) as CacheIndexV3StorageConfiguration; if (configObj != null) { configObj.SanityCheckAndInitializeCustomFields(); } return(configObj); }
internal static void Initialize(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary<string, Dictionary<string, MessageQueue>> errorQueues) { lock (_instanceLock) { if (!_initialized) { Instance.InitializeInstance(config, forwardingConfig, errorQueues); _initialized = true; } } }
private void InitializeInstance(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary<string, Dictionary<string, MessageQueue>> errorQueues) { Counters = new ForwardingCounters(); if (config != null) { //without this we'll get a null ref exception if (forwardingConfig == null) throw new ArgumentNullException("forwardingConfig", "Requires a forwardingConfig to initialize"); Config = config; ForwardingConfig = forwardingConfig; _zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions; Counters.Initialize(Config.InstanceName); if (InMessageDispatcher != null) { if (_log.IsInfoEnabled) _log.Info("Relay Forwarder Node Manager Initialized with non-null Dispatcher."); } else { InMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder"); } if (OutMessageDispatcher == null) { OutMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwader Out Messages"); } NodeGroup.MaximumQueuedItems = forwardingConfig.MaximumTaskQueueDepth; BuildNodeGroups(config, errorQueues); if (config.MyAddresses != null && config.MyAddresses.Count > 0) { for (int i = 0; i < config.MyAddresses.Count; i++) { AddressFamily family = config.MyAddresses[i].AddressFamily; if (family == AddressFamily.InterNetwork && !IPAddress.Loopback.Equals(config.MyAddresses[i]) ) { MyIpAddress = config.MyAddresses[i]; break; } } } _queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000); _aggregateCounterTickTimer = new Timer(AggregateCounterTicker, null, 500, 500); _myNodeDefinition = GetMyNodeDefinition(); } }
internal static void Initialize(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary <string, Dictionary <string, MessageQueue> > errorQueues) { lock (_instanceLock) { if (!_initialized) { Instance.InitializeInstance(config, forwardingConfig, errorQueues); _initialized = true; } } }
/// <summary> /// Initializes the compress options. /// </summary> /// <param name="config">The config.</param> /// <returns>CompressOptions</returns> private static Dictionary <short, bool> InitializeCompressOptions(RelayNodeConfig config) { Dictionary <short, bool> compressOptions = new Dictionary <short, bool>(); if (config != null) { foreach (TypeSetting typeSetting in config.TypeSettings.TypeSettingCollection) { compressOptions.Add(typeSetting.TypeId, typeSetting.Compress); } } return(compressOptions); }
/// <summary> /// this (or <see cref="ReloadConfig"/>) gets called (depending) when the TypeSettings.Config file /// are changed. /// </summary> /// <remarks> /// Added: craigbro /// cachedTypeSettings now held with the forwarder for reference of /// exceptions on Synchronous "in" messages. /// To reload, we just null out the cached TypeSettingsCollection object and the /// accessor will reload it on next call /// While ConfigurationManager.GetSection is quite performant after the 1st hit, /// keeping them cached is about twice as fast. /// </remarks> /// <param name="config"></param> /// <param name="runState"></param> private void LoadConfig(RelayNodeConfig config, ComponentRunState runState) { if (config != null) { if (config.RelayComponents != null) { object configObject = config.RelayComponents.GetConfigFor(GetComponentName()); ForwardingConfig forwardingConfig = configObject as ForwardingConfig; if (forwardingConfig == null) { if (log.IsInfoEnabled) { log.Info("No forwarding configuration supplied. Using defaults."); } forwardingConfig = new ForwardingConfig(); } NodeManager.Initialize(config, forwardingConfig, GetErrorQueues(runState)); TypeSettingCollection typeSettingCollection = null; if (NodeManager.Instance.Config != null) { if (NodeManager.Instance.Config.TypeSettings != null) { typeSettingCollection = NodeManager.Instance.Config.TypeSettings.TypeSettingCollection; } } TypeSpecificStatisticsManager.Initialize(typeSettingCollection); _enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets; _myNodeDefinition = NodeManager.Instance.GetMyNodeDefinition(); _myZone = Node.DetermineZone(_myNodeDefinition); short maxTypeId = 0; if (config.TypeSettings != null) { maxTypeId = config.TypeSettings.MaxTypeId; } DebugWriter.SetTraceSettings(maxTypeId, forwardingConfig.TraceSettings); DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod; DebugWriter.WriteMessageTrace = forwardingConfig.WriteMessageTrace; } else { NodeManager.Initialize(null, null, null); TypeSpecificStatisticsManager.Initialize(null); } } else { NodeManager.Initialize(null, null, null); TypeSpecificStatisticsManager.Initialize(null); } }
private void UpdateConfig(RelayNodeConfig config) { if (config != null) { _log.Info("Loading RelayNodeConfig."); _servers.UpdateConfig(config); _typeSettings.UpdateConfig(config); } else { _log.Error("Attempt to reload a RelayNode config with null config"); } }
/// <summary> /// this (or <see cref="LoadConfig"/>) gets called (depending) when the TypeSettings.Config file /// are changed. /// </summary> /// <remarks> /// Added: craigbro /// cachedTypeSettings now held with the forwarder for reference of /// exceptions on Synchronous "in" messages. /// To reload, we just null out the cached TypeSettingsCollection object and the /// accessor will reload it on next call /// While ConfigurationManager.GetSection is quite performant after the 1st hit, /// keeping them cached is about twice as fast. /// </remarks> /// <param name="config">The config to reload</param> public void ReloadConfig(RelayNodeConfig config) { lock (reloadLock) { if (config != null) { try { object configObject = config.RelayComponents.GetConfigFor(GetComponentName()); ForwardingConfig forwardingConfig = configObject as ForwardingConfig; if (forwardingConfig == null) { if (log.IsInfoEnabled) { log.InfoFormat("No forwarding configuration supplied. Reloading using defaults."); } forwardingConfig = new ForwardingConfig(); } NodeManager.Instance.ReloadConfig(config, forwardingConfig); if (NodeManager.Instance.Config != null) { if (NodeManager.Instance.Config.TypeSettings != null) { TypeSpecificStatisticsManager.Instance.ReloadMapping( NodeManager.Instance.Config.TypeSettings.TypeSettingCollection); } } _enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets; _myNodeDefinition = NodeManager.Instance.GetMyNodeDefinition(); _myZone = Node.DetermineZone(_myNodeDefinition); short maxTypeId = 0; if (config.TypeSettings != null) { maxTypeId = config.TypeSettings.MaxTypeId; } DebugWriter.SetTraceSettings(maxTypeId, forwardingConfig.TraceSettings); DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod; DebugWriter.WriteMessageTrace = forwardingConfig.WriteMessageTrace; } catch (Exception ex) { if (log.IsErrorEnabled) { log.ErrorFormat("Exception reloading config: {0}", ex); } } } } }
private void InitializeInstance(RelayNodeConfig config, ForwardingConfig forwardingConfig, Dictionary <string, Dictionary <string, ErrorQueue> > errorQueues) { Counters = new ForwardingCounters(); if (config != null) { //without this we'll get a null ref exception if (forwardingConfig == null) { throw new ArgumentNullException("forwardingConfig", "Requires a forwardingConfig to initialize"); } Config = config; ForwardingConfig = forwardingConfig; _zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions; Counters.Initialize(Config.InstanceName); ExtractCommonConfigValues(forwardingConfig); if (InMessageDispatcher != null) { if (_log.IsInfoEnabled) { _log.Info("Relay Forwarder Node Manager Initialized with non-null Dispatcher."); } } else { InMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder"); } if (OutMessageDispatcher == null) { OutMessageDispatcher = new Dispatcher(forwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwader Out Messages"); } BuildNodeGroups(config, errorQueues); MyIpAddress = config.GetAddressToUse(); _queuedMessageCounterTimer = new Timer(CountQueuedMessages, null, 5000, 5000); _aggregateCounterTickTimer = new Timer(AggregateCounterTicker, null, 500, 500); _myNodeDefinition = GetMyNodeDefinition(); _myZone = Node.DetermineZone(_myNodeDefinition); } }
/// <summary> /// Initializes the related type ids. /// </summary> /// <param name="config">The config.</param> /// <returns>RelatedTypeIds</returns> private static Dictionary <short, short> InitializeRelatedTypeIds(RelayNodeConfig config) { Dictionary <short, short> relatedTypeIds = new Dictionary <short, short>(); if (config != null) { foreach (TypeSetting typeSetting in config.TypeSettings.TypeSettingCollection) { if (typeSetting.RelatedIndexTypeId > 0) { relatedTypeIds.Add(typeSetting.TypeId, typeSetting.RelatedIndexTypeId); } } } return(relatedTypeIds); }
internal void ReloadMapping(RelayNodeConfig newConfig, ForwardingConfig forwardingConfig) { RelayNodeMapping relayNodeMapping = newConfig.RelayNodeMapping; RelayNodeGroupDefinitionCollection groupDefinitions = relayNodeMapping.RelayNodeGroups; foreach (RelayNodeGroupDefinition groupDefinition in groupDefinitions) { if (Contains(groupDefinition.Name)) { this[groupDefinition.Name].ReloadMapping(groupDefinition, newConfig, forwardingConfig); } else { if (_log.IsInfoEnabled) { _log.InfoFormat("Adding new node group {0}", groupDefinition.Name); } Add(new NodeGroup(groupDefinition, newConfig, forwardingConfig)); } } bool removedOne; //make sure if any groups have been removed they are removed! do { removedOne = false; foreach (NodeGroup group in this) { if (!groupDefinitions.Contains(group.GroupName)) { if (_log.IsInfoEnabled) { _log.InfoFormat("Removing node group {0}", group.GroupName); } Remove(group.GroupName); removedOne = true; break; //collection modified can't continue with foreach! } } } while (removedOne); _groupsByTypeId = GenerateGroupsByTypeId(newConfig.TypeSettings); }
/// <summary> /// Initializes the <see cref="ComponentTestManager"/>, gets the <see cref="RelayNodeConfig"/> /// and Initializes the forwarder. /// </summary> /// <param name="createTransports">Optional, creates other /// <see cref="IRelayTransport"/>s to be added to the transports.</param> public void Initialize(params CreateTransportDelegate[] createTransports) { _createTransports = createTransports; TransportFactory.CreateTransportMethod = _createTransportDelegate; _forwarder = new Forwarder(); //we initialize because there's a static singleton we're wanting to get set. RelayNodeConfig config = RelayNodeConfig.GetRelayNodeConfig(); if (config == null) { throw new InvalidOperationException("RelayNodeConfig not found."); } if (config.TransportSettings != null && config.TransportSettings.ListenPort != 0) { //do we fix for them? throw new InvalidOperationException("TransportSettings.ListenPort must be zero to make forwarder act like a client."); } _config = config; _forwarder.Initialize(config, null); }
private void BuildNodeGroups(RelayNodeConfig relayNodeConfig, Dictionary <string, Dictionary <string, MessageQueue> > errorQueues) { RelayNodeMapping relayNodeMapping = relayNodeConfig.RelayNodeMapping; if (relayNodeMapping != null) { if (relayNodeMapping.Validate()) { NodeGroupCollection nodeGroups = new NodeGroupCollection(relayNodeMapping.RelayNodeGroups, relayNodeConfig, ForwardingConfig); NodeGroups = nodeGroups; RelayNodeGroupDefinition myGroupDefinition = Config.GetMyGroup(); if (myGroupDefinition != null && NodeGroups.Contains(myGroupDefinition.Name)) { MyNodeGroup = NodeGroups[myGroupDefinition.Name]; } else { MyNodeGroup = null; } if (errorQueues != null) { nodeGroups.PopulateQueues(errorQueues, true); } } else { if (_log.IsErrorEnabled) { _log.Error("Forwarder not loading invalid config."); } NodeGroups = new NodeGroupCollection(); } } else { NodeGroups = new NodeGroupCollection(); } }
/// <summary> /// this (or <see cref="ReloadConfig"/>) gets called (depending) when the TypeSettings.Config file /// are changed. /// </summary> /// <remarks> /// Added: craigbro /// cachedTypeSettings now held with the forwarder for reference of /// exceptions on Synchronous "in" messages. /// To reload, we just null out the cached TypeSettingsCollection object and the /// accessor will reload it on next call /// While ConfigurationManager.GetSection is quite performant after the 1st hit, /// keeping them cached is about twice as fast. /// </remarks> /// <param name="config"></param> /// <param name="runState"></param> private void LoadConfig(RelayNodeConfig config, ComponentRunState runState) { if (config != null) { if (config.RelayComponents != null) { object configObject = config.RelayComponents.GetConfigFor(GetComponentName()); ForwardingConfig forwardingConfig = configObject as ForwardingConfig; if(forwardingConfig == null) { if(_log.IsInfoEnabled) { _log.Info("No forwarding configuration supplied. Using defaults."); } forwardingConfig = new ForwardingConfig(); } NodeManager.Initialize(config, forwardingConfig, GetErrorQueues(runState)); _enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets; _myNodeDefinition = NodeManager.Instance.GetMyNodeDefinition(); short maxTypeId = 0; if(config.TypeSettings != null) { maxTypeId = config.TypeSettings.MaxTypeId; } DebugWriter.SetTraceSettings(maxTypeId,forwardingConfig.TraceSettings); DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod; DebugWriter.WriteMessageTrace = forwardingConfig.WriteMessageTrace; } else { NodeManager.Initialize(null, null, null); } } else { NodeManager.Initialize(null, null, null); } }
/// <summary> /// Initializes the cluster info. /// </summary> /// <param name="myClusterPos">My cluster pos.</param> /// <param name="numClustersInGroup">The num clusters in group.</param> /// <param name="myZone">My zone.</param> private static void InitializeClusterInfo(out int myClusterPos, out int numClustersInGroup, out ushort myZone) { RelayNodeGroupDefinition myGroup = RelayNodeConfig.GetRelayNodeConfig().GetMyGroup(); RelayNodeClusterDefinition myCluster = RelayNodeConfig.GetRelayNodeConfig().GetMyCluster(); RelayNodeDefinition myNode = RelayNodeConfig.GetRelayNodeConfig().GetMyNode(); myZone = myNode.Zone; numClustersInGroup = myGroup.RelayNodeClusters.Length; myClusterPos = 0; foreach (RelayNodeClusterDefinition cluster in myGroup.RelayNodeClusters) { if (cluster.RelayNodes.Length == myCluster.RelayNodes.Length && cluster.ContainsNode(myNode.IPAddress, myNode.Port)) { // this cluster contains my Node break; } myClusterPos++; } }
public void ReloadConfig(RelayNodeConfig config) { bdbConfig = GetConfig(config); ReloadConfig(bdbConfig); }
internal NodeGroupCollection(IEnumerable <RelayNodeGroupDefinition> groupDefinitions, RelayNodeConfig nodeConfig, ForwardingConfig forwardingConfig) { foreach (RelayNodeGroupDefinition groupDefinition in groupDefinitions) { Add(new NodeGroup(groupDefinition, nodeConfig, forwardingConfig)); } _groupsByTypeId = GenerateGroupsByTypeId(nodeConfig.TypeSettings); }
/// <summary> /// Reloads the configuration from the given <see cref="FlexForwarder"/> and applies the new settings. /// </summary> /// <param name="config">The given <see cref="T:MySpace.DataRelay.Configuration.RelayNodeConfig"/>.</param> public void ReloadConfig(RelayNodeConfig config) { LoadConfig(config); }
internal void ReloadConfig(RelayNodeConfig config, ForwardingConfig newForwardingConfig) { if (config.RelayNodeMapping == null) { if (_log.IsErrorEnabled) _log.Error("Got new config with no defined groups."); } else { if (config.RelayNodeMapping.Validate()) { _zoneDefinitions = config.RelayNodeMapping.ZoneDefinitions; //make sure this is set before reloading the mapping so any changes propogate Dictionary<string, Dictionary<string, MessageQueue>> errorQueues = GetErrorQueues(); NodeGroups.ReloadMapping(config, newForwardingConfig); //note that if a node changes groups, the error queue won't make it! NodeGroups.PopulateQueues(errorQueues, false); } else { if (_log.IsErrorEnabled) _log.Error("Forwarder not reloading invalid config."); } } Config = config; _myNodeDefinition = GetMyNodeDefinition(); bool doNewInDispatcher, doNewOutDispatcher; if (newForwardingConfig.NumberOfThreads != ForwardingConfig.NumberOfThreads) { doNewInDispatcher = true; } else { doNewInDispatcher = false; } if (newForwardingConfig.NumberOfOutMessageThreads != ForwardingConfig.NumberOfOutMessageThreads) { doNewOutDispatcher = true; } else { doNewOutDispatcher = false; } if (doNewInDispatcher || doNewOutDispatcher) { Dispatcher oldInDispatcher = null, newInDispatcher, oldOutDispatcher = null, newOutDispatcher; if (doNewInDispatcher) { if (_log.IsInfoEnabled) _log.InfoFormat("Changing number of messaging threads from {0} to {1}", ForwardingConfig.NumberOfThreads, newForwardingConfig.NumberOfThreads); oldInDispatcher = InMessageDispatcher; newInDispatcher = new Dispatcher(newForwardingConfig.NumberOfThreads, ThreadPriority.Normal, true, "Relay Forwarder"); } else { newInDispatcher = InMessageDispatcher; } if (doNewOutDispatcher) { if (_log.IsInfoEnabled) _log.InfoFormat("Changing number of out message threads from {0} to {1}", ForwardingConfig.NumberOfOutMessageThreads, newForwardingConfig.NumberOfOutMessageThreads); oldOutDispatcher = OutMessageDispatcher; newOutDispatcher = new Dispatcher(newForwardingConfig.NumberOfOutMessageThreads, ThreadPriority.Normal, true, "Relay Forwarder"); } else { newOutDispatcher = OutMessageDispatcher; } InMessageDispatcher = newInDispatcher; OutMessageDispatcher = newOutDispatcher; NodeGroups.SetNewDispatchers(newInDispatcher, newOutDispatcher); ForwardingConfig = newForwardingConfig; if (doNewInDispatcher) { if (_log.IsInfoEnabled) _log.Info("Disposing old in message Dispatcher"); oldInDispatcher.Dispose(); } if (doNewOutDispatcher) { if (_log.IsInfoEnabled) _log.Info("Disposing old out message Dispatcher"); oldOutDispatcher.Dispose(); } } else { ForwardingConfig = newForwardingConfig; } }
/// <summary> /// Initializes the compress options. /// </summary> /// <param name="config">The config.</param> /// <returns>CompressOptions</returns> private static Dictionary<short, bool> InitializeCompressOptions(RelayNodeConfig config) { Dictionary<short, bool> compressOptions = new Dictionary<short, bool>(); if (config != null) { foreach (TypeSetting typeSetting in config.TypeSettings.TypeSettingCollection) { compressOptions.Add(typeSetting.TypeId, typeSetting.Compress); } } return compressOptions; }
/// <summary> /// Initializes a new instance of the <see cref="CacheClient"/> class, whit a specified relay node config. Used in unit tests. /// </summary> /// <param name="nodeConfig">The node config.</param> internal CacheClient(RelayNodeConfig nodeConfig) : base(nodeConfig) { }
/// <summary> /// Reloads the configuration from the given <see cref="RelayNodeCofig"/> and applies the new settings. /// </summary> /// <param name="config">The given <see cref="RelayNodeConfig"/>.</param> public void ReloadConfig(RelayNodeConfig config) { LoggingUtil.Log.Info("Reloading CacheIndexV3Storage"); storeContext.InitializeReloadConfig(config, false); }
public void Initialize(RelayNodeConfig config, ComponentRunState runState) { try { if (config == null) { if (Log.IsErrorEnabled) { Log.ErrorFormat("RelayNodeConfig is NULL"); } throw new ApplicationException("RelayNodeConfig is NULL"); } relayNodeConfig = config; Initialize(GetConfig(config), GetInstanceName(), runState); } catch (Exception exc) { if (Log.IsErrorEnabled) { Log.ErrorFormat("Error initializing: {0}", exc); } throw; } }
/// <summary> /// Initializes the reload config. /// </summary> /// <param name="config">The config.</param> /// <param name="isInit">if set to <c>true</c> [is init].</param> internal void InitializeReloadConfig(RelayNodeConfig config, bool isInit) { #region Set Component Configs if (config == null) { Exception ex = new Exception("Unable to Initialize/Reload Config for CacheIndexV3Store because RelayNodeConfig is null"); LoggingUtil.Log.Error(ex.Message); throw ex; } Interlocked.Exchange(ref nodeConfig, config); Interlocked.Exchange(ref storageConfiguration, InitializeConfig(nodeConfig)); #endregion #region Setup Forwarder if (ForwarderComponent == null) { ForwarderComponent = new Forwarder(); ForwarderComponent.Initialize(config, null); } else { ForwarderComponent.ReloadConfig(config); } #endregion #region Init/Reload Component if (IndexStorageComponent == null) { IndexStorageComponent = InitializeStorageComponent(storageConfiguration.BerkeleyDbConfig); } else { ReloadStorageComponent(storageConfiguration.BerkeleyDbConfig, IndexStorageComponent); } #endregion #region init DataMembers Interlocked.Exchange(ref relatedTypeIds, InitializeRelatedTypeIds(nodeConfig)); Interlocked.Exchange(ref compressOptions, InitializeCompressOptions(nodeConfig)); InitializeClusterInfo(out myClusterPosition, out numClustersInGroup, out myZone); LockingUtil.Instance.InitializeLockerObjects(storageConfiguration.CacheIndexV3StorageConfig.LockMultiplier, numClustersInGroup); LegacySerializationUtil.Instance.InitializeLegacySerializtionTypes(nodeConfig.TypeSettings, storageConfiguration.CacheIndexV3StorageConfig.SupportLegacySerialization); List<short> typeIdList = new List<short>(); #region Index Capping Check // Index Capping feature for multiple indexes not supported // TBD - Remove this check when feature is supported foreach (IndexTypeMapping indexTypeMapping in storageConfiguration.CacheIndexV3StorageConfig.IndexTypeMappingCollection) { typeIdList.Add(indexTypeMapping.TypeId); if (indexTypeMapping.IndexCollection.Count > 1 && indexTypeMapping.IndexServerMode == IndexServerMode.Databound) { foreach (Index indexInfo in indexTypeMapping.IndexCollection) { if (indexInfo.MaxIndexSize > 0) { LoggingUtil.Log.ErrorFormat("TypeId {0} -- Index Capping feature for multiple indexes not supported", indexTypeMapping.TypeId); throw new Exception("Index Capping feature for multiple indexes not supported"); } } } } #endregion #region init performance counters // get the max type id short maxTypeId = config.TypeSettings.MaxTypeId; // initialize or re-initialize performance counters, // counter category will also be created if it is not there PerformanceCounters.Instance.InitializeCounters( config.TransportSettings.ListenPort, typeIdList, maxTypeId, isInit); #endregion #region Set HashCollections Interlocked.Exchange(ref tagHashCollection, InitializeTagHashCollection(storageConfiguration)); Interlocked.Exchange(ref stringHashCollection, InitializeStringHashCollection(storageConfiguration)); #endregion #endregion }
/// <summary> /// Initializes the reload config. /// </summary> /// <param name="config">The config.</param> /// <param name="isInit">if set to <c>true</c> [is init].</param> internal void InitializeReloadConfig(RelayNodeConfig config, bool isInit) { #region Set Component Configs if (config == null) { Exception ex = new Exception("Unable to Initialize/Reload Config for CacheIndexV3Store because RelayNodeConfig is null"); LoggingUtil.Log.Error(ex.Message); throw ex; } Interlocked.Exchange(ref nodeConfig, config); Interlocked.Exchange(ref storageConfiguration, InitializeConfig(nodeConfig)); #endregion #region Setup Forwarder if (ForwarderComponent == null) { ForwarderComponent = new Forwarder(); ForwarderComponent.Initialize(config, null); } else { ForwarderComponent.ReloadConfig(config); } #endregion #region Init/Reload Component if (IndexStorageComponent == null) { IndexStorageComponent = InitializeStorageComponent(storageConfiguration.BerkeleyDbConfig); } else { ReloadStorageComponent(storageConfiguration.BerkeleyDbConfig, IndexStorageComponent); } #endregion #region init memoryPool if (this.myMemoryPool == null) { this.myMemoryPool = new MemoryStreamPool( storageConfiguration.CacheIndexV3StorageConfig.MemPoolItemInitialSizeInBytes, ResourcePool.ResourcePool <MemoryStream> .InfiniteReuse, storageConfiguration.CacheIndexV3StorageConfig.MemPoolMinItemNumber); } #region init DataMembers Interlocked.Exchange(ref relatedTypeIds, InitializeRelatedTypeIds(nodeConfig)); Interlocked.Exchange(ref compressOptions, InitializeCompressOptions(nodeConfig)); InitializeClusterInfo(out myClusterPosition, out numClustersInGroup, out myZone); LockingUtil.Instance.InitializeLockerObjects(storageConfiguration.CacheIndexV3StorageConfig.LockMultiplier, numClustersInGroup); LegacySerializationUtil.Instance.InitializeLegacySerializtionTypes(nodeConfig.TypeSettings, storageConfiguration.CacheIndexV3StorageConfig.SupportLegacySerialization); #region init performance counters List <short> typeIdList = new List <short>(); foreach (IndexTypeMapping indexTypeMapping in storageConfiguration.CacheIndexV3StorageConfig.IndexTypeMappingCollection) { typeIdList.Add(indexTypeMapping.TypeId); } // get the max type id short maxTypeId = config.TypeSettings.MaxTypeId; // initialize or re-initialize performance counters, // counter category will also be created if it is not there PerformanceCounters.Instance.InitializeCounters( config.TransportSettings.ListenPort, typeIdList, maxTypeId, isInit); #endregion #region Set HashCollections Interlocked.Exchange(ref tagHashCollection, InitializeTagHashCollection(storageConfiguration)); Interlocked.Exchange(ref stringHashCollection, InitializeStringHashCollection(storageConfiguration)); #endregion #endregion #region Init Domain Specific Config DomainSpecificConfig = new DomainSpecificConfig { StreamRecencyConfig = ConfigurationManager.GetSection("StreamRecencyConfig") as StreamRecencyConfig }; #endregion }
/// <summary> /// Initializes the Index Cache config. /// </summary> /// <param name="config">The config.</param> /// <returns>Index Cache Configuration</returns> private static CacheIndexV3StorageConfiguration InitializeConfig(RelayNodeConfig config) { CacheIndexV3StorageConfiguration configObj = config.RelayComponents.GetConfigFor(COMPONENT_NAME) as CacheIndexV3StorageConfiguration; if (configObj != null) { configObj.InitializeCustomFields(); } return configObj; }
private static BerkeleyDbConfig GetConfig(RelayNodeConfig config) { object configObject = config.RelayComponents.GetConfigFor(componentName); BerkeleyDbConfig getConfig = configObject as BerkeleyDbConfig; if (getConfig == null) { if (Log.IsInfoEnabled) { Log.Info("Initialize() No configuration found, using defaults."); } getConfig = new BerkeleyDbConfig(); } return getConfig; }
/// <summary> /// this (or <see cref="LoadConfig"/>) gets called (depending) when the TypeSettings.Config file /// are changed. /// </summary> /// <remarks> /// Added: craigbro /// cachedTypeSettings now held with the forwarder for reference of /// exceptions on Synchronous "in" messages. /// To reload, we just null out the cached TypeSettingsCollection object and the /// accessor will reload it on next call /// While ConfigurationManager.GetSection is quite performant after the 1st hit, /// keeping them cached is about twice as fast. /// </remarks> /// <param name="config">The config to reload</param> public void ReloadConfig(RelayNodeConfig config) { lock (_reloadLock) { if (config != null) { try { object configObject = config.RelayComponents.GetConfigFor(GetComponentName()); ForwardingConfig forwardingConfig = configObject as ForwardingConfig; if (forwardingConfig == null) { if(_log.IsInfoEnabled) { _log.InfoFormat("No forwarding configuration supplied. Reloading using defaults."); } forwardingConfig = new ForwardingConfig(); } NodeManager.Instance.ReloadConfig(config, forwardingConfig); _enableAsyncBulkGets = forwardingConfig.EnableAsyncBulkGets; _myNodeDefinition = NodeManager.Instance.GetMyNodeDefinition(); short maxTypeId = 0; if (config.TypeSettings != null) { maxTypeId = config.TypeSettings.MaxTypeId; } DebugWriter.SetTraceSettings(maxTypeId, forwardingConfig.TraceSettings); DebugWriter.WriteCallingMethod = forwardingConfig.WriteCallingMethod; DebugWriter.WriteMessageTrace = forwardingConfig.WriteMessageTrace; } catch (Exception ex) { if (_log.IsErrorEnabled) _log.ErrorFormat("Exception reloading config: {0}", ex); } } } }
private void GetConfig() { EventHandler reloadEventHandler = ReloadConfig; configuration = RelayNodeConfig.GetRelayNodeConfig(reloadEventHandler); if (configuration != null) { if (configuration.GetMyNode() != null) { MyZone = configuration.GetMyNode().Zone; } instanceName = configuration.InstanceName; if (configuration.TransportSettings != null) { portNumber = configuration.TransportSettings.ListenPort; httpPortNumber = configuration.TransportSettings.HttpListenPort; } } else { if (log.IsErrorEnabled) log.Error("NO CONFIG SECTION FOUND, SERVICE NOT STARTING."); } }
/// <summary> /// Initializes the component. Any error queues in runState will be reinstantiated. /// </summary> public void Initialize(RelayNodeConfig config, ComponentRunState runState) { LoadConfig(config, runState); _initDate = DateTime.Now; }
private void SetupOutMessagesOnRelayThreads(RelayNodeConfig newConfiguration) { //if it was off and is now on, or if it was on and the number of threads changed bool setupNewOutMessages = (newConfiguration.OutMessagesOnRelayThreads && configuration.OutMessagesOnRelayThreads == false) || (configuration.OutMessagesOnRelayThreads && newConfiguration.OutMessagesOnRelayThreads && newConfiguration.NumberOfOutMessageThreads != configuration.NumberOfOutMessageThreads); Dispatcher oldOutDispatcher = outDispatcher; DispatcherQueue oldOutMessageQueue = outMessageQueue; if (setupNewOutMessages) { try { const string outThreadsName = "DataRelayNodeOUT"; outMessagePort = new Port<RelayMessageAsyncResult>(); //atomic outMessagesPort = new Port<RelayMessageListAsyncResult>(); //atomic if (newConfiguration.NumberOfOutMessageThreads > 0) { outDispatcher = new Dispatcher(newConfiguration.NumberOfOutMessageThreads, ThreadPriority.Normal, true, outThreadsName); } else { outDispatcher = new Dispatcher { Name = outThreadsName }; } outMessageQueue = new DispatcherQueue("DataRelayDispatcherQueueOUT", outDispatcher, TaskExecutionPolicy.ConstrainQueueDepthThrottleExecution, newConfiguration.MaximumOutMessageQueueDepth); Arbiter.Activate(outMessageQueue, Arbiter.ReceiveWithIterator(true, outMessagePort, HandleOutMessage)); Arbiter.Activate(outMessageQueue, Arbiter.ReceiveWithIterator(true, outMessagesPort, HandleOutMessages)); } catch (Exception e) { if(log.IsErrorEnabled) log.ErrorFormat("Error setting up Out Message Threads on RelayNode: {0}", e); throw; } } if (newConfiguration.OutMessagesOnRelayThreads == false) { outMessagePort = null; outMessagesPort = null; if (oldOutDispatcher != null) oldOutDispatcher.Dispose(); if (oldOutMessageQueue != null) oldOutMessageQueue.Dispose(); } }
internal void ReloadMapping(RelayNodeClusterDefinition relayNodeClusterDefinition, RelayNodeConfig newConfig, ForwardingConfig forwardingConfig) { _minimumId = relayNodeClusterDefinition.MinId; _maximumId = relayNodeClusterDefinition.MaxId; _mapNetwork = forwardingConfig.MapNetwork; //figure out if anything changed. if it did, rebuild bool rebuild = false; ushort newLocalZone = newConfig.GetLocalZone(); if (newLocalZone != _localZone) { rebuild = true; _localZone = newLocalZone; } else { if((_zoneDefinitions == null && newConfig.RelayNodeMapping.ZoneDefinitions != null) || (_zoneDefinitions != null && newConfig.RelayNodeMapping.ZoneDefinitions == null) || (_zoneDefinitions != null && !_zoneDefinitions.Equals(newConfig.RelayNodeMapping.ZoneDefinitions))) { rebuild = true; _zoneDefinitions = newConfig.RelayNodeMapping.ZoneDefinitions; } } int effectiveSize = (!_meInThisCluster ? Nodes.Count : Nodes.Count + 1); //if there's a different number of nodes, we definitely have to rebuild if (relayNodeClusterDefinition.RelayNodes.Length != effectiveSize) { if(_log.IsInfoEnabled) _log.InfoFormat("Number of nodes in a cluster in group {0} changed from {1} to {2}, rebuilding", _nodeGroup.GroupName, effectiveSize, relayNodeClusterDefinition.RelayNodes.Length); rebuild = true; } else { //if any of the nodes we do have aren't in the config, rebuild foreach (Node node in Nodes) { if (!relayNodeClusterDefinition.ContainsNode(node.EndPoint.Address, node.EndPoint.Port)) { if (_log.IsInfoEnabled) _log.InfoFormat("Node {0} is no longer found in its cluster in group {1}, rebuilding.", node, _nodeGroup.GroupName); rebuild = true; break; } } if (!rebuild && _nodeGroup.NodeSelectionHopWindowSize != NodeSelectionHopWindowSize) { NodeSelectionHopWindowSize = _nodeGroup.NodeSelectionHopWindowSize; rebuild = true; } if (!rebuild && _meInThisCluster) { if (!relayNodeClusterDefinition.ContainsNode(Me.EndPoint.Address, Me.EndPoint.Port)) { if (_log.IsInfoEnabled) _log.InfoFormat("Node {0} (this machine) is no longer found in its cluster in group {1}, rebuilding.", Me, _nodeGroup.GroupName); rebuild = true; } } //or if there are any nodes in the config that aren't here, rebuild if (!rebuild) { foreach(RelayNodeDefinition nodeDefinition in relayNodeClusterDefinition.RelayNodes) { if (!ContainsNode(nodeDefinition)) { if (_log.IsInfoEnabled) _log.InfoFormat("Node {0} is defined in the new config but does not exist in this cluster in group {1}, rebuilding.", nodeDefinition, _nodeGroup.GroupName); rebuild = true; break; } } } } if (rebuild) { Dictionary<ushort, List<Node>> newZoneNodes = new Dictionary<ushort, List<Node>>(); List<Node> newNodes = new List<Node>(); RelayNodeDefinition meDefinition = newConfig.GetMyNode(); DispatcherQueue nodeInQueue, nodeOutQueue; if (meDefinition != null) { GetMessageQueuesFor(meDefinition, relayNodeClusterDefinition, NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher, out nodeInQueue, out nodeOutQueue); //Me is in the new config //Either create it new or overwrite the old one Me = new Node(meDefinition, _nodeGroup, this, forwardingConfig, nodeInQueue, nodeOutQueue); } else { //me is NOT in the new config. Me = null; } ushort maxDetectedZone = _localZone; foreach (RelayNodeDefinition nodeDefinition in relayNodeClusterDefinition.RelayNodes) { if (nodeDefinition != meDefinition) { GetMessageQueuesFor(nodeDefinition, relayNodeClusterDefinition, NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher, out nodeInQueue, out nodeOutQueue); Node node = new Node(nodeDefinition, _nodeGroup, this, forwardingConfig, nodeInQueue, nodeOutQueue); newNodes.Add(node); if (node.DetectedZone > maxDetectedZone) { maxDetectedZone = node.DetectedZone; } if (node.Zone > maxDetectedZone) { maxDetectedZone = node.Zone; } if (!newZoneNodes.ContainsKey(nodeDefinition.Zone)) { newZoneNodes[nodeDefinition.Zone] = new List<Node>(); } newZoneNodes[nodeDefinition.Zone].Add(node); } } Nodes = newNodes; ZoneNodes = newZoneNodes; _nodesByNumberOfHops = CalculateTopography(Nodes, MaximumHops); _nodeLayers = CalculateNodeLayers(_nodesByNumberOfHops, NodeSelectionHopWindowSize); _nodesByDetectedZone = CalculateNodesByDetectedZone(Nodes, maxDetectedZone); lock (_chooseLock) { ChosenNode = null; } ChosenZoneNodes = new Dictionary<ushort, Node>(); } else { //just reload the configs to get any new network or queue settings bool hitMe = false; string meString = String.Empty; if (Me != null) { meString = Me.ToString(); } for (int i = 0; i < relayNodeClusterDefinition.RelayNodes.Length; i++) { string definitionString = relayNodeClusterDefinition.RelayNodes[i].Host + ":" + relayNodeClusterDefinition.RelayNodes[i].Port; if (definitionString == meString) { hitMe = true; Me.ReloadMapping(relayNodeClusterDefinition.RelayNodes[i], forwardingConfig); } else { Nodes[(hitMe ? i - 1 : i)].ReloadMapping(relayNodeClusterDefinition.RelayNodes[i],forwardingConfig); } } lock (_chooseLock) { ChosenNode = null; } } }
/// <summary> /// Initializes and starts the component. /// </summary> /// <param name="config">The configuration to use.</param> /// <param name="runState">Component Run State</param> public void Initialize(RelayNodeConfig config, ComponentRunState runState) { LoggingUtil.Log.Info("Initializing CacheIndexV3Storage"); storeContext.InitializeReloadConfig(config, true); }
/// <summary> /// Initializes the related type ids. /// </summary> /// <param name="config">The config.</param> /// <returns>RelatedTypeIds</returns> private static Dictionary<short, short> InitializeRelatedTypeIds(RelayNodeConfig config) { Dictionary<short, short> relatedTypeIds = new Dictionary<short, short>(); if (config != null) { foreach (TypeSetting typeSetting in config.TypeSettings.TypeSettingCollection) { if (typeSetting.RelatedIndexTypeId > 0) { relatedTypeIds.Add(typeSetting.TypeId, typeSetting.RelatedIndexTypeId); } } } return relatedTypeIds; }
internal NodeCluster(RelayNodeClusterDefinition clusterDefinition, RelayNodeConfig nodeConfig, NodeGroup nodeGroup, ForwardingConfig forwardingConfig) { _nodeGroup = nodeGroup; _clusterDefinition = clusterDefinition; _minimumId = clusterDefinition.MinId; _maximumId = clusterDefinition.MaxId; NodeSelectionHopWindowSize = nodeGroup.NodeSelectionHopWindowSize; RelayNodeDefinition meDefinition = nodeConfig.GetMyNode(); _meInThisCluster = false; _mapNetwork = forwardingConfig.MapNetwork; _localZone = nodeConfig.GetLocalZone(); _zoneDefinitions = nodeConfig.RelayNodeMapping.ZoneDefinitions; foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes) { if (meDefinition == nodeDefinition) { _meInThisCluster = true; } } DispatcherQueue nodeInQueue, nodeOutQueue; if (_meInThisCluster) { GetMessageQueuesFor(meDefinition, clusterDefinition, NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher, out nodeInQueue, out nodeOutQueue); Me = new Node(meDefinition, nodeGroup, this, forwardingConfig, nodeInQueue, nodeOutQueue); } ushort maxDetectedZone = _localZone; foreach (RelayNodeDefinition nodeDefinition in clusterDefinition.RelayNodes) { if (nodeDefinition != meDefinition) { GetMessageQueuesFor(nodeDefinition, clusterDefinition, NodeManager.Instance.InMessageDispatcher, NodeManager.Instance.OutMessageDispatcher, out nodeInQueue, out nodeOutQueue); Node node = new Node(nodeDefinition, nodeGroup, this, forwardingConfig, nodeInQueue, nodeOutQueue); Nodes.Add(node); if (node.DetectedZone > maxDetectedZone) { maxDetectedZone = node.DetectedZone; } if (node.Zone > maxDetectedZone) { maxDetectedZone = node.Zone; } if (!ZoneNodes.ContainsKey(nodeDefinition.Zone)) { ZoneNodes[nodeDefinition.Zone] = new List<Node>(); } ZoneNodes[nodeDefinition.Zone].Add(node); } } _nodesByNumberOfHops = CalculateTopography(Nodes, MaximumHops); _nodeLayers = CalculateNodeLayers(_nodesByNumberOfHops, NodeSelectionHopWindowSize); _nodesByDetectedZone = CalculateNodesByDetectedZone(Nodes, maxDetectedZone); }
internal void ReloadConfig(RelayNodeConfig newConfiguration) { if (newConfiguration != null) { if (log.IsInfoEnabled) log.Info("Reloading configs."); fatalFailureTimeout = newConfiguration.FatalShutdownTimeout < 0 ? TimeSpan.FromMinutes(5) : TimeSpan.FromSeconds(newConfiguration.FatalShutdownTimeout); if (newConfiguration.GetMyNode() != null) { MyZone = newConfiguration.GetMyNode().Zone; } SetClusterAddresses(newConfiguration); messageTracer.ReloadConfig(newConfiguration.TypeSettings.MaxTypeId, newConfiguration.TraceSettings); messageTracer.Activated = newConfiguration.OutputTraceInfo; //TODO: handle changes in component definition components.ReloadConfig(newConfiguration, newConfiguration.IgnoredMessageTypes); if (newConfiguration.TransportSettings != null) { if(newConfiguration.TransportSettings.ListenPort != portNumber) { log.InfoFormat("Changing Socket Transport Port to {0}", newConfiguration.TransportSettings.ListenPort); portNumber = newConfiguration.TransportSettings.ListenPort; SocketServerAdapter.ChangePort(portNumber); } if(newConfiguration.TransportSettings.HttpListenPort != httpPortNumber) { if (httpPortNumber < 1 && newConfiguration.TransportSettings.HttpListenPort > 0) //there was no http server and now we want one { httpPortNumber = newConfiguration.TransportSettings.HttpListenPort; StartHttpServer(); } else if (newConfiguration.TransportSettings.HttpListenPort < 1 && httpPortNumber > 0) //shut off a running server { httpPortNumber = newConfiguration.TransportSettings.HttpListenPort; StopHttpServer(); } else //just change the port on an existing server { log.InfoFormat("Changing Http Transport Port to {0}", newConfiguration.TransportSettings.HttpListenPort); httpPortNumber = newConfiguration.TransportSettings.HttpListenPort; _httpServer.ChangePort(httpPortNumber); } } } if (newConfiguration.NumberOfThreads != configuration.NumberOfThreads) { if(log.IsInfoEnabled) log.InfoFormat("Changing number of relay node threads from {0} to {1}", configuration.NumberOfThreads, newConfiguration.NumberOfThreads); try { Dispatcher oldInDispatcher = inDispatcher; Dispatcher newInDispatcher; const string inThreadsName = "DataRelayNode"; if (newConfiguration.NumberOfThreads > 0) { newInDispatcher = new Dispatcher(newConfiguration.NumberOfThreads, ThreadPriority.Normal, true, inThreadsName); } else { newInDispatcher = new Dispatcher() { Name = inThreadsName }; } DispatcherQueue newInQueue = new DispatcherQueue("DataRelayDispatcherQueue", newInDispatcher, TaskExecutionPolicy.ConstrainQueueDepthThrottleExecution, newConfiguration.MaximumMessageQueueDepth); Interlocked.Exchange(ref inMessagePort, new Port<RelayMessage>()); Interlocked.Exchange(ref inMessageWithContextPort, new Port<RelayMessageWithContext>()); Interlocked.Exchange(ref inMessagesPort, new Port<IList<RelayMessage>>()); Arbiter.Activate(newInQueue, Arbiter.Receive<RelayMessage>(true, inMessagePort, HandleInMessage)); Arbiter.Activate(newInQueue, Arbiter.Receive<RelayMessageWithContext>(true, inMessageWithContextPort, HandleInMessage)); Arbiter.Activate(newInQueue, Arbiter.Receive<IList<RelayMessage>>(true, inMessagesPort, HandleInMessages)); inMessageQueue = newInQueue; inDispatcher = newInDispatcher; oldInDispatcher.Dispose(); } catch (Exception e) { if (log.IsErrorEnabled) log.ErrorFormat("Error changing number of relay node threads: {0}", e); } } else { //not rebuilding the queue, but reset its max queue depth anyway inMessageQueue.MaximumQueueDepth = newConfiguration.MaximumMessageQueueDepth; } SetupOutMessagesOnRelayThreads(newConfiguration); queuedTaskThreshold = (int)Math.Floor(0.9 * newConfiguration.MaximumMessageQueueDepth); configuration = newConfiguration; if (log.IsInfoEnabled) log.Info("Done Reloading configs."); } else { if (log.IsErrorEnabled) log.Error("Attempt to reload null config"); } }
private void SetClusterAddresses(RelayNodeConfig config) { HashSet<IPAddress> localClusterAddresses = null; if (config != null) { var cluster = config.GetMyCluster(); if (cluster != null) { localClusterAddresses = new HashSet<IPAddress>(); foreach (var clusterNode in cluster.RelayNodes) { if (clusterNode.Activated) { var addr = clusterNode.IPAddress; if (!localClusterAddresses.Contains(addr)) { localClusterAddresses.Add(addr); } } } } } clusterAddresses = localClusterAddresses; }
/// <summary> /// Initializes the component. Any error queues in runState will be reinstantiated. /// </summary> public void Initialize(RelayNodeConfig config, ComponentRunState runState) { LoadConfig(config); }
internal void ReloadMapping(RelayNodeGroupDefinition groupDefinition, RelayNodeConfig newConfig, ForwardingConfig newForwardingConfig) { RelayNodeClusterDefinition myClusterDefinition = newConfig.GetMyCluster(); Activated = groupDefinition.Activated; GroupDefinition = groupDefinition; _clusterByRange = groupDefinition.UseIdRanges; _forwardingConfig = newForwardingConfig; NodeSelectionHopWindowSize = groupDefinition.NodeSelectionHopWindowSize; if (groupDefinition.RelayNodeClusters.Length == Clusters.Count) { //same number of clusters, just let the clusters rebuild themselves. the clusters will entirely rebuild, so shuffinling around servers should be okay if (_log.IsInfoEnabled) _log.InfoFormat("Rebuilding existing clusters in group {0}.", groupDefinition.Name); for (int i = 0; i < groupDefinition.RelayNodeClusters.Length; i++) { Clusters[i].ReloadMapping(groupDefinition.RelayNodeClusters[i], newConfig, newForwardingConfig); if (groupDefinition.RelayNodeClusters[i] == myClusterDefinition) { MyCluster = Clusters[i]; } } if (myClusterDefinition == null && MyCluster != null) { if (_log.IsInfoEnabled) _log.InfoFormat("Group {0} no longer contains this server. Removing.", GroupName); //this group no longer contains "me". If it DID contain "me", it would've been set above. MyCluster = null; } } else { //build new clusters and replace the existing ones with them if (_log.IsInfoEnabled) _log.InfoFormat("Number of clusters in group {0} changed, rebuilding.", groupDefinition.Name); NodeCluster myCluster = null; List<NodeCluster> newClusters = new List<NodeCluster>(); foreach (RelayNodeClusterDefinition clusterDefintion in groupDefinition.RelayNodeClusters) { NodeCluster nodeCluster = new NodeCluster(clusterDefintion, newConfig, this, newForwardingConfig); if (clusterDefintion == myClusterDefinition) { myCluster = nodeCluster; } newClusters.Add(nodeCluster); } Clusters = newClusters; MyCluster = myCluster; } _nodeReselectTimer.Change(NodeReselectIntervalMilliseconds, NodeReselectIntervalMilliseconds); }
private void BuildNodeGroups(RelayNodeConfig relayNodeConfig, Dictionary<string, Dictionary<string, MessageQueue>> errorQueues) { RelayNodeMapping relayNodeMapping = relayNodeConfig.RelayNodeMapping; if (relayNodeMapping != null) { if (relayNodeMapping.Validate()) { NodeGroupCollection nodeGroups = new NodeGroupCollection(relayNodeMapping.RelayNodeGroups, relayNodeConfig, ForwardingConfig); NodeGroups = nodeGroups; RelayNodeGroupDefinition myGroupDefinition = Config.GetMyGroup(); if (myGroupDefinition != null && NodeGroups.Contains(myGroupDefinition.Name)) { MyNodeGroup = NodeGroups[myGroupDefinition.Name]; } else { MyNodeGroup = null; } if (errorQueues != null) { nodeGroups.PopulateQueues(errorQueues, true); } } else { if (_log.IsErrorEnabled) _log.Error("Forwarder not loading invalid config."); NodeGroups = new NodeGroupCollection(); } } else { NodeGroups = new NodeGroupCollection(); } }