Exemple #1
0
 void ICompactSerializable.Deserialize(CompactReader reader)
 {
     _lockId=reader.ReadObject();
     _lockDate = reader.ReadDateTime();
     _lockExpiration = reader.ReadObject() as LockExpiration;
     _lockManager = reader.ReadObject() as LockManager;                
 }
Exemple #2
0
 void ICompactSerializable.Deserialize(CompactReader reader)
 {
     _lockId         = reader.ReadObject();
     _lockDate       = reader.ReadDateTime();
     _lockExpiration = reader.ReadObject() as LockExpiration;
     _lockManager    = reader.ReadObject() as LockManager;
 }
Exemple #3
0
        public LockExpiration DeepClone(PoolManager poolManager)
        {
            var clonedLockExpiration = new LockExpiration();

            clonedLockExpiration._lastTimeStamp = _lastTimeStamp;
            clonedLockExpiration._lockTTL       = _lockTTL;
            clonedLockExpiration._ttl           = _ttl;

            return(clonedLockExpiration);
        }
 public override LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
 {
     if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCache.Lock", "");
     if (Cluster.Servers.Count > 1)
     {
         Clustered_Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext);
         return new LockOptions(lockId, lockDate);
     }
     else
     {
         return Local_Lock(key, lockExpiration, lockId, lockDate, operationContext);
     }
 }
 /// <summary>
 /// Retrieve the object from the local cache only. 
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <returns>cache entry.</returns>
 private CacheEntry Local_Get(object key,  ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType access, OperationContext operationContext)
 {
     CacheEntry retVal = null;
     if (_internalCache != null)
         retVal = _internalCache.Get(key, ref lockId, ref lockDate, lockExpiration, access, operationContext);
     return retVal;
 }
Exemple #6
0
 public override LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
 {
     return Internal.Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext);
 }
