IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24540


Ignore:
Timestamp:
Jun 24, 2009, 12:50:43 PM (17 years ago)
Author:
jhoblitt
Message:

nebdiskd bug fixes: fix debug mode outpoint going to mail, remove db passwd requirement (not all dbs require a password param)
completely rework how mountedvol is populated, drop mount table

Location:
trunk/Nebulous-Server
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r24500 r24540  
    2424    - add nebdiskd mountpoint test retyring
    2525    - rework delete_instance() to avoid requiring an index on instance.uri
     26    - nebdiskd bug fixes: fix debug mode outpoint going to mail, remove db
     27      passwd requirement (not all dbs require a password param)
     28    - completely rework how mountedvol is populated, drop mount table
    2629     
    27300.16
  • trunk/Nebulous-Server/bin/nebdiskd

    r24539 r24540  
    3737
    3838GetOptions(
    39     'dbhost|h=s'    => \$dbhost,
     39    'dbhost|H=s'    => \$dbhost,
    4040    'dbpass|p=s'    => \$dbpass,
    4141    'dbuser|u=s'    => \$dbuser,
     
    4747    'retry=i'       => \$retry,
    4848    'stop|s'        => \$stop,
    49     'user=s'        => \$user,
     49    'user|U=s'      => \$user,
    5050    'verbose|v'     => \$verbose,
    5151) || pod2usage( 2 );
     
    6161$dbhost     ||= $c->get_dbhost  || $ENV{'NEB_DBHOST'} || 'localhost';
    6262$dbuser     ||= $c->get_dbuser  || $ENV{'NEB_USER'};
    63 $dbpass     ||= $c->get_dbpass  || $ENV{'NEB_PASS'};
     63$dbpass     ||= $c->get_dbpass  || $ENV{'NEB_PASS'} || undef;
    6464$pidfile    ||= $c->get_pidfile || "/var/tmp/nebdiskd";
    6565$user       ||= $c->get_user    || $<; # user
     
    8585
    8686pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    87 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
    88     unless $db && $dbuser && $dbpass;
     87pod2usage( -msg => "Required options: --db --dbuser", -exitval => 2 )
     88    unless $db && $dbuser;
    8989
    9090# start up logging
     
    111111    log4perl.appender.Mailer.subject = nebdiskd alert
    112112    log4perl.appender.Mailer.buffered = 0
    113     log4perl.appender.AppError.Filter= MatchWarn
     113    log4perl.appender.Mailer.Filter= MatchWarn
    114114    log4perl.appender.Mailer.layout = Log::Log4perl::Layout::PatternLayout
    115115    log4perl.appender.Mailer.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} | %H | %p | %M - %m%n
     
    163163    my $dbhost          = $p{dbhost} or return;
    164164    my $dbuser          = $p{dbuser} or return;
    165     my $dbpass          = $p{dbpass} or return;
     165#    my $dbpass          = $p{dbpass} or return;
    166166    my $poll_interval   = $p{poll_interval} || 60;
    167167    my $debug           = $p{debug} || 0;
     
    177177
    178178    eval {
    179         my $r_query = $dbh->prepare_cached("REPLACE INTO mount VALUES(?, ?, ?)");
    180         my $d_query = $dbh->prepare_cached("DELETE FROM mount, mountedvol WHERE mountpoint = ?");
     179        my $r_query = $dbh->prepare_cached("REPLACE INTO mountedvol SELECT *, ?, ? FROM volume WHERE mountpoint = ?");
     180        my $d_query = $dbh->prepare_cached("DELETE FROM mountedvol WHERE mountpoint = ?");
    181181
    182182        # get list of mount points
    183183        my $mounts = [];
    184184        {
    185             my $query = $dbh->prepared_cached("SELECT mountpoint FROM volume");
     185            # there may be multiple vol_ids per mountpoint but we only need to
     186            # check each mointpont once
     187            my $query = $dbh->prepare_cached("SELECT DISTINCT mountpoint FROM volume");
    186188            $query->execute;
    187189            while (my $row = $query->fetchrow_hashref) {
    188                 push @$mounts, $row->{'mountpoint'};
     190                push @$mounts, $row;
    189191            }
    190192            $query->finish;
     
    193195        # determine valid mountpoints
    194196        foreach my $mnt (@$mounts) {
    195             $log->debug("checking $mnt");
     197            my $mountpoint = $mnt->{'mountpoint'};
     198            $log->debug("checking $mountpoint");
    196199            # this /SHOULD/ fail if the mount point is handled by the
    197200            # automounter and it fails to mount
     
    199202            TEST: eval {
    200203                $tries++;
    201                 unless (is_mountpoint($mnt)) {
     204                unless (is_mountpoint($mountpoint)) {
    202205                    $log->warn("$mnt is not a valid mountpoint");
    203206                }
     
    206209                # try is_mountpoint() again if $retry > 1
    207210                if ($tries < $retry) {
    208                     $log->warn("retrying test of $mnt");
     211                    $log->warn("retrying test of $mountpoint");
    209212                    goto TEST;
    210213                }
    211214                $log->warn($@);
    212                 $d_query->execute($mnt);
     215                $d_query->execute($mountpoint);
    213216                next;
    214217            }
     
    217220            # we determine if it's a valid mountpoint incase
    218221            # is_mountpoint() invokes the automounter
    219             my $dev_info = df($mnt, 1024);
     222            my $dev_info = df($mountpoint, 1024);
    220223            unless (defined $dev_info) {
    221                 $log->error("can't find device info for $mnt");
     224                $log->error("can't find device info for $mountpoint");
    222225                next;
    223226            }
    224227
    225228            # find vol_id(s) for mountpoint
    226             $r_query->execute($mnt, @$dev_info{qw( blocks used )});
    227             $log->debug("adding $mnt to db");
     229            $r_query->execute(@$dev_info{qw( blocks used )}, $mountpoint);
     230            $log->debug("adding $mountpoint to db");
    228231
    229232        }
    230233
    231         $dbh->do("call getmountedvol()");
     234#        $dbh->do("call getmountedvol()");
    232235
    233236        $dbh->commit;
     
    263266    my %p = @_;
    264267
     268    # $p{dbpass} may be undef;
     269
    265270    return unless defined $p{db}
    266271              and defined $p{dbhost}
    267               and defined $p{dbuser}
    268               and defined $p{dbpass};
     272              and defined $p{dbuser};
    269273
    270274    my $sql = Nebulous::Server::SQL->new;
     
    372376=head1 SYNOPSIS
    373377
    374     nebdiskd [--db <db name>] [--user <db username>] [--pass <db password>] [--debug] [--pidfile <filename>] [--stop] [--restart] [--verbose]
     378    nebdiskd [--db|-D <db name>] [--dbhost|-H <db hostname>
     379    [--dbuser|-u <db username>] [--dbpass|-p <db password>] [--debug|-d]
     380    [--user|-U <username>] [--group|-g <groupname>] [--pidfile <filename>]
     381    [--retry <n>] [--stop|-s] [--restart|-r] [--verbose|-v]
    375382
    376383=head1 DESCRIPTION
     
    383390=over 4
    384391
    385 =item * --db|-d <db name>
     392=item * --db|-D <db name>
    386393
    387394Name of database (C<namespace>) to write too.
     
    390397variable is set.
    391398
    392 =item * --user|-u <db username>
     399=item * --dbuser|-u <username>
    393400
    394401Username to authenticate with.
     
    397404variable is set.
    398405
    399 =item * --pass|-p <db password>
     406=item * --dbpass|-p <password>
    400407
    401408Password to authenticate with.
     409
     410Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
     411variable is set or if the database does not require a password.
     412
     413=item * --dbhost|-H <hostname>
     414
     415Database host to connect to.
    402416
    403417Optional if defined in the F<.nebdiskdrc> file or the appropriate environment
    404418variable is set.
    405419
    406 =item * --debug
     420=item * --debug|-d
    407421
    408422This flag prevents the program from "daemonizing" so output can be sent to
     
    425439instance.
    426440
    427 =item * --verbose|-r
     441=item * --retry
     442
     443The number of times to test a mountpoint for "mountedness" before giving up on
     444it.
     445
     446=item * --verbose|-v
    428447
    429448Turns on informational/debugging messages to be sent to the
     
    431450with C<--debug>.
    432451
     452=item * --user|-U
     453
     454user account to run daemon as.
     455
     456=item * --group|-g
     457
     458group to run daemon as.
     459
    433460=back
    434461
     
    443470=item * C<NEB_DB>
    444471
    445 Equivalent to --db|-d
     472Equivalent to --db|-D
    446473
    447474=item * C<NEB_USER>
    448475
    449 Equivalent to --user|-u
     476Equivalent to --dbuser|-u
    450477
    451478=item * C<NEB_PASS>
    452479
    453 Equivalent to --pass|-p
     480Equivalent to --dbpass|-p
    454481
    455482=back
     
    467494    dbpass: '@neb@'
    468495    dbuser: nebulous
    469     mounts:
    470       - /mnt
    471       - /tmp
    472       - /usr
    473496    pidfile: /var/tmp/nebdiskd
    474497    poll_interval: 5
     
    480503=over 4
    481504
    482 =item * C<mounts>
    483 
    484 A list of "paths" to C<stat(2)> before mounted volumes are polled.  The propose
    485 of this option is to attempt to keep "automounted" volumes mounted while this
    486 program is running.
    487 
    488505This value may be omitted or left blank.
    489506
     
    493510
    494511This value may be omitted or left blank.  The default value is C<60>s.
     512
     513=item * C<retry>
     514
     515Same as C<--retry>.
    495516
    496517=back
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r24539 r24540  
    396396    },
    397397    get_mounted_volumes => qq{
    398         SELECT * FROM mountedvol ORDER BY host, name
     398        SELECT mountpoint, total, used, vol_id, name, host, path, allocate, available, xattr FROM mountedvol ORDER BY host, name
    399399    },
    400400);
     
    423423DROP TABLE IF EXISTS lock_record;
    424424DROP TABLE IF EXISTS volume;
    425 DROP TABLE IF EXISTS mount;
     425DROP TABLE IF EXISTS mountedvol;
    426426DROP TABLE IF EXISTS log;
    427 DROP TABLE IF EXISTS mountedvol;
    428427DROP TABLE IF EXISTS directory;
    429428DROP PROCEDURE IF EXISTS getmountedvol;
     
    518517    host VARCHAR(255) NOT NULL,
    519518    path VARCHAR(255) UNIQUE NOT NULL,
    520     mountpoint VARCHAR(255) NOT NULL,
    521519    allocate BOOLEAN DEFAULT FALSE,
    522520    available BOOLEAN DEFAULT FALSE,
    523521    xattr BOOLEAN DEFAULT FALSE,
     522    mountpoint VARCHAR(255) NOT NULL,
    524523    PRIMARY KEY(vol_id),
    525524    KEY(host(16)),
     
    527526    KEY(allocate),
    528527    KEY(available)
     528) ENGINE=innodb DEFAULT CHARSET=latin1;
     529
     530###
     531
     532CREATE TABLE mountedvol(
     533    vol_id INT UNIQUE NOT NULL,
     534    FOREIGN KEY(vol_id) REFERENCES volume(vol_id) ON DELETE CASCADE,
     535    name VARCHAR(255) NOT NULL,
     536    host VARCHAR(255) NOT NULL,
     537    path VARCHAR(255) NOT NULL,
     538    FOREIGN KEY(path) REFERENCES volume(path) ON DELETE CASCADE,
     539    allocate BOOLEAN DEFAULT FALSE,
     540    available BOOLEAN DEFAULT FALSE,
     541    xattr BOOLEAN DEFAULT FALSE,
     542    mountpoint VARCHAR(255) NOT NULL,
     543    FOREIGN KEY(mountpoint) REFERENCES volume(mountpoint) ON DELETE CASCADE,
     544    total BIGINT NOT NULL,
     545    used BIGINT NOT NULL,
     546    PRIMARY KEY(vol_id),
     547    KEY(name),
     548    KEY(host),
     549    KEY(path),
     550    KEY(allocate),
     551    KEY(available),
     552    KEY(xattr),
     553    KEY(mountpoint(255))
    529554) ENGINE=innodb DEFAULT CHARSET=latin1;
    530555
     
    548573###
    549574
    550 CREATE TABLE mount (
    551     mountpoint VARCHAR(255) NOT NULL,
    552     total BIGINT NOT NULL,
    553     used BIGINT NOT NULL,
    554     PRIMARY KEY(mountpoint)
    555 ) ENGINE=innodb DEFAULT CHARSET=latin1;
    556 
    557 ###
    558 
    559575CREATE TABLE log (
    560576    timestamp TIMESTAMP,
     
    564580    message VARCHAR(2048) NOT NULL,
    565581    PRIMARY KEY(timestamp)
    566 ) ENGINE=innodb DEFAULT CHARSET=latin1;
    567 
    568 ###
    569 
    570 CREATE TABLE mountedvol(
    571     mountpoint VARCHAR(255) NOT NULL,
    572     FOREIGN KEY(mountpoint) REFERENCES mount(mountpoint) ON DELETE CASCADE,
    573     total BIGINT NOT NULL,
    574     used BIGINT NOT NULL,
    575     vol_id INT NOT NULL,
    576     FOREIGN KEY(vol_id) REFERENCES volume(vol_id) ON DELETE CASCADE,
    577     name VARCHAR(255) NOT NULL,
    578     host VARCHAR(255) NOT NULL,
    579     path VARCHAR(255) NOT NULL,
    580     FOREIGN KEY(path) REFERENCES volume(path) ON DELETE CASCADE,
    581     allocate BOOLEAN DEFAULT FALSE,
    582     available BOOLEAN DEFAULT FALSE,
    583     xattr BOOLEAN DEFAULT FALSE,
    584     PRIMARY KEY(mountpoint),
    585     KEY(vol_id),
    586     KEY(name),
    587     KEY(host),
    588     KEY(path),
    589     KEY(allocate),
    590     KEY(available),
    591     KEY(xattr)
    592582) ENGINE=innodb DEFAULT CHARSET=latin1;
    593583
  • trunk/Nebulous-Server/lib/Test/Nebulous.pm

    r24372 r24540  
    5555
    5656    # node01/node02: allocate = TRUE
    57     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (1, 'node01', 'node01', ?, TRUE, TRUE) }, undef, $dir1);
    58     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1);
     57    $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (1, 'node01', 'node01', ?, '/', TRUE, TRUE) }, undef, $dir1);
     58    $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 1);
     59#    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1);
    5960
    60     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (2, 'node02', 'node02', ?, TRUE, TRUE) }, undef, $dir2);
    61     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2);
     61    $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (2, 'node02', 'node02', ?, '/', TRUE, TRUE) }, undef, $dir2);
     62    $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e8 FROM volume WHERE vol_id = ? }, undef, 2);
     63#    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2);
    6264
    6365    # node03: allocate = TRUE
    64     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (3, 'node03', 'node03', ?, TRUE, TRUE) }, undef, $dir3);
    65     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3);
     66    $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (3, 'node03', 'node03', ?, '/', TRUE, TRUE) }, undef, $dir3);
     67    $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e8 FROM volume WHERE vol_id = ? }, undef, 3);
     68#    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3);
    6669
    6770    # node04: allocate = FALSE, available = FALSE
    68     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (4, 'node04', 'node04', ?, FALSE, FALSE) }, undef, $dir4);
    69     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir4);
     71    $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (4, 'node04', 'node04', ?, '/', FALSE, FALSE) }, undef, $dir4);
     72    $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 4);
     73#    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir4);
    7074
    7175    # node05: allocate = FALSE, available = TRUE
    72     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (5, 'node05', 'node05', ?, FALSE, TRUE) }, undef, $dir5);
    73     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir5);
     76    $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (5, 'node05', 'node05', ?, '/', FALSE, TRUE) }, undef, $dir5);
     77    $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 5);
     78#    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir5);
    7479
    7580    # node06: allocate = TRUE, available = FALSE
    76     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (6, 'node06', 'node06', ?, TRUE, FALSE) }, undef, $dir6);
    77     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6);
     81    $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (6, 'node06', 'node06', ?, '/', TRUE, FALSE) }, undef, $dir6);
     82    $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 6);
     83#    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6);
    7884
    7985    # node07: full
    80     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, allocate, available) VALUES (7, 'node07', 'node07', ?, TRUE, TRUE) }, undef, $dir7);
    81     $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir7);
     86    $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (7, 'node07', 'node07', ?, '/', TRUE, TRUE) }, undef, $dir7);
     87    $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e10 FROM volume WHERE vol_id = ? }, undef, 7);
     88#    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir7);
    8289
    83     $dbh->do(qq{ call getmountedvol() });
     90#    $dbh->do(qq{ call getmountedvol() });
    8491}
    8592
Note: See TracChangeset for help on using the changeset viewer.