Changeset 24915
- Timestamp:
- Jul 23, 2009, 4:14:20 PM (17 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 1 added
- 4 edited
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (1 diff)
-
lib/Nebulous/Server.pm (modified) (2 diffs)
-
lib/Nebulous/Server/SQL.pm (modified) (3 diffs)
-
t/19_server_prune_object.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r24639 r24915 35 35 - change Nebulous::Server->stat_object() to return both the total number of 36 36 instance and just those that are available 37 - add Nebulous::Server->prune_object() API 37 38 38 39 0.16 -
trunk/Nebulous-Server/MANIFEST
r24358 r24915 49 49 t/17_server_swap_objects.t 50 50 t/18_server_chmod_object.t 51 t/19_server_prune_object.t 51 52 t/75_parse_neb_key.t -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r24637 r24915 844 844 845 845 846 sub prune_object 847 { 848 my $self = shift; 849 850 my $log = $self->log; 851 $log->debug("entered - @_"); 852 853 my ($key) = validate_pos(@_, 854 { 855 type => SCALAR, 856 callbacks => { 857 'is valid object key' 858 => sub { $self->_is_valid_object_key($_[0]) }, 859 }, 860 }, 861 ); 862 863 my $sql = $self->sql; 864 865 eval { 866 $key = parse_neb_key($key); 867 }; 868 $log->logdie("$@") if $@; 869 870 my $db = $self->db($key); 871 872 my $rows_removed = 0; 873 TRANS: while (1) { 874 eval { 875 # remove key from cache 876 $self->cache->delete($key->path) if defined $self->cache; 877 878 my $so_id; 879 { 880 my $query = $db->prepare_cached( $sql->find_object_by_ext_id ); 881 $query->execute( $key->path ); 882 $so_id = $query->fetchrow_hashref->{'so_id'}; 883 $query->finish; 884 } 885 886 # record the path of the innaccesible files for deferred 887 # deletion 888 my $rows_copied; 889 { 890 my $query = $db->prepare_cached( $sql->copy_dead_instances_to_deleted ); 891 $rows_copied = $query->execute( $so_id ); 892 } 893 894 # check to see if there is anything to be done 895 unless ($rows_copied > 0) { 896 $db->rollback; 897 return; 898 } 899 900 # In MySQL you can't select from a table your deleting rows from so 901 # we first have to get a list of instances to be removed, and then 902 # removed them. 903 my $rows_found; 904 { 905 my $query = $db->prepare_cached( $sql->find_dead_instances_by_so_id ); 906 $rows_found = $query->execute( $so_id ); 907 foreach my $row ($query->fetchrow_hashref) { 908 # remove dead instances 909 my $query = $db->prepare_cached( $sql->delete_instance_by_ins_id); 910 $rows_removed += $query->execute( $row->{ins_id} ); 911 } 912 $query->finish; 913 } 914 915 # sanity check 916 die("instances inaccessible ($rows_copied) != instances removed ($rows_removed)") 917 unless $rows_copied == $rows_removed; 918 919 $db->commit; 920 $log->debug("commit"); 921 }; 922 if ($@) { 923 $db->rollback; 924 $log->debug("rollback"); 925 if ($@ =~ $trans_regex) { 926 $log->warn("database error, retrying transaction: $@"); 927 sleep TRANS_RETRY_WAIT; 928 redo TRANS; 929 } 930 $log->logdie("error: $@"); 931 } 932 last; 933 } 934 935 $log->debug("leaving"); 936 937 return $rows_removed; 938 } 939 940 846 941 sub lock_object 847 942 { … … 1674 1769 # remove key from cache 1675 1770 $self->cache->delete($key->path) if defined $self->cache; 1676 1677 # record the path of the innaccesible files for deferred 1678 # deletion 1679 { 1680 my $query = $db->prepare_cached( $sql->copy_instances_to_deleted ); 1681 $query->execute( $so_id ); 1682 } 1683 # remove all instances... not strictly nessicary as the delete 1684 # from storage_object should cascade but the fkey was specified 1685 # without the cascade 1686 { 1687 my $query = $db->prepare_cached( $sql->delete_instance_by_so_id ); 1688 $query->execute( $so_id ); 1771 1772 if ($total > $available) { 1773 $self->prune_object("$key"); 1689 1774 } 1690 1775 -
trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
r24643 r24915 183 183 WHERE ins_id = ? 184 184 }, 185 delete_instance_by_so_id => qq{186 DELETE FROM instance187 WHERE so_id = ?188 },189 185 get_object_from_uri => qq{ 190 186 SELECT so_id … … 218 214 GROUP BY so_id 219 215 }, 220 copy_ instances_to_deleted => qq{216 copy_dead_instances_to_deleted => qq{ 221 217 INSERT INTO deleted 222 218 SELECT vol_id, uri, NULL 223 219 FROM instance 220 LEFT JOIN mountedvol 221 USING(vol_id) 224 222 WHERE 225 223 so_id = ? 224 AND (mountedvol.available IS NULL || mountedvol.available = 0) 225 }, 226 find_dead_instances_by_so_id => qq{ 227 SELECT so_id, ins_id, vol_id, uri 228 FROM instance 229 LEFT JOIN mountedvol 230 USING(vol_id) 231 WHERE 232 so_id = ? 233 AND (mountedvol.available IS NULL || mountedvol.available = 0) 226 234 }, 227 235 get_object_instances => qq{ … … 329 337 }, 330 338 find_object_by_ext_id => qq{ 331 SELECT ext_id, ext_id_basename339 SELECT so_id, ext_id, ext_id_basename 332 340 FROM storage_object 333 341 WHERE ext_id = ?
Note:
See TracChangeset
for help on using the changeset viewer.