Exemple #7
0
        public void CopyLock(object lockId, DateTime lockDate, LockExpiration lockExpiration)
        {
            lock (this)
            {
                if(lockId != null)
                    this.Flag.SetBit(BitSetConstants.LockedItem);
                else
                    this.Flag.UnsetBit(BitSetConstants.LockedItem);

                this.LockId = lockId;
                this.LockDate = lockDate;
                this.LockExpiration = lockExpiration;
            }
        }
 /// <summary>
 /// Retrieve the object from the cache. A string key is passed as parameter.
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <param name="lockId"></param>
 /// <param name="lockDate"></param>
 /// <param name="lockExpiration"></param>
 /// <param name="accessType"></param>
 /// <param name="operationContext"></param>
 /// <returns>cache entry.</returns>
 public sealed override CacheEntry Get(object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     return Get(key, true, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);
 }
        public override LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
        {
            LockOptions lockInfo = new LockOptions();

            CacheEntry e = GetInternal(key, false, operationContext);
            if (e != null)
            {
                e.Lock(lockExpiration, ref lockId, ref lockDate);
                lockInfo.LockDate = lockDate;
                lockInfo.LockId = lockId;
                return lockInfo;
            }
            else
            {
                lockInfo.LockId = lockId = null;
                return lockInfo;
            }
        }
 private LockOptions Local_Lock(object key, LockExpiration lockExpiration, object lockId, DateTime lockDate, OperationContext operationContext)
 {
     if (_internalCache != null)
         return _internalCache.Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext);
     return null;
 }
        /// <summary>
        /// Retrieve the object from the cluster. 
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="excludeSelf">Set false to do a complete cluster lookup.</param>
        /// <returns>cache entry.</returns>
        protected CacheEntry Clustered_Get(Address address, object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType access, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("ClustCacheBase.Get", "");

            CacheEntry retVal = null;
            try
            {
                Function func = new Function((int)OpCodes.Get, new object[] { key, lockId, lockDate, access, lockExpiration, operationContext });
                object result = Cluster.SendMessage(address, func, GetFirstResponse);
                if (result == null)
                {
                    return retVal;
                }

                object[] objArr = (object[])((OperationResponse)result).SerializablePayload;
                retVal = objArr[0] as CacheEntry;
                if (retVal != null)
                {
                    retVal.Value = ((OperationResponse)result).UserPayload;
                }
                lockId = objArr[1];
                lockDate = (DateTime)objArr[2];
            }
            catch (Runtime.Exceptions.TimeoutException te)
            {
                throw;
            }
            catch (Runtime.Exceptions.SuspectedException se)
            {
                throw;
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return retVal;
        }
Exemple #12
0
 /// <summary>
 /// Retrieve the object from the cache. A string key is passed as parameter.
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <param name="lockId"></param>
 /// <param name="lockDate"></param>
 /// <param name="lockExpiration"></param>
 /// <param name="accessType"></param>
 /// <param name="operationContext"></param>
 /// <returns>cache entry.</returns>
 public virtual CacheEntry Get(object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     lockId = null;
     lockDate = DateTime.Now;
     return null;
 }
Exemple #13
0
 public virtual LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
 {
     lockId = null;
     lockDate = DateTime.Now;
     return null;
 }
Exemple #14
0
 public virtual CacheEntry Get(object key, bool isUserOperation, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     return null;
 }
Exemple #15
0
 internal virtual void UpdateLockInfo(object key, object lockId, DateTime lockDate, LockExpiration lockExpiration, OperationContext operationContext)
 {
 }
Exemple #16
0
        public CompressedValueEntry Get(object key, BitSet flagMap,ref object lockId, ref DateTime lockDate, TimeSpan lockTimeout, LockAccessType accessType, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("Cache.GetGrp", "");
            // Cache has possibly expired so do default.
            if (!IsRunning) return null; 

            CompressedValueEntry result = new CompressedValueEntry();
            CacheEntry e = null;
            try
            {
                _context.PerfStatsColl.MsecPerGetBeginSample();
                _context.PerfStatsColl.IncrementGetPerSecStats();
                _context.PerfStatsColl.IncrementHitsRatioPerSecBaseStats();
                HPTimeStats getTime = new HPTimeStats();
                getTime.BeginSample();

                LockExpiration lockExpiration = null;
                if (accessType == LockAccessType.ACQUIRE)
                {
                    lockId = GetLockId(key);
                    lockDate = DateTime.UtcNow;

                    if (!TimeSpan.Equals(lockTimeout, TimeSpan.Zero))
                    {
                        lockExpiration = new LockExpiration(lockTimeout);
                    }
                }

                object generatedLockId = lockId;

                e = _context.CacheImpl.Get(key, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);
                

                if (e == null && accessType == LockAccessType.ACQUIRE)
                {
                    if (lockId == null || generatedLockId.Equals(lockId))
                    {
                        lockId = null;
                        lockDate = new DateTime();
                    }
                }
                if (flagMap != null)
                {
                    
                    if (e != null)
                    {
                        /// increment the counter for hits/sec
                        _context.PerfStatsColl.MsecPerGetEndSample();
                        result.Value = e.Value;
                        result.Flag = e.Flag;
                    }

                }
                _context.PerfStatsColl.MsecPerGetEndSample();
                getTime.EndSample();
                
                /// update the counter for hits/sec or misses/sec
                if (result.Value != null)
                {
                    _context.PerfStatsColl.IncrementHitsRatioPerSecStats();
                    _context.PerfStatsColl.IncrementHitsPerSecStats();
                }
                else
                {
                    _context.PerfStatsColl.IncrementMissPerSecStats();
                }
                if (result.Value is CallbackEntry)
                    result.Value = ((CallbackEntry)result.Value).Value;
            }
            catch (OperationFailedException inner)
            {
                if (inner.IsTracable) _context.NCacheLog.Error("Cache.Get()", "Get operation failed. Error : " + inner.ToString());
                throw;
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.Get()", "Get operation failed. Error : " + inner.ToString());
                throw new OperationFailedException("Get operation failed. Error :" + inner.Message, inner);
            }

            return result;
        }
Exemple #17
0
        public bool Lock(object key, TimeSpan lockTimeout, out object lockId, out DateTime lockDate, OperationContext operationContext)
        {
            lockId = null;
            lockDate = DateTime.UtcNow;
            LockExpiration lockExpiration = null;
            if (!TimeSpan.Equals(lockTimeout, TimeSpan.Zero))
            {
                lockExpiration = new LockExpiration(lockTimeout);
            }

            if (IsRunning)
            {
                object generatedLockId = lockId = GetLockId(key);
                LockOptions lockInfo = _context.CacheImpl.Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext);
                if (lockInfo != null)
                {
                    lockId = lockInfo.LockId;
                    lockDate = lockInfo.LockDate;
                    if (generatedLockId.Equals(lockInfo.LockId))
                        return true;
                    return false;
                }
                else
                {
                    lockId = null;
                    return false;
                }
            }
            return false;
        }
