Changeset 24354 for trunk/Nebulous-Server
- Timestamp:
- Jun 8, 2009, 11:23:24 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r24350 r24354 86 86 87 87 my $db_index = 0; 88 die "key not defined"unless defined $key;88 $log->logdie("key not defined") unless defined $key; 89 89 90 90 # hash the key to select the correct database instance … … 126 126 # lookup database info 127 127 my $db_config = $config->db($db_index); 128 die "can't find database configuration info for database # $db_index"128 $log->logdie("can't find database configuration info for db # $db_index") 129 129 unless $db_config; 130 130 … … 168 168 my $self = shift; 169 169 170 my $log = $self->log; 171 $log->debug( "entered - @_" ); 172 170 173 my ($key) = validate_pos(@_, 171 174 { … … 174 177 ); 175 178 176 my $log = $self->log;177 179 my $sql = $self->sql; 178 180 my $config = $self->config; 179 181 180 die "key not defined"unless defined $key;182 $log->logdie("key not defined") unless defined $key; 181 183 my $db_index = $self->_db_index_for_key($key); 182 184 … … 229 231 $vol_name = undef; 230 232 } else { 231 die "$vol_name is not a valid volume name"233 $log->logdie("$vol_name is not a valid volume name"); 232 234 } 233 235 } … … 317 319 318 320 # add new key to the cache 319 $self->cache->set(id => $key->path, value => 1) ;321 $self->cache->set(id => $key->path, value => 1) if defined $self->cache; 320 322 $log->debug( "key added to cache" ); 321 323 … … 559 561 my $dbidx1 = $self->_db_index_for_key($key1); 560 562 my $dbidx2 = $self->_db_index_for_key($key2); 561 die "cannot swap keys not stored on the same database" unless ($dbidx1 == $dbidx2); 563 $log->logdie("cannot swap keys not stored on the same database") 564 unless ($dbidx1 == $dbidx2); 562 565 563 566 my $dbh1 = $self->_db_for_index($dbidx1); 564 567 my $dbh2 = $self->_db_for_index($dbidx2); 565 die "different db handles for the same db?" unless ($dbh1 == $dbh2); 568 $log->logdie("different db handles for the same db?") 569 unless ($dbh1 == $dbh2); 566 570 567 571 # order of operations for the swap with a single db is: … … 703 707 $vol_name = undef; 704 708 } else { 705 die "$vol_name is not a valid volume name"709 $log->logdie("$vol_name is not a valid volume name"); 706 710 } 707 711 } … … 1586 1590 if ( $instances == 1 ) { 1587 1591 # remove key from cache 1588 $self->cache->delete($key->path) ;1592 $self->cache->delete($key->path) if defined $self->cache; 1589 1593 1590 1594 # we just removed the last instance … … 1747 1751 my $path = URI->new($inst)->path; 1748 1752 1749 _retry(sub { chmod($mode, $path) })1753 $self->_retry(sub { chmod($mode, $path) }) 1750 1754 or $log->logdie("can not chmod() $path: $!"); 1751 1755 … … 1754 1758 # write permissions. 1755 1759 my $fh; 1756 _retry(sub { open($fh, '<', $path) })1760 $self->_retry(sub { open($fh, '<', $path) }) 1757 1761 or $log->logdie("can not open() $path: $!"); 1758 1762 1759 1763 # fsync(3c) 1760 _retry(sub { $fh->sync() })1764 $self->_retry(sub { $fh->sync() }) 1761 1765 or $log->logdie("can not sync() $path: $!"); 1762 1766 1763 _retry(sub { close($fh) })1767 $self->_retry(sub { close($fh) }) 1764 1768 or $log->logdie("can not close() $path: $!"); 1765 1769 } … … 1907 1911 1908 1912 # check cache first 1909 my $cached = $self->cache->get($key->path) ;1913 my $cached = $self->cache->get($key->path) if defined $self->cache; 1910 1914 if (defined $cached) { 1911 1915 $log->debug( "key $key found in cache" ); … … 1934 1938 $log->debug( "key found in db" ); 1935 1939 # add key to cache 1936 $self->cache->set(id => $key->path, value => 1) ;1940 $self->cache->set(id => $key->path, value => 1) if defined $self->cache; 1937 1941 $log->debug( "key added to cache" ); 1938 1942 $log->debug( "leaving" ); … … 2013 2017 my $storage_filename = $self->_generate_storage_filename($key->path, $ins_id); 2014 2018 unless (-d $storage_path) { 2015 _retry(sub { mkpath([$storage_path], 0, 0775) })2016 or die "can't create storage path: $storage_path";2019 $self->_retry(sub { mkpath([$storage_path], 0, 0775) }) 2020 or $log->logdie("can't create storage path: $storage_path"); 2017 2021 } 2018 2022 # check to make sure at least the parent directory has the proper 2019 2023 # permissions 2020 my $mode = [ _retry(sub { stat($storage_path) } )]->[2] & 07777;2024 my $mode = [$self->_retry(sub { stat($storage_path) } )]->[2] & 07777; 2021 2025 unless ($mode == 0775) { 2022 2026 $log->error("$storage_path has the wrong permissions of: 0", sprintf("%o", $mode)); 2023 _retry(sub { chmod(0775, $storage_path) })2027 $self->_retry(sub { chmod(0775, $storage_path) }) 2024 2028 or $log->logdie("can not chmod() $storage_path: $!"); 2025 2029 } … … 2036 2040 if ($xattr) { 2037 2041 my $path = $uri->file; 2038 die "can not set xattr on $path: $!"2042 $log->logdie("can not set xattr on $path: $!") 2039 2043 unless (setfattr($path, 'user.nebulous_key', $key->path)); 2040 2044 } … … 2059 2063 2060 2064 my $fh; 2061 _retry(sub { open($fh, '>', $path) })2065 $self->_retry(sub { open($fh, '>', $path) }) 2062 2066 or $log->logdie("can not open() $path: $!"); 2063 2067 2064 2068 # chmod before fsync() to make sure the changed perms hit the disk too 2065 _retry(sub { chmod(0664, $path) })2069 $self->_retry(sub { chmod(0664, $path) }) 2066 2070 or $log->logdie("can not chmod() $path: $!"); 2067 2071 2068 _retry(sub { $fh->sync() })2072 $self->_retry(sub { $fh->sync() }) 2069 2073 or $log->logdie("can not sync() $path: $!"); 2070 2074 2071 _retry(sub { close($fh) })2075 $self->_retry(sub { close($fh) }) 2072 2076 or $log->logdie("can not close() $path: $!"); 2073 2077 … … 2107 2111 sub _retry 2108 2112 { 2113 my $self = shift; 2114 2115 my $log = $self->log; 2116 $log->debug( "entered - @_" ); 2117 2109 2118 my $func = shift; 2110 2119 … … 2115 2124 }; 2116 2125 if ($@) { 2117 die $@;2126 $log->logdie($@); 2118 2127 sleep 1; 2119 2128 next; … … 2125 2134 # if the loop ended and $@ is set, rethrow the error 2126 2135 if ($@) { 2127 die $@;2136 $log->logdie($@); 2128 2137 } 2129 2138
Note:
See TracChangeset
for help on using the changeset viewer.
