DIRECTORY DBCommon, DBSegment, DBStorage, DBStorageInternal, DBIndex, DBIndexHandle, IO; DBIndexHandleImpl: CEDAR PROGRAM IMPORTS DBCommon, DBSegment, DBStorageInternal, IO EXPORTS DBIndexHandle = { RealIndexHandle: TYPE = DBIndex.RealIndexHandle; IndexObject: TYPE = DBIndex.IndexObject; PriorityList: RealIndexHandle; FinalizeIndexHandle: PUBLIC PROC [s: DBCommon.Segment] = BEGIN i: RealIndexHandle; FOR i _ PriorityList, i.back UNTIL i.back = PriorityList DO IF DBSegment.SegmentFromTID[i.tid] = s THEN { IF i.free AND i.depth # 0 THEN ERROR; i.free _ TRUE; i.depth _ 0 }; ENDLOOP; END; CreateNewRealIndexHandle: PUBLIC PROC [tid: DBStorageInternal.TID] = BEGIN q: RealIndexHandle; IF PriorityList.front.free THEN BEGIN PriorityList _ PriorityList.front; GOTO Initialize END ELSE BEGIN q _ NEW[IndexObject]; q.front _ PriorityList.front; q.back _ PriorityList; PriorityList.front.back _ q; PriorityList.front _ q; PriorityList _ q; GOTO Initialize END; EXITS Initialize => { PriorityList^ _ [tid, Segment[tid], DBCommon.NullDBPage, NIL, 0, PriorityList.front, PriorityList.back, FALSE]}; END; GetOldRealIndexHandle: PUBLIC PROC [x: DBStorage.IndexHandle] RETURNS [RealIndexHandle] = BEGIN q: RealIndexHandle _ PriorityList; tid: DBStorageInternal.TID _ DBStorageInternal.TIDOfTuple[x]; DO IF q.free THEN GOTO NotFound; IF q.tid = tid THEN { IF q = PriorityList THEN GOTO Found; q.front.back _ q.back; q.back.front _ q.front; q.front _ PriorityList.front; PriorityList.front.back _ q; PriorityList.front _ q; q.back _ PriorityList; PriorityList _ q; GOTO Found}; q _ q.back; IF q = PriorityList THEN GOTO NotFound; REPEAT Found => {RETURN[q]}; NotFound => { ttr: DBStorageInternal.TupleTree_ NEW[DBStorageInternal.TupleTreeRecord]; CreateNewRealIndexHandle[tid]; DBStorageInternal.ReadIndexObject[x, ttr]; PriorityList.rootDB _ ttr.rootPA; PriorityList.depth _ ttr.depth; RETURN[PriorityList]}; ENDLOOP; END; DestroyIndexHandle: PUBLIC PROC [q: RealIndexHandle] = BEGIN IF q.front = q THEN -- there is only on item NULL ELSE IF q = PriorityList THEN PriorityList _ PriorityList.back ELSE BEGIN q.front.back _ q.back; q.back.front _ q.front; q.front _ PriorityList.front; q.back _ PriorityList; q.front.back _ q; PriorityList.front _ q END; q.free _ TRUE; END; DeleteHandle: PUBLIC PROC [q: RealIndexHandle] = BEGIN IF q.front = q THEN -- there is only on item NULL ELSE IF q = PriorityList THEN PriorityList _ PriorityList.back ELSE BEGIN q.front.back _ q.back; q.back.front _ q.front; q.front _ PriorityList.front; q.back _ PriorityList; q.front.back _ q; PriorityList.front _ q END; q.rootDB _ DBCommon.NullDBPage; q.root _ NIL; q.depth _ 0; q.free _ TRUE; END; Segment: PROC [tid: DBStorageInternal.TID] RETURNS [DBCommon.DBPage] = BEGIN OPEN DBStorageInternal; segment: DBCommon.DBPage; tuple: DBStorage.TupleHandle _ MakeTupleHandle[tid, ]; segment _ SegmentIDOfTuple[tuple]; ReleaseTupleHandle[tuple]; RETURN[segment] END; PrintHandle: PROC = { q: RealIndexHandle _ PriorityList; DO DBCommon.GetDebugStream[].PutF["tid: %12bB, rootDB: %12bB, depth: %bB, %s*n", IO.card[q.tid], IO.card[q.rootDB], IO.card[q.depth], IO.rope[IF q.free THEN "free" ELSE "not free"]]; q _ q.back; IF q=PriorityList THEN EXIT; ENDLOOP; }; PriorityList _ NEW[IndexObject]; PriorityList.front _ PriorityList.back _ PriorityList; PriorityList.free _ TRUE; }. CHANGE LOG Changed by MBrown on December 15, 1980 10:15 AM Changed by MBrown on February 27, 1981 5:34 PM Changed by Cattell sometime in March 1981 Changed by Cattell on June 20, 1982 6:23 pm Changed by Willie-Sue on June 25, 1982 9:19 am Changed by Willie-Sue on June 30, 1982 4:50 pm Changed by Cattell on August 6, 1982 4:48 pm Changed by Cattell on September 21, 1982 9:20 pm Changed by Willie-Sue on February 18, 1985 κFile: DBIndexHandleImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Created by: Suzuki, December 8, 1980 2:19 PM Last edited by: Suzuki, December 8, 1980 3:09 PM MBrown, February 27, 1981 5:31 PM Cattell, September 15, 1983 4:05 pm Willie-Sue on February 18, 1985 1:19:53 pm PST Widom on September 4, 1985 9:12:43 pm PDT this points to a ring buffer of RealIndexHandle's. They form a LRU list, with PriorityList pointing to the most recently used Index and the next one is PriorityList.back, ...back. If what PriorityList points to is free, then everything on the ring buffer is free. If there is any free Index, PriorityList.fron points to a free Index. IndexHandle manipulation Creates a RealIndexHandle at the head of LRU queue, and set tid. Returns the actual index handle out of the tuple level's tuple that represents it. put it at the front of PriorityList Deallocates the IndexObject. The real one, not the tuple level's. Doesn't actually free any storage to system, just marks it free. Deallocates the IndexObject Returns the segment in which "tid" exists In FinalizeIndexHandle, set i.free _ TRUE in loop. Allocate from zone. Use CWF instead of IODefs and StringDefs (!) Removed use of CWF. Added some comments to procedures. Bad names for procs, should change the interface and recompile everything sometime. IOStream => IO PrivateIO.DebugStream => DBCommon.GetDebugStream[] POINTERs to REFs. Re-organization of DBIndex level. made Cedar, added tioga formatting Κ’˜šœ™Icodešœ Οmœ1™<—Jšœ.™.Jšœ™Jšœ!™!Jšœ"™"Jšœ#™#Jšœ.™.J™)J˜šΟk ˜ J˜ J˜ J˜ J˜J˜J˜Jšžœ˜J˜—šœž œ˜!šž˜J˜ J˜ J˜Jšž˜—šž˜J˜ —J˜J˜Jšœžœ˜0Jšœ žœ˜(J˜J˜JšœΠ™ΠJ˜šΟnœžœžœ˜8Jšž˜J˜šžœžœž˜;šžœ%žœ˜-Jšžœžœ žœžœ˜%Jšœ žœ˜—Jšžœ˜—Jšžœ˜J˜—Jšœ™J˜šŸœžœžœžœ˜DJšœ@™@Jšž˜J˜šžœž˜Jšžœ$žœ ž˜<—šž˜Jšž˜Jšœžœ˜J˜J˜J˜J˜J˜Jšžœ ˜Jšžœ˜—šž˜˜˜šœ)žœ˜DJšœžœ˜————Jšžœ˜J˜—šŸœžœžœ˜=Jšžœ˜JšœR™RJšž˜J˜"Jšœžœ#˜=šž˜Jšžœžœžœ ˜šžœ žœ˜Jšœ#™#Jšžœžœžœ˜$J˜J˜J˜J˜J˜J˜J˜Jšžœ˜ —J˜ Jšžœžœžœ ˜'šžœ˜Jšœ žœ˜˜ Jšœ"žœ$˜IJ˜J˜*J˜"J˜Jšžœ˜——Jšžœ˜—Jšžœ˜J˜—šŸœžœžœ˜6JšœB™BJšœA™AJšž˜šžœ žœΟc˜,Jšž˜—šž˜Jšžœžœ!˜9šž˜Jšž˜J˜J˜J˜J˜J˜J˜Jšžœ˜——Jšœ žœ˜Jšžœ˜J˜—šŸ œžœžœ˜0Jšœ™Jšž˜šžœ žœ ˜,Jšž˜—šž˜Jšžœžœ!˜9šž˜Jšž˜J˜J˜J˜J˜J˜J˜Jšžœ˜——J˜Jšœ žœ˜ J˜ Jšœ žœ˜Jšžœ˜J˜—šŸœžœžœžœ˜FJšœ)™)Jšžœžœ˜J˜J˜6J˜"J˜Jšžœ ˜Jšžœ˜J˜—šŸ œžœ˜J˜"šž˜˜NJšžœžœžœžœžœžœžœ˜e—J˜ Jšžœžœžœ˜—Jšžœ˜J˜J˜—Jšœžœ˜ J˜6Jšœžœ˜J˜—J˜J˜Jšžœž˜ J˜Jšœ.ž˜0Jšœ2™2J˜Jšœ-ž˜/JšœA™AJ˜J˜)Jšœ™J˜J˜+Jšœw™wJ˜J˜.Jšœ™J˜J˜.Jšœ2™2J˜J˜,Jšœ™J˜J˜0Jšœ!™!J™J˜*J™"J™—…—ΦR