Changeset 40980 for branches/eam_branches/ipp-20191011
- Timestamp:
- Oct 28, 2019, 2:13:12 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20191011/Nebulous-Server/lib/Nebulous/Server.pm
r39926 r40980 15 15 use Cache::Memcached; 16 16 use DBI; 17 use Digest::SHA1 qw( sha1_hex ); 17 ## for gentoo: use Digest::SHA1 qw( sha1_hex ); 18 use Digest::SHA qw( sha1_hex ); 18 19 use Fcntl ':mode'; 19 20 use File::Basename qw( basename dirname fileparse ); … … 77 78 Cache::Memcached->new({ 78 79 servers => $config->memcached_servers, 79 })80 );80 }) 81 ); 81 82 # $self->cache->set("foo", "bar") or die "set failed"; 82 83 # $self->cache->get("foo") or die "get failed"; … … 215 216 } 216 217 218 my $get_storage_volume_calls = 0; 219 217 220 sub create_object 218 221 { … … 252 255 # the key's volume can't be validiated on input for this method so we have 253 256 # 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)) { 256 258 unless ($key->hard_volume) { 257 259 $log->warn( "$vol_name is not a known volume name" ); … … 262 264 } 263 265 266 $get_storage_volume_calls = 0; 267 264 268 my ($vol_id, $vol_host, $vol_path, $vol_xattr) 265 269 = $self->_get_storage_volume($key, $vol_name, $key->hard_volume); … … 273 277 # create storage_object 274 278 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; 276 282 } 277 283 … … 292 298 my $query = $db->prepare_cached( $sql->new_object_attr ); 293 299 $query->execute($so_id); 300 $query->finish; 294 301 } 295 302 … … 300 307 my $query = $db->prepare_cached( $sql->new_object_instance ); 301 308 $query->execute($vol_id); 309 $query->finish; 302 310 } 303 311 … … 327 335 # vol_id, uri, ins_id 328 336 $query->execute($vol_id, "$uri", $ins_id); 337 $query->finish; 329 338 } 330 339 … … 421 430 } 422 431 $query->finish; 432 $db->commit; 423 433 } 424 434 … … 441 451 my $query = $db->prepare_cached($sql->new_directory); 442 452 $query->execute($dir, $parent_id); 453 $query->finish; 454 $db->commit; 443 455 } 444 456 … … 452 464 ($parent_id) = $query->fetchrow_array; 453 465 $query->finish; 466 $db->commit; 454 467 } 455 468 die("failed to get LAST_INSERT_ID()") 456 469 unless $parent_id; 457 458 $db->commit;459 470 } 460 471 }; … … 744 755 # puke if the source volume is bogus, we may want to actually use this as 745 756 # 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)) { 748 758 unless ($key->hard_volume) { 749 759 $log->warn($key->volume . " not a known volume name"); … … 752 762 } 753 763 } 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 756 765 if (defined $dest_vol_name 757 766 and not $self->_is_valid_volume_name($key, $dest_vol_name)) { 758 767 $log->logdie($key->volume . " is not a valid volume name"); 759 768 } 760 769 770 $get_storage_volume_calls = 0; 771 761 772 my ($vol_id, $vol_host, $vol_path, $vol_xattr); 762 773 if (defined $dest_vol_name) { … … 784 795 $so_id = $query->fetchrow_hashref->{ 'so_id' }; 785 796 $query->finish; 797 $db->commit; 786 798 } 787 799 … … 800 812 # time LAST_INSERT_ID() is invoked 801 813 $query->finish; 814 $db->commit; 802 815 } 803 816 … … 841 854 eval { 842 855 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); 845 858 } 846 859 }; … … 852 865 853 866 $log->debug("leaving"); 854 855 867 return "$uri"; 856 868 } … … 1323 1335 die( "xattr $key:$name does not exist" ); 1324 1336 } 1337 1325 1338 # if we go more then one row bad something very bad has happened. 1326 1339 unless ($rows == 1) { … … 1335 1348 $value = $row->{ 'value' }; 1336 1349 }; 1350 $db->commit; 1351 1337 1352 if ($@) { 1338 1353 if ($@ =~ /user\..*? does not exist/) { 1339 1354 # do not log xattr does not exist messages 1355 # NOTE: the client is using the reported message to interpret the errors 1340 1356 die $@; 1341 1357 } … … 1386 1402 }; 1387 1403 $log->logdie("database error: $@") if $@; 1404 $db->commit; 1388 1405 1389 1406 $log->debug("leaving"); … … 1442 1459 die( "affected row count is $rows instead of 1" ); 1443 1460 } 1444 1445 1461 $db->commit; 1446 1462 $log->debug("commit"); … … 1545 1561 $work_dir = $pattern; 1546 1562 $file_pattern = '%'; 1547 } 1548 else { 1563 } else { 1549 1564 my $dir_plain = dirname($pattern); 1550 1565 if ($dir_plain eq 'neb:') { … … 1575 1590 my $query = $db->prepare_cached( $sql->find_dir_by_parent_id . " AND dirname LIKE ? "); 1576 1591 $query->execute( $dir_id, $file_pattern ); 1592 $db->commit; 1577 1593 1578 1594 while ( my $row = $query->fetchrow_hashref ) { … … 1595 1611 my $query = $db->prepare_cached( $sql->find_object_by_dir_id . " AND ext_id_basename LIKE ? "); 1596 1612 $query->execute( $dir_id , $file_pattern); 1613 $db->commit; 1597 1614 1598 1615 while ( my $row = $query->fetchrow_hashref ) { … … 1624 1641 my $sql = $self->sql; 1625 1642 my $db = $self->_db_for_index($index); 1626 1627 1643 1628 1644 # first check to see if the key is an exact match … … 1645 1661 $log->logdie("database error: $@"); 1646 1662 } 1663 $db->commit; 1647 1664 1648 1665 if (scalar @keys) { … … 1678 1695 }; 1679 1696 $log->logdie("database error: $@") if $@; 1697 $db->commit; 1680 1698 1681 1699 # find files under dir … … 1692 1710 }; 1693 1711 $log->logdie("database error: $@") if $@; 1712 $db->commit; 1694 1713 1695 1714 $log->debug( "leaving" ); … … 1753 1772 } 1754 1773 1774 # sub find_instances 1755 1775 sub find_instances_old 1756 1776 { … … 1829 1849 # ext_id, available 1830 1850 if (defined($find_invalid)) { 1851 # XXX returns instances which are NOT available 1831 1852 $rows = $query->execute($key->path, 0); 1832 1853 } … … 1865 1886 } 1866 1887 1867 # sub find_instances_by_proximity1888 # sub find_instances_by_proximity 1868 1889 sub find_instances 1869 1890 { … … 1897 1918 }, 1898 1919 ); 1899 1900 1920 my $sql = $self->sql; 1901 1921 … … 1932 1952 } 1933 1953 } 1934 1935 1936 1954 } 1937 1955 … … 1972 1990 # ext_id, name, available 1973 1991 # 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 1974 1994 my $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 1); 1975 1995 unless ($rows > 0) { 1976 1996 $query->finish; 1977 die("no instances on storage volume or volume is not avai able for key: $key volume: $vol_name");1997 die("no instances on storage volume or volume is not available for key: $key volume: $vol_name"); 1978 1998 } 1979 1999 } else { … … 1982 2002 # ext_id, available 1983 2003 if (defined($find_invalid)) { 2004 # returns instances which are NOT available (volume not available) 1984 2005 $rows = $query->execute($key->path, 0); 1985 2006 } … … 1992 2013 } 1993 2014 } 2015 $db->commit; 2016 ## if we do not call commit here, the transaction stays 2017 ## open blocking some operations below. 1994 2018 1995 2019 while (my $row = $query->fetchrow_hashref) { … … 2018 2042 } 2019 2043 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 2020 2048 sub find_instances_for_cull 2021 2049 { … … 2061 2089 my $db = $self->db($key); 2062 2090 2091 ## XXX this method is missing the alias deference section (see find_instances) 2092 2063 2093 # the key's volume can't be validiated on input for this method so we have 2064 2094 # to check it after parsing the key … … 2111 2141 $log->logdie("database error: $@"); 2112 2142 } 2143 $db->commit; 2113 2144 2114 2145 # XXX remove this? … … 2222 2253 } 2223 2254 } 2224 2225 2255 $db->commit; 2226 2256 $log->debug("commit"); … … 2282 2312 $stat = $query->fetchrow_arrayref; 2283 2313 $query->finish; 2314 $db->commit; 2284 2315 }; 2285 2316 $log->logdie("database error: $@") if $@; … … 2318 2349 }; 2319 2350 $log->logdie("database error: $@") if $@; 2351 $db->commit; 2320 2352 2321 2353 $log->logdie("no mounted volumes found") unless (scalar @$stats); … … 2415 2447 my ($key, $name, $hard_volume) = @_; 2416 2448 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<"); 2418 2454 my $sql = $self->sql; 2419 2455 my $db = $self->db($key); … … 2430 2466 unless ($rows > 0) { 2431 2467 $query->finish; 2468 $db->commit; 2432 2469 2433 2470 # if a volume name was specified, and is soft, and we failed to … … 2442 2479 if ($rows > 1) { 2443 2480 $query->finish; 2481 $db->commit; 2444 2482 die("affected row count is $rows instead of 1"); 2445 2483 } … … 2449 2487 $rows = $query->execute($max_used_space, 1, 1, $topfew_count); 2450 2488 # $log->warn("Storage_volume: $rows $topfew_count"); 2451 # there has to be at least one storage volume2489 # there has to be at least one storage volume 2452 2490 unless ($rows > 0) { 2453 2491 $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"); 2455 2497 } 2456 2498 } … … 2465 2507 $log->error($@); 2466 2508 $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: $@"); 2468 2514 } 2469 2515 # else … … 2502 2548 unless ($rows > 0) { 2503 2549 $query->finish; 2504 die("Requested key $key does not exist ");2550 die("Requested key $key does not exist (or cabinet is undefined)"); 2505 2551 } 2506 2552 if ($rows == 1) { … … 2513 2559 } 2514 2560 $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 2517 2564 $forbidden_cabinet = 0; 2518 2565 $forbidden_site = 0; 2519 2566 $query->finish; 2520 2567 } 2521 2568 $db->commit; 2522 2569 2523 2570 $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id ); 2524 # ext_id, %free, avaiable, allocate 2571 # ext_id, %free, available, allocate 2572 2525 2573 $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $forbidden_site, $topfew_count); 2526 # XXX destinguish between non-existant and unav iable2574 # XXX destinguish between non-existant and unavailable 2527 2575 unless ($rows > 0) { 2528 2576 $query->finish; … … 2544 2592 ($vol_id, $vol_host, $vol_path, $xattr, $free) = $query->fetchrow_array; 2545 2593 $query->finish; 2594 $db->commit; 2546 2595 }; 2547 2596 $log->logdie("database error: $@") if $@; … … 2590 2639 ($ext_id) = $query->fetchrow_array; 2591 2640 $query->finish; 2641 $db->commit; 2642 ## if we do not call commit here, the transaction stays open blocking some operations below 2592 2643 }; 2593 2644 if ($@) { … … 2612 2663 } 2613 2664 2614 2665 # in the past, _is_valid_volume_name returned 'undef'. 2666 # now it either returns 1 (success) or 0 (failure) 2615 2667 sub _is_valid_volume_name 2616 2668 { … … 2650 2702 ($vol_id, $vol_path, $free) = $query->fetchrow_array; 2651 2703 $query->finish; 2704 $db->commit; 2652 2705 }; 2653 2706 $log->logdie("database error: $@") if $@;
Note:
See TracChangeset
for help on using the changeset viewer.
