I'm just about ready to start committing this work. Out of an abundance of
caution, I propose to do it in phases:
Phase 1: Commit new modules only. This will leave existing functionality
intact and not change anything in the build.
Phase 2: Commit build changes. This will take care of translation and make
files to include the new work, but not activate the new code.
Phase 3: Commit final changes to activate the new code. Turn it loose for
broader testing in the dev community
Phase 4: Remove any modules deprecated by the new structure.
As I go I will be throughly testing the new code against all gramps
functions from create to editing to reports to database repair and rebuild.
I expect that each phase will include clean-up work as well.
I should be ready to begin the phased commits within the next week. Please
let me know if you have any issues with the plan. As I do the commits, I'll
be blogging about the work and the benefits I hope to be achieve.
On Wed, Aug 5, 2009 at 12:57 PM, Gerald Britton <gerald.britton@...:
> Update:
> Project is going well. I've separated the Transaction class to its own
> module and merged in the commit code from the old base.py and dbdir.py. To
> my eye, it looks more readable. I also added context manager support. Now,
> I'm percolating some related changes through the various editors and trying
> to use with...as constructs where possible.
>
> I also moved the gramps 1.3 to 1.4 upgrade code out to it's own module that
> is only imported when needed. Initially I did it to reduce the clutter but
> now I see we are better positioned for future revisions of the database
> structure.
>
> I'm also taking a look at how the undo/redo operations are handled. I'm
> leaning towards splitting them out to their own module and creating a
> GrampsDbUndo class to manage it. However, along the way I got curious about
> one thing: Why is it an on-disk database? Just creating the undo database
> at every startup uses about 150k of memory, probably enough for 250-500
> average undo transactions if they were kept in a list or dictionary in
> memory. The undo database is not persistent; it is created afresh upon each
> startup. Currently there is a hard-coded limit of 1000 undo operations. If
> kept in memory 1000 operations would probably be less than 500k and of
> course much faster.
>
> What I will do for now, is make it possible to switch between an on-disk
> undo database and in-memory version built on a Python list. Then we can
> play with it both ways before deciding which way to go.
>
> Note: I still haven't committed any of this work. I've a ways to go and I
> want to do pretty through unit testing before I do that.
>
> Just keeping everyone in the loop!
>
>
> On Mon, Aug 3, 2009 at 1:30 PM, Benny Malengier <benny.malengier@...
> > wrote:
>
>> Sounds all very good to me.
>>
>> 2009/7/28, Gerald Britton <gerald.britton@...>:
>> > I'm working on the Transaction class and the BdbTransaction class
>> > derived from it. Basically, this is the setup as far as I can see:
>> >
>> > 1. At a basic level, we use BSDDB transactions to protect our commits
>> > to the database. That is, if there is a failure before calling the
>> > commit method, BSDDB will roll back the changes for us or at least
>> > that's how I understand it. Of course, these are pure record-level
>> > (key/data pair) updates with no intelligence about related
>> > transactions.
>> >
>> > 2. A a "meta" level, we often group transactions together for purposes
>> > of undo/redo. This is what the Transaction/BdbTransaction classes are
>> > for. The groupings are intelligent and usually accompanied by a
>> > human-readable message like "Add Person" which may comprise several
>> > database updates.
>> >
>> > The code for #2 is split between base.py and dbdir.py. I don't think
>> > that this is good. At the very least, it makes it hard to follow
>> > (took me quite a while to figure it out). I propose creating a new
>> > module gen.db.metatrans, that covers the functions of #2. Also the
>> > Transaction class tries to be generic but since we only support BSDDB
>> > at this point I'm not sure that I see the value in it. In any case,
>> > the BdbTransaction class extends Transaction in some ways that we'd
>> > have to duplicate if we went to a second back-end. For the time being
>> > though, I'd like to move Transaction and BdbTransaction into their own
>> > module, and probably rename them MetaTrans and BdbMetaTrans or
>> > something like that.
>> >
>> > Also, key methods to accessing these classes are split between base.py
>> > and dbdir.py but are NOT methods of Transaction or BdbTransaction. I
>> > think that this is not the best design. Among those methods are key
>> > functions like "begin" and "commit." I propose moving those methods
>> > into the class(es) proper but leave a stub in the GrampsDbDir class so
>> > that we don't have to ripple this change through the codebase. This
>> > approach would make these classes mirror the general arrangement of
>> > the lower-level transactions in BSDDB which will hopefully help future
>> > readers.
>> >
>> > While I'm at it, I'll add context-management methods to the revised
>> > classes, so that modules like EditPerson would be able to do something
>> > like:
>> >
>> > with MetaTrans(...) as transaction:
>> > do stuff
>> >
>> > The context manager would automagically commit the metatransaction
>> > when control flows off the end of the "with" statement unless an
>> > error occurred.
>> >
>> > BTW, it appears that the meta commit routines in Transaction do NOT
>> > use BSDDB transactions to protect the db-level changes. I think that
>> > that is risky. I'd like to rectify that.
>> >
>> > So, unless I've missed something fundamental, I'll get started on this
>> > in the next day or two.
>> >
>> > On Tue, Jul 28, 2009 at 2:22 PM, Gerald Britton<
>> gerald.britton@...>
>> > wrote:
>> >> Just to let you know that I'm making good progress on this but don't
>> >> want to commit the new code for a while.
>> >>
>> >> On Fri, Jul 24, 2009 at 7:24 PM, Gerald Britton<
>> gerald.britton@...>
>> >> wrote:
>> >>> Thanks Brian, I'll get to the bottom of it all somehow!
>> >>>
>> >>> On Fri, Jul 24, 2009 at 5:35 PM, Brian Matherly<
>> brian@...>
>> >>> wrote:
>> >>>>
>> >>>> Gerald,
>> >>>>
>> >>>>> Indeed. I wonder if you can
>> >>>>> help me understand another thing:
>> >>>>>
>> >>>>> Lately, I've been experimenting with build a context
>> >>>>> manager for BSDDB
>> >>>>> transactions. That is, instead of writing:
>> >>>>>
>> >>>>> txn = self.env.txn_begin()
>> >>>>>
>> >>>>> ...do stuff
>> >>>>>
>> >>>>> txn.commit()
>> >>>>>
>> >>>>> you could write:
>> >>>>>
>> >>>>> with BSDT() as txn: # use new context
>> >>>>> manager
>> >>>>> ...do stuff
>> >>>>>
>> >>>>> You don't have to remember to do a txn.commit(). In
>> >>>>> fact, it's better
>> >>>>> than that, since the commit will happen automagically at
>> >>>>> the end of
>> >>>>> the block controlled by "with" unless you do a txn.abort()
>> >>>>> or
>> >>>>> txn.commit() before leaving the block.
>> >>>>>
>> >>>>> Anyway, that's just the "context" to my question.
>> >>>>> base.py has a
>> >>>>> generic class "Transaction" that dbdir.py extends in
>> >>>>> BdbTransaction.
>> >>>>> However, neither of these seem to be concerned with DBTxn
>> >>>>> objects.
>> >>>>> I'd like to understand a little more about what Transaction
>> >>>>> and its
>> >>>>> children do. First off, I want to be sure that the
>> >>>>> Transaction class
>> >>>>> is in the right module (possibly its own). Second, I
>> >>>>> want to be sure
>> >>>>> that, if I use the context manager I'm playing with, it
>> >>>>> plays nice
>> >>>>> with Transaction.
>> >>>>
>> >>>> These are great questions. You have completely surpassed anything and
>> >>>> everything I know about how the database works. I have never done any
>> >>>> database programming for Gramps - I always stayed away from the BSDDB
>> >>>> stuff and I only use the read-only functions in the database
>> interface.
>> >>>> I hope somebody else can take a shot at helping you.
>> >>>>
>> >>>> ~BM
>> >>>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Gerald Britton
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Gerald Britton
>> >>
>> >
>> >
>> >
>> > --
>> > Gerald Britton
>> >
>>
>
>
>
> --
> Gerald Britton
>
--
Gerald Britton
|