示例#1
0
        internal GetNextChunkCommand(EnumerationPointer pointer)
        {
            base.name = "GetNextChunkCommand";

            _getNextChunkCommand = new Alachisoft.NCache.Common.Protobuf.GetNextChunkCommand();
            _getNextChunkCommand.enumerationPointer = EnumerationPointerConversionUtil.ConvertToProtobufEnumerationPointer(pointer);
        }
示例#2
0
        public EnumerationDataChunk GetNextChunk(Alachisoft.NCache.Common.DataStructures.EnumerationPointer pointer)
        {
            int count = 0;
            EnumerationDataChunk chunk = new EnumerationDataChunk();

            chunk.Data = new List <string>();
            int currentIndex = pointer.ChunkId;

            while (currentIndex < _snapshot.Length - 1 && count < ServiceConfiguration.EnumeratorChunkSize)
            {
                currentIndex++;
                chunk.Data.Add(_snapshot.GetValue(currentIndex).ToString());
                count++;
            }

            if (currentIndex == _snapshot.Length - 1)
            {
                _pointer.ChunkId = -1;
            }
            else
            {
                _pointer.ChunkId = currentIndex; //Set the chunkId to strating index of the next chunk to fetch.
            }
            chunk.Pointer = _pointer;

            return(chunk);
        }
示例#3
0
        internal EnumerationDataChunk GetNextChunk(EnumerationPointer pointer)
        {
            EnumerationDataChunk nextChunk = null;
            IEnumerationProvider provider = GetProvider(pointer);

            if (pointer.isDisposable && provider != null)
            {
                provider.Dispose();
                if (_index.ContainsKey(pointer))
                {
                    _index.Remove(pointer);
                }
                nextChunk = new EnumerationDataChunk();
                nextChunk.Pointer = pointer;
            }
            else if (provider != null)
            {
                nextChunk = provider.GetNextChunk(pointer);
                //Dispose the provider if this is the last chunk for it
                if(nextChunk.IsLastChunk)
                {
                    provider.Dispose();
                    if (_index.ContainsKey(pointer))
                    {
                        _index.Remove(pointer);
                    }
                }
            }

            return nextChunk;
        }
 public void Initialize(EnumerationPointer pointer, IndexedLocalCache cache)
 {
     _cache = cache;
     _pointer = pointer;
     if (System.Configuration.ConfigurationSettings.AppSettings.Get("NCacheServer.EnumeratorChunkSize") != null)
         _chunkSize = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings.Get("NCacheServer.EnumeratorChunkSize"));
     _snapshot = CacheSnapshotPool.Instance.GetSnaphot(pointer.Id, cache);
 }
示例#5
0
 internal bool Contains(EnumerationPointer pointer)
 {
     if (_index != null)
     {
         return _index.ContainsKey(pointer);
     }
     else
         return false;
 }
示例#6
0
文件: NCache.cs 项目: nonomal/NCache
 public void DisposeEnumerator(EnumerationPointer pointer)
 {
     if (_cache != null)
     {
         //Just a dummy call to dispose enumerator
         pointer.isDisposable          = true;
         pointer.IsSocketServerDispose = true;
         _cache.GetNextChunk(pointer, new OperationContext());
     }
 }
示例#7
0
        public override bool Equals(object obj)
        {
            bool equals = false;

            if (obj is EnumerationPointer)
            {
                EnumerationPointer other = obj as EnumerationPointer;
                equals = _id.Equals(other._id);
            }

            return(equals);
        }
