WalnutLog.Mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Willie-Sue, July 3, 1985 11:06:32 am PDT
Donahue, August 5, 1985 2:25:20 pm PDT
Contents: types and procedures which take the current log file as implicit parameter
Last Edited by: Willie-Sue, January 10, 1985 12:24:49 pm PST
Last Edited by: Donahue, December 11, 1984 1:09:54 pm PST
DIRECTORY
BasicTime USING [GMT],
IO USING [STREAM],
Rope USING [ROPE],
ViewerTools USING [TiogaContents],
WalnutKernelDefs USING [LogEntry, WhichTempLog];
WalnutLog: CEDAR DEFINITIONS =
BEGIN
Types
GMT: TYPE = BasicTime.GMT;
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
LogEntry: TYPE = WalnutKernelDefs.LogEntry;
WhichTempLog: TYPE = WalnutKernelDefs.WhichTempLog;
TiogaContents: TYPE = ViewerTools.TiogaContents;
Logging of operations that perform actions on the Walnut database
ExpungeMsgs: PROC RETURNS[at, next: INT];
WriteExpungeLog: PROC RETURNS[at, next: INT];
CreateMsgSet: PROC[name: ROPE] RETURNS[at, next: INT];
EmptyMsgSet: PROC[msgSet: ROPE] RETURNS[at, next: INT];
DestroyMsgSet: PROC[msgSet: ROPE] RETURNS[at, next: INT];
AddMsg: PROC[msg: ROPE, to: ROPE] RETURNS[at, next: INT];
RemoveMsg: PROC[msg: ROPE, from: ROPE] RETURNS[at, next: INT];
MoveMsg: PROC[msg: ROPE, from, to: ROPE] RETURNS[at, next: INT];
DestroyMsg: PROC[msg: ROPE] RETURNS[at, next: INT];
HasBeenRead: PROC[msg: ROPE] RETURNS[at, next: INT];
RecordNewMailInfo: PROC[logLen: INT, when: GMT, server: ROPE, num: INT]
RETURNS[at, next: INT];
StartCopyNewMail: PROC RETURNS[at, next: INT]; -- endCopy written by WalnutLogImpl
AcceptNewMail: PROC RETURNS[at, next: INT];
StartReadArchiveFile: PROC[file: ROPE, msgSet: ROPE] RETURNS[at, next: INT];
EndReadArchiveFile: PROC RETURNS[at, next: INT];
StartCopyReadArchive: PROC RETURNS[at, next: INT]; -- endCopy written by WalnutLogImpl
Write a message on the current log
WriteMessage: PROC [msg: ROPE, body: TiogaContents] RETURNS[at: INT];
Writes a CreateMsg entry on the log. Caller is expected to have manufactured a unique name for the message. This operation flushes the log.
Parsing a log (used by Scavenge and Replay)
SetPosition: PROC[startPos: INT] RETURNS[charsSkipped: INT];
Set the position of the log to begin at the first log entry at or beyond startPos. Each of the parsing operations below take the current position of the log as an implicit argument. This procedure will skip ahead to the beginning of a log entry if startPos is not one -- the number of characters skipped is returned in charsSkipped.
SetIndex: PROC[pos: INT];
sets the current log to the indicated position; used during expunge. The difference with SetPosition is that this asserts that the position is at the beginning of a log entry.
NextAt: PROC RETURNS[at: INT];
returns the same value that NextEntry would return for at
NextEntry: PROC RETURNS[le: LogEntry, at: INT];
The returned values include the entry found and the position it occupies on the log. If entry = NIL, then no more entries remain in the log (at = logLength); if at = -1 then the current read position does not point to the beginning of a log entry. A valid entry is "consumed", ie., a subsequent call to NextEntry will return a different position for "at".
Note: Successive calls to NextEntry may reuse the log entry returned -- if you need to keep information, copy it!
QuickScan: PUBLIC PROC RETURNS[le: LogEntry, at: INT];
Basically the same as NextEntry, but does not parse a message entry into its headers, but just returns the length of the headers section - used for the lazy enumeration of messages.
ArchiveEntry: PUBLIC PROC[to: IO.STREAM] RETURNS[ok: BOOL];
Copies the next entry of the current log to an archive stream.
CopyBytesToArchive: PROC[to: IO.STREAM, startPos, num: INT];
used to copy (parts) of messages to an archive stream; the format of the archive log bears little resemblence to walnut's log - it conforms to the laurel standard
Managing the current Log
AcquireWriteLock: PROC;
upgrades the lock on the log to write - used for long running operations
ForgetLogStreams: PROC;
clears WalnutLog's local variables - to be used when the transaction has aborted
CloseLogStreams: PROC;
call this when there has been no recent activity
LogLength: PROC RETURNS[length: INT];
returns the length of the current log file
OpenLogStreams: PROC;
ReleaseWriteLock: PROC;
for now, simply closes and re-opens the streams to downgrade the lock to none
ResetLog: PROC[newLength: INT];
ReturnCurrentLogStreams: PROC;
closes any open currentLog or expungeLog streams; does a commitAndContinue of the transaction; may raise WalnutDefs.Error
ShutdownLog: PROC;
does more thorough job of shutting down the log
Copying NewMail/ReadArchive logs
PrepareToCopyTempLog: PROC[which: WhichTempLog, pagesAlreadyCopied: INT, reportProc: PROC[msg1, msg2, msg3: ROPENIL] ] RETURNS[ok: BOOL];
makes sure there is enough space to copy the WhichTempLog onto the currentLog; returns FALSE if there is not enough space to extend the log
CopyTempLog: PROC[
which: WhichTempLog, startCopyPos, fromPos: INT,
reportProc: PROC[msg1, msg2, msg3: ROPENIL] ];
copies the which templog, starting at fromPos to the end of the currentLog; writes an EndCopy log entry, and sets the length of which to 0, as an atomic operation; if the operation fails, WalnutDefs.Error is raised
FinishTempLogCopy: PROC[which: WhichTempLog];
releases the write lock on on the currentLog and reset the length of the temp log to something reasonable
CreateArchiveLog: PROC[
fileToRead: STREAM, msgSet: ROPE, reportProc: PROC[msg1, msg2, msg3: ROPENIL]]
RETURNS[ok: BOOL];
reads fileToRead from the beginning and writes the readArchiveLog; writes an endReadArchive entry on the currentLog; returns TRUE if all went well; leaves the readArchiveLog closed, fileToRead open
Utilities
GetTiogaContents: PROC[textStart, textLen, formatLen: INT] RETURNS[contents: TiogaContents];
reads tioga text from log, returns NIL if EndOfStream is encountered
GetRefTextFromLog: PROC[startPos, length: INT, text: REF TEXT];
reads length characters from log, sets length of text to 0 if EndOfStream is encountered
END.