Changeset 20091
- Timestamp:
- Oct 13, 2008, 10:41:17 AM (18 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 1 added
- 3 edited
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (1 diff)
-
lib/Nebulous/Server.pm (modified) (2 diffs)
-
t/16_server_swap_objects.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r20057 r20091 29 29 - change Nebulous::Server->new() to call ->db() instead of setting up the 30 30 DBH itself; cleanup Nebulous::Server->db() 31 - add Nebulous::Server->swap_objects() method 31 32 32 33 0.15 Thu Sep 11 13:00:59 HST 2008 -
trunk/Nebulous-Server/MANIFEST
r19887 r20091 49 49 t/14_server_xattr.t 50 50 t/15_mounts.t 51 t/16_server_swap_objects.t 51 52 t/75_parse_neb_key.t -
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.