示例#8
0
        private IEnumerationProvider GetProvider(EnumerationPointer pointer)
        {
            if (_index == null)
                _index = new Dictionary<EnumerationPointer, IEnumerationProvider>();

            IEnumerationProvider provider = null;

            if (_index.ContainsKey(pointer))
            {
                provider = _index[pointer];
            }
            else if(pointer.ChunkId == -1 && !pointer.IsSocketServerDispose && !pointer.isDisposable)
            {
                provider = new SnapshotEnumerationProvider();
                provider.Initialize(pointer, _cache);
                _index.Add(pointer, provider);
            }

            return provider;
        }
        private EnumerationDataChunk Clustered_GetNextChunk(Address address, EnumerationPointer pointer,
            OperationContext operationContext)
        {
            try
            {
                Function func = new Function((int) OpCodes.GetNextChunk, new object[] {pointer, operationContext});
                object result = Cluster.SendMessage(address,
                    func,
                    GroupRequest.GET_FIRST,
                    Cluster.Timeout);



                EnumerationDataChunk nextChunk = result as EnumerationDataChunk;


                return nextChunk;
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
        private EnumerationDataChunk Clustered_GetNextChunk(ArrayList dests, EnumerationPointer pointer, OperationContext operationContext)
        {
            try
            {
                Function func = new Function((int)OpCodes.GetNextChunk, new object[] { pointer, operationContext }, false);

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

                ClusterHelper.ValidateResponses(results, typeof(EnumerationDataChunk), Name);

                /// Get a single resulting enumeration data chunk from a request
                EnumerationDataChunk nextChunk = ClusterHelper.FindAtomicEnumerationDataChunkReplicated(results) as EnumerationDataChunk;

                return nextChunk;
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
        }
        public override EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext)
        {
            /*[KS]: All clustered operation have been removed as they use to return duplicate keys because the snapshots
            created on all the nodes of replicated for a particular enumerator were not sorted and in case of node up and down we might 
            get duplicate keys when a request is routed to another client. As per discussion with iqbal sahab it has been decided that 
            whenever a node leaves the cluster we will throw Enumeration has been modified exception to the client.*/
           
            /// Wait until the object enters any running status
            _statusLatch.WaitForAny(NodeStatus.Initializing | NodeStatus.Running);

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

            EnumerationDataChunk nextChunk = null;

            if (Cluster.Servers.Count > 1)
            {

                //Enumeration Pointer came to this node on rebalance of clients and node is currently in state transfer or pointer came to this node and node is intitialized but doesnt have snapshot
                if ((_statusLatch.IsAnyBitsSet(NodeStatus.Initializing) && (pointer.ChunkId > 0 || !InternalCache.HasEnumerationPointer(pointer)))
                    || (!_statusLatch.IsAnyBitsSet(NodeStatus.Initializing) && pointer.ChunkId > 0 && !InternalCache.HasEnumerationPointer(pointer)))
                {
                    throw new OperationFailedException("Enumeration Has been Modified");
                }
                else //Node is initialized with data and has snapshot should return the next chunk locally
                {
                    nextChunk = InternalCache.GetNextChunk(pointer, operationContext);
                }

                //Dispose the pointer on all nodes as this is the last chunk for this particular enumeration pointer
                if (pointer.IsSocketServerDispose && nextChunk == null)
                {                    
                    pointer.isDisposable = true;
                    InternalCache.GetNextChunk(pointer, operationContext);
                }
                else if (nextChunk.IsLastChunk)
                {
                    pointer = nextChunk.Pointer;
                    pointer.isDisposable = true;
                    InternalCache.GetNextChunk(pointer, operationContext);
                }
            }
            else if (pointer.ChunkId > 0 && !InternalCache.HasEnumerationPointer(pointer))
            {
                throw new OperationFailedException("Enumeration Has been Modified");
            }
            else
            {
                nextChunk = InternalCache.GetNextChunk(pointer, operationContext);
            }

            return nextChunk;
        }
示例#12
0
        public override EnumerationDataChunk GetNextChunk(EnumerationPointer pointer)
        {
            EnumerationDataChunk nextChunk = null;

            if (_nCache != null)
            {
                nextChunk = _nCache.GetNextChunk(pointer, new OperationContext());
            }

            return nextChunk;
        }
示例#13
0
 public override bool HasEnumerationPointer(EnumerationPointer pointer)
 {
     Sync.AcquireWriterLock(Timeout.Infinite);
     try
     {
         return Internal.HasEnumerationPointer(pointer);
     }
     finally
     {
         Sync.ReleaseWriterLock();
     }
 }
示例#14
0
        public EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext)
        {
            EnumerationDataChunk chunk = null;

            if (!IsRunning)
                return null;

            try
            {
                chunk = _context.CacheImpl.GetNextChunk(pointer, operationContext);
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.GetNextChunk()", inner.ToString());
                throw new OperationFailedException("GetNextChunk failed. Error : " + inner.Message, inner);
            }

            return chunk;
        }
示例#15
0
 public void Deserialize(Runtime.Serialization.IO.CompactReader reader)
 {
     _data    = (List <string>)reader.ReadObject();
     _pointer = (EnumerationPointer)reader.ReadObject();
 }
        public override EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext)
        {
            /// Wait until the object enters the running status
            _statusLatch.WaitForAny(NodeStatus.Running);

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

            EnumerationDataChunk nextChunk = null;

            long clientLastViewId = GetClientLastViewId(operationContext);
            string intenededRecepient = GetIntendedRecipient(operationContext);
            Array servers = Array.CreateInstance(typeof (Address), Cluster.Servers.Count);
            Cluster.Servers.CopyTo(servers);
            Address targetNode = null;

            if (clientLastViewId == -1 && !string.IsNullOrEmpty(intenededRecepient))
            {
                for (int i = 0; i < servers.Length; i++)
                {
                    Address server = servers.GetValue(i) as Address;
                    if (server.IpAddress.ToString() == intenededRecepient)
                    {
                        targetNode = server;
                        break;
                    }
                }
                if (targetNode != null)
                {
                    if (targetNode.Equals(Cluster.LocalAddress))
                        nextChunk = InternalCache.GetNextChunk(pointer, operationContext);
                    else
                        nextChunk = Clustered_GetNextChunk(targetNode, pointer, operationContext);
                }
                else
                {
                    nextChunk = new EnumerationDataChunk();
                    nextChunk.Pointer = pointer;
                }
            }
            else
            {
                nextChunk = InternalCache.GetNextChunk(pointer, operationContext);
            }

            return nextChunk;
        }
