Brad Fitzpatrick (bradfitz) wrote in lj_dev,
Brad Fitzpatrick
bradfitz
lj_dev

new get_dbh

Good news: a new kick-ass get_dbh is now in CVS.

Properties of new kick-ass get_dbh():

  • two layer cache (role to DSN, and DSN to handle).... no duplicate connections to same db for different roles. (as noted earlier, this hasn't been a problem yet, but would've, with cluster1 and master going to be on the same server initially)
  • dead db tracking. if a server is down for maintenance or whatever, the code doesn't return that dead db handle ... instead, it pretends like it doesn't exist and picks another randomonly (with weighting, still). when the server is back alive, it'll be reconsidered for usage later. Best part: site keeps on working smooth if a DB dies in the middle of the night.
  • idle connection killing. connections that aren't used in a few minutes are disconnected.
  • no complicated inheritance logic. you have to explicitly request the roles you want now. if you want a read-only connection: my $dbh = LJ::get_dbh("slave", "master"). just giving "slave" is like what doing "slave!" was before, a request to ONLY get a slave, never a master. there is no longer any exclamation mark logic. on that code will shortly die here.... only a few spots.
  • new function LJ::use_diff_db($role1, $role2) which returns true if the two roles are served by separate databases for sure. this is useful for moveucluster.pl, which doesn't want to delete from a db, insert in other, and delete from source, if those were the same DB.
Anyway, glad this is done. So much better than before.

I'm moving on now to the final stretch of the cluster stuff, which depended on this get_dbh re-write.

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments