Changeset 23714
- Timestamp:
- Apr 6, 2009, 12:01:40 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/neb_distrib_20081210/Nebulous-Server/lib/Nebulous/Server.pm
r23628 r23714 15 15 use DBI; 16 16 use Digest::SHA1 qw( sha1_hex ); 17 use File::Basename qw( dirname ); 17 18 use File::ExtAttr qw( setfattr ); 18 19 use File::Path; … … 355 356 356 357 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; 373 374 374 375 my $dbidx1 = $self->db_index_for_key($key1); … … 391 392 # key1.swap -> key2 392 393 393 my $db h= $dbh1;394 my $db = $dbh1; 394 395 TRANS: while (1) { 395 eval {396 {397 # key1 -> key1.swap398 my $query = $db->prepare_cached($sql->rename_object);399 # this SQL statment takes the new key name as the first param400 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 -> key1411 my $query = $db->prepare_cached($sql->rename_object);412 # this SQL statment takes the new key name as the first param413 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 -> key2424 my $query = $db->prepare_cached($sql->rename_object);425 # this SQL statment takes the new key name as the first param426 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 } 447 448 last; 448 449 } … … 569 570 570 571 # TODO add some stuff here to retry if unsucessful 571 # XXX if this fails, it should try to generate the572 # 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) 573 574 $uri = $self->_create_empty_instance_file($key->path, $so_id, $ins_id, $vol_path, $vol_xattr); 574 575 … … 1090 1091 1091 1092 my @keys = (); 1092 my $n_dbs = $self-> n_db();1093 my $n_dbs = $self->config->n_db(); 1093 1094 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; 1097 1097 } 1098 1098 $log->logdie("no keys found") unless ( scalar @keys ); … … 1110 1110 my $index = shift; 1111 1111 my $pattern = shift; 1112 1113 my $log = $self->log; 1114 my $sql = $self->sql; 1112 1115 my $db = $self->db_for_index($index); 1113 1116 … … 1521 1524 my $ext_id; 1522 1525 eval { 1523 my $query = $db->prepare_cached( $sql-> get_object);1526 my $query = $db->prepare_cached( $sql->check_object_name ); 1524 1527 $query->execute($key->path); 1525 1528 ($ext_id) = $query->fetchrow_array;
Note:
See TracChangeset
for help on using the changeset viewer.
