-- File: RandomIndexTest.mesa -- Contents: program to add and delete random numbers of CedarDB index entries -- Last edited by -- Rick Cattell on September 20, 1982 2:38 pm DIRECTORY DBStorage, DBTuplesConcrete, DBView, DBViewPrivate, IO, Process, Random, Rope, UserExec, UserExecExtras; RandomIndexTest: PROGRAM IMPORTS DBStorage, DBView, DBViewPrivate, IO, Process, Random, Rope, UserExec, UserExecExtras = BEGIN ROPE: TYPE = Rope.ROPE; in, out: IO.Handle; keys: LIST OF ROPE_ NIL; value: DBStorage.TupleHandle; keyListLength: INT_ 0; nIterations, maxInsertions: INT; cycleCount: INT; stopAtThisCycle: INT_ 0; pleaseStop: BOOL_ FALSE; paddingStringLength: INT_ 5; paddingString: ROPE; index: DBStorage.IndexHandle; prefixArray: ARRAY [0..50) OF ROPE; prefixCount: INT_ 10; averageCommitFrequency: INT; WhatNow: SIGNAL = CODE; SystemTSTuple: TYPE = REF tupleSet DBTuplesConcrete.TupleObject; TickTock: PROC = BEGIN cycleCount_ cycleCount+1; IF Random.Choose[0, averageCommitFrequency] = 0 THEN BEGIN -- close and re-set-up database out.PutF["Closing & Re-opening..."]; DBView.CloseDatabase[]; []_ DBView.OpenDatabase[databaseName: dbName, version: OldOnly]; value_ index_ DBViewPrivate.systemIndex; END; IF cycleCount=stopAtThisCycle THEN SIGNAL WhatNow; END; GenRandomKey: PROC RETURNS [ROPE] = -- prefix random key with a randomly chosen rope, and follow with padding BEGIN prefix: ROPE _ IF prefixCount#0 THEN prefixArray[Random.Choose[0, prefixCount-1]] ELSE NIL; RETURN[IO.PutFR[ "%g%g%g", IO.rope[prefix], IO.int[Random.Next[]], IO.rope[paddingString] ]]; END; GenPlainRandomKey: PROC RETURNS [ROPE] = -- same as above but without prefix, or padding after {RETURN[IO.PutFR[, IO.int[Random.Next[]] ]]}; PlayWithIndex: PROC = BEGIN out.PutF["Testing index...\n"]; THROUGH [1 .. nIterations] DO AddSomeEntries[]; DeleteSomeEntries[]; ENDLOOP; CheckEntries[]; END; AddSomeEntries: PROC = BEGIN key: ROPE; nToInsert: INT_ Random.Choose[0, maxInsertions]; FOR j: INT IN [0..nToInsert) DO TickTock[]; IF pleaseStop THEN RETURN; key_ GenRandomKey[]; DBStorage.InsertIntoIndex[index, key, value]; keyListLength_ keyListLength + 1; keys_ CONS[key, keys]; IF j MOD 10 = 0 THEN out.PutChar['+]; ENDLOOP; out.PutF["... Added %g index entries (now %g)\n", IO.int[nToInsert], IO.int[keyListLength]]; END; DeleteSomeEntries: PROC = BEGIN prevKey: LIST OF ROPE; mDeleted, estToDelete: INT; estToDelete_ Random.Choose[0, keyListLength]; -- Delete approx estToDelete entries by deleting each one -- with probability of estToDelete/keyListLength: mDeleted_ 0; prevKey_ NIL; FOR keysT: LIST OF ROPE_ keys, keysT.rest UNTIL keysT=NIL DO IF Random.Choose[0, keyListLength] {out.PutF["Aborting..."]; DBView.CloseDatabase[]; out.PutF["Done. Bye.\n"]}; END; dbName: ROPE _ "[Local]IndexTest"; Start: PROC = {Process.Detach[FORK Main[]]}; Start[]; END. To run: run ExtraCedar run CedarDB compile RandomIndexTest run RandomImpl run RandomIndexTest