示例#1
0
        private void ProcessBadQueue(T last)
        {
            if (_queueReader == null)
            {
                return;
            }
            var oldpostion = _queueReader.ReadedPostion();

            while (true)
            {
                if (_queueReader.PostionNextSplitChar())
                {
                    var newpostion = _queueReader.ReadedPostion();

                    if (_queueReader.ReadObject <T>() != default(T))
                    {
                        _queueReader.SetPostion(newpostion);
                        OnProcessError(last, new Exception(string.Format("队列损环,将尝试读取下一个队列。损坏位置{0},恢复位置{1},损坏长度:{2}kb。", oldpostion, newpostion, (newpostion - oldpostion) / 1000)));

                        break;
                    }
                }
                else
                {
                    throw new Exception("队列已损坏,无法恢复。");
                }
            }
        }
示例#2
0
        private EntityTableIndexItemBag LoadIndex(string tablename, string indexname, EntityTableMeta meta)
        {
            string key = string.Format("{0}##{1}", tablename, indexname);
            EntityTableIndexItemBag temp = null;

            if (indexdic.TryGetValue(key, out temp))
            {
                temp.LastUsed = DateTime.Now;
            }

            string indexfile = GetIndexFile(tablename, indexname);
            var    locker    = GetKeyLocker(tablename, "index_" + indexname);

            lock (locker)
            {
                if (indexdic.TryGetValue(key, out temp))
                {
                    temp.LastUsed = DateTime.Now;
                }
                else
                {
                    temp = new EntityTableIndexItemBag();
                }

                using (ObjTextReader idxreader = ObjTextReader.CreateReader(indexfile))
                {
                    if (temp.LastOffset > 0)
                    {
                        idxreader.SetPostion(temp.LastOffset);
                    }

                    Dictionary <long, EntityTableIndexItem> al = null;
                    foreach (var newindex in idxreader.ReadObjectsWating <EntityTableIndexItem>(1))
                    {
                        temp.LastOffset = idxreader.ReadedPostion();
                        if (!temp.Dics.TryGetValue(newindex.Key, out al))
                        {
                            al = new Dictionary <long, EntityTableIndexItem>();
                            temp.Dics.TryAdd(newindex.Key, al);
                        }

                        if (newindex.Del)
                        {
                            al.Remove(newindex.Offset);
                        }
                        else
                        {
                            al.Add(newindex.Offset, newindex);
                        }
                    }
                }

                if (temp.LastUsed == DateTime.MinValue)
                {
                    temp.LastUsed = DateTime.Now;
                    indexdic.TryAdd(key, temp);
                    LJC.FrameWork.Comm.Coroutine.CoroutineEngine.DefaultCoroutineEngine.Dispatcher(new IndexDestroy(indexdic, key));
                }
                else
                {
                    temp.LastUsed = DateTime.Now;
                }
            }

            return(temp);
        }