IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 30, 2016, 1:38:49 PM (10 years ago)
Author:
watersc1
Message:

Commit of test version of Nebulous location based code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20160809/Nebulous-Server/lib/Nebulous/Server.pm

    r31370 r39662  
    18651865}
    18661866
     1867sub find_instances_by_proximity
     1868{
     1869    my $self = shift;
     1870
     1871    my $log = $self->log;
     1872    $log->debug("entered - @_");
     1873
     1874    my ($key, $vol_name, $find_invalid) = validate_pos(@_,
     1875        {
     1876            type        => SCALAR,
     1877            callbacks   => {
     1878                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     1879            },
     1880        },
     1881        {
     1882            type        => SCALAR|UNDEF,
     1883#            callbacks   => {
     1884#                # check that the volume name requested is valid
     1885#                'is valid volume name' => sub {
     1886#                    return 1 if not defined $_[0];
     1887#                    $self->_is_valid_volume_name($_[0])
     1888#                },
     1889#            },
     1890            optional    => 1,
     1891        },
     1892        {
     1893            # find_invalid
     1894            type        => SCALAR|UNDEF,
     1895            optional    => 1,
     1896        },
     1897    );
     1898
     1899    my $sql = $self->sql;
     1900
     1901#    unless ($key) {
     1902#        $log->warn("key was undefined after validate_pos(), trying again...");
     1903#        return $self->find_instances(@_);
     1904#    }
     1905
     1906    # vol_name overrides the key implied volume
     1907    my ($h_vol_id, $h_cab_id, $h_site_id);
     1908    eval {
     1909        $key = parse_neb_key($key, $vol_name);
     1910    };
     1911    $log->logdie("$@") if $@;
     1912    $vol_name = $key->volume;
     1913
     1914    my $db  = $self->db($key);
     1915
     1916    # Convert possible alias to real volume.
     1917    if (defined $vol_name) {
     1918        my ($tmp_vol_id, $tmp_name, $tmp_host, $tmp_path);
     1919        eval {
     1920            my $query = $db->prepare_cached( $sql->get_volume_by_alias );
     1921            $query->execute( $vol_name );
     1922            ($tmp_vol_id, $tmp_name, $tmp_host, $tmp_path) = $query->fetchrow_array;
     1923            $query->finish;
     1924        };
     1925        $log->logdie("$@") if $@;
     1926       
     1927        if (defined $tmp_vol_id and defined $tmp_name and defined $tmp_host and defined $tmp_path) {
     1928            if ($tmp_name ne $vol_name) {
     1929                $vol_name = $tmp_name;
     1930            }
     1931        }
     1932    }
     1933
     1934    # the key's volume can't be validiated on input for this method so we have
     1935    # to check it after parsing the key
     1936    if (defined $vol_name
     1937        and not $self->_is_valid_volume_name($key, $key->volume)) {
     1938        if ($key->hard_volume) {
     1939            $log->logdie("$vol_name is not a valid volume name");
     1940        } else {
     1941            $log->warn( "$vol_name is not a known volume name" );
     1942            $vol_name = undef;
     1943        }
     1944    }
     1945
     1946    # Get the host volume information encoded in the vol_name.
     1947    # I am unhappy that we have three different if(defined($vol_name)) entries, but I don't see a better way.
     1948    my ($h_vol_id, $h_cab_id, $h_site_id);
     1949    if (defined $vol_name) {
     1950        eval {
     1951            my $query = $db->prepare_cached( $sql->get_site_info_by_name );
     1952            $query->execute( $vol_name );
     1953            ($h_vol_id, $h_cab_id, $h_site_id) = $query->fetchrow_array;
     1954            $query->finish;
     1955        };
     1956        $log->logdie("$@") if $@;
     1957
     1958        unless(defined $h_vol_id and defined $h_cab_id and defined $h_site_id) {
     1959            $vol_name = undef;
     1960        }
     1961    }
     1962
     1963    my @locations;
     1964    eval {
     1965        my $query;
     1966        if ($vol_name && $h_vol_id && $h_cab_id && $h_site_id) {
     1967            $query = $db->prepare_cached( $sql->get_object_instances_by_proximity );
     1968            # ext_id, name, available
     1969            # host_vol_id host_cab_id host_site_id ext_id available
     1970            my $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 1);
     1971            unless ($rows > 0) {
     1972                $query->finish;
     1973                die("no instances on storage volume or volume is not avaiable for key: $key volume: $vol_name");
     1974            }
     1975        } else {
     1976            $query = $db->prepare_cached( $sql->get_object_instances );
     1977            my $rows;
     1978            # ext_id, available
     1979            if (defined($find_invalid)) {
     1980                $rows = $query->execute($key->path, 0);
     1981            }
     1982            else {
     1983                $rows = $query->execute($key->path, 1);
     1984            }
     1985            unless ($rows > 0) {
     1986                $query->finish;
     1987                die("no instances available for key: $key");
     1988            }
     1989        }
     1990
     1991        while (my $row = $query->fetchrow_hashref) {
     1992            my $instance = $row->{ 'uri' };
     1993            push @locations, $instance if $instance;
     1994        }
     1995    };
     1996    if ($@) {
     1997        $db->rollback;
     1998        # handle soft volumes
     1999        if (defined $vol_name and not defined $key->hard_volume) {
     2000            $log->debug("retrying with 'any' volume");
     2001            return $self->find_instances($key->path, 'any');
     2002        }
     2003        $log->logdie("database error: $@");
     2004    }
     2005
     2006    # XXX remove this?
     2007    $log->logdie("no instances found") unless (scalar @locations);
     2008
     2009    $log->debug("found: @locations");
     2010
     2011    $log->debug("leaving");
     2012
     2013    return \@locations;
     2014}
     2015
    18672016sub find_instances_for_cull
    18682017{
     
    23412490    my $db  = $self->db($key);
    23422491
    2343     my ($vol_id, $vol_host, $vol_path, $xattr, $forbidden_cabinet);
     2492    my ($vol_id, $vol_host, $vol_path, $xattr, $forbidden_cabinet, $forbidden_site);
    23442493    eval {
    23452494        my $rows;
     
    23522501        }
    23532502        if ($rows == 1) {
    2354             ($forbidden_cabinet) = $query->fetchrow_array;
     2503            ($forbidden_cabinet, $forbidden_site) = $query->fetchrow_array;
    23552504            unless (defined($forbidden_cabinet)) {
    23562505                $forbidden_cabinet = 0;
     2506            }
     2507            unless (defined($forbidden_site)) {
     2508                $forbidden_site = 0;
    23572509            }
    23582510            $query->finish;
     
    23602512        else {
    23612513            $forbidden_cabinet = 0;
     2514            $forbidden_site    = 0;
    23622515            $query->finish;
    23632516        }
     
    23662519        $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id );
    23672520        # ext_id, %free, avaiable, allocate
    2368         $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $topfew_count);
     2521        $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $forbidden_site, $topfew_count);
    23692522        # XXX destinguish between non-existant and unaviable
    23702523        unless ($rows > 0) {
    23712524            $query->finish;
    2372             die("can't find a suitable storage volume to replicate $key to");
     2525            # CZW: 2016-08-23 This wasn't right.  If we don't get an entry, we may have been too strict.
     2526            #      I'm not fully convinced this is complete, as we may want to back out the cabinet criterion as well.
     2527            #      In any case, I don't think we're generally in the situation where replication can't find a host.
     2528            $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, 0, $topfew_count);
     2529            unless ($rows > 0) {
     2530                die("can't find a suitable storage volume to replicate $key to");
     2531            }
    23732532        }
    23742533        # when matching by name we shouldn't ever match more than once
Note: See TracChangeset for help on using the changeset viewer.