Beispiel #1
0
        /// <summary>
        /// Does a seek operation on the current stream when there is a seek filter on the reader.
        /// </summary>
        /// <returns>
        /// True if the provided key is still valid within the next best fitting frame.
        /// </returns>
        private bool AdvanceSeekableFilter(bool isValid, TKey key)
        {
TryAgain:
            if (m_keySeekFilter != null && m_keySeekFilter.NextWindow())
            {
                //If the current point is a valid point.
                //Check to see if the seek operation can be avoided.
                //or if the next available point does not exist in this window.
                if (isValid)
                {
                    //If the current point is within this window
                    if (key.IsGreaterThanOrEqualTo(m_keySeekFilter.StartOfFrame) &&
                        key.IsLessThanOrEqualTo(m_keySeekFilter.EndOfFrame))
                    {
                        return(true);
                    }

                    //If the current point is after this window, seek to the next window.
                    if (key.IsGreaterThan(m_keySeekFilter.EndOfFrame))
                    {
                        goto TryAgain;
                    }
                }

                //If the current point is not valid, or is before m_startKey
                //Advance the scanner to the next window.
                SeekAllArchiveStreamsForward(m_keySeekFilter.StartOfFrame);
                return(false);
            }
            Dispose();
            m_firstTableScanner = null;
            m_firstTable        = null;
            return(false);
        }
Beispiel #2
0
        public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList,
                                      SortedTreeEngineReaderOptions readerOptions             = null,
                                      SeekFilterBase <TKey> keySeekFilter                     = null,
                                      MatchFilterBase <TKey, TValue> keyMatchFilter           = null,
                                      WorkerThreadSynchronization workerThreadSynchronization = null)
        {
            if (readerOptions is null)
            {
                readerOptions = SortedTreeEngineReaderOptions.Default;
            }
            if (keySeekFilter is null)
            {
                keySeekFilter = new SeekFilterUniverse <TKey>();
            }
            if (keyMatchFilter is null)
            {
                keyMatchFilter = new MatchFilterUniverse <TKey, TValue>();
            }
            if (workerThreadSynchronization is null)
            {
                m_ownsWorkerThreadSynchronization = true;
                workerThreadSynchronization       = new WorkerThreadSynchronization();
            }

            m_workerThreadSynchronization = workerThreadSynchronization;
            m_pointCount         = 0;
            m_keySeekFilter      = keySeekFilter;
            m_keyMatchFilter     = keyMatchFilter;
            m_keyMatchIsUniverse = m_keyMatchFilter as MatchFilterUniverse <TKey, TValue> != null;

            if (readerOptions.Timeout.Ticks > 0)
            {
                m_timeout = new TimeoutOperation();
                m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true);
            }

            m_snapshot = archiveList.CreateNewClientResources();
            m_snapshot.UpdateSnapshot();
            m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >();

            for (int x = 0; x < m_snapshot.Tables.Count(); x++)
            {
                ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x];
                if (table != null)
                {
                    if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange))
                    {
                        try
                        {
                            m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table));
                        }
                        catch (Exception e)
                        {
                            //ToDo: Make sure firstkey.tostring doesn't ever throw an exception.
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine($"Archive ID {table.FileId}");
                            sb.AppendLine($"First Key {table.FirstKey.ToString()}");
                            sb.AppendLine($"Last Key {table.LastKey.ToString()}");
                            sb.AppendLine($"File Size {table.SortedTreeTable.BaseFile.ArchiveSize}");
                            sb.AppendLine($"File Name {table.SortedTreeTable.BaseFile.FilePath}");
                            Log.Publish(MessageLevel.Error, "Error while reading file", sb.ToString(), null, e);
                        }
                    }
                    else
                    {
                        m_snapshot.Tables[x] = null;
                    }
                }
            }

            m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan);

            m_keySeekFilter.Reset();
            if (m_keySeekFilter.NextWindow())
            {
                SeekToKey(m_keySeekFilter.StartOfFrame);
            }
            else
            {
                Dispose();
            }
        }
Beispiel #3
0
        public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList,
                                      SortedTreeEngineReaderOptions readerOptions             = null,
                                      SeekFilterBase <TKey> keySeekFilter                     = null,
                                      MatchFilterBase <TKey, TValue> keyMatchFilter           = null,
                                      WorkerThreadSynchronization workerThreadSynchronization = null)
        {
            if (readerOptions == null)
            {
                readerOptions = SortedTreeEngineReaderOptions.Default;
            }
            if (keySeekFilter == null)
            {
                keySeekFilter = new SeekFilterUniverse <TKey>();
            }
            if (keyMatchFilter == null)
            {
                keyMatchFilter = new MatchFilterUniverse <TKey, TValue>();
            }
            if (workerThreadSynchronization == null)
            {
                m_ownsWorkerThreadSynchronization = true;
                workerThreadSynchronization       = new WorkerThreadSynchronization();
            }

            m_workerThreadSynchronization = workerThreadSynchronization;
            m_pointCount         = 0;
            m_keySeekFilter      = keySeekFilter;
            m_keyMatchFilter     = keyMatchFilter;
            m_keyMatchIsUniverse = (m_keyMatchFilter as MatchFilterUniverse <TKey, TValue>) != null;

            if (readerOptions.Timeout.Ticks > 0)
            {
                m_timeout = new TimeoutOperation();
                m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true);
            }

            m_snapshot = archiveList.CreateNewClientResources();
            m_snapshot.UpdateSnapshot();
            m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >();

            for (int x = 0; x < m_snapshot.Tables.Count(); x++)
            {
                ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x];
                if (table != null)
                {
                    if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange))
                    {
                        m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table));
                    }
                    else
                    {
                        m_snapshot.Tables[x] = null;
                    }
                }
            }

            m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan);

            m_keySeekFilter.Reset();
            if (m_keySeekFilter.NextWindow())
            {
                SeekToKey(m_keySeekFilter.StartOfFrame);
            }
            else
            {
                Dispose();
            }
        }