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 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 < _chunkSize)
            {
                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;
        }
        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;
        }
Exemple #4
0
        internal void MergeResponse(Common.Net.Address address, CommandResponse response)
        {
            if (_finalResponse == null && response.Type != Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK)
            {
                _finalResponse = response;

                if (response.IsBrokerReset)
                {
                    MergeFailedResponse(response);
                }

            }
            else
            {
                if (response.IsBrokerReset)
                {
                    MergeFailedResponse(response);
                }
                else
                {
                    IDictionaryEnumerator ide = null;
                    switch (response.Type)
                    {
                        case Alachisoft.NCache.Common.Protobuf.Response.Type.ADD_BULK:
                        case Alachisoft.NCache.Common.Protobuf.Response.Type.INSERT_BULK:
                        case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_BULK:
                        case Alachisoft.NCache.Common.Protobuf.Response.Type.REMOVE_BULK:
                            ide = response.KeyValueDic.GetEnumerator();
                            while (ide.MoveNext())
                            {
                                _finalResponse.KeyValueDic[ide.Key] = ide.Value;
                            }
                            break;
                        case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH:

                            if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND)
                                || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND))
                            {
                                _finalResponse = response;
                                break;
                            }

                            switch (response.ResultSet.AggregateFunctionType)
                            {
                                case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE:
                                    _finalResponse.KeyList.AddRange(response.KeyList);
                                    break;

                                default:
                                    if (!_finalResponse.ResultSet.IsInitialized)
                                    {
                                        SetAggregateFunctionResult();
                                        _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet);
                                    }
                                    _finalResponse.ResultSet.Compile(response.ResultSet);
                                    break;
                            }
                            break;

                       case Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES:

                            if ((_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.TYPE_INDEX_NOT_FOUND)
                                || (_finalResponse.ExceptionType == Alachisoft.NCache.Common.Enum.ExceptionType.ATTRIBUTE_INDEX_NOT_FOUND))
                            {
                                _finalResponse = response;
                                break;
                            }
                                    switch (response.ResultSet.AggregateFunctionType)
                                    {
                                        case Alachisoft.NCache.Common.Enum.AggregateFunctionType.NOTAPPLICABLE:
                                            ide = response.KeyValueDic.GetEnumerator();
                                            while (ide.MoveNext())
                                            {
                                                _finalResponse.KeyValueDic[ide.Key] = ide.Value;
                                            }
                                            break;

                                        default:
                                            if (!_finalResponse.ResultSet.IsInitialized)
                                            {
                                                SetAggregateFunctionResult();
                                                _finalResponse.ResultSet.Initialize(_finalResponse.ResultSet);
                                            }
                                            _finalResponse.ResultSet.Compile(response.ResultSet);
                                            break;
                                    }
                            break;

                        case Alachisoft.NCache.Common.Protobuf.Response.Type.GET_NEXT_CHUNK:
                            if (_finalResponse == null)
                                _finalResponse = response;

                            EnumerationDataChunk chunk = null;
                            if (_chunks.ContainsKey(address))
                            {
                                chunk = _chunks[address];
                            }
                            else
                            {
                                chunk = new EnumerationDataChunk();
                                chunk.Data = new List<string>();
                                _chunks.Add(address, chunk);
                            }

                            for (int i = 0; i < response.NextChunk.Count; i++)
                            {
                                chunk.Data.AddRange(response.NextChunk[i].Data);
                                chunk.Pointer = response.NextChunk[i].Pointer;
                                if (chunk.Pointer.NodeIpAddress==null)
                                    chunk.Pointer.NodeIpAddress = address;
                            }

                            _finalResponse.NextChunk = new List<EnumerationDataChunk>(_chunks.Values);

                            break;

                        case Alachisoft.NCache.Common.Protobuf.Response.Type.EXCEPTION:
                            if (response.ExceptionType == Common.Enum.ExceptionType.STATE_TRANSFER_EXCEPTION)
                            {
                                _finalResponse = response;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }