- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/Nebulous-Server/lib/Nebulous/Server.pm
r24995 r27840 36 36 use constant TRANS_RETRY_WAIT => 1; 37 37 38 # This is the umask hack. 39 umask(0002); 40 41 # This determines how many entries from the list of volumes sorted by free space are randomized. 42 my $topfew_count = 15; 43 my $max_used_space = 0.98; 38 44 # transaction restart/retry regex 39 45 my $trans_regex = qr/Deadlock Found|Lock wait timeout exceeded|try restarting transaction|Can't connect to MySQL server/i; … … 905 911 } 906 912 907 # In MySQL you can't select from a table you rdeleting rows from so913 # In MySQL you can't select from a table you're deleting rows from so 908 914 # we first have to get a list of instances to be removed, and then 909 # remove dthem.915 # remove them. 910 916 my $rows_found; 911 917 { 912 918 my $query = $db->prepare_cached( $sql->find_dead_instances_by_so_id ); 913 919 $rows_found = $query->execute( $so_id ); 914 foreach my $row ($query->fetchrow_hashref) { 920 my $i = 0; 921 while (my $row = $query->fetchrow_hashref) { 915 922 # remove dead instances 923 # $log->warn("copied: $rows_copied found: $rows_found removed: $rows_removed"); 916 924 my $query = $db->prepare_cached( $sql->delete_instance_by_ins_id); 917 925 $rows_removed += $query->execute( $row->{ins_id} ); … … 919 927 $query->finish; 920 928 } 921 929 # $log->warn("copied: $rows_copied found: $rows_found removed: $rows_removed"); 922 930 # sanity check 923 931 die("instances inaccessible ($rows_copied) != instances removed ($rows_removed)") … … 1598 1606 $log->debug("entered - @_"); 1599 1607 1600 my ($key, $vol_name ) = validate_pos(@_,1608 my ($key, $vol_name, $find_invalid) = validate_pos(@_, 1601 1609 { 1602 1610 type => SCALAR, … … 1616 1624 optional => 1, 1617 1625 }, 1626 { 1627 # find_invalid 1628 type => SCALAR|UNDEF, 1629 optional => 1, 1630 }, 1618 1631 ); 1619 1632 … … 1659 1672 } else { 1660 1673 $query = $db->prepare_cached( $sql->get_object_instances ); 1674 my $rows; 1675 # ext_id, available 1676 if (defined($find_invalid)) { 1677 $rows = $query->execute($key->path, 0); 1678 } 1679 else { 1680 $rows = $query->execute($key->path, 1); 1681 } 1682 unless ($rows > 0) { 1683 $query->finish; 1684 die("no instances available for key: $key"); 1685 } 1686 } 1687 1688 while (my $row = $query->fetchrow_hashref) { 1689 my $instance = $row->{ 'uri' }; 1690 push @locations, $instance if $instance; 1691 } 1692 }; 1693 if ($@) { 1694 $db->rollback; 1695 # handle soft volumes 1696 if (defined $vol_name and not defined $key->hard_volume) { 1697 $log->debug("retrying with 'any' volume"); 1698 return $self->find_instances($key->path, 'any'); 1699 } 1700 $log->logdie("database error: $@"); 1701 } 1702 1703 # XXX remove this? 1704 $log->logdie("no instances found") unless (scalar @locations); 1705 1706 $log->debug("found: @locations"); 1707 1708 $log->debug("leaving"); 1709 1710 return \@locations; 1711 } 1712 1713 sub find_instances_for_cull 1714 { 1715 my $self = shift; 1716 1717 my $log = $self->log; 1718 $log->debug("entered - @_"); 1719 1720 my ($key, $vol_name) = validate_pos(@_, 1721 { 1722 type => SCALAR, 1723 callbacks => { 1724 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 1725 }, 1726 }, 1727 { 1728 type => SCALAR|UNDEF, 1729 # callbacks => { 1730 # # check that the volume name requested is valid 1731 # 'is valid volume name' => sub { 1732 # return 1 if not defined $_[0]; 1733 # $self->_is_valid_volume_name($_[0]) 1734 # }, 1735 # }, 1736 optional => 1, 1737 }, 1738 ); 1739 1740 my $sql = $self->sql; 1741 1742 # unless ($key) { 1743 # $log->warn("key was undefined after validate_pos(), trying again..."); 1744 # return $self->find_instances(@_); 1745 # } 1746 1747 # vol_name overrides the key implied volume 1748 eval { 1749 $key = parse_neb_key($key, $vol_name); 1750 }; 1751 $log->logdie("$@") if $@; 1752 $vol_name = $key->volume; 1753 1754 my $db = $self->db($key); 1755 1756 # the key's volume can't be validiated on input for this method so we have 1757 # to check it after parsing the key 1758 if (defined $vol_name 1759 and not $self->_is_valid_volume_name($key, $key->volume)) { 1760 if ($key->hard_volume) { 1761 $log->logdie("$vol_name is not a valid volume name"); 1762 } else { 1763 $log->warn( "$vol_name is not a known volume name" ); 1764 $vol_name = undef; 1765 } 1766 } 1767 1768 my @locations; 1769 eval { 1770 my $query; 1771 if ($vol_name) { 1772 $query = $db->prepare_cached( $sql->get_object_instances_by_vol_name ); 1773 # ext_id, name, available 1774 my $rows = $query->execute($key->path, $vol_name, 1); 1775 unless ($rows > 0) { 1776 $query->finish; 1777 die("no instances on storage volume or volume is not avaiable for key: $key volume: $vol_name"); 1778 } 1779 } else { 1780 $query = $db->prepare_cached( $sql->get_object_instances ); 1661 1781 # ext_id, available 1662 1782 my $rows = $query->execute($key->path, 1); … … 1666 1786 } 1667 1787 } 1668 1788 1669 1789 while (my $row = $query->fetchrow_hashref) { 1670 my $instance = $row->{ 'uri' }; 1671 push @locations, $instance if $instance; 1790 # my $instance_hash = { uri => $row->{ 'uri' }, 1791 # vol_id => $row->{ 'vol_id' }, 1792 # cab_id => $row->{ 'cab_id'} }; 1793 my $instance = $row->{ 'uri' }; 1794 push @locations, $row if $instance; 1672 1795 } 1673 1796 }; … … 1984 2107 1985 2108 my ($key, $name, $hard_volume) = @_; 1986 2109 2110 # $log->warn("_g_s_v: key:>$key< name:>$name< hard_vol:>$hard_volume<"); 1987 2111 my $sql = $self->sql; 1988 2112 my $db = $self->db($key); … … 1995 2119 $query = $db->prepare_cached( $sql->get_storage_volume_by_name ); 1996 2120 # %free, name, avaiable, allocate 1997 $rows = $query->execute( 0.95, $name, 1, 1);1998 # XXX destinguish between non-existant and unav iable2121 $rows = $query->execute($max_used_space, $name, 1, 1); 2122 # XXX destinguish between non-existant and unavailable 1999 2123 unless ($rows > 0) { 2000 2124 $query->finish; … … 2016 2140 $query = $db->prepare_cached( $sql->get_storage_volume ); 2017 2141 # %free, avaiable, allocate 2018 $rows = $query->execute(0.95, 1, 1); 2142 $rows = $query->execute($max_used_space, 1, 1, $topfew_count); 2143 # $log->warn("Storage_volume: $rows $topfew_count"); 2019 2144 # there has to be atleast one storage volume 2020 2145 unless ($rows > 0) { … … 2062 2187 my $db = $self->db($key); 2063 2188 2064 my ($vol_id, $vol_host, $vol_path, $xattr );2189 my ($vol_id, $vol_host, $vol_path, $xattr, $forbidden_cabinet); 2065 2190 eval { 2066 2191 my $rows; 2067 my $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id ); 2192 2193 my $query = $db->prepare_cached( $sql->get_cabinets_for_ext_id ); 2194 $rows = $query->execute($key->path); 2195 unless ($rows > 0) { 2196 $query->finish; 2197 die("Requested key $key does not exist"); 2198 } 2199 if ($rows == 1) { 2200 ($forbidden_cabinet) = $query->fetchrow_array; 2201 unless (defined($forbidden_cabinet)) { 2202 $forbidden_cabinet = 0; 2203 } 2204 $query->finish; 2205 } 2206 else { 2207 $forbidden_cabinet = 0; 2208 $query->finish; 2209 } 2210 2211 2212 $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id ); 2068 2213 # ext_id, %free, avaiable, allocate 2069 $rows = $query->execute($key->path, 0.95, 1, 1);2214 $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $topfew_count); 2070 2215 # XXX destinguish between non-existant and unaviable 2071 2216 unless ($rows > 0) { … … 2175 2320 2176 2321 # handle "any" volume 2177 if ( $vol_name eq 'any') {2322 if (($vol_name eq 'any')||($vol_name eq 'any.0')) { 2178 2323 $log->debug( "found volume name $vol_name" ); 2179 2324 $log->debug( "leaving" ); … … 2200 2345 $log->debug( "leaving" ); 2201 2346 2202 return ;2347 return 0; 2203 2348 } 2204 2349
Note:
See TracChangeset
for help on using the changeset viewer.
