Changeset 20091 for trunk/Nebulous-Server/lib/Nebulous/Server.pm
- Timestamp:
- Oct 13, 2008, 10:41:17 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r20090 r20091 1 1 # Copyright (c) 2004-2008 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.9 2 2008-10-13 20:09:38jhoblitt Exp $3 # $Id: Server.pm,v 1.93 2008-10-13 20:41:17 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 296 296 297 297 298 sub swap_objects 299 { 300 my $self = shift; 301 302 my ($key1, $key2) = validate_pos(@_, 303 { 304 type => SCALAR, 305 callbacks => { 306 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 307 }, 308 }, 309 { 310 type => SCALAR, 311 callbacks => { 312 'is valid object key' => sub { $self->_is_valid_object_key($_[0]) }, 313 }, 314 }, 315 ); 316 317 my $log = $self->log; 318 my $sql = $self->sql; 319 my $db =$self->db; 320 321 $log->debug("entered - @_"); 322 323 # ignore volumes 324 $key1 = parse_neb_key($key1); 325 $key2 = parse_neb_key($key2); 326 327 # order of operations for the swap: 328 # key1 -> key1.swap 329 # key2 -> key1 330 # key1.swap -> key2 331 332 eval { 333 { 334 # key1 -> key1.swap 335 my $query = $db->prepare_cached($sql->rename_object); 336 # this SQL statment takes the new key name as the first param 337 my $rows = $query->execute($key1->path . ".swap", $key1->path); 338 339 # if we affected more then one row something very bad has happened. 340 unless ($rows == 1) { 341 $query->finish; 342 $log->logdie("affected row count is $rows instead of 1"); 343 } 344 } 345 346 { 347 # key2 -> key1 348 my $query = $db->prepare_cached($sql->rename_object); 349 # this SQL statment takes the new key name as the first param 350 my $rows = $query->execute($key1->path, $key2->path); 351 352 # if we affected more then one row something very bad has happened. 353 unless ($rows == 1) { 354 $query->finish; 355 $log->logdie("affected row count is $rows instead of 1"); 356 } 357 } 358 359 { 360 # key1.swap -> key2 361 my $query = $db->prepare_cached($sql->rename_object); 362 # this SQL statment takes the new key name as the first param 363 my $rows = $query->execute($key2->path, $key1->path . ".swap"); 364 365 # if we affected more then one row something very bad has happened. 366 unless ($rows == 1) { 367 $query->finish; 368 $log->logdie("affected row count is $rows instead of 1"); 369 } 370 } 371 372 $db->commit; 373 $log->debug("commit"); 374 }; 375 if ($@) { 376 $db->rollback; 377 $log->debug("rollback"); 378 $log->logdie("database error: $@"); 379 } 380 381 $log->debug("leaving"); 382 383 return 1; 384 } 385 386 298 387 sub replicate_object 299 388 {
Note:
See TracChangeset
for help on using the changeset viewer.
