Changeset 13087
- Timestamp:
- Apr 30, 2007, 4:00:07 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
-
Nebulous-Server/Changes (modified) (1 diff)
-
Nebulous-Server/MANIFEST (modified) (1 diff)
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (2 diffs)
-
Nebulous-Server/lib/Nebulous/Server/SQL.pm (modified) (4 diffs)
-
Nebulous-Server/t/14_server_xattr.t (added)
-
Nebulous/Changes (modified) (1 diff)
-
Nebulous/MANIFEST (modified) (1 diff)
-
Nebulous/lib/Nebulous/Server.pm (modified) (2 diffs)
-
Nebulous/lib/Nebulous/Server/SQL.pm (modified) (4 diffs)
-
Nebulous/t/14_server_xattr.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r13080 r13087 2 2 3 3 0.05 4 - add Nebulous::Server->{setxattr_object, listxattr_object, 5 getxattr_object, removexattr_object}() 4 6 - add neb-cat 5 7 - add neb-mv -
trunk/Nebulous-Server/MANIFEST
r13080 r13087 91 91 t/12_server_find_objects.t 92 92 t/13_server_rename_object.t 93 t/14_server_xattr.t 93 94 t/50_client_new.t 94 95 t/51_client_create.t -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r13071 r13087 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.2 6 2007-04-28 00:44:38jhoblitt Exp $3 # $Id: Server.pm,v 1.27 2007-05-01 02:00:07 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 614 614 615 615 616 sub setxattr_object 617 { 618 my $self = shift; 619 620 my ($key, $name, $value, $flags) = validate_pos(@_, 621 { 622 type => SCALAR, 623 }, 624 { 625 type => SCALAR, 626 }, 627 { 628 type => SCALAR, 629 }, 630 { 631 type => SCALAR, 632 callbacks => { 633 'is read or write' => sub { $_[0] =~ /^(?:create|replace)$/i }, 634 }, 635 }, 636 ); 637 638 my $log = $self->log; 639 my $sql = $self->sql; 640 my $db =$self->db; 641 642 $log->debug("entered - @_"); 643 644 eval { 645 my $query; 646 647 if ($flags eq 'create') { 648 $query = $db->prepare_cached( $sql->new_object_xattr ); 649 } else { 650 # replace 651 $query = $db->prepare_cached( $sql->replace_object_xattr ); 652 } 653 654 # name, value, ext_id 655 my $rows = $query->execute($name, $value, $key); 656 657 # if we affected more then one row something very bad has happened. 658 if ($flags eq 'create') { 659 unless ($rows == 1) { 660 $log->logdie( "affected row count is $rows instead of 1" ); 661 } 662 } else { 663 unless ($rows == 2) { 664 $log->logdie( "affected row count is $rows instead of 2" ); 665 } 666 } 667 }; 668 if ($@) { 669 $db->rollback; 670 $log->logdie("database error: $@"); 671 } 672 673 eval { 674 $db->commit; 675 }; 676 if ($@) { 677 $db->rollback; 678 $log->logdie("database error: $@"); 679 } 680 681 $log->debug("leaving"); 682 683 return 1; 684 } 685 686 687 sub getxattr_object 688 { 689 my $self = shift; 690 691 my ($key, $name) = validate_pos(@_, 692 { 693 type => SCALAR, 694 }, 695 { 696 type => SCALAR, 697 }, 698 ); 699 700 my $log = $self->log; 701 my $sql = $self->sql; 702 my $db =$self->db; 703 704 $log->debug("entered - @_"); 705 706 my $query; 707 eval { 708 $query = $db->prepare_cached( $sql->get_object_xattr ); 709 # ext_id, name 710 my $rows = $query->execute($key, $name); 711 712 # if we affected more then one row something very bad has happened. 713 unless ($rows == 1) { 714 $log->logdie( "affected row count is $rows instead of 1" ); 715 } 716 }; 717 if ($@) { 718 $db->rollback; 719 $log->logdie("database error: $@"); 720 } 721 722 my $row = $query->fetchrow_hashref; 723 my $value = $row->{ 'value' }; 724 $query->finish; 725 726 $log->debug("leaving"); 727 728 return $value; 729 } 730 731 732 sub listxattr_object 733 { 734 my $self = shift; 735 736 my ($key) = validate_pos(@_, 737 { 738 type => SCALAR, 739 }, 740 ); 741 742 my $log = $self->log; 743 my $sql = $self->sql; 744 my $db =$self->db; 745 746 $log->debug("entered - @_"); 747 748 my $query; 749 eval { 750 $query = $db->prepare_cached( $sql->list_object_xattr ); 751 # ext_id 752 my $rows = $query->execute($key); 753 }; 754 if ($@) { 755 $db->rollback; 756 $log->logdie("database error: $@"); 757 } 758 759 my @xattrs; 760 while (my $row = $query->fetchrow_hashref) { 761 push @xattrs, $row->{ 'name' }; 762 } 763 764 $log->debug("leaving"); 765 766 return @xattrs; 767 } 768 769 770 sub removexattr_object 771 { 772 my $self = shift; 773 774 my ($key, $name) = validate_pos(@_, 775 { 776 type => SCALAR, 777 }, 778 { 779 type => SCALAR, 780 }, 781 ); 782 783 my $log = $self->log; 784 my $sql = $self->sql; 785 my $db =$self->db; 786 787 $log->debug("entered - @_"); 788 789 my $query; 790 eval { 791 $query = $db->prepare_cached( $sql->remove_object_xattr ); 792 # ext_id, name 793 my $rows = $query->execute($key, $name); 794 795 # if we affected more then one row something very bad has happened. 796 unless ($rows == 1) { 797 $log->logdie( "affected row count is $rows instead of 1" ); 798 } 799 }; 800 if ($@) { 801 $db->rollback; 802 $log->logdie("database error: $@"); 803 } 804 805 eval { 806 $db->commit; 807 }; 808 if ($@) { 809 $db->rollback; 810 $log->logdie("database error: $@"); 811 } 812 813 $log->debug("leaving"); 814 815 return 1; 816 } 817 818 616 819 sub find_objects { 617 820 my $self = shift; -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r13071 r13087 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.2 8 2007-04-28 00:44:38jhoblitt Exp $3 # $Id: SQL.pm,v 1.29 2007-05-01 02:00:07 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 63 63 WHERE ext_id = ? 64 64 FOR UPDATE 65 }, 66 new_object_xattr => qq{ 67 INSERT INTO storage_object_xattr 68 SELECT 69 so_id, 70 ?, 71 ? 72 FROM storage_object 73 WHERE ext_id = ? 74 }, 75 replace_object_xattr => qq{ 76 REPLACE INTO storage_object_xattr 77 SELECT 78 so_id, 79 ?, 80 ? 81 FROM storage_object 82 WHERE ext_id = ? 83 }, 84 list_object_xattr => qq{ 85 SELECT storage_object_xattr.name 86 FROM storage_object 87 JOIN storage_object_xattr 88 USING (so_id) 89 WHERE ext_id = ? 90 }, 91 get_object_xattr => qq{ 92 SELECT storage_object_xattr.value 93 FROM storage_object 94 JOIN storage_object_xattr 95 USING (so_id) 96 WHERE ext_id = ? 97 AND name = ? 98 }, 99 remove_object_xattr => qq{ 100 DELETE FROM storage_object_xattr 101 WHERE so_id = (SELECT so_id from storage_object where ext_id = ?) 102 AND name = ? 65 103 }, 66 104 set_write_lock => qq{ … … 179 217 DROP TABLE IF EXISTS storage_object; 180 218 DROP TABLE IF EXISTS storage_object_attr; 219 DROP TABLE IF EXISTS storage_object_xattr; 181 220 DROP TABLE IF EXISTS instance; 182 221 DROP TABLE IF EXISTS lock_record; … … 226 265 PRIMARY KEY(so_id), 227 266 KEY(class_id) 267 ) ENGINE=innodb; 268 269 ### 270 271 CREATE TABLE storage_object_xattr ( 272 so_id BIGINT NOT NULL AUTO_INCREMENT, 273 name VARCHAR(255), 274 value BLOB, 275 PRIMARY KEY(so_id, name) 228 276 ) ENGINE=innodb; 229 277 -
trunk/Nebulous/Changes
r13080 r13087 2 2 3 3 0.05 4 - add Nebulous::Server->{setxattr_object, listxattr_object, 5 getxattr_object, removexattr_object}() 4 6 - add neb-cat 5 7 - add neb-mv -
trunk/Nebulous/MANIFEST
r13080 r13087 91 91 t/12_server_find_objects.t 92 92 t/13_server_rename_object.t 93 t/14_server_xattr.t 93 94 t/50_client_new.t 94 95 t/51_client_create.t -
trunk/Nebulous/lib/Nebulous/Server.pm
r13071 r13087 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.2 6 2007-04-28 00:44:38jhoblitt Exp $3 # $Id: Server.pm,v 1.27 2007-05-01 02:00:07 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 614 614 615 615 616 sub setxattr_object 617 { 618 my $self = shift; 619 620 my ($key, $name, $value, $flags) = validate_pos(@_, 621 { 622 type => SCALAR, 623 }, 624 { 625 type => SCALAR, 626 }, 627 { 628 type => SCALAR, 629 }, 630 { 631 type => SCALAR, 632 callbacks => { 633 'is read or write' => sub { $_[0] =~ /^(?:create|replace)$/i }, 634 }, 635 }, 636 ); 637 638 my $log = $self->log; 639 my $sql = $self->sql; 640 my $db =$self->db; 641 642 $log->debug("entered - @_"); 643 644 eval { 645 my $query; 646 647 if ($flags eq 'create') { 648 $query = $db->prepare_cached( $sql->new_object_xattr ); 649 } else { 650 # replace 651 $query = $db->prepare_cached( $sql->replace_object_xattr ); 652 } 653 654 # name, value, ext_id 655 my $rows = $query->execute($name, $value, $key); 656 657 # if we affected more then one row something very bad has happened. 658 if ($flags eq 'create') { 659 unless ($rows == 1) { 660 $log->logdie( "affected row count is $rows instead of 1" ); 661 } 662 } else { 663 unless ($rows == 2) { 664 $log->logdie( "affected row count is $rows instead of 2" ); 665 } 666 } 667 }; 668 if ($@) { 669 $db->rollback; 670 $log->logdie("database error: $@"); 671 } 672 673 eval { 674 $db->commit; 675 }; 676 if ($@) { 677 $db->rollback; 678 $log->logdie("database error: $@"); 679 } 680 681 $log->debug("leaving"); 682 683 return 1; 684 } 685 686 687 sub getxattr_object 688 { 689 my $self = shift; 690 691 my ($key, $name) = validate_pos(@_, 692 { 693 type => SCALAR, 694 }, 695 { 696 type => SCALAR, 697 }, 698 ); 699 700 my $log = $self->log; 701 my $sql = $self->sql; 702 my $db =$self->db; 703 704 $log->debug("entered - @_"); 705 706 my $query; 707 eval { 708 $query = $db->prepare_cached( $sql->get_object_xattr ); 709 # ext_id, name 710 my $rows = $query->execute($key, $name); 711 712 # if we affected more then one row something very bad has happened. 713 unless ($rows == 1) { 714 $log->logdie( "affected row count is $rows instead of 1" ); 715 } 716 }; 717 if ($@) { 718 $db->rollback; 719 $log->logdie("database error: $@"); 720 } 721 722 my $row = $query->fetchrow_hashref; 723 my $value = $row->{ 'value' }; 724 $query->finish; 725 726 $log->debug("leaving"); 727 728 return $value; 729 } 730 731 732 sub listxattr_object 733 { 734 my $self = shift; 735 736 my ($key) = validate_pos(@_, 737 { 738 type => SCALAR, 739 }, 740 ); 741 742 my $log = $self->log; 743 my $sql = $self->sql; 744 my $db =$self->db; 745 746 $log->debug("entered - @_"); 747 748 my $query; 749 eval { 750 $query = $db->prepare_cached( $sql->list_object_xattr ); 751 # ext_id 752 my $rows = $query->execute($key); 753 }; 754 if ($@) { 755 $db->rollback; 756 $log->logdie("database error: $@"); 757 } 758 759 my @xattrs; 760 while (my $row = $query->fetchrow_hashref) { 761 push @xattrs, $row->{ 'name' }; 762 } 763 764 $log->debug("leaving"); 765 766 return @xattrs; 767 } 768 769 770 sub removexattr_object 771 { 772 my $self = shift; 773 774 my ($key, $name) = validate_pos(@_, 775 { 776 type => SCALAR, 777 }, 778 { 779 type => SCALAR, 780 }, 781 ); 782 783 my $log = $self->log; 784 my $sql = $self->sql; 785 my $db =$self->db; 786 787 $log->debug("entered - @_"); 788 789 my $query; 790 eval { 791 $query = $db->prepare_cached( $sql->remove_object_xattr ); 792 # ext_id, name 793 my $rows = $query->execute($key, $name); 794 795 # if we affected more then one row something very bad has happened. 796 unless ($rows == 1) { 797 $log->logdie( "affected row count is $rows instead of 1" ); 798 } 799 }; 800 if ($@) { 801 $db->rollback; 802 $log->logdie("database error: $@"); 803 } 804 805 eval { 806 $db->commit; 807 }; 808 if ($@) { 809 $db->rollback; 810 $log->logdie("database error: $@"); 811 } 812 813 $log->debug("leaving"); 814 815 return 1; 816 } 817 818 616 819 sub find_objects { 617 820 my $self = shift; -
trunk/Nebulous/lib/Nebulous/Server/SQL.pm
r13071 r13087 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: SQL.pm,v 1.2 8 2007-04-28 00:44:38jhoblitt Exp $3 # $Id: SQL.pm,v 1.29 2007-05-01 02:00:07 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server::SQL; … … 63 63 WHERE ext_id = ? 64 64 FOR UPDATE 65 }, 66 new_object_xattr => qq{ 67 INSERT INTO storage_object_xattr 68 SELECT 69 so_id, 70 ?, 71 ? 72 FROM storage_object 73 WHERE ext_id = ? 74 }, 75 replace_object_xattr => qq{ 76 REPLACE INTO storage_object_xattr 77 SELECT 78 so_id, 79 ?, 80 ? 81 FROM storage_object 82 WHERE ext_id = ? 83 }, 84 list_object_xattr => qq{ 85 SELECT storage_object_xattr.name 86 FROM storage_object 87 JOIN storage_object_xattr 88 USING (so_id) 89 WHERE ext_id = ? 90 }, 91 get_object_xattr => qq{ 92 SELECT storage_object_xattr.value 93 FROM storage_object 94 JOIN storage_object_xattr 95 USING (so_id) 96 WHERE ext_id = ? 97 AND name = ? 98 }, 99 remove_object_xattr => qq{ 100 DELETE FROM storage_object_xattr 101 WHERE so_id = (SELECT so_id from storage_object where ext_id = ?) 102 AND name = ? 65 103 }, 66 104 set_write_lock => qq{ … … 179 217 DROP TABLE IF EXISTS storage_object; 180 218 DROP TABLE IF EXISTS storage_object_attr; 219 DROP TABLE IF EXISTS storage_object_xattr; 181 220 DROP TABLE IF EXISTS instance; 182 221 DROP TABLE IF EXISTS lock_record; … … 226 265 PRIMARY KEY(so_id), 227 266 KEY(class_id) 267 ) ENGINE=innodb; 268 269 ### 270 271 CREATE TABLE storage_object_xattr ( 272 so_id BIGINT NOT NULL AUTO_INCREMENT, 273 name VARCHAR(255), 274 value BLOB, 275 PRIMARY KEY(so_id, name) 228 276 ) ENGINE=innodb; 229 277
Note:
See TracChangeset
for help on using the changeset viewer.
