Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13309)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13310)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.43 2007-05-08 23:47:03 jhoblitt Exp $
+# $Id: Server.pm,v 1.44 2007-05-09 00:27:03 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -133,4 +133,5 @@
 }
 
+
 sub create_object
 {
@@ -281,4 +282,5 @@
 }
 
+
 sub replicate_object
 {
@@ -308,5 +310,5 @@
     $log->debug("entered - @_");
 
-    my $ins_id;
+    my ($uri, $vol_id);
     eval {
         my $so_id;
@@ -331,4 +333,5 @@
         }
 
+        my $ins_id;
         {
             my $query = $db->prepare_cached( $sql->last_insert_id );
@@ -340,27 +343,12 @@
             $query->finish;
         }
-    };
-    if ($@) {
-        $db->rollback;
-        $log->debug("rollback");
-        $log->logdie( "database error: $@" );
-    }
-
-    # Unfortunately, since we want to use the instance row's ID as part of the
-    # actual on disk file name we can't try to create the file until after
-    # we've create both a new storage_storage object and instance.
-
-    # TODO add some stuff here to retry if unsucessful
-    my ($uri, $vol_id);
-    eval {
+
+        # Unfortunately, since we want to use the instance row's ID as part of
+        # the actual on disk file name we can't try to create the file until
+        # after we've create both a new storage_storage object and instance.
+
+        # TODO add some stuff here to retry if unsucessful
         ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
-    };
-    if ($@) {
-        $db->rollback;
-        $log->debug("rollback");
-        $log->logdie($@);
-    }
-
-    eval {
+
         {
             my $query = $db->prepare_cached( $sql->update_instance_uri );
@@ -375,5 +363,5 @@
         $db->rollback;
         $log->debug("rollback");
-        $log->logdie("database error: $@");
+        $log->logdie("error: $@");
     }
 
@@ -414,102 +402,70 @@
 
     eval {
-        # this will set update locks
-        $query = $db->prepare_cached( $sql->get_object_locks );
-        my $rows = $query->execute( $key );
-        unless ( $rows == 1 ) {
-            $log->logdie( "storage object does not exist" );
-        }
-
-        my $row = $query->fetchrow_hashref;
-        $query->finish;
-
-        $so_id      = $row->{ 'so_id' };
-        $read_lock  = $row->{ 'read_lock' };
-        $write_lock = $row->{ 'write_lock' };
-    };
-    if ( $@ ) {
-        $query->finish;
-        $db->rollback;
-        $log->debug("rollback");
-        $log->logdie( "database error: $@" );
-    }
-
-    if ( $type eq 'write' ) {
-        # can't set a write lock twice and
-        # can't set a write lock if there are read locks
-        if ( $write_lock ) {
-            eval { $db->rollback; };
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" ) if $@;
-
-            $log->logdie( "can not write lock twice" );
-        }
+        {
+            # this will set update locks
+            $query = $db->prepare_cached( $sql->get_object_locks );
+            my $rows = $query->execute( $key );
+            unless ( $rows == 1 ) {
+                $log->logdie( "storage object does not exist" );
+            }
+
+            my $row = $query->fetchrow_hashref;
+            $query->finish;
+
+            $so_id      = $row->{ 'so_id' };
+            $read_lock  = $row->{ 'read_lock' };
+            $write_lock = $row->{ 'write_lock' };
+        }
+
+        if ($type eq 'write') {
+            # can't set a write lock twice and
+            # can't set a write lock if there are read locks
+            if ($write_lock) {
+                $log->logdie("can not write lock twice");
+            }
             
-        if ( $read_lock > 0 ) {
-            eval { $db->rollback; };
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" ) if $@;
-
-            $log->logdie( "can not write lock after read lock" );
-        }
-
-        eval {
-            my $query = $db->prepare_cached( $sql->set_write_lock );
-            my $rows = $query->execute( $key );
-        
-            # if we affected more then one row something very bad has happened.
-            unless ( $rows == 1 ) {
-                $log->logdie( "affected row count is $rows instead of 1" );
-            }
-
-            $db->commit;
-            $log->debug("commit");
-        };
-        if ( $@ ) {
-            $db->rollback;
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" );
-        }
-
-        $log->debug( "leaving" );
-
-        return 1;
-    }
-
-    if ( $type eq 'read' ) {
-        # can't set a read lock if there's a write lock
-        if ( $write_lock ) {
-            eval { $db->rollback; };
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" ) if $@;
-
-            $log->logdie( "can not read lock after write lock" );
-        }
-
-        eval {
-            my $query = $db->prepare_cached( $sql->increment_read_lock );
-            my $rows = $query->execute( $key );
-        
-            # if we affected more then one row something very bad has happened.
-            unless ( $rows == 1 ) {
-                $log->logdie( "affected row count is $rows instead of 1" );
-            }
-
-            $db->commit;
-            $log->debug("commit");
-        };
-        if ( $@ ) {
-            $db->rollback;
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" );
-        }
-
-        $log->debug( "leaving" );
-
-        return 1;
-    }
-
-    # never reached
-    $log->logdie( "this should never happen" );
+            if ($read_lock > 0) {
+                $log->logdie("can not write lock after read lock");
+            }
+
+            {
+                my $query = $db->prepare_cached( $sql->set_write_lock );
+                my $rows = $query->execute($key);
+            
+                # if we affected more then one row something very bad has happened.
+                unless ($rows == 1) {
+                    $log->logdie("affected row count is $rows instead of 1");
+                }
+
+            }
+        } elsif ($type eq 'read') {
+            # can't set a read lock if there's a write lock
+            if ($write_lock) {
+                $log->logdie("can not read lock after write lock");
+            }
+
+            {
+                my $query = $db->prepare_cached( $sql->increment_read_lock );
+                my $rows = $query->execute($key);
+            
+                # if we affected more then one row something very bad has happened.
+                unless ($rows == 1) {
+                    $log->logdie("affected row count is $rows instead of 1");
+                }
+            }
+        }
+
+        $db->commit;
+        $log->debug("commit");
+    };
+    if ($@) {
+        $db->rollback;
+        $log->debug("rollback");
+        $log->logdie("error: $@");
+    }
+
+    $log->debug("leaving");
+
+    return 1;
 }
 
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13309)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 13310)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.43 2007-05-08 23:47:03 jhoblitt Exp $
+# $Id: Server.pm,v 1.44 2007-05-09 00:27:03 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -133,4 +133,5 @@
 }
 
