Committer: gprochaev
LJSUP-8104. Add parameter for forcing use a master server for upload dataU trunk/cgi-bin/LJ/Browse.pm U trunk/cgi-bin/LJ/Vertical.pm U trunk/cgi-bin/ljlib.pl U trunk/htdocs/admin/browse/load_all_structure.bml
Modified: trunk/cgi-bin/LJ/Browse.pm =================================================================== --- trunk/cgi-bin/LJ/Browse.pm 2011-03-16 09:27:57 UTC (rev 18584) +++ trunk/cgi-bin/LJ/Browse.pm 2011-03-16 09:37:15 UTC (rev 18585) @@ -150,6 +150,7 @@ undef, $self->{catid}, $tm->class_to_typeid('children'), $tm->class_to_typeid('top_children')); $parent->clear_props_memcache; + $parent->clear_memcache; # if top-level category clear top-level category cache } else { LJ::MemCache::delete("category_top2"); @@ -220,8 +221,9 @@ return $c if $c; # For now use Hash in Config file - my $dbh = LJ::get_db_reader() - or die "unable to contact global db slave to load category"; + my $dbh = $LJ::VERTICALS_FORCE_USE_MASTER ? LJ::get_db_writer() : LJ::get_db_reader(); + die "unable to contact global db slave to load category" + unless $dbh; my $parent_check = ''; if ($parent) { @@ -251,8 +253,9 @@ my $class = shift; my $vertical = shift; - my $dbh = LJ::get_db_reader() - or die "unable to contact global db slave to load categories"; + my $dbh = $LJ::VERTICALS_FORCE_USE_MASTER ? LJ::get_db_writer() : LJ::get_db_reader(); + die "unable to contact global db slave to load categories" + unless $dbh; my $vert_id = $vertical ? $vertical->vert_id : 0; my $where = " WHERE vert_id = $vert_id "; @@ -298,8 +301,9 @@ return sort { lc $a->display_name cmp lc $b->display_name } @cats; } - my $dbh = LJ::get_db_reader() - or die "unable to contact global db slave to load categories"; + my $dbh = $LJ::VERTICALS_FORCE_USE_MASTER ? LJ::get_db_writer() : LJ::get_db_reader(); + die "unable to contact global db slave to load categories" + unless $dbh; my $sth = $dbh->prepare("SELECT * FROM category WHERE parentcatid IS NULL"); $sth->execute; @@ -611,8 +615,9 @@ return 1 unless @vals; # now hit the db for what was left - my $dbh = LJ::get_db_reader() - or die "unable to contact global db slave to load category"; + my $dbh = $LJ::VERTICALS_FORCE_USE_MASTER ? LJ::get_db_writer() : LJ::get_db_reader(); + die "unable to contact global db slave to load category" + unless $dbh; my $bind = LJ::bindstr(@vals); my $sth = $dbh->prepare("SELECT * FROM category WHERE catid IN ($bind)"); @@ -651,7 +656,7 @@ sub preload_children { my $self = shift; - my $dbh = LJ::get_db_reader (); + my $dbh = $LJ::VERTICALS_FORCE_USE_MASTER ? LJ::get_db_writer() : LJ::get_db_reader (); my $sth = $dbh->prepare ("SELECT * FROM category WHERE parentcatid = ?"); $sth->execute($self->catid); @@ -769,8 +774,9 @@ return; } - my $dbh = LJ::get_db_reader() - or die "unable to contact global db slave to load category"; + my $dbh = $LJ::VERTICALS_FORCE_USE_MASTER ? LJ::get_db_writer() : LJ::get_db_reader(); + die "unable to contact global db slave to load category" + unless $dbh; my @cats = ( $self->catid ); if ($args{'is_need_child'}) { Modified: trunk/cgi-bin/LJ/Vertical.pm =================================================================== --- trunk/cgi-bin/LJ/Vertical.pm 2011-03-16 09:27:57 UTC (rev 18584) +++ trunk/cgi-bin/LJ/Vertical.pm 2011-03-16 09:37:15 UTC (rev 18585) @@ -1011,15 +1011,20 @@ next unless $row; $obj->absorb_row($row); + + $obj->set_memcache; + + $singletons{$obj->{vert_id}} = $obj; + delete $need{$obj->{vert_id}}; } - # now hit the db for what was left - my $dbh = LJ::get_db_writer() - or die "unable to contact global db master to load vertical"; - my @vals = keys %need; if (scalar @vals) { + # now hit the db for what was left + my $dbh = LJ::get_db_writer() + or die "unable to contact global db master to load vertical"; + my $bind = LJ::bindstr(@vals); my $sth = $dbh->prepare("SELECT * FROM vertical2 WHERE vert_id IN ($bind)"); $sth->execute(@vals); @@ -1028,6 +1033,7 @@ # what singleton does this DB row represent? my $obj = $need{$row->{vert_id}}; + $obj = __PACKAGE__->new (vert_id => $row->{vert_id}) unless $obj; # and update singleton (request cache) $obj->absorb_row($row); @@ -1035,6 +1041,9 @@ # set in memcache $obj->set_memcache; + # update request cache + $singletons{$row->{vert_id}} = $obj; + # and delete from %need for error reporting delete $need{$obj->{vert_id}}; @@ -1042,6 +1051,7 @@ } # weird, vertids that we couldn't find in memcache or db? + $_->{_loaded_row} = 1 foreach values %need; warn "unknown vertical(s): " . join(",", keys %need) if %need; # now memcache and request cache are both updated, we're done Modified: trunk/cgi-bin/ljlib.pl =================================================================== --- trunk/cgi-bin/ljlib.pl 2011-03-16 09:27:57 UTC (rev 18584) +++ trunk/cgi-bin/ljlib.pl 2011-03-16 09:37:15 UTC (rev 18585) @@ -2166,6 +2166,8 @@ %LJ::REQ_CACHE_USERTAGS = (); # uid -> { ... }; populated by get_usertags, so we don't load it twice %LJ::LOCK_OUT = (); + $LJ::VERTICALS_FORCE_USE_MASTER = 0; # It need to load a new created category from master insteed slave server. + $LJ::CACHE_REMOTE_BOUNCE_URL = undef; LJ::Userpic->reset_singletons; LJ::Comment->reset_singletons; Modified: trunk/htdocs/admin/browse/load_all_structure.bml =================================================================== --- trunk/htdocs/admin/browse/load_all_structure.bml 2011-03-16 09:27:57 UTC (rev 18584) +++ trunk/htdocs/admin/browse/load_all_structure.bml 2011-03-16 09:37:15 UTC (rev 18585) @@ -17,6 +17,8 @@ $title = "Load All Structure"; my $ret = ""; + $LJ::VERTICALS_FORCE_USE_MASTER = 1; + if (LJ::did_post() && $POST{'all_structure'}) { my $csv = LJ::Request->upload('all_structure'); my $content = '';