--- loncom/lonnet/perl/lonnet.pm 2003/11/12 19:51:43 1.448 +++ loncom/lonnet/perl/lonnet.pm 2003/11/12 20:32:04 1.449 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.448 2003/11/12 19:51:43 albertel Exp $ +# $Id: lonnet.pm,v 1.449 2003/11/12 20:32:04 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,6 +51,29 @@ use Storable qw(lock_store lock_nstore l use Time::HiRes(); my $readit; +=pod + +=head1 Package Variables + +These are largely undocumented, so if you decipher one please note it here. + +=over 4 + +=item $processmarker + +Contains the time this process was started and this servers host id. + +=item $dumpcount + +Counts the number of times a message log flush has been attempted (regardless +of success) by this process. Used as part of the filename when messages are +delayed. + +=back + +=cut + + # --------------------------------------------------------------------- Logging sub logtouch { @@ -1311,12 +1334,24 @@ sub flushcourselogs { # File accesses # Writes to the dynamic metadata of resources to get hit counts, etc. # - foreach (keys %accesshash) { - my $entry=$_; - $entry=~/\_\_\_(\w+)\/(\w+)\/(.*)\_\_\_(\w+)$/; + foreach my $entry (keys(%accesshash)) { + my ($dom,$name,undef,$type)=($entry=~m:___(\w+)/(\w+)/(.*)___(\w+)$:); my %temphash=($entry => $accesshash{$entry}); - if (&Apache::lonnet::put('nohist_resevaldata',\%temphash,$1,$2) eq 'ok') { - delete $accesshash{$entry}; + if ($type eq 'count'){ + my $result = &inc('nohist_accesscount',\%temphash,$dom,$name); + if ($result eq 'ok') { + delete $accesshash{$entry}; + } elsif ($result eq 'unknown_cmd') { + # Target server has old code running on it. + if (&put('nohist_resevaldata',\%temphash,$dom,$name) eq 'ok') { + delete $accesshash{$entry}; + } + } + &logthis('incrementing '.$entry.' by '.$accesshash{$entry}.' result is '.$result); + } else { + if (&put('nohist_resevaldata',\%temphash,$dom,$name) eq 'ok') { + delete $accesshash{$entry}; + } } } # @@ -2352,6 +2387,30 @@ sub convert_dump_to_currentdump{ return \%returnhash; } +# --------------------------------------------------------------- inc interface + +sub inc { + my ($namespace,$store,$udomain,$uname) = @_; + if (!$udomain) { $udomain=$ENV{'user.domain'}; } + if (!$uname) { $uname=$ENV{'user.name'}; } + my $uhome=&homeserver($uname,$udomain); + my $items=''; + if (! ref($store)) { + # got a single value, so use that instead + $items = &escape($store).'=&'; + } elsif (ref($store) eq 'SCALAR') { + $items = &escape($$store).'=&'; + } elsif (ref($store) eq 'ARRAY') { + $items = join('=&',map {&escape($_);} @{$store}); + } elsif (ref($store) eq 'HASH') { + while (my($key,$value) = each(%{$store})) { + $items.= &escape($key).'='.&escape($value).'&'; + } + } + $items=~s/\&$//; + return &reply("inc:$udomain:$uname:$namespace:$items",$uhome); +} + # --------------------------------------------------------------- put interface sub put { @@ -5210,6 +5269,14 @@ dumps the complete (or key matching rege =item * +inc($namespace,$store,$udom,$uname) : increments $store in $namespace. +$store can be a scalar, an array reference, or if the amount to be +incremented is > 1, a hash reference. + +($udom and $uname are optional) + +=item * + put($namespace,$storehash,$udom,$uname) : stores hash in namesp ($udom and $uname are optional)