Exemple #18
0
        /// <summary>
        /// Get the CacheEntry stored in the cache.
        /// </summary>
        /// <param name="key">The key used as reference to find the desired object</param>
        /// <param name="lockId"></param>
        /// <param name="lockDate"></param>
        /// <param name="lockTimeout"></param>
        /// <param name="accessType"></param>
        /// <param name="operationContext"></param>
        /// <returns>Returns a CacheEntry</returns>
        public object GetCacheEntry(object key, ref object lockId, ref DateTime lockDate, TimeSpan lockTimeout, LockAccessType accessType, OperationContext operationContext)
        {
            if (key == null) throw new ArgumentNullException("key");
            if (!key.GetType().IsSerializable)
                throw new ArgumentException("key is not serializable");

            // Cache has possibly expired so do default.
            if (!IsRunning) return null; 

            try
            {
                _context.PerfStatsColl.MsecPerGetBeginSample();
                _context.PerfStatsColl.IncrementGetPerSecStats();
                CacheEntry entry = null;

                LockExpiration lockExpiration = null;

                //if lockId will be empty if item is not already lock provided by user
                if ((lockId != null && lockId.ToString() == "") || lockId == null)
                {
                    if (accessType == LockAccessType.ACQUIRE)
                    {
                        lockId = GetLockId(key);
                        lockDate = DateTime.Now;

                        if (!TimeSpan.Equals(lockTimeout, TimeSpan.Zero))
                        {
                            lockExpiration = new LockExpiration(lockTimeout);
                        }
                    }
                }

                object generatedLockId = lockId;

                // if only key is provided by user
                if ((accessType == LockAccessType.IGNORE_LOCK || accessType == LockAccessType.DONT_ACQUIRE))
                {
                    entry = _context.CacheImpl.Get(key, operationContext);
                }

                 //if key and locking information is provided by user
                else
                {

                    entry = _context.CacheImpl.Get(key, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);
                }

                if (entry == null && accessType == LockAccessType.ACQUIRE)
                {
                    if (lockId == null || generatedLockId.Equals(lockId))
                    {
                        lockId = null;
                        lockDate = new DateTime();
                    }
                }

                
                _context.PerfStatsColl.MsecPerGetEndSample();

                if (entry != null)
                {
                    _context.PerfStatsColl.IncrementHitsPerSecStats();
                }
                else
                {
                    _context.PerfStatsColl.IncrementMissPerSecStats();
                }

                return entry;
            }
            catch (OperationFailedException inner)
            {
                if (inner.IsTracable) _context.NCacheLog.Error("Cache.Get()", inner.ToString());
                throw;
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.Get()", inner.ToString());
                throw new OperationFailedException("Get operation failed. Error : " + inner.Message, inner);
            }
        }
        protected LockOptions Clustered_Lock(Address address, object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("ClustCacheBase.Lock", "");
            LockOptions retVal = null;
            try
            {
                Function func = new Function((int)OpCodes.LockKey, new object[] { key, lockId, lockDate, lockExpiration, operationContext });
                object result = Cluster.SendMessage(address, func, GroupRequest.GET_FIRST);
                if (result == null)
                {
                    return retVal;
                }

                retVal = result as LockOptions;
                if (retVal != null)
                {
                    lockId = retVal.LockId;
                    lockDate = retVal.LockDate;
                }
            }
            catch (Runtime.Exceptions.TimeoutException te)
            {
                throw;
            }
            catch (Runtime.Exceptions.SuspectedException se)
            {
                throw;
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }

            return retVal;
        }
        /// <summary>
        /// Retrieve the object from the cache. A string key is passed as parameter.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="lockId"></param>
        /// <param name="lockDate"></param>
        /// <param name="lockExpiration"></param>
        /// <param name="access"></param>
        /// <param name="operationContext"></param>
        /// <returns>cache entry.</returns>
        public override CacheEntry Get(object key, ref object lockId, ref DateTime lockDate,
            LockExpiration lockExpiration, LockAccessType access, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PrtCache.Get", "");

            /// Wait until the object enters the running status
            _statusLatch.WaitForAny(NodeStatus.Running);

            if (_internalCache == null) throw new InvalidOperationException();

            Address address = null;
            CacheEntry e = null;
            bool suspectedErrorOccured = false;

            while (true)
            {
                address = GetNextNode(key as string);

                if (address == null)
                {
                    NCacheLog.Error("PartitionedServerCache.Get()", "specified key does not map to any node. return.");
                    return null;
                }

                try
                {
                    if (address.CompareTo(Cluster.LocalAddress) == 0)
                    {
                        e = Local_Get(key, ref lockId, ref lockDate, lockExpiration, access, operationContext);
                    }
                    else
                    {
                        e = Clustered_Get(address, key, ref lockId, ref lockDate, lockExpiration, access,
                            operationContext);

                    }

                    if (e == null)
                    {
                        _stats.BumpMissCount();
                    }
                    else
                    {
                        _stats.BumpHitCount();
                    }
                    break;
                }
                catch (Runtime.Exceptions.SuspectedException se)
                {
                    suspectedErrorOccured = true;
                    //we redo the operation
                    if (NCacheLog.IsInfoEnabled)
                        NCacheLog.Info("PartitionedServerCache.Get",
                            address + " left while Get. Error: " + se.ToString());
                    continue;
                }
                catch (Runtime.Exceptions.TimeoutException te)
                {
                    if (NCacheLog.IsInfoEnabled)
                        NCacheLog.Info("PartitionedServerCache.Get",
                            address + " operation timed out. Error: " + te.ToString());
                    if (suspectedErrorOccured)
                    {
                        suspectedErrorOccured = false;
                        continue;
                    }
                    else
                    {
                        throw new GeneralFailureException(te.Message, te);
                    }
                }
                catch (Alachisoft.NCache.Caching.Exceptions.StateTransferException se)
                {
                    _distributionMgr.Wait(key);
                }
            }
            return e;

        }
        protected bool Clustered_Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
        {
            try
            {
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCacheBase.Lock", "enter");
                Function func = new Function((int)OpCodes.LockKey, new object[] { key, lockId, lockDate, lockExpiration, operationContext }, false);

                RspList results = Cluster.BroadcastToMultiple(Cluster.Servers,
                        func,
                        GroupRequest.GET_ALL);

                try
                {
                    ClusterHelper.ValidateResponses(results, typeof(LockOptions), Name);
                }
                catch (LockingException le)
                {
                    //release the lock preemptively...
                    Clustered_UnLock(key, null, true, operationContext);
                    return false;
                }

                return ClusterHelper.FindAtomicLockStatusReplicated(results, ref lockId, ref lockDate);
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            finally
            {
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCacheBase.Lock", "exit");
            }
        }
        public override LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId,
            ref DateTime lockDate, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PartCache.lock", "lock_id :" + lockId);

            /// Wait until the object enters the running status
            _statusLatch.WaitForAny(NodeStatus.Running);

            if (_internalCache == null) throw new InvalidOperationException();

            LockOptions lockInfo = null;
            Address address = null;
            bool suspectedErrorOccured = false;

            while (true)
            {
                address = GetNextNode(key as string);

                if (address == null)
                {
                    NCacheLog.Error("PartitionedServerCache.lock()", "specified key does not map to any node. return.");
                    return null;
                }

                try
                {
                    if (address.CompareTo(Cluster.LocalAddress) == 0)
                    {
                        lockInfo = Local_Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext);
                    }
                    else
                    {
                        lockInfo = Clustered_Lock(address, key, lockExpiration, ref lockId, ref lockDate,
                            operationContext);
                    }
                    return lockInfo;
                }
                catch (Runtime.Exceptions.SuspectedException se)
                {
                    suspectedErrorOccured = true;
                    //we redo the operation
                    if (NCacheLog.IsInfoEnabled)
                        NCacheLog.Info("PartitionedServerCache.lock",
                            address + " left while trying to lock the key. Error: " + se.ToString());
                    continue;
                }
                catch (Runtime.Exceptions.TimeoutException te)
                {
                    if (NCacheLog.IsInfoEnabled)
                        NCacheLog.Info("PartitionedServerCache.lock",
                            address + " operation timed out. Error: " + te.ToString());
                    if (suspectedErrorOccured)
                    {
                        suspectedErrorOccured = false;
                        continue;
                    }
                    else
                    {
                        throw new GeneralFailureException(te.Message, te);
                    }
                }
                catch (Alachisoft.NCache.Caching.Exceptions.StateTransferException se)
                {
                    _distributionMgr.Wait(key);
                }
            }
            return lockInfo;
        }
        internal override void UpdateLockInfo(object key, object lockId, DateTime lockDate, LockExpiration lockExpiration, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.UpdLock", "enter");

            Sync.AcquireWriterLock(Timeout.Infinite);
            try
            {
                Internal.UpdateLockInfo(key, lockId, lockDate, lockExpiration, operationContext);
            }
            finally
            {
                Sync.ReleaseWriterLock();
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.UpdLock", "exit");

            }
        }
        /// <summary>
        /// Retrieve the object from the cache. A string key is passed as parameter.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="lockId"></param>
        /// <param name="lockDate"></param>
        /// <param name="lockExpiration"></param>
        /// <param name="access"></param>
        /// <param name="operationContext"></param>
        /// <returns>cache entry.</returns>
        public override CacheEntry Get(object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType access, OperationContext operationContext)
        {
            CacheEntry entry = null;
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Get_2", "enter");

            Sync.AcquireReaderLock(Timeout.Infinite);
            try
            {
                entry = Internal.Get(key, ref lockId, ref lockDate, lockExpiration, access, operationContext);

                    if (access == LockAccessType.ACQUIRE && entry != null && _context.CacheImpl.RequiresReplication)
                    {
                        string uniqueKey = System.Guid.NewGuid().ToString() + key;
#if !CLIENT
                        _context.CacheImpl.EnqueueForReplication(null, (int)ClusterCacheBase.OpCodes.UpdateLockInfo, new object[] { true, key, lockId, lockDate, lockExpiration, operationContext });
#endif
                    }

            }
            finally
            {
                Sync.ReleaseReaderLock();
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Get_2", "exit");

            }
            return entry;
        }
