IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13251


Ignore:
Timestamp:
May 4, 2007, 1:36:46 PM (19 years ago)
Author:
jhoblitt
Message:

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.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r13228 r13251  
    22
    330.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.
    48    - fix a nasty logic bug in Nebulous::Client->replicate()
    59    - break 1:1 relationship between key names and on disk file names
  • trunk/Nebulous-Server/bin/nebdiskd

    r13023 r13251  
    33# Copyright (C) 2007  Joshua Hoblitt
    44#
    5 # $Id: nebdiskd,v 1.3 2007-04-25 19:52:49 jhoblitt Exp $
     5# $Id: nebdiskd,v 1.4 2007-05-04 23:36:46 jhoblitt Exp $
    66
    77use strict;
     
    9898        stat_dirs($mounts);
    9999
    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 $@;
    110121        }
    111 
    112         $dbh->commit;
    113122
    114123        sleep $poll_interval;
     
    155164    );
    156165
    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    }
    159174
    160175    return $dbh;
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r13244 r13251  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.37 2007-05-04 20:46:29 jhoblitt Exp $
     3# $Id: Server.pm,v 1.38 2007-05-04 23:36:46 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    930930    my $query;
    931931    eval {
    932         {
    933             # ask the db to generate the table of mounted Nebulous volume
    934             my $query = $db->prepare_cached("call getmountedvol()");
    935             $query->execute();
    936         }
    937 
    938         $log->debug("generated mountedvol table");
    939 
    940932        if ($vol_name) {
    941933            $query = $db->prepare_cached( $sql->get_object_instances_by_vol_name );
     
    11141106    my ($vol_id, $vol_path);
    11151107    eval {
    1116         {
    1117             # ask the db to generate the table of mounted Nebulous volume
    1118             my $query = $db->prepare_cached("call getmountedvol()");
    1119             $query->execute();
    1120         }
    1121 
    11221108        # TODO cache this?
    11231109        my $query;
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r13245 r13251  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.39 2007-05-04 21:20:43 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.40 2007-05-04 23:36:46 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    274274DROP TABLE IF EXISTS class;
    275275DROP TABLE IF EXISTS log;
     276DROP TABLE IF EXISTS mountedvol;
    276277DROP PROCEDURE IF EXISTS getmountedvol;
    277278SET FOREIGN_KEY_CHECKS=1
     
    386387###
    387388
     389CREATE 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
    388405CREATE PROCEDURE getmountedvol() DETERMINISTIC
    389406BEGIN
     
    401418    SELECT @@session.tx_isolation INTO trans_level;
    402419
    403     -- set trans level
     420    -- set trans level to repeatable-read so the volume table does not change
     421    -- out from under our cursor
    404422    SET @@session.tx_isolation = 'REPEATABLE-READ';
    405 
    406     -- create a temp table to hold the merged results of the volume & mount
    407     -- tables.  One would hope the that the transaction isolation level will
    408     -- stop one session from stomping on another sessions version of this
    409     -- 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;
    425423
    426424    -- iterate over the volume table finding the coresponding entry in the
    427425    -- mount table and inserting union of the volume & mount row into the
    428426    -- mountedvol table
    429 
    430427    OPEN cur1;
     428
     429    DELETE FROM mountedvol;
    431430
    432431    myloop: LOOP
     
    446445    -- restore the original transaction level
    447446    SET @@session.tx_isolation = trans_level;
     447
     448    COMMIT;
    448449END
  • trunk/Nebulous/Changes

    r13228 r13251  
    22
    330.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.
    48    - fix a nasty logic bug in Nebulous::Client->replicate()
    59    - break 1:1 relationship between key names and on disk file names
  • trunk/Nebulous/bin/nebdiskd

    r13023 r13251  
    33# Copyright (C) 2007  Joshua Hoblitt
    44#
    5 # $Id: nebdiskd,v 1.3 2007-04-25 19:52:49 jhoblitt Exp $
     5# $Id: nebdiskd,v 1.4 2007-05-04 23:36:46 jhoblitt Exp $
    66
    77use strict;
     
    9898        stat_dirs($mounts);
    9999
    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 $@;
    110121        }
    111 
    112         $dbh->commit;
    113122
    114123        sleep $poll_interval;
     
    155164    );
    156165
    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    }
    159174
    160175    return $dbh;
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r13244 r13251  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.37 2007-05-04 20:46:29 jhoblitt Exp $
     3# $Id: Server.pm,v 1.38 2007-05-04 23:36:46 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    930930    my $query;
    931931    eval {
    932         {
    933             # ask the db to generate the table of mounted Nebulous volume
    934             my $query = $db->prepare_cached("call getmountedvol()");
    935             $query->execute();
    936         }
    937 
    938         $log->debug("generated mountedvol table");
    939 
    940932        if ($vol_name) {
    941933            $query = $db->prepare_cached( $sql->get_object_instances_by_vol_name );
     
    11141106    my ($vol_id, $vol_path);
    11151107    eval {
    1116         {
    1117             # ask the db to generate the table of mounted Nebulous volume
    1118             my $query = $db->prepare_cached("call getmountedvol()");
    1119             $query->execute();
    1120         }
    1121 
    11221108        # TODO cache this?
    11231109        my $query;
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r13245 r13251  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.39 2007-05-04 21:20:43 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.40 2007-05-04 23:36:46 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    274274DROP TABLE IF EXISTS class;
    275275DROP TABLE IF EXISTS log;
     276DROP TABLE IF EXISTS mountedvol;
    276277DROP PROCEDURE IF EXISTS getmountedvol;
    277278SET FOREIGN_KEY_CHECKS=1
     
    386387###
    387388
     389CREATE 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
    388405CREATE PROCEDURE getmountedvol() DETERMINISTIC
    389406BEGIN
     
    401418    SELECT @@session.tx_isolation INTO trans_level;
    402419
    403     -- set trans level
     420    -- set trans level to repeatable-read so the volume table does not change
     421    -- out from under our cursor
    404422    SET @@session.tx_isolation = 'REPEATABLE-READ';
    405 
    406     -- create a temp table to hold the merged results of the volume & mount
    407     -- tables.  One would hope the that the transaction isolation level will
    408     -- stop one session from stomping on another sessions version of this
    409     -- 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;
    425423
    426424    -- iterate over the volume table finding the coresponding entry in the
    427425    -- mount table and inserting union of the volume & mount row into the
    428426    -- mountedvol table
    429 
    430427    OPEN cur1;
     428
     429    DELETE FROM mountedvol;
    431430
    432431    myloop: LOOP
     
    446445    -- restore the original transaction level
    447446    SET @@session.tx_isolation = trans_level;
     447
     448    COMMIT;
    448449END
  • trunk/Nebulous/t/Test/Nebulous.pm

    r13131 r13251  
    11# Copyright (C) 2004  Joshua Hoblitt
    22#
    3 # $Id: Nebulous.pm,v 1.14 2007-05-02 20:53:42 jhoblitt Exp $
     3# $Id: Nebulous.pm,v 1.15 2007-05-04 23:36:46 jhoblitt Exp $
    44
    55package Test::Nebulous;
     
    6666    $dbh->do(qq{ INSERT INTO volume (vol_id, name, path, allocate, available) VALUES (6, 'node06', ?, TRUE, FALSE) }, undef, $dir4);
    6767    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6);
     68
     69    $dbh->do(qq{ call getmountedvol() });
    6870}
    6971
Note: See TracChangeset for help on using the changeset viewer.