示例#17
0
 public void DisposeEnumerator(EnumerationPointer pointer)
 {
     if (_cache != null)
     {
         //Just a dummy call to dispose enumerator
         pointer.isDisposable = true;
         pointer.IsSocketServerDispose = true;
         _cache.GetNextChunk(pointer, new OperationContext());
     }
 }
示例#18
0
 public virtual bool HasEnumerationPointer(EnumerationPointer pointer)
 {
     return false;
 }
示例#19
0
 public virtual EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext)
 {
     return null;
 }
 public void Dispose()
 {
     CacheSnapshotPool.Instance.DiposeSnapshot(_pointer.Id, _cache); //Disposes the snapshot from pool for this particular pointer
     _cache = null;
     _pointer = null;
     _snapshot = null;
 }
示例#21
0
        public override bool HasEnumerationPointer(EnumerationPointer pointer)
        {
            if (_enumerationIndex == null)
                return false;

            return _enumerationIndex.Contains(pointer);
        }
示例#22
0
 public void Deserialize(Runtime.Serialization.IO.CompactReader reader)
 {
     _data = (List<string>)reader.ReadObject();
     _pointer = (EnumerationPointer)reader.ReadObject();
 }
示例#23
0
        public override EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext)
        {
            if (_enumerationIndex == null)
                _enumerationIndex = new EnumerationIndex(this);

            EnumerationDataChunk nextChunk = _enumerationIndex.GetNextChunk(pointer);

            return nextChunk;
        }
示例#24
0
 public override EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext)
 {
     return Internal.GetNextChunk(pointer, operationContext);
 }
示例#25
0
 public override EnumerationDataChunk GetNextChunk(EnumerationPointer pointer, OperationContext operationContext)
 {
     Sync.AcquireWriterLock(Timeout.Infinite);
     try
     {
         return Internal.GetNextChunk(pointer, operationContext);
     }
     finally
     {
         Sync.ReleaseWriterLock();
     }
 }
示例#26
0
 public virtual EnumerationDataChunk GetNextChunk(EnumerationPointer pointer)
 {
     return null;
 }