Exemple #25
0
 internal override void UpdateLockInfo(object key, object lockId, DateTime lockDate, LockExpiration lockExpiration, OperationContext operationContext)
 {
     CacheEntry entry = GetInternal(key, false, operationContext);
     if (entry != null)
     {
         entry.CopyLock(lockId, lockDate, lockExpiration);
     }
 }
        public override LockOptions Lock(object key, LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate, OperationContext operationContext)
        {
            LockOptions lockInfo = null;
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Lock", "enter");

            Sync.AcquireWriterLock(Timeout.Infinite);
            try
            {
                lockInfo = Internal.Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext);

                    if (_context.CacheImpl.RequiresReplication)
                    {
                        string uniqueKey = System.Guid.NewGuid().ToString() + key;
#if !CLIENT
                        _context.CacheImpl.EnqueueForReplication(null, (int)ClusterCacheBase.OpCodes.UpdateLockInfo, new object[] { true, key, lockId, lockDate, lockExpiration, operationContext });
#endif
                    }
            }
            finally
            {
                Sync.ReleaseWriterLock();
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Lock", "exit");

            }
            return lockInfo;
        }
Exemple #27
0
        /// <summary>
        /// Retrieve the object from the cache. A string key is passed as parameter.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="isUserOperation"></param>
        /// <param name="lockId"></param>
        /// <param name="lockDate"></param>
        /// <param name="lockExpiration"></param>
        /// <param name="accessType"></param>
        /// <param name="operationContext"></param>
        /// <returns>cache entry.</returns>
        public sealed override CacheEntry Get(object key, bool isUserOperation, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
        {
            CacheEntry e = GetInternal(key, isUserOperation, operationContext);

            if (accessType != LockAccessType.IGNORE_LOCK)
            {
                if (e != null)
                {
                    if (accessType == LockAccessType.DONT_ACQUIRE)
                    {
                        bool success = e.CompareLock(lockId);
                        if (success)
                        {
                            //explicitly set the lockdate incase of compare lock.
                            //compare lock does not set the lockdate.
                            lockDate = e.LockDate;
                        }
                        else
                        {
                            success = !e.IsLocked(ref lockId, ref lockDate);
                        }

                        if (!success) { e = null; }


                    }
                    else if (accessType == LockAccessType.ACQUIRE && !e.Lock(lockExpiration, ref lockId, ref lockDate))//internally sets the out parameters
                    {
                        e = null;
                    }
                }
                else
                {
                    lockId = null;
                }
            }

            ExpirationHint exh = (e == null ? null : e.ExpirationHint);
            if (exh != null)
            {
                if (exh.CheckExpired(_context))
                {
                    // If cache forward is set we skip the expiration.
                    if (!exh.NeedsReSync)
                    {

                        ItemRemoveReason reason = ItemRemoveReason.Expired;
                        
                        Remove(key, reason, true, null, LockAccessType.IGNORE_LOCK, operationContext);

                        e = null;
                    }
                }

                if (exh.IsVariant && isUserOperation)
                {
                    try
                    {
                        _context.ExpiryMgr.ResetVariant(exh);
                    }
                    catch (Exception ex)
                    {
                        RemoveInternal(key, ItemRemoveReason.Removed, false, operationContext);
                        throw ex;
                    }
                }
            }

            _stats.UpdateCount(this.Count);
            if (e != null)
                _stats.BumpHitCount();
            else
                _stats.BumpMissCount();

            return e;
        }
        /// <summary>
        /// Retrieve the object from the cache. A string key is passed as parameter.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        public override CacheEntry Get(object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType access, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("RepCache.Get", "");
            /// Wait until the object enters any running status
            _statusLatch.WaitForAny(NodeStatus.Initializing | NodeStatus.Running);

            if (_internalCache == null) throw new InvalidOperationException();
            CacheEntry e = null;

           
            if (access == LockAccessType.ACQUIRE || access == LockAccessType.DONT_ACQUIRE)
            {
                if (Cluster.Servers.Count > 1)
                {
                    e = Local_Get(key, false, operationContext);
                    if (e != null)
                    {
                        if (access == LockAccessType.DONT_ACQUIRE)
                        {
                            if (e.IsItemLocked() && !e.CompareLock(lockId))
                            {
                                lockId = e.LockId;
                                lockDate = e.LockDate;
                                e = null;
                            }
                            else
                            {
                                lockDate = e.LockDate; //compare lock does not set the lockdate internally.
                            }
                        }
                        else if (!e.IsLocked(ref lockId, ref lockDate))
                        {
                            if (Clustered_Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext))
                            {
                                e = Local_Get(key,  ref lockId, ref lockDate, lockExpiration, LockAccessType.IGNORE_LOCK, operationContext);
                            }
                        }
                        else
                        {
                            //dont send the entry back if it is locked.
                            e = null;
                        }
                    }
                    else if (_statusLatch.IsAnyBitsSet(NodeStatus.Initializing))
                    {
                        if (access == LockAccessType.ACQUIRE)
                        {
                            if (Clustered_Lock(key, lockExpiration, ref lockId, ref lockDate, operationContext))
                            {
                                e = Clustered_Get(key, ref lockId, ref lockDate, access, operationContext);
                            }
                        }
                        else
                        {
                            e = Clustered_Get(key, ref lockId, ref lockDate, access, operationContext);
                        }
                    }
                }
                else
                {
                    e = Local_Get(key,  ref lockId, ref lockDate, lockExpiration, access, operationContext);
                }
            }
            else
            {
                e = Local_Get(key, operationContext);

                if (e == null && _statusLatch.IsAnyBitsSet(NodeStatus.Initializing))
                {
                    e = Clustered_Get(key, ref lockId, ref lockDate, LockAccessType.IGNORE_LOCK, operationContext);
                }
            }

            if (e == null)
            {
                _stats.BumpMissCount();
            }
            else
            {
                _stats.BumpHitCount();
                // update the indexes on other nodes in the cluster
                if ((e.ExpirationHint != null && e.ExpirationHint.IsVariant) /*|| (e.EvictionHint !=null && e.EvictionHint.IsVariant)*/ )
                {
                    UpdateIndices(key, true, operationContext);
                    Local_Get(key, operationContext); //to update the index locally.
                }
            }
            return e;
        }
