Пример #1
0
        /// <summary>
        /// Initializes the counter instances and category.
        /// </summary>
        public void InitializePerfCounters(bool enableDebuggingCounters)
        {
            try
            {
                if (!UserHasAccessRights)
                {
                    return;
                }

                lock (this)
                {
                    string instname = _instanceName;

                    _instanceName = instname;
                    if (enableDebuggingCounters)
                    {
                        _pcTcpDownQueueCount   = new PerformanceCounter(PC_CATEGORY, "TcpDownQueueCount", _instanceName, false);
                        _pcTcpUpQueueCount     = new PerformanceCounter(PC_CATEGORY, "TcpUpQueueCount", _instanceName, false);
                        _pcBcastQueueCount     = new PerformanceCounter(PC_CATEGORY, "BcastQueueCount", _instanceName, false);
                        _pcMcastQueueCount     = new PerformanceCounter(PC_CATEGORY, "McastQueueCount", _instanceName, false);
                        _pcSocketSendTime      = new PerformanceCounter(PC_CATEGORY, "Socket send time (msec)", _instanceName, false);
                        _pcSocketSendSize      = new PerformanceCounter(PC_CATEGORY, "Socket send size (bytes)", _instanceName, false);
                        _pcSocketReceiveTime   = new PerformanceCounter(PC_CATEGORY, "Socket recv time (msec)", _instanceName, false);
                        _pcSocketReceiveSize   = new PerformanceCounter(PC_CATEGORY, "Socket recv size (bytes)", _instanceName, false);
                        _pcNagglingMsgCount    = new PerformanceCounter(PC_CATEGORY, "NaglingMsgCount", _instanceName, false);
                        _pcBytesSentPerSec     = new PerformanceCounter(PC_CATEGORY, "Bytes sent/sec", _instanceName, false);
                        _pcBytesReceivedPerSec = new PerformanceCounter(PC_CATEGORY, "Bytes received/sec", _instanceName, false);
                    }

                    _pcClusteredOperationsPerSec = new PerformanceCounter(PC_CATEGORY, "Cluster ops/sec", _instanceName, false);

                    if (System.Configuration.ConfigurationSettings.AppSettings["printClusterStats"] != null)
                    {
                        bool printStats = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["printClusterStats"]);
                        if (printStats)
                        {
                            if (System.Configuration.ConfigurationSettings.AppSettings["statsPrintInterval"] != null)
                            {
                                _printInterval = new TimeSpan(Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["statsPrintInterval"]), 0, 0);
                            }

                            _logger = new Logs();
                            _logger.Initialize(instname + ".clstats", "ClusterPerfMonStats");

                            _printThread = new Thread(new ThreadStart(PrintStats));
                            _printThread.Start();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                NCacheLog.Warn("PerfStatsCollector.PerfStatsCollector()    " + e.Message);
            }
        }
Пример #2
0
 /// <summary>
 /// Called when an existing member leaves the group.
 /// </summary>
 /// <param name="address">address of the joining member</param>
 /// <returns>true if the node left successfuly</returns>
 internal virtual int OnMemberLeft(Address address, Hashtable bucketsOwnershipMap)
 {
     if (_members.Contains(address))
     {
         NCacheLog.Warn("SubCluster.OnMemberJoined()", "Memeber " + address + " left sub-cluster " + _groupid);
         _members.Remove(address);
         _servers.Remove(address);
         return(_members.Count);
     }
     return(-1);
 }
Пример #3
0
        /// <summary>
        /// Initializes the counter instances and category.
        /// </summary>
        public void InitializePerfCounters(bool enableDebuggingCounters)
        {
#if NETCORE
            if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
            {
                return;
            }
#endif
            try
            {
                if (!UserHasAccessRights)
                {
                    return;
                }

                lock (this)
                {
                    string instname = _instanceName;

                    _instanceName = instname;
                    if (enableDebuggingCounters)
                    {
                        _pcTcpDownQueueCount   = new PerformanceCounter(PC_CATEGORY, "TcpDownQueueCount", _instanceName, false);
                        _pcTcpUpQueueCount     = new PerformanceCounter(PC_CATEGORY, "TcpUpQueueCount", _instanceName, false);
                        _pcBcastQueueCount     = new PerformanceCounter(PC_CATEGORY, "BcastQueueCount", _instanceName, false);
                        _pcMcastQueueCount     = new PerformanceCounter(PC_CATEGORY, "McastQueueCount", _instanceName, false);
                        _pcSocketSendTime      = new PerformanceCounter(PC_CATEGORY, "Socket send time (msec)", _instanceName, false);
                        _pcSocketSendSize      = new PerformanceCounter(PC_CATEGORY, "Socket send size (bytes)", _instanceName, false);
                        _pcSocketReceiveTime   = new PerformanceCounter(PC_CATEGORY, "Socket recv time (msec)", _instanceName, false);
                        _pcSocketReceiveSize   = new PerformanceCounter(PC_CATEGORY, "Socket recv size (bytes)", _instanceName, false);
                        _pcBytesSentPerSec     = new PerformanceCounter(PC_CATEGORY, "Bytes sent/sec", _instanceName, false);
                        _pcBytesReceivedPerSec = new PerformanceCounter(PC_CATEGORY, "Bytes received/sec", _instanceName, false);
                    }

                    _pcClusteredOperationsPerSec = new PerformanceCounter(PC_CATEGORY, "Cluster ops/sec", _instanceName, false);

                    _printInterval = ServiceConfiguration.StatsPrintInterval;

                    _logger = new Logs();
                    _logger.Initialize(instname + ".clstats", "ClusterPerfMonStats");

                    _printThread = new Thread(new ThreadStart(PrintStats));
                    _printThread.Start();
                }
            }
            catch (Exception e)
            {
                NCacheLog.Warn("PerfStatsCollector.PerfStatsCollector()    " + e.Message);
            }
        }
Пример #4
0
        private Address SelectNodeInternal(string key)
        {
            int hashCode = AppUtil.GetHashCode(key);
            int index    = hashCode / this.BucketSize;

            if (index < 0)
            {
                index = index * -1;
            }

            _sync.AcquireReaderLock(Timeout.Infinite);

            try
            {
                if (_installedHashMap != null)
                {
                    HashMapBucket bucket = _installedHashMap[index] as HashMapBucket;
                    if (bucket != null)
                    {
                        //if (bucket.Status != BucketStatus.Functional)
                        {
                            /// This is special case that handles operations during stateTransfer.
                            /// If a bucket is not yet transfered to the new coordinator from the replica. then
                            /// the replica's address is returned.
                            Address   coordinatorNodeAddress = bucket.TempAddress; // this should be the sub-coordinator addres
                            ArrayList ownershipMap           = _bucketsOwnershipMap[coordinatorNodeAddress] as ArrayList;
                            if (ownershipMap == null)
                            {
                                NCacheLog.Warn("DistributionManager.SelectNodeInternal()", "ownershipMap is null. Returning permanent address of bucket.");
                                return(bucket.PermanentAddress);
                            }
                            int indexOfOwnedBucket = ownershipMap.IndexOf(bucket);

                            if (indexOfOwnedBucket != -1)
                            {
                                HashMapBucket ownedBucket = ownershipMap[indexOfOwnedBucket] as HashMapBucket;
                                return(ownedBucket.PermanentAddress);
                            }
                        }
                        return(bucket.PermanentAddress);
                    }
                }
                return(null);
            }
            finally
            {
                _sync.ReleaseReaderLock();
            }
        }
Пример #5
0
        /// <summary>
        /// Called when a new member joins the group.
        /// </summary>
        /// <param name="address">address of the joining member</param>
        /// <param name="identity">additional identity information</param>
        /// <returns>true if the node joined successfuly</returns>
        internal virtual int OnMemberJoined(Address address, NodeIdentity identity)
        {
            if (identity.SubGroupName != _groupid)
            {
                return(-1);
            }

            NCacheLog.Warn("SubCluster.OnMemberJoined()", "Memeber " + address + " added to sub-cluster " + _groupid);

            _members.Add(address);
            if (identity.HasStorage && !identity.IsStartedAsMirror)
            {
                _servers.Add(address);
            }
            return(_members.Count);
        }
Пример #6
0
        private object getSessionStoreItem(bool acquireLock, IAspEnvironmentContext context, string id, out bool locked, out TimeSpan lockAge, out object lockID, out SessionInitializationActions action)
        {
            //lock age is set to zero, so SessionStateModule will,
            //after 0.5 sec, calls this GetItemExclusive function until a value or
            //null reference is returned. If no data was found, 'locked' is set to false and
            //null reference is returned which tells SessionStateModule to call CreateDataStore
            //function to create new data store

            locked  = false;
            lockAge = TimeSpan.Zero;
            lockID  = null;
            action  = SessionInitializationActions.InitializeItem;
            DateTime lockDate = DateTime.UtcNow;

            LockHandle lockHandle   = new LockHandle(null, lockDate);
            object     items        = null;
            Hashtable  table        = null;
            bool       lockTimedOut = false;
            string     locationID   = GetLocationID(context, id);


            if (_cache == null)
            {
                LogError(new OperationFailedException("The specified cache is not running. "), id);
                return(null);
            }

            try
            {
                _cache.IsSessionCookieless = IsSessionCookieless(context);
                byte[] buffer = null;
                lock (s_dataLock)
                {
                    if (s_cacheNeedInit)
                    {
                        InitializeCache();
                    }
                }
                if (_lockSessions)
                {
                    try
                    {
                        buffer = (byte[])_cache.Get(locationID, GetUniqueSessionId(id), ref lockHandle, acquireLock, true);
                    }
                    catch (Exception)
                    {
                        buffer = (byte[])_cache.Get(locationID, GetUniqueSessionId(id), ref lockHandle, acquireLock, false);
                    }


                    lockID   = lockHandle.LockId == null ? null : lockHandle;
                    lockDate = lockHandle == null ? DateTime.UtcNow : lockHandle.LockDate;
                }
                else
                {
                    try
                    {
                        buffer = (byte[])_cache.Get(locationID, GetUniqueSessionId(id), true);
                    }
                    catch (Exception)
                    {
                        buffer = (byte[])_cache.Get(locationID, GetUniqueSessionId(id), false);
                    }
                }

                if (buffer != null)
                {
                    using (MemoryStream stream = new MemoryStream(buffer))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        table = formatter.Deserialize(stream) as Hashtable;
                        stream.Close();
                    }
                }

                if (_lockSessions && !String.IsNullOrEmpty(lockHandle.LockId))
                {
                    DateTime now = DateTime.UtcNow;
                    if ((0L < lockDate.Ticks) && (lockDate.Ticks < now.Ticks))
                    {
                        lockAge = (TimeSpan)(now - lockDate);
                    }
                    else
                    {
                        lockAge = TimeSpan.Zero;
                    }

                    /// Following 'if' block is executed if item is locked.
                    /// i.e NCache API returns null and out variables are populated with lockId and lockDate
                    /// Note: Item exists in cache but is locked.
                    if (table == null)
                    {
                        if (this._sessionLockingRetries >= 0)
                        {
                            if (!context.ContainsItem(SESSION_LOCK_COUNT))
                            {
                                context[SESSION_LOCK_COUNT] = 0;
                            }

                            int retriesCompleted = (int)context[SESSION_LOCK_COUNT];

                            if (retriesCompleted < this._sessionLockingRetries)
                            {
                                context[SESSION_LOCK_COUNT] = retriesCompleted + 1;
                            }
                            else ///this will construct and send a dummy session to application
                            {
                                if (this._emptySessionWhenLocked)
                                {
                                    locked       = false;///a dummy session is going to be returned
                                    lockID       = null;
                                    lockTimedOut = true;

                                    return(CreateEmptySession(context, _defaultTimeout));
                                }
                                else
                                {
                                    throw new ProviderException("Cannot acquire session lock. Session is already locked.");
                                }
                            }
                        }

                        locked = true;
                        return(null);
                    }
                }

                /// If item exists in cahce and lock acqusition was successfull or locking was disabled.
                if (table != null)
                {
                    items = GetContents(context, table, ref action);
                    if (action == SessionInitializationActions.InitializeItem)
                    {
                        int timeout = (int)table[TIMEOUT_KEY];
                        items = CreateNewStoreData(context, timeout);
                    }
                }
                else
                {
                    if (NCacheLog != null && NCacheLog.IsInfoEnabled)
                    {
                        NCacheLog.Warn("SessionStoreBase.GetSessionItem", "Session not found in cache. " + id);
                    }
                }
            }
            catch (Exception exc)
            {
                /// If item is not found in Remote cache.
                /// Update cookies to do any further operations for this session request on current primary cache;
                /// and do not raise exception.

                LogError(exc, id);
            }
            finally
            {
                if ((lockTimedOut || table != null) && context.ContainsItem(SESSION_LOCK_COUNT))
                {
                    context.RemoveItem(SESSION_LOCK_COUNT);
                }
                //    throw new ProviderException("Cannot acquire session lock. Session is already locked.");
            }
            return(items);
        }