From: JT S. <jt...@pl...> - 2004-07-09 20:16:42
|
Hey everyone, just thought I'd let you know that I've made my decision, and have implemented it. Sorry for not giving much notice for input on this one. I'm trying to get 6.1 out the door and this and the page tree stuff is all that is remaining. Here's what I decided to do: I implemented a new method: my $dbh = WebGUI::SQL->getSlave; getSlave will return a random slave dbh, unless admin mode is enabled, then it will return undef. Likewise it will return undef if no slaves have been defined. You can define up to 3 slaves in the config file like this: dbslave1 = dsn => "DBI:mysql:name_of_slave_db", \ user => "webgui", \ pass => "password" I chose this way because: 1) It was easy to implement. 2) It was the least disruptive implementation. 3) By adding the undef return in admin mode it accomplished what the other thing was going to do. I'm going to put the new method to use in a few heavily traffic'd areas of WebGUI. But by all means not everywhere that it could be used. As time goes forward and we see more people using and wanting to use replicated databases, we can update the other parts of the system to use this functionality. On Fri, 09 Jul 2004 09:49:29 -0500 JT Smith <jt...@pl...> wrote: >I've been struggling over the last week with how to implement the ability to use a >replicated database as a read source. I've experimented with about 10 different ways of >doing this and all either didn't work or were way too convoluted to be useful. I've >come down to two ways to implement this, but I need about 2 seconds of feedback from a >couple of people on this list to make sure I'm on the right track. > >Way #1: Refactor WebGUI::SQL >Change WebGUI::SQL to not use all those class methods, but instead instance methods. So >we'd add several constructors and remove the ability to pass in a new database handler >on each seperate method. The new constructors would be: > >new ( [ dbh ] ) > >This would default to the WebGUI db handler, but you could override it by passing in a >dbh. This would be the common one everyone would use. > >newReplicant ( ) > >This would use a random one of the defined replicated databases, except if the user was >in admin mode. > > >newHandler ( dsn, user, pass [ , options ] ) > >This would create a new DBH and set it in the object instance. And would require the >use of a disconnect() method to destroy it. > > >So to use any of these you'd do something like this: > > >my $db = WebGUI::SQL->newReplicant; >my @arr = $db->quickArray($sql); > > > > >Way #2: Progie does more work, but gets more control >We leave WebGUI::SQL as is, except for adding one method like: > >WebGUI::SQL->getReplicant() > > >Then the programmer in his code would write something like (when he wants to use a >replicant): > >my $dbh = $session{dbh}; >unless ($session{var}{adminOn} || $shouldntUseReplicant) { > $dbh = WebGUI::SQL->getReplicant; >} >my @arr = WebGUI::SQL->quickAarry($sql,$dbh); > > > >Way #1 is cleaner, but requires refactoring all of WebGUI. (which I'll do if you guys >think this is the best way to go) > >Way #2 is not nearly as clean, but requires no change to the rest of WebGUI. > > >I hope to implement one of these in a few hours, so quick feedback is appreciated. > > >JT ~ Plain Black > >Create like a god, command like a king, work like a slave. > >------------------------------------------------------- >This SF.Net email sponsored by Black Hat Briefings & Training. >Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top >technical experts, no vendor pitches, unmatched networking opportunities. Visit >www.blackhat.com >_______________________________________________ >Pbwebgui-development mailing list >Pbw...@li... >https://lists.sourceforge.net/lists/listinfo/pbwebgui-development JT ~ Plain Black Create like a god, command like a king, work like a slave. |