Changeset 13251
- Timestamp:
- May 4, 2007, 1:36:46 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
-
Nebulous-Server/Changes (modified) (1 diff)
-
Nebulous-Server/bin/nebdiskd (modified) (3 diffs)
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (3 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (5 diffs)
-
Nebulous/Changes (modified) (1 diff)
-
Nebulous/bin/nebdiskd (modified) (3 diffs)
-
Nebulous/lib/Nebulous/Server.pm (modified) (3 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (5 diffs)
-
Nebulous/t/Test/Nebulous.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r13228 r13251 2 2 3 3 0.05 4 - rework the getmountedvol() stored procedure to attempt to work around 5 what appears to be some nasty transacational isolation leak throught that 6 was causing getmountedvol() to randomly hang when nebdiskd changed the 7 mount table. 4 8 - fix a nasty logic bug in Nebulous::Client->replicate() 5 9 - break 1:1 relationship between key names and on disk file names -
trunk/Nebulous-Server/bin/nebdiskd
r13023 r13251 3 3 # Copyright (C) 2007 Joshua Hoblitt 4 4 # 5 # $Id: nebdiskd,v 1. 3 2007-04-25 19:52:49jhoblitt Exp $5 # $Id: nebdiskd,v 1.4 2007-05-04 23:36:46 jhoblitt Exp $ 6 6 7 7 use strict; … … 98 98 stat_dirs($mounts); 99 99 100 my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)"); 101 $dbh->do("DELETE FROM mount"); 102 print "flushed mount table\n" if $debug; 103 104 my $stats = $lxs->get; 105 foreach my $dev (keys %$stats) { 106 my $mnt = $stats->{$dev}; 107 my %mount; 108 $query->execute(@$mnt{qw( mountpoint total usage )}); 109 print "adding $mnt->{mountpoint} to db\n" if $debug; 100 eval { 101 my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)"); 102 $dbh->do("DELETE FROM mount"); 103 104 print "flushed mount table\n" if $debug; 105 106 my $stats = $lxs->get; 107 foreach my $dev (keys %$stats) { 108 my $mnt = $stats->{$dev}; 109 my %mount; 110 $query->execute(@$mnt{qw( mountpoint total usage )}); 111 print "adding $mnt->{mountpoint} to db\n" if $debug; 112 } 113 114 $dbh->do("call getmountedvol()"); 115 116 $dbh->commit; 117 }; 118 if ($@) { 119 $db->rollback; 120 warn $@; 110 121 } 111 112 $dbh->commit;113 122 114 123 sleep $poll_interval; … … 155 164 ); 156 165 157 $dbh->do( $sql->set_transaction_model ); 158 $dbh->commit; 166 eval { 167 $dbh->do( $sql->set_transaction_model ); 168 $dbh->commit; 169 }; 170 if ($@) { 171 $db->rollback; 172 die $@; 173 } 159 174 160 175 return $dbh; -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r13244 r13251 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.3 7 2007-05-04 20:46:29jhoblitt Exp $3 # $Id: Server.pm,v 1.38 2007-05-04 23:36:46 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 930 930 my $query; 931 931 eval { 932 {933 # ask the db to generate the table of mounted Nebulous volume934 my $query = $db->prepare_cached("call getmountedvol()");935 $query->execute();936 }937 938 $log->debug("generated mountedvol table");939 940 932 if ($vol_name) { 941 933 $query = $db->prepare_cached( $sql->get_object_instances_by_vol_name ); … … 1114 1106 my ($vol_id, $vol_path); 1115 1107 eval { 1116 {1117 # ask the db to generate the table of mounted Nebulous volume1118 my $query = $db->prepare_cached("call getmountedvol()");1119 $query->execute();1120 }1121 1122 1108 # TODO cache this? 1123 1109 my $query; -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r13245 r13251 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1. 39 2007-05-04 21:20:43jhoblitt Exp $3 # $Id: SQL.pm,v 1.40 2007-05-04 23:36:46 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 274 274 DROP TABLE IF EXISTS class; 275 275 DROP TABLE IF EXISTS log; 276 DROP TABLE IF EXISTS mountedvol; 276 277 DROP PROCEDURE IF EXISTS getmountedvol; 277 278 SET FOREIGN_KEY_CHECKS=1 … … 386 387 ### 387 388 389 CREATE TABLE mountedvol( 390 mountpoint VARCHAR(255) NOT NULL, 391 total BIGINT NOT NULL, 392 used BIGINT NOT NULL, 393 vol_id INT NOT NULL, 394 name VARCHAR(255) NOT NULL, 395 path VARCHAR(255) NOT NULL, 396 allocate BOOLEAN DEFAULT FALSE, 397 available BOOLEAN DEFAULT FALSE, 398 KEY(vol_id), 399 KEY(allocate), 400 KEY(available) 401 ) ENGINE=innodb; 402 403 ### 404 388 405 CREATE PROCEDURE getmountedvol() DETERMINISTIC 389 406 BEGIN … … 401 418 SELECT @@session.tx_isolation INTO trans_level; 402 419 403 -- set trans level 420 -- set trans level to repeatable-read so the volume table does not change 421 -- out from under our cursor 404 422 SET @@session.tx_isolation = 'REPEATABLE-READ'; 405 406 -- create a temp table to hold the merged results of the volume & mount407 -- tables. One would hope the that the transaction isolation level will408 -- stop one session from stomping on another sessions version of this409 -- table.410 411 DROP TABLE IF EXISTS mountedvol;412 CREATE TEMPORARY TABLE mountedvol(413 mountpoint VARCHAR(255) NOT NULL,414 total BIGINT NOT NULL,415 used BIGINT NOT NULL,416 vol_id INT NOT NULL,417 name VARCHAR(255) NOT NULL,418 path VARCHAR(255) NOT NULL,419 allocate BOOLEAN DEFAULT FALSE,420 available BOOLEAN DEFAULT FALSE,421 KEY(vol_id),422 KEY(allocate),423 KEY(available)424 ) ENGINE=MEMORY;425 423 426 424 -- iterate over the volume table finding the coresponding entry in the 427 425 -- mount table and inserting union of the volume & mount row into the 428 426 -- mountedvol table 429 430 427 OPEN cur1; 428 429 DELETE FROM mountedvol; 431 430 432 431 myloop: LOOP … … 446 445 -- restore the original transaction level 447 446 SET @@session.tx_isolation = trans_level; 447 448 COMMIT; 448 449 END -
trunk/Nebulous/Changes
r13228 r13251 2 2 3 3 0.05 4 - rework the getmountedvol() stored procedure to attempt to work around 5 what appears to be some nasty transacational isolation leak throught that 6 was causing getmountedvol() to randomly hang when nebdiskd changed the 7 mount table. 4 8 - fix a nasty logic bug in Nebulous::Client->replicate() 5 9 - break 1:1 relationship between key names and on disk file names -
trunk/Nebulous/bin/nebdiskd
r13023 r13251 3 3 # Copyright (C) 2007 Joshua Hoblitt 4 4 # 5 # $Id: nebdiskd,v 1. 3 2007-04-25 19:52:49jhoblitt Exp $5 # $Id: nebdiskd,v 1.4 2007-05-04 23:36:46 jhoblitt Exp $ 6 6 7 7 use strict; … … 98 98 stat_dirs($mounts); 99 99 100 my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)"); 101 $dbh->do("DELETE FROM mount"); 102 print "flushed mount table\n" if $debug; 103 104 my $stats = $lxs->get; 105 foreach my $dev (keys %$stats) { 106 my $mnt = $stats->{$dev}; 107 my %mount; 108 $query->execute(@$mnt{qw( mountpoint total usage )}); 109 print "adding $mnt->{mountpoint} to db\n" if $debug; 100 eval { 101 my $query = $dbh->prepare_cached("INSERT INTO mount VALUES(?, ?, ?)"); 102 $dbh->do("DELETE FROM mount"); 103 104 print "flushed mount table\n" if $debug; 105 106 my $stats = $lxs->get; 107 foreach my $dev (keys %$stats) { 108 my $mnt = $stats->{$dev}; 109 my %mount; 110 $query->execute(@$mnt{qw( mountpoint total usage )}); 111 print "adding $mnt->{mountpoint} to db\n" if $debug; 112 } 113 114 $dbh->do("call getmountedvol()"); 115 116 $dbh->commit; 117 }; 118 if ($@) { 119 $db->rollback; 120 warn $@; 110 121 } 111 112 $dbh->commit;113 122 114 123 sleep $poll_interval; … … 155 164 ); 156 165 157 $dbh->do( $sql->set_transaction_model ); 158 $dbh->commit; 166 eval { 167 $dbh->do( $sql->set_transaction_model ); 168 $dbh->commit; 169 }; 170 if ($@) { 171 $db->rollback; 172 die $@; 173 } 159 174 160 175 return $dbh; -
trunk/Nebulous/lib/Nebulous/Server.pm
r13244 r13251 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.3 7 2007-05-04 20:46:29jhoblitt Exp $3 # $Id: Server.pm,v 1.38 2007-05-04 23:36:46 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 930 930 my $query; 931 931 eval { 932 {933 # ask the db to generate the table of mounted Nebulous volume934 my $query = $db->prepare_cached("call getmountedvol()");935 $query->execute();936 }937 938 $log->debug("generated mountedvol table");939 940 932 if ($vol_name) { 941 933 $query = $db->prepare_cached( $sql->get_object_instances_by_vol_name ); … … 1114 1106 my ($vol_id, $vol_path); 1115 1107 eval { 1116 {1117 # ask the db to generate the table of mounted Nebulous volume1118 my $query = $db->prepare_cached("call getmountedvol()");1119 $query->execute();1120 }1121 1122 1108 # TODO cache this? 1123 1109 my $query; -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13245 r13251 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1. 39 2007-05-04 21:20:43jhoblitt Exp $3 # $Id: SQL.pm,v 1.40 2007-05-04 23:36:46 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 274 274 DROP TABLE IF EXISTS class; 275 275 DROP TABLE IF EXISTS log; 276 DROP TABLE IF EXISTS mountedvol; 276 277 DROP PROCEDURE IF EXISTS getmountedvol; 277 278 SET FOREIGN_KEY_CHECKS=1 … … 386 387 ### 387 388 389 CREATE TABLE mountedvol( 390 mountpoint VARCHAR(255) NOT NULL, 391 total BIGINT NOT NULL, 392 used BIGINT NOT NULL, 393 vol_id INT NOT NULL, 394 name VARCHAR(255) NOT NULL, 395 path VARCHAR(255) NOT NULL, 396 allocate BOOLEAN DEFAULT FALSE, 397 available BOOLEAN DEFAULT FALSE, 398 KEY(vol_id), 399 KEY(allocate), 400 KEY(available) 401 ) ENGINE=innodb; 402 403 ### 404 388 405 CREATE PROCEDURE getmountedvol() DETERMINISTIC 389 406 BEGIN … … 401 418 SELECT @@session.tx_isolation INTO trans_level; 402 419 403 -- set trans level 420 -- set trans level to repeatable-read so the volume table does not change 421 -- out from under our cursor 404 422 SET @@session.tx_isolation = 'REPEATABLE-READ'; 405 406 -- create a temp table to hold the merged results of the volume & mount407 -- tables. One would hope the that the transaction isolation level will408 -- stop one session from stomping on another sessions version of this409 -- table.410 411 DROP TABLE IF EXISTS mountedvol;412 CREATE TEMPORARY TABLE mountedvol(413 mountpoint VARCHAR(255) NOT NULL,414 total BIGINT NOT NULL,415 used BIGINT NOT NULL,416 vol_id INT NOT NULL,417 name VARCHAR(255) NOT NULL,418 path VARCHAR(255) NOT NULL,419 allocate BOOLEAN DEFAULT FALSE,420 available BOOLEAN DEFAULT FALSE,421 KEY(vol_id),422 KEY(allocate),423 KEY(available)424 ) ENGINE=MEMORY;425 423 426 424 -- iterate over the volume table finding the coresponding entry in the 427 425 -- mount table and inserting union of the volume & mount row into the 428 426 -- mountedvol table 429 430 427 OPEN cur1; 428 429 DELETE FROM mountedvol; 431 430 432 431 myloop: LOOP … … 446 445 -- restore the original transaction level 447 446 SET @@session.tx_isolation = trans_level; 447 448 COMMIT; 448 449 END -
trunk/Nebulous/t/Test/Nebulous.pm
r13131 r13251 1 1 # Copyright (C) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Nebulous.pm,v 1.1 4 2007-05-02 20:53:42jhoblitt Exp $3 # $Id: Nebulous.pm,v 1.15 2007-05-04 23:36:46 jhoblitt Exp $ 4 4 5 5 package Test::Nebulous; … … 66 66 $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (6, 'node06', ?, TRUE, FALSE) }, undef, $dir4); 67 67 $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6); 68 69 $dbh->do(qq{ call getmountedvol() }); 68 70 } 69 71
Note:
See TracChangeset
for help on using the changeset viewer.
