示例#1
0
 public ClassEntry Search(uint cid)
 {
     //time consuming operations, that's the reason for cache
     if (m_cid_cache.ContainsKey(cid))
     {
         ClassEntry t = (ClassEntry)m_cid_cache[cid];
         t.BreakLinks();
         t.BuildLinks(m_LRU, m_LRU.Next);
         return(t);
     }
     else
     {
         //do the sequential search, :(
         OOD.Imp.Storage.BTree.BTEnumerator bt = m_tree.GetEnumerator();
         while (bt.MoveNext())
         {
             KCatalog key = (KCatalog)bt.Current;
             Debug.Assert(key != null);
             if (key.ClassInfo != null && key.ClassInfo.CId == cid)
             {
                 //found
                 _put_in_cache(cid, key.ClassName, key.ClassInfo.FieldNames, key.ClassInfo.TopNodeSId);
                 return((ClassEntry)m_cid_cache[cid]);
             }
         }
         return(null);
     }
 }
示例#2
0
        public void BreakLinks()
        {
            this.m_prev.m_next = this.m_next;
            this.m_next.m_prev = this.m_prev;

            this.m_prev = this.m_next = this;
        }
示例#3
0
		public void BreakLinks()
		{
			this.m_prev.m_next = this.m_next;
			this.m_next.m_prev = this.m_prev;

			this.m_prev = this.m_next = this;
		}
示例#4
0
 public ClassEntry Search(string className)
 {
     if (m_name_cache.ContainsKey(className))
     {
         ClassEntry result = (ClassEntry)m_name_cache[className];
         result.BreakLinks();
         result.BuildLinks(m_LRU, m_LRU.Next);
         return(result);
     }
     else
     {
         //not in cache, get it from disk
         KCatalog target = new KCatalog(className);
         KCatalog t      = (KCatalog)m_tree.Search(target);
         if (t != null)
         {
             _put_in_cache(t.ClassInfo.CId, className, t.ClassInfo.FieldNames, t.ClassInfo.TopNodeSId);
             return((ClassEntry)m_cid_cache[t.ClassInfo.CId]);
         }
         else
         {
             return(null);
         }
     }
 }
示例#5
0
        public void BuildLinks(ClassEntry prev, ClassEntry next)
        {
            this.m_next = next;
            this.m_prev = prev;

            prev.m_next = this;
            next.m_prev = this;
        }
示例#6
0
        private ClassEntry m_LRU;                                      //maintain the least recently used list for cached class info

        public CatalogTree(uint topNodeSId, SegmentManager sgManager, uint nextCId)
        {
            m_tree       = new BTree(topNodeSId, sgManager, new KCatalog());
            m_next_cid   = nextCId;
            m_cid_cache  = new Hashtable(m_cache_limit);
            m_name_cache = new Hashtable(m_cache_limit);
            m_LRU        = new ClassEntry();
        }
示例#7
0
		public void BuildLinks(ClassEntry prev, ClassEntry next)
		{
			this.m_next = next;
			this.m_prev = prev;

			prev.m_next = this;
			next.m_prev = this;
		}
示例#8
0
		private			ClassEntry		m_LRU; //maintain the least recently used list for cached class info

		public CatalogTree(uint topNodeSId, SegmentManager sgManager, uint nextCId)
		{
			m_tree = new BTree(topNodeSId, sgManager, new KCatalog());
			m_next_cid = nextCId;
			m_cid_cache = new Hashtable(m_cache_limit);
			m_name_cache = new Hashtable(m_cache_limit);
			m_LRU = new ClassEntry();
		}	
示例#9
0
 public bool Delete(string className)
 {
     //remove it from cache if needed
     if (m_name_cache.ContainsKey(className))
     {
         ClassEntry t = (ClassEntry)m_name_cache[className];
         t.BreakLinks();
         m_name_cache.Remove(className);
         m_cid_cache.Remove(t.CId);
     }
     return(m_tree.Delete(new KCatalog(className)));
 }
示例#10
0
        internal void _put_in_cache(uint cid, string className, string[] fields, uint topNodeSId)
        {
            Debug.Assert(m_name_cache.Count == m_cid_cache.Count);

            if (m_name_cache.Count > m_cache_limit)
            {
                //kick one out needed
                ClassEntry victim = m_LRU.Previous;

                Debug.Assert(victim != null);

                victim.BreakLinks();                 //remove from LRU list
                m_name_cache.Remove(victim.ClassName);
                m_cid_cache.Remove(victim.CId);
            }

            ClassEntry ce = new ClassEntry(cid, className, fields, topNodeSId);

            m_name_cache.Add(className, ce);
            m_cid_cache.Add(cid, ce);
            ce.BuildLinks(m_LRU, m_LRU.Next);             //put it to the front of the list, -- most recently used
        }
示例#11
0
        public bool UpdateTopNodeSId(string className, uint newTopNodeSId)
        {
            ClassEntry oldValue = Search(className);

            if (oldValue != null)
            {
                //update cache
                ((ClassEntry)m_cid_cache[oldValue.CId]).SetTopNodeSId(newTopNodeSId);
                //update the b-tree file
                KCatalog newKey = new KCatalog(className);
                newKey.ClassInfo = new DCatalog(oldValue.CId, oldValue.FieldNames, newTopNodeSId);
                if (m_tree.UpdateData(newKey) == false)
                {
                    throw new OOD.Exception.ProgramLogicError(
                              this,
                              "Update operation failed for class info b-tree.");
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
 public ClassEntry()
 {
     m_prev = m_next = this;
 }
示例#13
0
 public ClassEntry(uint cid, string className, string[] fields, uint topNodeSId)
     : base(cid, className, fields, topNodeSId)
 {
     m_prev = m_next = this;
 }
示例#14
0
		public ClassEntry()
		{
			m_prev = m_next = this;
		}
示例#15
0
		public ClassEntry(uint cid, string className, string[] fields, uint topNodeSId)
			:base(cid, className, fields, topNodeSId)
		{			
			m_prev = m_next = this;
		}
示例#16
0
		internal void _put_in_cache(uint cid, string className, string[] fields, uint topNodeSId)
		{
			Debug.Assert(m_name_cache.Count == m_cid_cache.Count);

			if (m_name_cache.Count > m_cache_limit)
			{
				//kick one out needed
				ClassEntry victim = m_LRU.Previous;

				Debug.Assert(victim != null);

				victim.BreakLinks(); //remove from LRU list
				m_name_cache.Remove(victim.ClassName);
				m_cid_cache.Remove(victim.CId);
			}
			
			ClassEntry ce = new ClassEntry(cid, className, fields, topNodeSId);
			m_name_cache.Add(className, ce);
			m_cid_cache.Add(cid, ce);
			ce.BuildLinks(m_LRU, m_LRU.Next); //put it to the front of the list, -- most recently used
		}