Index: trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24350)
+++ trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24354)
@@ -86,5 +86,5 @@
 
     my $db_index = 0;
-    die "key not defined" unless defined $key;
+    $log->logdie("key not defined") unless defined $key;
 
     # hash the key to select the correct database instance
@@ -126,5 +126,5 @@
     # lookup database info
     my $db_config = $config->db($db_index);
-    die "can't find database configuration info for database # $db_index"
+    $log->logdie("can't find database configuration info for db # $db_index")
         unless $db_config;
 
@@ -168,4 +168,7 @@
     my $self = shift;
 
+    my $log     = $self->log;
+    $log->debug( "entered - @_" );
+
     my ($key) = validate_pos(@_,
         {
@@ -174,9 +177,8 @@
     );
 
-    my $log     = $self->log;
     my $sql     = $self->sql;
     my $config  = $self->config;
 
-    die "key not defined" unless defined $key;
+    $log->logdie("key not defined") unless defined $key;
     my $db_index = $self->_db_index_for_key($key);
 
@@ -229,5 +231,5 @@
             $vol_name = undef;
         } else {
-            die "$vol_name is not a valid volume name"
+           $log->logdie("$vol_name is not a valid volume name");
         }
     }
@@ -317,5 +319,5 @@
 
     # add new key to the cache
-    $self->cache->set(id => $key->path, value => 1);
+    $self->cache->set(id => $key->path, value => 1) if defined $self->cache;
     $log->debug( "key added to cache" );
 
@@ -559,9 +561,11 @@
     my $dbidx1 = $self->_db_index_for_key($key1);
     my $dbidx2 = $self->_db_index_for_key($key2);
-    die "cannot swap keys not stored on the same database" unless ($dbidx1 == $dbidx2);
+    $log->logdie("cannot swap keys not stored on the same database")
+        unless ($dbidx1 == $dbidx2);
 
     my $dbh1 = $self->_db_for_index($dbidx1);
     my $dbh2 = $self->_db_for_index($dbidx2);
-    die "different db handles for the same db?" unless ($dbh1 == $dbh2);
+    $log->logdie("different db handles for the same db?")
+        unless ($dbh1 == $dbh2);
 
     # order of operations for the swap with a single db is:
@@ -703,5 +707,5 @@
             $vol_name = undef;
         } else {
-            die "$vol_name is not a valid volume name"
+           $log->logdie("$vol_name is not a valid volume name");
         }
     }
@@ -1586,5 +1590,5 @@
             if ( $instances == 1 ) {
                 # remove key from cache
-                $self->cache->delete($key->path);
+                $self->cache->delete($key->path) if defined $self->cache;
 
                 # we just removed the last instance
@@ -1747,5 +1751,5 @@
         my $path = URI->new($inst)->path;
 
-        _retry(sub { chmod($mode, $path) })
+        $self->_retry(sub { chmod($mode, $path) })
             or $log->logdie("can not chmod() $path: $!");
 
@@ -1754,12 +1758,12 @@
         # write permissions.
         my $fh;
-        _retry(sub { open($fh, '<', $path) })
+        $self->_retry(sub { open($fh, '<', $path) })
             or $log->logdie("can not open() $path: $!");
 
         # fsync(3c)
-        _retry(sub { $fh->sync() })
+        $self->_retry(sub { $fh->sync() })
             or $log->logdie("can not sync() $path: $!");
 
-        _retry(sub { close($fh) })
+        $self->_retry(sub { close($fh) })
             or $log->logdie("can not close() $path: $!");
     }
@@ -1907,5 +1911,5 @@
 
     # check cache first
-    my $cached = $self->cache->get($key->path);
+    my $cached = $self->cache->get($key->path) if defined $self->cache;
     if (defined $cached) {
         $log->debug( "key $key found in cache" );
@@ -1934,5 +1938,5 @@
         $log->debug( "key found in db" );
     	# add key to cache
-        $self->cache->set(id => $key->path, value => 1);
+        $self->cache->set(id => $key->path, value => 1) if defined $self->cache;
         $log->debug( "key added to cache" );
         $log->debug( "leaving" );
@@ -2013,13 +2017,13 @@
         my $storage_filename = $self->_generate_storage_filename($key->path, $ins_id);
         unless (-d $storage_path) {
-            _retry(sub { mkpath([$storage_path], 0, 0775) })
-                or die "can't create storage path: $storage_path";
+            $self->_retry(sub { mkpath([$storage_path], 0, 0775) })
+                or $log->logdie("can't create storage path: $storage_path");
         }
         # check to make sure at least the parent directory has the proper
         # permissions
-        my $mode = [_retry(sub { stat($storage_path) } )]->[2] & 07777;
+        my $mode = [$self->_retry(sub { stat($storage_path) } )]->[2] & 07777;
         unless ($mode == 0775) {
             $log->error("$storage_path has the wrong permissions of: 0", sprintf("%o", $mode));
-            _retry(sub { chmod(0775, $storage_path) })
+            $self->_retry(sub { chmod(0775, $storage_path) })
                 or $log->logdie("can not chmod() $storage_path: $!");
         }
@@ -2036,5 +2040,5 @@
     if ($xattr) {
         my $path = $uri->file;
-        die "can not set xattr on $path: $!"
+        $log->logdie("can not set xattr on $path: $!")
             unless (setfattr($path, 'user.nebulous_key', $key->path));
     }
@@ -2059,15 +2063,15 @@
 
     my $fh;
-    _retry(sub { open($fh, '>', $path) })
+    $self->_retry(sub { open($fh, '>', $path) })
         or $log->logdie("can not open() $path: $!");
 
     # chmod before fsync() to make sure the changed perms hit the disk too
-    _retry(sub { chmod(0664, $path) })
+    $self->_retry(sub { chmod(0664, $path) })
         or $log->logdie("can not chmod() $path: $!");
 
-    _retry(sub { $fh->sync() })
+    $self->_retry(sub { $fh->sync() })
         or $log->logdie("can not sync() $path: $!");
 
-    _retry(sub { close($fh) })
+    $self->_retry(sub { close($fh) })
         or $log->logdie("can not close() $path: $!");
 
@@ -2107,4 +2111,9 @@
 sub _retry
 {
+    my $self = shift;
+
+    my $log = $self->log;
+    $log->debug( "entered - @_" );
+
     my $func = shift;
 
@@ -2115,5 +2124,5 @@
         };
         if ($@) {
-            die $@;
+            $log->logdie($@);
             sleep 1;
             next;
@@ -2125,5 +2134,5 @@
     # if the loop ended and $@ is set, rethrow the error
     if ($@) {
-        die $@;
+        $log->logdie($@);
     }
 
