Matthew Scott <gldnspud@...> writes:
> Hi Donnal,
> There may be other use cases that Pat can point out, but one that
> comes to mind that I've made use of a few days ago is this: A
> transaction that wants to use the time that its execution occurred to
> set an attribute of some object.
> Since setting the attribute of said object is based on when the
> transaction was executed, the transaction itself must store the time
> at which it was executed in order to maintain the deterministic nature
> of transactions if they are replayed from a log.
> Donnal Walter wrote:
> > Hi all,
> > The Clock and EngineClock classes obviously play central roles in
> > PyPerSyst, and at one time I was certain that I understood those
> > roles. Months later, however, I am having a hard time seeing why
> > the time stamp is needed. If the transaction log stores
> > transactions in order in which they were executed, why is this
> > sequestial order not sufficient for reconstructing the database if
> > a crash occurs?
> > Regards,
> > Donnal
Matt's explanation is correct. Here are some additional points.
First, the clock module was recently simplified a good deal. So now
there is only one Clock class (EngineClock went away). And it is no
longer a shared-state Borg thingie, because that made it difficult to
have more than one database open at the same time, since each database
is controlled by its own clock. Actually, it's really the engine that
is responsible for the clock. Each database has one engine, and each
engine has a clock. (Maybe I should have named it the "timing belt"
instead of the clock.)
Having said all that, the clock internals shouldn't be of concern to
most developers. The engine is responsible for the clock. The engine
ensures that timestamps are deterministic when replaying transactions
from a log. The transaction's execute method now takes a time value
as a required parameter. The engine provides this value when it
executes a transaction. So now only the engine should be importing
the clock module. If you want access to the database time elsewhere,
just ask the engine for it: engine.time(). Or, if you use the
database class, just ask it, which will ask the engine, which will ask
the clock, etc.
Clear as mud?
Patrick K. O'Brien