Index: trunk/Nebulous-Server/Changes
===================================================================
--- trunk/Nebulous-Server/Changes	(revision 13245)
+++ trunk/Nebulous-Server/Changes	(revision 13251)
@@ -2,4 +2,8 @@
 
 0.05
+    - rework the getmountedvol() stored procedure to attempt to work around
+      what appears to be some nasty transacational isolation leak throught that
+      was causing getmountedvol() to randomly hang when nebdiskd changed the
+      mount table.
     - fix a nasty logic bug in Nebulous::Client->replicate()
     - break 1:1 relationship between key names and on disk file names
Index: trunk/Nebulous-Server/bin/nebdiskd
===================================================================
--- trunk/Nebulous-Server/bin/nebdiskd	(revision 13245)
+++ trunk/Nebulous-Server/bin/nebdiskd	(revision 13251)
@@ -3,5 +3,5 @@
 # Copyright (C) 2007  Joshua Hoblitt
 # 
-# $Id: nebdiskd,v 1.3 2007-04-25 19:52:49 jhoblitt Exp $
+# $Id: nebdiskd,v 1.4 2007-05-04 23:36:46 jhoblitt Exp $
 
 use strict;
@@ -98,17 +98,26 @@
         stat_dirs($mounts);
 
-        my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)");
-        $dbh->do("DELETE FROM mount");
-        print "flushed mount table\n" if $debug;
-
-        my $stats = $lxs->get;
-        foreach my $dev (keys %$stats) {
-            my $mnt = $stats->{$dev};
-            my %mount;
-            $query->execute(@$mnt{qw( mountpoint total usage )});
-            print "adding $mnt->{mountpoint} to db\n" if $debug;
+        eval {
+            my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)");
+            $dbh->do("DELETE FROM mount");
+
+            print "flushed mount table\n" if $debug;
+
+            my $stats = $lxs->get;
+            foreach my $dev (keys %$stats) {
+                my $mnt = $stats->{$dev};
+                my %mount;
+                $query->execute(@$mnt{qw( mountpoint total usage )});
+                print "adding $mnt->{mountpoint} to db\n" if $debug;
+            }
+
+            $dbh->do("call getmountedvol()");
+
+            $dbh->commit;
+        };
+        if ($@) {
+            $db->rollback;
+            warn $@;
         }
-
-        $dbh->commit;
 
         sleep $poll_interval;
@@ -155,6 +164,12 @@
     );
 
-    $dbh->do( $sql->set_transaction_model );
-    $dbh->commit;
+    eval {
+        $dbh->do( $sql->set_transaction_model );
+        $dbh->commit;
+    };
+    if ($@) { 
+        $db->rollback;
+        die $@;
+    }
 
     return $dbh;
Index: trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13245)
+++ trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 13251)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.37 2007-05-04 20:46:29 jhoblitt Exp $
+# $Id: Server.pm,v 1.38 2007-05-04 23:36:46 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -930,12 +930,4 @@
     my $query;
     eval {
-        {
-            # ask the db to generate the table of mounted Nebulous volume 
-            my $query = $db->prepare_cached("call getmountedvol()");
-            $query->execute();
-        }
-
-        $log->debug("generated mountedvol table");
-
         if ($vol_name) {
             $query = $db->prepare_cached( $sql->get_object_instances_by_vol_name );
@@ -1114,10 +1106,4 @@
     my ($vol_id, $vol_path);
     eval {
-        {
-            # ask the db to generate the table of mounted Nebulous volume 
-            my $query = $db->prepare_cached("call getmountedvol()");
-            $query->execute();
-        }
-
         # TODO cache this?
         my $query;
Index: trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13245)
+++ trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 13251)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.39 2007-05-04 21:20:43 jhoblitt Exp $
+# $Id: SQL.pm,v 1.40 2007-05-04 23:36:46 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -274,4 +274,5 @@
 DROP TABLE IF EXISTS class;
 DROP TABLE IF EXISTS log;
+DROP TABLE IF EXISTS mountedvol;
 DROP PROCEDURE IF EXISTS getmountedvol;
 SET FOREIGN_KEY_CHECKS=1
@@ -386,4 +387,20 @@
 ###
 
+CREATE TABLE mountedvol(
+    mountpoint VARCHAR(255) NOT NULL,
+    total BIGINT NOT NULL,
+    used BIGINT NOT NULL,
+    vol_id INT NOT NULL,
+    name VARCHAR(255) NOT NULL,
+    path VARCHAR(255) NOT NULL,
+    allocate BOOLEAN DEFAULT FALSE,
+    available BOOLEAN DEFAULT FALSE,
+    KEY(vol_id),
+    KEY(allocate),
+    KEY(available)
+) ENGINE=innodb;
+
+###
+
 CREATE PROCEDURE getmountedvol() DETERMINISTIC
 BEGIN
@@ -401,32 +418,14 @@
     SELECT @@session.tx_isolation INTO trans_level; 
 
-    -- set trans level
+    -- set trans level to repeatable-read so the volume table does not change
+    -- out from under our cursor
     SET @@session.tx_isolation = 'REPEATABLE-READ';
-
-    -- create a temp table to hold the merged results of the volume & mount
-    -- tables.  One would hope the that the transaction isolation level will
-    -- stop one session from stomping on another sessions version of this
-    -- table.
-
-    DROP TABLE IF EXISTS mountedvol;
-    CREATE TEMPORARY TABLE mountedvol(
-        mountpoint VARCHAR(255) NOT NULL,
-        total BIGINT NOT NULL,
-        used BIGINT NOT NULL,
-        vol_id INT NOT NULL,
-        name VARCHAR(255) NOT NULL,
-        path VARCHAR(255) NOT NULL,
-        allocate BOOLEAN DEFAULT FALSE,
-        available BOOLEAN DEFAULT FALSE,
-        KEY(vol_id),
-        KEY(allocate),
-        KEY(available)
-    ) ENGINE=MEMORY;
 
     -- iterate over the volume table finding the coresponding entry in the
     -- mount table and inserting union of the volume & mount row into the
     -- mountedvol table
-
     OPEN cur1;
+
+    DELETE FROM mountedvol;
 
     myloop: LOOP
@@ -446,3 +445,5 @@
     -- restore the original transaction level
     SET @@session.tx_isolation = trans_level;
+
+    COMMIT;
 END 