Exemple #29
0
        public bool Lock(LockExpiration lockExpiration, ref object lockId, ref DateTime lockDate)
        {
            lock (this)
            {
                if (!this.IsLocked(ref lockId, ref lockDate))
                {
                    this.Flag.SetBit(BitSetConstants.LockedItem);
                    this.LockId = lockId;
                    this.LockDate = lockDate;
                    this.LockExpiration = lockExpiration;
                    if (this.LockExpiration != null) this.LockExpiration.Set();
                    return true;
                }
                else
                {
                    lockId = this.LockId;
                    lockDate = this.LockDate;
                }

                return false;
            }
        }
Exemple #30
0
 /// <summary>
 /// Retrieve the object from the cache. A string key is passed as parameter.
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <param name="lockId"></param>
 /// <param name="lockDate"></param>
 /// <param name="lockExpiration"></param>
 /// <param name="accessType"></param>
 /// <param name="operationContext"></param>
 /// <returns>cache entry.</returns>
 public override CacheEntry Get(object key, ref object lockId, ref DateTime lockDate, LockExpiration lockExpiration, LockAccessType accessType, OperationContext operationContext)
 {
     CacheEntry entry = Internal.Get(key, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);
     if (entry != null && KeepDeflattedValues)
     {
         entry.KeepDeflattedValue(_context.SerializationContext);
     }
     return entry;
 }