--Transport Mechanism Filestore - Mailbox restart -- -- [Indigo]MS>MailboxRestart.mesa -- Andrew Birrell 10-Sep-82 16:37:56 -- DIRECTORY BitMapDefs USING[ Create, Set ], BodyDefs USING[ oldestTime, RName, Timestamp ], BTreeDefs USING[ CreateAndInitializeBTree, NullProc ], MailboxAlloc, ObjectDirDefs USING[ noObject, ObjectNumber, RestartObject ], RestartDefs, --EXPORT only-- VMDefs USING[ OpenFile, Page, ReadPage, Release, MarkStartWait, PageIndex, PageNumber, GetFileLength ]; MailboxRestart: MONITOR[ initHeap: BOOLEAN ] IMPORTS BitMapDefs, BTreeDefs, MailboxAlloc, ObjectDirDefs, VMDefs EXPORTS RestartDefs --MailboxRestart-- SHARES MailboxAlloc = BEGIN OPEN MailboxAlloc; initMBX: BOOLEAN _ FALSE; maxMBXPages: CARDINAL _ 4000; DuplicatePage: ERROR = CODE; Init: ENTRY PROCEDURE = BEGIN pos: VMDefs.PageNumber; handle _ VMDefs.OpenFile[options:oldOrNew, name: "MBX.Mailboxes"L, cacheFraction: 0]; lockMap _ BitMapDefs.Create[maxMBXPages]; pageMap _ BitMapDefs.Create[maxMBXPages]; conflictMap _ BitMapDefs.Create[maxMBXPages]; tree _ BTreeDefs.CreateAndInitializeBTree [ fileH: LOOPHOLE[VMDefs.OpenFile[options:oldOrNew, name: "MBX.BTree", cacheFraction: 10] ], initializeFile: TRUE, useDefaultOrderingRoutines: TRUE, isFirstGreaterOrEqual: BTreeDefs.NullProc, areTheyEqual: BTreeDefs.NullProc ]; nextVirginPage _ VMDefs.GetFileLength[handle].page; FOR pos IN [0 .. nextVirginPage ) DO BEGIN page: VMDefs.Page = VMDefs.ReadPage[[handle,pos],lookAhead]; base: VMDefs.PageIndex = FIRST[VMDefs.PageIndex]; header: POINTER TO MBXHeader = LOOPHOLE[page,POINTER]+base; IF initMBX OR initHeap THEN BEGIN header.first_header.free; VMDefs.MarkStartWait[ page ]; END; IF header.first # header.free THEN BEGIN buffer: DESCRIPTOR FOR ARRAY OF ObjectDirDefs.ObjectNumber; index: CARDINAL; rName: BodyDefs.RName = LOOPHOLE[page,POINTER] +base+SIZE[MBXHeader]; otherValue: TreeRec = FindInTree[rName]; otherN: CARDINAL; oldest: BodyDefs.Timestamp; -- estimate of oldest in mailbox -- timeWantedInThisPage: BOOLEAN; WITH otherV: otherValue SELECT FROM empty => { oldest _ BodyDefs.oldestTime; timeWantedInThisPage _ TRUE }; found => BEGIN otherP: VMDefs.Page = VMDefs.ReadPage[[handle,otherV.where],0]; otherH: POINTER TO MBXHeader = LOOPHOLE[otherP,POINTER] + base; otherN _ otherH.number; IF header.number = otherN THEN ERROR DuplicatePage[]; oldest _ otherV.oldest; timeWantedInThisPage _ (otherN > header.number OR oldest = BodyDefs.oldestTime); VMDefs.Release[otherP]; END; ENDCASE => ERROR; BitMapDefs.Set[pageMap, pos]; buffer _ DESCRIPTOR[page+header.first, (header.free-header.first)/SIZE[ObjectDirDefs.ObjectNumber] ]; FOR index IN [0..LENGTH[buffer]) DO IF buffer[index].type = TOC THEN ObjectDirDefs.RestartObject[buffer[index]]; IF buffer[index] # ObjectDirDefs.noObject THEN BEGIN body: ObjectDirDefs.ObjectNumber = GetBodyObj[buffer[index]]; ObjectDirDefs.RestartObject[body]; IF timeWantedInThisPage AND body.type # archived THEN BEGIN oldest _ ReadPostmark[body]; timeWantedInThisPage _ FALSE; END; END; mailboxContents _ mailboxContents + 1; ENDLOOP; WITH otherV: otherValue SELECT FROM empty => BEGIN ChangeInTree[who:rName, where:pos, lock:pos, oldest:oldest]; mailboxes _ mailboxes+1; END; found => ChangeInTree[who:rName, where: IF header.number > otherN THEN pos ELSE otherV.where, lock: IF header.number = 0 THEN pos ELSE otherV.lock, oldest:oldest]; ENDCASE => ERROR; END; VMDefs.Release[page]; END ENDLOOP; END; ArchiverProcess: PROCESS; START MailboxAlloc; Init[]; ArchiverProcess _ FORK MailboxAlloc.Archiver[]; END.