IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23714


Ignore:
Timestamp:
Apr 6, 2009, 12:01:40 PM (17 years ago)
Author:
jhoblitt
Message:

fix runtime errors from untested changes
merge minor changes from head
expand tabs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm

    r23628 r23714  
    1515use DBI;
    1616use Digest::SHA1 qw( sha1_hex );
     17use File::Basename qw( dirname );
    1718use File::ExtAttr qw( setfattr );
    1819use File::Path;
     
    355356
    356357    my ($key1, $key2) = validate_pos(@_,
    357                                      {
    358                                         type        => SCALAR,
    359                                         callbacks   => {
    360                                              'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
    361                                         },
    362                                      },
    363                                      {
    364                                         type        => SCALAR,
    365                                         callbacks   => {
    366                                              'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
    367                                         },
    368                                      },
    369         );
    370 
    371     my $log  = $self->log;
    372     my $sql  = $self->sql;
     358        {
     359            type        => SCALAR,
     360            callbacks   => {
     361                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     362            },
     363        },
     364        {
     365            type        => SCALAR,
     366            callbacks   => {
     367                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     368            },
     369        },
     370    );
     371
     372    my $log = $self->log;
     373    my $sql = $self->sql;
    373374
    374375    my $dbidx1 = $self->db_index_for_key($key1);
     
    391392    # key1.swap -> key2
    392393
    393     my $dbh = $dbh1;
     394    my $db = $dbh1;
    394395  TRANS: while (1) {
    395       eval {
    396           {
    397               # key1 -> key1.swap
    398               my $query = $db->prepare_cached($sql->rename_object);
    399               # this SQL statment takes the new key name as the first param
    400               my $rows = $query->execute($key1->path . ".swap", $key1->path);
    401 
    402               # if we affected more then one row something very bad has happened.
    403               unless ($rows == 1) {
    404                   $query->finish;
    405                   $log->logdie("affected row count is $rows instead of 1");
    406               }
    407           }
    408 
    409           {
    410               # key2 -> key1
    411               my $query = $db->prepare_cached($sql->rename_object);
    412               # this SQL statment takes the new key name as the first param
    413               my $rows = $query->execute($key1->path, $key2->path);
    414 
    415               # if we affected more then one row something very bad has happened.
    416               unless ($rows == 1) {
    417                   $query->finish;
    418                   $log->logdie("affected row count is $rows instead of 1");
    419               }
    420           }
    421 
    422           {
    423               # key1.swap -> key2
    424               my $query = $db->prepare_cached($sql->rename_object);
    425               # this SQL statment takes the new key name as the first param
    426               my $rows = $query->execute($key2->path, $key1->path . ".swap");
    427 
    428               # if we affected more then one row something very bad has happened.
    429               unless ($rows == 1) {
    430                   $query->finish;
    431                   $log->logdie("affected row count is $rows instead of 1");
    432               }
    433           }
    434 
    435           $db->commit;
    436           $log->debug("commit");
    437       };
    438       if ($@) {
    439           $db->rollback;
    440           $log->debug("rollback");
    441           if ($@ =~ /Deadlock found/) {
    442               $log->warn("database deadlock retrying transaction: $@");
    443               redo TRANS;
    444           }
    445           $log->logdie("database error: $@");
    446       }
     396        eval {
     397            {
     398              # key1 -> key1.swap
     399              my $query = $db->prepare_cached($sql->rename_object);
     400              # this SQL statment takes the new key name as the first param
     401              my $rows = $query->execute($key1->path . ".swap", $key1->path);
     402
     403              # if we affected more then one row something very bad has happened.
     404              unless ($rows == 1) {
     405                  $query->finish;
     406                  $log->logdie("affected row count is $rows instead of 1");
     407              }
     408          }
     409
     410          {
     411              # key2 -> key1
     412              my $query = $db->prepare_cached($sql->rename_object);
     413              # this SQL statment takes the new key name as the first param
     414              my $rows = $query->execute($key1->path, $key2->path);
     415
     416              # if we affected more then one row something very bad has happened.
     417              unless ($rows == 1) {
     418                  $query->finish;
     419                  $log->logdie("affected row count is $rows instead of 1");
     420              }
     421          }
     422
     423          {
     424              # key1.swap -> key2
     425              my $query = $db->prepare_cached($sql->rename_object);
     426              # this SQL statment takes the new key name as the first param
     427              my $rows = $query->execute($key2->path, $key1->path . ".swap");
     428
     429              # if we affected more then one row something very bad has happened.
     430              unless ($rows == 1) {
     431                  $query->finish;
     432                  $log->logdie("affected row count is $rows instead of 1");
     433              }
     434          }
     435
     436            $db->commit;
     437            $log->debug("commit");
     438        };
     439        if ($@) {
     440            $db->rollback;
     441            $log->debug("rollback");
     442            if ($@ =~ /Deadlock found/) {
     443                $log->warn("database deadlock retrying transaction: $@");
     444                redo TRANS;
     445            }
     446            $log->logdie("database error: $@");
     447        }
    447448      last;
    448449  }
     
    569570
    570571            # TODO add some stuff here to retry if unsucessful
    571             # XXX if this fails, it should try to generate the
    572             # instance on another volume (unless !$soft_volume)
     572            # XXX if this fails, it should try to generate the
     573            # instance on another volume (unless !$soft_volume)
    573574            $uri = $self->_create_empty_instance_file($key->path, $so_id, $ins_id, $vol_path, $vol_xattr);
    574575
     
    10901091
    10911092    my @keys = ();
    1092     my $n_dbs = $self->n_db();
     1093    my $n_dbs = $self->config->n_db();
    10931094    for (my $index = 0; $index < $n_dbs; $index ++) {
    1094        
    1095         my $newkeys = $self->find_objects_for_index($index, $pattern);
    1096         push @keys, @$newkeys;
     1095        my $newkeys = $self->find_objects_for_index($index, $pattern);
     1096        push @keys, @$newkeys;
    10971097    }
    10981098    $log->logdie("no keys found") unless ( scalar @keys );
     
    11101110    my $index = shift;
    11111111    my $pattern = shift;
     1112
     1113    my $log = $self->log;
     1114    my $sql = $self->sql;
    11121115    my $db  = $self->db_for_index($index);
    11131116
     
    15211524    my $ext_id;
    15221525    eval {
    1523         my $query = $db->prepare_cached( $sql->get_object );
     1526        my $query = $db->prepare_cached( $sql->check_object_name );
    15241527        $query->execute($key->path);
    15251528        ($ext_id) = $query->fetchrow_array;
Note: See TracChangeset for help on using the changeset viewer.