Changeset 41172 for trunk/Nebulous-Server/lib/Nebulous/Server.pm
- Timestamp:
- Nov 27, 2019, 12:04:14 PM (7 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm (modified) (60 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r39926 r41172 13 13 use base qw( Class::Accessor::Fast ); 14 14 15 use Carp; 16 15 17 use Cache::Memcached; 16 18 use DBI; 19 20 ## for gentoo: 17 21 use Digest::SHA1 qw( sha1_hex ); 22 23 ## for ubuntu: 24 # use Digest::SHA qw( sha1_hex ); 25 18 26 use Fcntl ':mode'; 19 27 use File::Basename qw( basename dirname fileparse ); … … 77 85 Cache::Memcached->new({ 78 86 servers => $config->memcached_servers, 79 })80 );87 }) 88 ); 81 89 # $self->cache->set("foo", "bar") or die "set failed"; 82 90 # $self->cache->get("foo") or die "get failed"; … … 215 223 } 216 224 225 my $get_storage_volume_calls = 0; 226 217 227 sub create_object 218 228 { … … 252 262 # the key's volume can't be validiated on input for this method so we have 253 263 # to check it after parsing the key 254 if (defined $vol_name 255 and not $self->_is_valid_volume_name($key, $key->volume)) { 264 if (defined $vol_name and not $self->_is_valid_volume_name($key, $key->volume)) { 256 265 unless ($key->hard_volume) { 257 266 $log->warn( "$vol_name is not a known volume name" ); … … 262 271 } 263 272 273 $get_storage_volume_calls = 0; 274 264 275 my ($vol_id, $vol_host, $vol_path, $vol_xattr) 265 276 = $self->_get_storage_volume($key, $vol_name, $key->hard_volume); … … 273 284 # create storage_object 274 285 my $query = $db->prepare_cached( $sql->new_object ); 275 $query->execute('NULL', $key->path, basename($key->path), $parent_id); 286 # bad syntax $query->execute('NULL', $key->path, basename($key->path), $parent_id); 287 $query->execute(0, $key->path, basename($key->path), $parent_id); 288 $query->finish; 276 289 } 277 290 … … 292 305 my $query = $db->prepare_cached( $sql->new_object_attr ); 293 306 $query->execute($so_id); 307 $query->finish; 294 308 } 295 309 … … 300 314 my $query = $db->prepare_cached( $sql->new_object_instance ); 301 315 $query->execute($vol_id); 316 $query->finish; 302 317 } 303 318 … … 327 342 # vol_id, uri, ins_id 328 343 $query->execute($vol_id, "$uri", $ins_id); 344 $query->finish; 329 345 } 330 346 … … 421 437 } 422 438 $query->finish; 439 $db->commit; 423 440 } 424 441 … … 441 458 my $query = $db->prepare_cached($sql->new_directory); 442 459 $query->execute($dir, $parent_id); 460 $query->finish; 461 $db->commit; 443 462 } 444 463 … … 452 471 ($parent_id) = $query->fetchrow_array; 453 472 $query->finish; 473 $db->commit; 454 474 } 455 475 die("failed to get LAST_INSERT_ID()") 456 476 unless $parent_id; 457 458 $db->commit;459 477 } 460 478 }; … … 712 730 { 713 731 type => SCALAR|UNDEF, 714 # callbacks => {715 # # check that the volume name requested is valid716 # 'is valid volume name' => sub {717 # return 1 if not defined $_[0];718 # $self->_is_valid_volume_name($_[0])719 # },720 # },721 732 optional => 1, 722 733 }, … … 726 737 727 738 # if a volume name is explicity specified then we should make the 728 # replication onto that volume (even if there is alread an instance on that739 # replication onto that volume (even if there is already an instance on that 729 740 # volume) if at all possible and throw an error if we can not. 741 730 742 # if a volume name IS NOT specified then we should make the replication 731 743 # onto any (hopefully the best) volume that DOES NOT already have an 732 # instance on it. If all av ilable volumealready have an instance on them744 # instance on it. If all available volumes already have an instance on them 733 745 # then we should throw an error 746 734 747 # volume names implied as part of the key are *IGNORED* as the source and 735 748 # *SHOULD NOT* be used as the destination either 736 749 737 750 eval { 738 $key = parse_neb_key($key); 751 # EAM 2019.10.31 : if I supply dest_vol_name here, then 752 # $key->volume will point at that volume and the section below 753 # will correctly be testing the validity of dest_vol_name 754 $key = parse_neb_key($key, $dest_vol_name); 739 755 }; 740 756 $log->logdie("$@") if $@; … … 742 758 my $db = $self->db($key); 743 759 760 ## Old comment: 744 761 # puke if the source volume is bogus, we may want to actually use this as 745 762 # the instance to be copied later 746 if (defined $key->volume 747 and not $self->_is_valid_volume_name($key, $key->volume)) { 763 764 # EAM 2019.10.31 : in the past, the key-implied volume was 765 # supplied here, which was inconsistent since above it says the 766 # key-implied volume is ignored. By supplying $dest_vol_name to 767 # parse_neb_key above, the key->volume now refers to the 768 # dest_volume 769 if (defined $key->volume and not $self->_is_valid_volume_name($key, $key->volume)) { 748 770 unless ($key->hard_volume) { 749 771 $log->warn($key->volume . " not a known volume name"); … … 752 774 } 753 775 } 754 # puke if the source volume is bogus, we may want to actually use this as 755 # the instance to be copied later 756 if (defined $dest_vol_name 757 and not $self->_is_valid_volume_name($key, $dest_vol_name)) { 758 $log->logdie($key->volume . " is not a valid volume name"); 759 } 760 776 777 # puke if the destination volume is bogus 778 ## XXX if I supply dest_vol_name to parse_neb_key above, this section below is redundant with the above 779 ## if (defined $dest_vol_name 780 ## and not $self->_is_valid_volume_name($key, $dest_vol_name)) { 781 ## $log->logdie($key->volume . " is not a valid volume name"); 782 ## } 783 784 $get_storage_volume_calls = 0; 785 761 786 my ($vol_id, $vol_host, $vol_path, $vol_xattr); 762 787 if (defined $dest_vol_name) { 788 # if we supplied dest_vol_name, then the call to parse_neb_key above 789 # will have set $key->volume to that value and hard_volume to match 763 790 ($vol_id, $vol_host, $vol_path, $vol_xattr) 764 = $self->_get_storage_volume($key, $ dest_vol_name);791 = $self->_get_storage_volume($key, $key->volume, $key->hard_volume); 765 792 } else { 766 793 ($vol_id, $vol_host, $vol_path, $vol_xattr) 767 794 = $self->_get_replication_volume($key); 768 795 } 796 797 # print "selected target: $vol_id, $vol_host\n"; 769 798 770 799 my $uri; … … 784 813 $so_id = $query->fetchrow_hashref->{ 'so_id' }; 785 814 $query->finish; 815 $db->commit; 786 816 } 787 817 … … 800 830 # time LAST_INSERT_ID() is invoked 801 831 $query->finish; 832 $db->commit; 802 833 } 803 834 … … 841 872 eval { 842 873 my $mode = $self->getxattr_object("$key", 'user.mode'); 843 if (defined $mode ) {844 $self->chmod_object("$key", $mode);874 if (defined $mode && $mode ne "") { 875 $self->chmod_object("$key", $mode); 845 876 } 846 877 }; … … 852 883 853 884 $log->debug("leaving"); 854 855 885 return "$uri"; 856 886 } … … 1323 1353 die( "xattr $key:$name does not exist" ); 1324 1354 } 1355 1325 1356 # if we go more then one row bad something very bad has happened. 1326 1357 unless ($rows == 1) { … … 1335 1366 $value = $row->{ 'value' }; 1336 1367 }; 1368 $db->commit; 1369 1337 1370 if ($@) { 1338 1371 if ($@ =~ /user\..*? does not exist/) { 1339 1372 # do not log xattr does not exist messages 1373 # NOTE: the client is using the reported message to interpret the errors 1340 1374 die $@; 1341 1375 } … … 1386 1420 }; 1387 1421 $log->logdie("database error: $@") if $@; 1422 $db->commit; 1388 1423 1389 1424 $log->debug("leaving"); … … 1442 1477 die( "affected row count is $rows instead of 1" ); 1443 1478 } 1444 1445 1479 $db->commit; 1446 1480 $log->debug("commit"); … … 1545 1579 $work_dir = $pattern; 1546 1580 $file_pattern = '%'; 1547 } 1548 else { 1581 } else { 1549 1582 my $dir_plain = dirname($pattern); 1550 1583 if ($dir_plain eq 'neb:') { … … 1575 1608 my $query = $db->prepare_cached( $sql->find_dir_by_parent_id . " AND dirname LIKE ? "); 1576 1609 $query->execute( $dir_id, $file_pattern ); 1610 $db->commit; 1577 1611 1578 1612 while ( my $row = $query->fetchrow_hashref ) { … … 1595 1629 my $query = $db->prepare_cached( $sql->find_object_by_dir_id . " AND ext_id_basename LIKE ? "); 1596 1630 $query->execute( $dir_id , $file_pattern); 1631 $db->commit; 1597 1632 1598 1633 while ( my $row = $query->fetchrow_hashref ) { … … 1624 1659 my $sql = $self->sql; 1625 1660 my $db = $self->_db_for_index($index); 1626 1627 1661 1628 1662 # first check to see if the key is an exact match … … 1645 1679 $log->logdie("database error: $@"); 1646 1680 } 1681 $db->commit; 1647 1682 1648 1683 if (scalar @keys) { … … 1678 1713 }; 1679 1714 $log->logdie("database error: $@") if $@; 1715 $db->commit; 1680 1716 1681 1717 # find files under dir … … 1692 1728 }; 1693 1729 $log->logdie("database error: $@") if $@; 1730 $db->commit; 1694 1731 1695 1732 $log->debug( "leaving" ); … … 1753 1790 } 1754 1791 1792 # sub find_instances 1755 1793 sub find_instances_old 1756 1794 { … … 1769 1807 { 1770 1808 type => SCALAR|UNDEF, 1771 # callbacks => {1772 # # check that the volume name requested is valid1773 # 'is valid volume name' => sub {1774 # return 1 if not defined $_[0];1775 # $self->_is_valid_volume_name($_[0])1776 # },1777 # },1778 1809 optional => 1, 1779 1810 }, … … 1787 1818 my $sql = $self->sql; 1788 1819 1789 # unless ($key) { 1790 # $log->warn("key was undefined after validate_pos(), trying again..."); 1791 # return $self->find_instances(@_); 1792 # } 1820 # default value for find_invalid is false 1821 if (not defined $find_invalid) { $find_invalid = 0; } 1793 1822 1794 1823 # vol_name overrides the key implied volume … … 1828 1857 my $rows; 1829 1858 # ext_id, available 1830 if (defined($find_invalid)) { 1859 if (defined($find_invalid) and $find_invalid) { 1860 # XXX returns instances which are NOT available 1831 1861 $rows = $query->execute($key->path, 0); 1832 1862 } … … 1865 1895 } 1866 1896 1867 # sub find_instances_by_proximity1897 # sub find_instances_by_proximity 1868 1898 sub find_instances 1869 1899 { … … 1882 1912 { 1883 1913 type => SCALAR|UNDEF, 1884 # callbacks => {1885 # # check that the volume name requested is valid1886 # 'is valid volume name' => sub {1887 # return 1 if not defined $_[0];1888 # $self->_is_valid_volume_name($_[0])1889 # },1890 # },1891 1914 optional => 1, 1892 1915 }, … … 1897 1920 }, 1898 1921 ); 1899 1900 1922 my $sql = $self->sql; 1901 1923 1902 # unless ($key) { 1903 # $log->warn("key was undefined after validate_pos(), trying again..."); 1904 # return $self->find_instances(@_); 1905 # } 1924 if (not defined $find_invalid) { $find_invalid = 0; } 1925 1926 if ($find_invalid eq "find them all") { 1927 $log->logdie("old neb-cull --one_only, neb-rm --invalid both disabled by new Server.pm"); 1928 } 1906 1929 1907 1930 # vol_name overrides the key implied volume … … 1932 1955 } 1933 1956 } 1934 1935 1936 1957 } 1937 1958 … … 1972 1993 # ext_id, name, available 1973 1994 # 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); 1995 1996 my $rows; 1997 if (defined($find_invalid) and $find_invalid) { 1998 # returns instances which are NOT available (volume not available) 1999 $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 0); 2000 } else { 2001 $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 1); 2002 } 1975 2003 unless ($rows > 0) { 1976 2004 $query->finish; 1977 die("no instances on storage volume or volume is not avai able for key: $key volume: $vol_name");2005 die("no instances on storage volume or volume is not available for key: $key volume: $vol_name"); 1978 2006 } 1979 2007 } else { 1980 2008 $query = $db->prepare_cached( $sql->get_object_instances ); 2009 # ext_id, available 2010 1981 2011 my $rows; 1982 # ext_id, available 1983 if (defined($find_invalid)) {2012 if (defined($find_invalid) and $find_invalid) { 2013 # returns instances which are NOT available (volume not available) 1984 2014 $rows = $query->execute($key->path, 0); 1985 } 1986 else { 2015 } else { 1987 2016 $rows = $query->execute($key->path, 1); 1988 2017 } … … 1992 2021 } 1993 2022 } 2023 $db->commit; 2024 ## if we do not call commit here, the transaction stays 2025 ## open blocking some operations below. 1994 2026 1995 2027 while (my $row = $query->fetchrow_hashref) { 1996 2028 my $instance = $row->{ 'uri' }; 1997 2029 push @locations, $instance if $instance; 2030 2031 # Carp::carp ("instance 2: $row->{ 'uri' }, $row->{ 'vol_id' }, $row->{ 'cab_id' }, $row->{ 'vol_idx' }\n"); 1998 2032 } 1999 2033 }; … … 2003 2037 if (defined $vol_name and not defined $key->hard_volume) { 2004 2038 $log->debug("retrying with 'any' volume"); 2005 return $self->find_instances($key->path, 'any' );2039 return $self->find_instances($key->path, 'any', $find_invalid); 2006 2040 } 2007 2041 $log->logdie("database error: $@"); … … 2018 2052 } 2019 2053 2054 # this method returns instances on the specified volume 2055 # or a list of all available instances 2056 # it does NOT choose instances based on proximity 2057 # and it does NOT return invalid instances 2020 2058 sub find_instances_for_cull 2021 2059 { … … 2061 2099 my $db = $self->db($key); 2062 2100 2101 ## XXX this method is missing the alias deference section (see find_instances) 2102 ## if aliases are intended to be compute nodes in the same cabinet / site as 2103 ## the storage nodes, then this is not needed. 2104 2063 2105 # the key's volume can't be validiated on input for this method so we have 2064 2106 # to check it after parsing the key … … 2082 2124 unless ($rows > 0) { 2083 2125 $query->finish; 2084 die("no instances on storage volume or volume is not avai able for key: $key volume: $vol_name");2126 die("no instances on storage volume or volume is not available for key: $key volume: $vol_name"); 2085 2127 } 2086 2128 } else { … … 2105 2147 $db->rollback; 2106 2148 # handle soft volumes 2107 if (defined $vol_name and not defined $key->hard_volume) { 2149 # we need to call find_intances_for_cull here so the returned structure 2150 # is the same (find_instances just returns an array of strings) 2151 if (defined $vol_name and not defined $key->hard_volume and ($vol_name ne "any")) { 2108 2152 $log->debug("retrying with 'any' volume"); 2109 return $self->find_instances ($key->path, 'any');2153 return $self->find_instances_for_cull($key->path, 'any'); 2110 2154 } 2111 2155 $log->logdie("database error: $@"); 2112 2156 } 2157 $db->commit; 2113 2158 2114 2159 # XXX remove this? … … 2222 2267 } 2223 2268 } 2224 2225 2269 $db->commit; 2226 2270 $log->debug("commit"); … … 2282 2326 $stat = $query->fetchrow_arrayref; 2283 2327 $query->finish; 2328 $db->commit; 2284 2329 }; 2285 2330 $log->logdie("database error: $@") if $@; … … 2318 2363 }; 2319 2364 $log->logdie("database error: $@") if $@; 2365 $db->commit; 2320 2366 2321 2367 $log->logdie("no mounted volumes found") unless (scalar @$stats); … … 2415 2461 my ($key, $name, $hard_volume) = @_; 2416 2462 2417 # $log->warn("_g_s_v: key:>$key< name:>$name< hard_vol:>$hard_volume<"); 2463 # track the number of calls to this function and 2464 # give up after 10 attempts 2465 $get_storage_volume_calls ++; 2466 2467 # $log->warn("_g_s_v: key:>$key< name:>$name< hard_vol:>$hard_volume<"); 2418 2468 my $sql = $self->sql; 2419 2469 my $db = $self->db($key); … … 2427 2477 # %free, name, avaiable, allocate 2428 2478 $rows = $query->execute($max_used_space, $name, 1, 1); 2429 # XXX d estinguish between non-existant and unavailable2479 # XXX distinguish between non-existant and unavailable 2430 2480 unless ($rows > 0) { 2431 2481 $query->finish; 2482 $db->commit; 2432 2483 2433 2484 # if a volume name was specified, and is soft, and we failed to … … 2442 2493 if ($rows > 1) { 2443 2494 $query->finish; 2495 $db->commit; 2444 2496 die("affected row count is $rows instead of 1"); 2445 2497 } … … 2449 2501 $rows = $query->execute($max_used_space, 1, 1, $topfew_count); 2450 2502 # $log->warn("Storage_volume: $rows $topfew_count"); 2451 # there has to be at least one storage volume2503 # there has to be at least one storage volume 2452 2504 unless ($rows > 0) { 2453 2505 $query->finish; 2454 die("no storage volume is available for key: $key volume: $name hard_volume: $hard_volume"); 2506 $db->commit; 2507 # prevent failure in the die due to undefined variables 2508 my $hard_volume_str = defined $hard_volume ? $hard_volume : "undefined"; 2509 my $name_str = defined $name ? $name : "undefined"; 2510 die("no storage volume is available for key: $key volume: $name_str hard_volume: $hard_volume_str"); 2455 2511 } 2456 2512 } … … 2465 2521 $log->error($@); 2466 2522 $log->debug("retrying..."); 2467 return $self->_get_storage_volume(@_); 2523 if ($get_storage_volume_calls < 10) { 2524 return $self->_get_storage_volume(@_); 2525 } 2526 # else 2527 $log->logdie("no available storage volume: $@"); 2468 2528 } 2469 2529 # else … … 2502 2562 unless ($rows > 0) { 2503 2563 $query->finish; 2504 die("Requested key $key does not exist ");2564 die("Requested key $key does not exist (or cabinet is undefined)"); 2505 2565 } 2506 2566 if ($rows == 1) { … … 2513 2573 } 2514 2574 $query->finish; 2515 } 2516 else { 2575 } else { 2576 # if instances are spread across multiple cabinets, allow the next instance to go anywhere 2577 # NOTE: this does not prevent the new instance from going to the same volume as one of the existing instances 2517 2578 $forbidden_cabinet = 0; 2518 2579 $forbidden_site = 0; 2519 2580 $query->finish; 2520 2581 } 2521 2582 $db->commit; 2522 2583 2523 2584 $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id ); 2524 # ext_id, %free, avaiable, allocate 2585 # ext_id, %free, available, allocate 2586 2525 2587 $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $forbidden_site, $topfew_count); 2526 # XXX d estinguish between non-existant and unaviable2588 # XXX distinguish between non-existant and unavailable 2527 2589 unless ($rows > 0) { 2528 2590 $query->finish; … … 2544 2606 ($vol_id, $vol_host, $vol_path, $xattr, $free) = $query->fetchrow_array; 2545 2607 $query->finish; 2608 $db->commit; 2546 2609 }; 2547 2610 $log->logdie("database error: $@") if $@; … … 2590 2653 ($ext_id) = $query->fetchrow_array; 2591 2654 $query->finish; 2655 $db->commit; 2656 ## if we do not call commit here, the transaction stays open blocking some operations below 2592 2657 }; 2593 2658 if ($@) { … … 2612 2677 } 2613 2678 2614 2679 # in the past, _is_valid_volume_name returned 'undef'. 2680 # now it either returns 1 (success) or 0 (failure) 2615 2681 sub _is_valid_volume_name 2616 2682 { … … 2650 2716 ($vol_id, $vol_path, $free) = $query->fetchrow_array; 2651 2717 $query->finish; 2718 $db->commit; 2652 2719 }; 2653 2720 $log->logdie("database error: $@") if $@;
Note:
See TracChangeset
for help on using the changeset viewer.
