IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40980


Ignore:
Timestamp:
Oct 28, 2019, 2:13:12 PM (7 years ago)
Author:
eugene
Message:

replace Digest::SHA1 with Digest::SHA; replace quoted NULL with 0 in new_object query; add query->finish and db->commit calls as needed; count calls to get_storage_volume and exit if tried 10x; do not apply user.mode if mode is an empty string (invalid); avoid failures in die (line 2493) due to undefined values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011/Nebulous-Server/lib/Nebulous/Server.pm

    r39926 r40980  
    1515use Cache::Memcached;
    1616use DBI;
    17 use Digest::SHA1 qw( sha1_hex );
     17## for gentoo: use Digest::SHA1 qw( sha1_hex );
     18use Digest::SHA qw( sha1_hex );
    1819use Fcntl ':mode';
    1920use File::Basename qw( basename dirname fileparse );
     
    7778        Cache::Memcached->new({
    7879            servers => $config->memcached_servers,
    79        })
    80     );
     80                              })
     81        );
    8182#    $self->cache->set("foo", "bar") or die "set failed";
    8283#    $self->cache->get("foo") or die "get failed";
     
    215216}
    216217
     218my $get_storage_volume_calls = 0;
     219
    217220sub create_object
    218221{
     
    252255    # the key's volume can't be validiated on input for this method so we have
    253256    # to check it after parsing the key
    254     if (defined $vol_name
    255         and not $self->_is_valid_volume_name($key, $key->volume)) {
     257    if (defined $vol_name and not $self->_is_valid_volume_name($key, $key->volume)) {
    256258        unless ($key->hard_volume) {
    257259            $log->warn( "$vol_name is not a known volume name" );
     
    262264    }
    263265       
     266    $get_storage_volume_calls = 0;
     267
    264268    my ($vol_id, $vol_host, $vol_path, $vol_xattr)
    265269        = $self->_get_storage_volume($key, $vol_name, $key->hard_volume);
     
    273277                # create storage_object
    274278                my $query = $db->prepare_cached( $sql->new_object );
    275                 $query->execute('NULL', $key->path, basename($key->path), $parent_id);
     279# bad syntax    $query->execute('NULL', $key->path, basename($key->path), $parent_id);
     280                $query->execute(0, $key->path, basename($key->path), $parent_id);
     281                $query->finish;
    276282            }
    277283
     
    292298                my $query = $db->prepare_cached( $sql->new_object_attr );
    293299                $query->execute($so_id);
     300                $query->finish;
    294301            }
    295302
     
    300307                my $query = $db->prepare_cached( $sql->new_object_instance );
    301308                $query->execute($vol_id);
     309                $query->finish;
    302310            }
    303311
     
    327335                # vol_id, uri, ins_id
    328336                $query->execute($vol_id, "$uri", $ins_id);
     337                $query->finish;
    329338            }
    330339
     
    421430                    }
    422431                    $query->finish;
     432                    $db->commit;
    423433                }
    424434
     
    441451                    my $query = $db->prepare_cached($sql->new_directory);
    442452                    $query->execute($dir, $parent_id);
     453                    $query->finish;
     454                    $db->commit;
    443455                }
    444456
     
    452464                    ($parent_id) = $query->fetchrow_array;
    453465                    $query->finish;
     466                    $db->commit;
    454467                }
    455468                die("failed to get LAST_INSERT_ID()")
    456469                    unless $parent_id;
    457 
    458                 $db->commit;
    459470            }
    460471        };
     
    744755    # puke if the source volume is bogus, we may want to actually use this as
    745756    # the instance to be copied later
    746     if (defined $key->volume
    747         and not $self->_is_valid_volume_name($key, $key->volume)) {
     757    if (defined $key->volume and not $self->_is_valid_volume_name($key, $key->volume)) {
    748758        unless ($key->hard_volume) {
    749759            $log->warn($key->volume . " not a known volume name");
     
    752762        }
    753763    }
    754     # puke if the source volume is bogus, we may want to actually use this as
    755     # the instance to be copied later
     764    # puke if the destination volume is bogus
    756765    if (defined $dest_vol_name
    757766        and not $self->_is_valid_volume_name($key, $dest_vol_name)) {
    758767           $log->logdie($key->volume . " is not a valid volume name");
    759768    }
    760        
     769
     770    $get_storage_volume_calls = 0;
     771
    761772    my ($vol_id, $vol_host, $vol_path, $vol_xattr);
    762773    if (defined $dest_vol_name) {
     
    784795                $so_id = $query->fetchrow_hashref->{ 'so_id' };
    785796                $query->finish;
     797                $db->commit;
    786798            }
    787799
     
    800812                # time LAST_INSERT_ID() is invoked
    801813                $query->finish;
     814                $db->commit;
    802815            }
    803816
     
    841854    eval {
    842855        my $mode = $self->getxattr_object("$key", 'user.mode');
    843         if (defined $mode) {
    844             $self->chmod_object("$key", $mode);
     856        if (defined $mode && $mode ne "") {
     857            $self->chmod_object("$key", $mode);
    845858        }
    846859    };
     
    852865
    853866    $log->debug("leaving");
    854 
    855867    return "$uri";
    856868}
     
    13231335            die( "xattr $key:$name does not exist" );
    13241336        }
     1337
    13251338        # if we go more then one row bad something very bad has happened.
    13261339        unless ($rows == 1) {
     
    13351348        $value = $row->{ 'value' };
    13361349    };
     1350    $db->commit;
     1351
    13371352    if ($@) {
    13381353        if ($@ =~ /user\..*? does not exist/) {
    13391354            # do not log xattr does not exist messages
     1355            # NOTE: the client is using the reported message to interpret the errors
    13401356            die $@;
    13411357        }
     
    13861402    };
    13871403    $log->logdie("database error: $@") if $@;
     1404    $db->commit;
    13881405
    13891406    $log->debug("leaving");
     
    14421459                die( "affected row count is $rows instead of 1" );
    14431460            }
    1444 
    14451461            $db->commit;
    14461462            $log->debug("commit");
     
    15451561        $work_dir = $pattern;
    15461562        $file_pattern = '%';
    1547     }
    1548     else {
     1563    } else {
    15491564        my $dir_plain = dirname($pattern);
    15501565        if ($dir_plain eq 'neb:') {
     
    15751590        my $query = $db->prepare_cached( $sql->find_dir_by_parent_id . " AND dirname LIKE ? ");
    15761591        $query->execute( $dir_id, $file_pattern );
     1592        $db->commit;
    15771593
    15781594        while ( my $row = $query->fetchrow_hashref ) {
     
    15951611        my $query = $db->prepare_cached( $sql->find_object_by_dir_id . " AND ext_id_basename LIKE ? ");
    15961612        $query->execute( $dir_id , $file_pattern);
     1613        $db->commit;
    15971614
    15981615        while ( my $row = $query->fetchrow_hashref ) {
     
    16241641    my $sql = $self->sql;
    16251642    my $db  = $self->_db_for_index($index);
    1626 
    16271643
    16281644    # first check to see if the key is an exact match
     
    16451661        $log->logdie("database error: $@");
    16461662    }
     1663    $db->commit;
    16471664
    16481665    if (scalar @keys) {
     
    16781695    };
    16791696    $log->logdie("database error: $@") if $@;
     1697    $db->commit;
    16801698
    16811699    # find files under dir
     
    16921710    };
    16931711    $log->logdie("database error: $@") if $@;
     1712    $db->commit;
    16941713
    16951714    $log->debug( "leaving" );
     
    17531772}
    17541773
     1774# sub find_instances
    17551775sub find_instances_old
    17561776{
     
    18291849            # ext_id, available
    18301850            if (defined($find_invalid)) {
     1851                # XXX returns instances which are NOT available
    18311852                $rows = $query->execute($key->path, 0);
    18321853            }
     
    18651886}
    18661887
    1867 #sub find_instances_by_proximity
     1888# sub find_instances_by_proximity
    18681889sub find_instances
    18691890{
     
    18971918        },
    18981919    );
    1899 
    19001920    my $sql = $self->sql;
    19011921
     
    19321952            }
    19331953        }
    1934 
    1935 
    19361954    }
    19371955
     
    19721990            # ext_id, name, available
    19731991            # host_vol_id host_cab_id host_site_id ext_id available
     1992
     1993            ### XXX EAM if find_invalid is true, the last arguement here should be 0
    19741994            my $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 1);
    19751995            unless ($rows > 0) {
    19761996                $query->finish;
    1977                 die("no instances on storage volume or volume is not avaiable for key: $key volume: $vol_name");
     1997                die("no instances on storage volume or volume is not available for key: $key volume: $vol_name");
    19781998            }
    19791999        } else {
     
    19822002            # ext_id, available
    19832003            if (defined($find_invalid)) {
     2004                # returns instances which are NOT available (volume not available)
    19842005                $rows = $query->execute($key->path, 0);
    19852006            }
     
    19922013            }
    19932014        }
     2015        $db->commit;
     2016        ## if we do not call commit here, the transaction stays
     2017        ## open blocking some operations below.
    19942018
    19952019        while (my $row = $query->fetchrow_hashref) {
     
    20182042}
    20192043
     2044# this method returns instances on the specified volume
     2045# or a list of all available instances
     2046# it does NOT choose instances based on proximity
     2047# and it does NOT return invalid instances
    20202048sub find_instances_for_cull
    20212049{
     
    20612089    my $db  = $self->db($key);
    20622090
     2091    ## XXX this method is missing the alias deference section (see find_instances)
     2092
    20632093    # the key's volume can't be validiated on input for this method so we have
    20642094    # to check it after parsing the key
     
    21112141        $log->logdie("database error: $@");
    21122142    }
     2143    $db->commit;
    21132144
    21142145    # XXX remove this?
     
    22222253                }
    22232254            }
    2224 
    22252255            $db->commit;
    22262256            $log->debug("commit");
     
    22822312        $stat = $query->fetchrow_arrayref;
    22832313        $query->finish;
     2314        $db->commit;
    22842315    };
    22852316    $log->logdie("database error: $@") if $@;
     
    23182349    };
    23192350    $log->logdie("database error: $@") if $@;
     2351    $db->commit;
    23202352
    23212353    $log->logdie("no mounted volumes found") unless (scalar @$stats);
     
    24152447    my ($key, $name, $hard_volume) = @_;
    24162448   
    2417 #    $log->warn("_g_s_v: key:>$key< name:>$name< hard_vol:>$hard_volume<");
     2449    # track the number of calls to this function and
     2450    # give up after 10 attempts
     2451    $get_storage_volume_calls ++;
     2452
     2453#   $log->warn("_g_s_v: key:>$key< name:>$name< hard_vol:>$hard_volume<");
    24182454    my $sql = $self->sql;
    24192455    my $db  = $self->db($key);
     
    24302466            unless ($rows > 0) {
    24312467                $query->finish;
     2468                $db->commit;
    24322469
    24332470                # if a volume name was specified, and is soft, and we failed to
     
    24422479            if ($rows > 1) {
    24432480                $query->finish;
     2481                $db->commit;
    24442482                die("affected row count is $rows instead of 1");
    24452483            }
     
    24492487            $rows = $query->execute($max_used_space, 1, 1, $topfew_count);
    24502488#           $log->warn("Storage_volume: $rows $topfew_count");
    2451             # there has to be atleast one storage volume
     2489            # there has to be at least one storage volume
    24522490            unless ($rows > 0) {
    24532491                $query->finish;
    2454                 die("no storage volume is available for key: $key volume: $name hard_volume: $hard_volume");
     2492                $db->commit;
     2493                # prevent failure in the die due to undefined variables
     2494                my $hard_volume_str = defined $hard_volume ? $hard_volume : "undefined";
     2495                my $name_str = defined $name ? $name : "undefined";
     2496                die("no storage volume is available for key: $key volume: $name_str hard_volume: $hard_volume_str");
    24552497            }
    24562498        }
     
    24652507            $log->error($@);
    24662508            $log->debug("retrying...");
    2467             return $self->_get_storage_volume(@_);
     2509            if ($get_storage_volume_calls < 10) {
     2510                return $self->_get_storage_volume(@_);
     2511            }
     2512            # else
     2513            $log->logdie("no available storage volume: $@");
    24682514        }
    24692515        # else
     
    25022548        unless ($rows > 0) {
    25032549            $query->finish;
    2504             die("Requested key $key does not exist");
     2550            die("Requested key $key does not exist (or cabinet is undefined)");
    25052551        }
    25062552        if ($rows == 1) {
     
    25132559            }
    25142560            $query->finish;
    2515         }
    2516         else {
     2561        } else {
     2562            # if instances are spread across multiple cabinets, allow the next instance to go anywhere
     2563            # NOTE: this does not prevent the new instance from going to the same volume as one of the existing instances
    25172564            $forbidden_cabinet = 0;
    25182565            $forbidden_site    = 0;
    25192566            $query->finish;
    25202567        }
    2521            
     2568        $db->commit;
    25222569
    25232570        $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id );
    2524         # ext_id, %free, avaiable, allocate
     2571        # ext_id, %free, available, allocate
     2572
    25252573        $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $forbidden_site, $topfew_count);
    2526         # XXX destinguish between non-existant and unaviable
     2574        # XXX destinguish between non-existant and unavailable
    25272575        unless ($rows > 0) {
    25282576            $query->finish;
     
    25442592        ($vol_id, $vol_host, $vol_path, $xattr, $free) = $query->fetchrow_array;
    25452593        $query->finish;
     2594        $db->commit;
    25462595    };
    25472596    $log->logdie("database error: $@") if $@;
     
    25902639        ($ext_id) = $query->fetchrow_array;
    25912640        $query->finish;
     2641        $db->commit;
     2642        ## if we do not call commit here, the transaction stays open blocking some operations below
    25922643    };
    25932644    if ($@) {
     
    26122663}
    26132664
    2614 
     2665# in the past, _is_valid_volume_name returned 'undef'. 
     2666# now it either returns 1 (success) or 0 (failure)
    26152667sub _is_valid_volume_name
    26162668{
     
    26502702        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
    26512703        $query->finish;
     2704        $db->commit;
    26522705    };
    26532706    $log->logdie("database error: $@") if $@;
Note: See TracChangeset for help on using the changeset viewer.