IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 6, 2017, 11:30:10 AM (9 years ago)
Author:
eugene
Message:

merging changes from czw dev branch (compare with r39924)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r31370 r39926  
    17531753}
    17541754
    1755 sub find_instances
     1755sub find_instances_old
    17561756{
    17571757    my $self = shift;
     
    18201820            # ext_id, name, available
    18211821            my $rows = $query->execute($key->path, $vol_name, 1);
     1822            unless ($rows > 0) {
     1823                $query->finish;
     1824                die("no instances on storage volume or volume is not avaiable for key: $key volume: $vol_name");
     1825            }
     1826        } else {
     1827            $query = $db->prepare_cached( $sql->get_object_instances );
     1828            my $rows;
     1829            # ext_id, available
     1830            if (defined($find_invalid)) {
     1831                $rows = $query->execute($key->path, 0);
     1832            }
     1833            else {
     1834                $rows = $query->execute($key->path, 1);
     1835            }
     1836            unless ($rows > 0) {
     1837                $query->finish;
     1838                die("no instances available for key: $key");
     1839            }
     1840        }
     1841
     1842        while (my $row = $query->fetchrow_hashref) {
     1843            my $instance = $row->{ 'uri' };
     1844            push @locations, $instance if $instance;
     1845        }
     1846    };
     1847    if ($@) {
     1848        $db->rollback;
     1849        # handle soft volumes
     1850        if (defined $vol_name and not defined $key->hard_volume) {
     1851            $log->debug("retrying with 'any' volume");
     1852            return $self->find_instances($key->path, 'any');
     1853        }
     1854        $log->logdie("database error: $@");
     1855    }
     1856
     1857    # XXX remove this?
     1858    $log->logdie("no instances found") unless (scalar @locations);
     1859
     1860    $log->debug("found: @locations");
     1861
     1862    $log->debug("leaving");
     1863
     1864    return \@locations;
     1865}
     1866
     1867#sub find_instances_by_proximity
     1868sub find_instances
     1869{
     1870    my $self = shift;
     1871
     1872    my $log = $self->log;
     1873    $log->debug("entered - @_");
     1874
     1875    my ($key, $vol_name, $find_invalid) = validate_pos(@_,
     1876        {
     1877            type        => SCALAR,
     1878            callbacks   => {
     1879                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     1880            },
     1881        },
     1882        {
     1883            type        => SCALAR|UNDEF,
     1884#            callbacks   => {
     1885#                # check that the volume name requested is valid
     1886#                'is valid volume name' => sub {
     1887#                    return 1 if not defined $_[0];
     1888#                    $self->_is_valid_volume_name($_[0])
     1889#                },
     1890#            },
     1891            optional    => 1,
     1892        },
     1893        {
     1894            # find_invalid
     1895            type        => SCALAR|UNDEF,
     1896            optional    => 1,
     1897        },
     1898    );
     1899
     1900    my $sql = $self->sql;
     1901
     1902#    unless ($key) {
     1903#        $log->warn("key was undefined after validate_pos(), trying again...");
     1904#        return $self->find_instances(@_);
     1905#    }
     1906
     1907    # vol_name overrides the key implied volume
     1908    my ($h_vol_id, $h_cab_id, $h_site_id);
     1909    eval {
     1910        $key = parse_neb_key($key, $vol_name);
     1911    };
     1912    $log->logdie("$@") if $@;
     1913    $vol_name = $key->volume;
     1914
     1915    my $db  = $self->db($key);
     1916
     1917    # Convert possible alias to real volume.
     1918    if (defined $vol_name) {
     1919        my ($tmp_vol_id, $tmp_name, $tmp_host, $tmp_path);
     1920        eval {
     1921            my $query = $db->prepare_cached( $sql->get_volume_by_alias );
     1922            $query->execute( $vol_name );
     1923            ($tmp_vol_id, $tmp_name, $tmp_host, $tmp_path) = $query->fetchrow_array;
     1924            $query->finish;
     1925        };
     1926        $log->logdie("$@") if $@;
     1927#       $log->warn("CZW: find_instance: deref alias: $vol_name => $tmp_vol_id $tmp_name $tmp_host $tmp_path (key vol: $key" . $key->volume . ")");
     1928        if (defined $tmp_vol_id and defined $tmp_name and defined $tmp_host and defined $tmp_path) {
     1929            if ($tmp_name ne $vol_name) {
     1930                $vol_name = $tmp_name;
     1931#               $key->volume = $vol_name;
     1932            }
     1933        }
     1934
     1935
     1936    }
     1937
     1938    # the key's volume can't be validiated on input for this method so we have
     1939    # to check it after parsing the key
     1940    if (defined $vol_name
     1941        and not $self->_is_valid_volume_name($key, $vol_name)) {
     1942        if ($key->hard_volume) {
     1943            $log->logdie("$vol_name is not a valid volume name");
     1944        } else {
     1945            $log->warn( "$vol_name is not a known volume name" );
     1946            $vol_name = undef;
     1947        }
     1948    }
     1949
     1950    # Get the host volume information encoded in the vol_name.
     1951    # I am unhappy that we have three different if(defined($vol_name)) entries, but I don't see a better way.
     1952#    my ($h_vol_id, $h_cab_id, $h_site_id);
     1953    if (defined $vol_name) {
     1954        eval {
     1955            my $query = $db->prepare_cached( $sql->get_site_info_by_name );
     1956            $query->execute( $vol_name );
     1957            ($h_vol_id, $h_cab_id, $h_site_id) = $query->fetchrow_array;
     1958            $query->finish;
     1959        };
     1960        $log->logdie("$@") if $@;
     1961
     1962        unless(defined $h_vol_id and defined $h_cab_id and defined $h_site_id) {
     1963            $vol_name = undef;
     1964        }
     1965    }
     1966
     1967    my @locations;
     1968    eval {
     1969        my $query;
     1970        if ($vol_name && $h_vol_id && $h_cab_id && $h_site_id) {
     1971            $query = $db->prepare_cached( $sql->get_object_instances_by_proximity );
     1972            # ext_id, name, available
     1973            # host_vol_id host_cab_id host_site_id ext_id available
     1974            my $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 1);
    18221975            unless ($rows > 0) {
    18231976                $query->finish;
     
    23412494    my $db  = $self->db($key);
    23422495
    2343     my ($vol_id, $vol_host, $vol_path, $xattr, $forbidden_cabinet);
     2496    my ($vol_id, $vol_host, $vol_path, $xattr, $forbidden_cabinet, $forbidden_site);
    23442497    eval {
    23452498        my $rows;
     
    23522505        }
    23532506        if ($rows == 1) {
    2354             ($forbidden_cabinet) = $query->fetchrow_array;
     2507            ($forbidden_cabinet, $forbidden_site) = $query->fetchrow_array;
    23552508            unless (defined($forbidden_cabinet)) {
    23562509                $forbidden_cabinet = 0;
     2510            }
     2511            unless (defined($forbidden_site)) {
     2512                $forbidden_site = 0;
    23572513            }
    23582514            $query->finish;
     
    23602516        else {
    23612517            $forbidden_cabinet = 0;
     2518            $forbidden_site    = 0;
    23622519            $query->finish;
    23632520        }
     
    23662523        $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id );
    23672524        # ext_id, %free, avaiable, allocate
    2368         $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $topfew_count);
     2525        $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $forbidden_site, $topfew_count);
    23692526        # XXX destinguish between non-existant and unaviable
    23702527        unless ($rows > 0) {
    23712528            $query->finish;
    2372             die("can't find a suitable storage volume to replicate $key to");
     2529            # CZW: 2016-08-23 This wasn't right.  If we don't get an entry, we may have been too strict.
     2530            #      I'm not fully convinced this is complete, as we may want to back out the cabinet criterion as well.
     2531            #      In any case, I don't think we're generally in the situation where replication can't find a host.
     2532            $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, 0, $topfew_count);
     2533            unless ($rows > 0) {
     2534                die("can't find a suitable storage volume to replicate $key to");
     2535            }
    23732536        }
    23742537        # when matching by name we shouldn't ever match more than once
     
    24902653    $log->logdie("database error: $@") if $@;
    24912654
     2655#    $log->warn("CZW: $vol_id $vol_path for >>$vol_name<<");
    24922656    if (defined $vol_id and defined $vol_path) {
    24932657        $log->debug( "found volume name $vol_name" );
    24942658        $log->debug( "leaving" );
     2659#       $log->warn("CZW: $vol_id $vol_path for >>$vol_name<<");
    24952660        return 1;
    24962661    }
Note: See TracChangeset for help on using the changeset viewer.