+
 sub create_object
 {
@@ -281,4 +282,5 @@
 }
 
+
 sub replicate_object
 {
@@ -308,5 +310,5 @@
     $log->debug("entered - @_");
 
-    my $ins_id;
+    my ($uri, $vol_id);
     eval {
         my $so_id;
@@ -331,4 +333,5 @@
         }
 
+        my $ins_id;
         {
             my $query = $db->prepare_cached( $sql->last_insert_id );
@@ -340,27 +343,12 @@
             $query->finish;
         }
-    };
-    if ($@) {
-        $db->rollback;
-        $log->debug("rollback");
-        $log->logdie( "database error: $@" );
-    }
-
-    # Unfortunately, since we want to use the instance row's ID as part of the
-    # actual on disk file name we can't try to create the file until after
-    # we've create both a new storage_storage object and instance.
-
-    # TODO add some stuff here to retry if unsucessful
-    my ($uri, $vol_id);
-    eval {
+
+        # Unfortunately, since we want to use the instance row's ID as part of
+        # the actual on disk file name we can't try to create the file until
+        # after we've create both a new storage_storage object and instance.
+
+        # TODO add some stuff here to retry if unsucessful
         ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
-    };
-    if ($@) {
-        $db->rollback;
-        $log->debug("rollback");
-        $log->logdie($@);
-    }
-
-    eval {
+
         {
             my $query = $db->prepare_cached( $sql->update_instance_uri );
@@ -375,5 +363,5 @@
         $db->rollback;
         $log->debug("rollback");
-        $log->logdie("database error: $@");
+        $log->logdie("error: $@");
     }
 
@@ -414,102 +402,70 @@
 
     eval {
-        # this will set update locks
-        $query = $db->prepare_cached( $sql->get_object_locks );
-        my $rows = $query->execute( $key );
-        unless ( $rows == 1 ) {
-            $log->logdie( "storage object does not exist" );
-        }
-
-        my $row = $query->fetchrow_hashref;
-        $query->finish;
-
-        $so_id      = $row->{ 'so_id' };
-        $read_lock  = $row->{ 'read_lock' };
-        $write_lock = $row->{ 'write_lock' };
-    };
-    if ( $@ ) {
-        $query->finish;
-        $db->rollback;
-        $log->debug("rollback");
-        $log->logdie( "database error: $@" );
-    }
-
-    if ( $type eq 'write' ) {
-        # can't set a write lock twice and
-        # can't set a write lock if there are read locks
-        if ( $write_lock ) {
-            eval { $db->rollback; };
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" ) if $@;
-
-            $log->logdie( "can not write lock twice" );
-        }
+        {
+            # this will set update locks
+            $query = $db->prepare_cached( $sql->get_object_locks );
+            my $rows = $query->execute( $key );
+            unless ( $rows == 1 ) {
+                $log->logdie( "storage object does not exist" );
+            }
+
+            my $row = $query->fetchrow_hashref;
+            $query->finish;
+
+            $so_id      = $row->{ 'so_id' };
+            $read_lock  = $row->{ 'read_lock' };
+            $write_lock = $row->{ 'write_lock' };
+        }
+
+        if ($type eq 'write') {
+            # can't set a write lock twice and
+            # can't set a write lock if there are read locks
+            if ($write_lock) {
+                $log->logdie("can not write lock twice");
+            }
             
-        if ( $read_lock > 0 ) {
-            eval { $db->rollback; };
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" ) if $@;
-
-            $log->logdie( "can not write lock after read lock" );
-        }
-
-        eval {
-            my $query = $db->prepare_cached( $sql->set_write_lock );
-            my $rows = $query->execute( $key );
-        
-            # if we affected more then one row something very bad has happened.
-            unless ( $rows == 1 ) {
-                $log->logdie( "affected row count is $rows instead of 1" );
-            }
-
-            $db->commit;
-            $log->debug("commit");
-        };
-        if ( $@ ) {
-            $db->rollback;
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" );
-        }
-
-        $log->debug( "leaving" );
-
-        return 1;
-    }
-
-    if ( $type eq 'read' ) {
-        # can't set a read lock if there's a write lock
-        if ( $write_lock ) {
-            eval { $db->rollback; };
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" ) if $@;
-
-            $log->logdie( "can not read lock after write lock" );
-        }
-
-        eval {
-            my $query = $db->prepare_cached( $sql->increment_read_lock );
-            my $rows = $query->execute( $key );
-        
-            # if we affected more then one row something very bad has happened.
-            unless ( $rows == 1 ) {
-                $log->logdie( "affected row count is $rows instead of 1" );
-            }
-
-            $db->commit;
-            $log->debug("commit");
-        };
-        if ( $@ ) {
-            $db->rollback;
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" );
-        }
-
-        $log->debug( "leaving" );
-
-        return 1;
-    }
-
-    # never reached
-    $log->logdie( "this should never happen" );
+            if ($read_lock > 0) {
+                $log->logdie("can not write lock after read lock");
+            }
+
+            {
+                my $query = $db->prepare_cached( $sql->set_write_lock );
+                my $rows = $query->execute($key);
+            
+                # if we affected more then one row something very bad has happened.
+                unless ($rows == 1) {
+                    $log->logdie("affected row count is $rows instead of 1");
+                }
+
+            }
+        } elsif ($type eq 'read') {
+            # can't set a read lock if there's a write lock
+            if ($write_lock) {
+                $log->logdie("can not read lock after write lock");
+            }
+
+            {
+                my $query = $db->prepare_cached( $sql->increment_read_lock );
+                my $rows = $query->execute($key);
+            
+                # if we affected more then one row something very bad has happened.
+                unless ($rows == 1) {
+                    $log->logdie("affected row count is $rows instead of 1");
+                }
+            }
+        }
+
+        $db->commit;
+        $log->debug("commit");
+    };
+    if ($@) {
+        $db->rollback;
+        $log->debug("rollback");
+        $log->logdie("error: $@");
+    }
+
+    $log->debug("leaving");
+
+    return 1;
 }
 
