Changeset 20176
- Timestamp:
- Oct 15, 2008, 10:58:02 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/bin/neb-admin (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/bin/neb-admin
r20060 r20176 3 3 # Copyright (C) 2005-2008 Joshua Hoblitt 4 4 # 5 # $Id: neb-admin,v 1.1 2 2008-10-11 02:13:23jhoblitt Exp $5 # $Id: neb-admin,v 1.13 2008-10-15 20:58:02 jhoblitt Exp $ 6 6 7 7 use strict; … … 12 12 13 13 use DBI; 14 use Nebulous::Client;15 #use Nebulous::Server::SQL;16 14 use Net::Server::Daemonize qw( check_pid_file create_pid_file unlink_pid_file ); 17 15 use URI; … … 20 18 use Pod::Usage qw( pod2usage ); 21 19 22 my ($db, $dbhost, $dbuser, $dbpass, $pending, $limit, $verbose); 20 my ( 21 $db, 22 $dbhost, 23 $dbpass, 24 $dbuser, 25 $limit, 26 $pending, 27 $removal, 28 $verbose, 29 ); 23 30 24 31 $db = $ENV{'NEB_DB'}; … … 33 40 'pass|p=s' => \$dbpass, 34 41 'pendingreplicate|r' => \$pending, 42 'pendingremoval' => \$removal, 35 43 'limit|l=i' => \$limit, 36 44 'verbose|v' => \$verbose, … … 44 52 if defined $limit and not defined $pending; 45 53 pod2usage( -msg => "no operation specified", -exitval => 2 ) 46 unless defined $pending ;54 unless defined $pending or defined $removal; 47 55 48 56 # set default limit to 5 … … 67 75 ); 68 76 69 #my $sql = Nebulous::Server::SQL->new(); 70 77 if ($pending) { 78 pending(); 79 } elsif ($removal) { 80 removal(); 81 } else { 82 die "THIS SHOULD NOT HAPPEN"; 83 } 84 85 sub pending 86 { 71 87 # so_id, ext_id, instances, available_instances, need_recovery, recoverable 88 $dbh->do("CREATE TEMPORARY TABLE mymountedvol LIKE mountedvol"); 89 $dbh->do("INSERT INTO mymountedvol SELECT * FROM mountedvol"); 90 $dbh->do("CREATE TEMPORARY TABLE myvolume LIKE volume"); 91 $dbh->do("INSERT INTO myvolume SELECT * FROM volume"); 92 93 my $query = $dbh->prepare( 94 " SELECT 95 storage_object.so_id, 96 ext_id, 97 count(ins_id) as instances, 98 myvolume.name as volume_name, 99 myvolume.host as volume_host, 100 count(mymountedvol.vol_id) as available_instances, 101 count(mymountedvol.vol_id) > 0 as recoverable, 102 storage_object_xattr.value as copies 103 FROM storage_object 104 JOIN instance 105 USING(so_id) 106 JOIN myvolume 107 USING(vol_id) 108 LEFT JOIN storage_object_xattr 109 ON storage_object.so_id = storage_object_xattr.so_id 110 JOIN mymountedvol 111 USING(vol_id) 112 WHERE mymountedvol.available = 1 113 -- WHERE storage_object_xattr.name = 'user.copies' 114 GROUP BY so_id 115 HAVING available_instances < instances OR instances < copies 116 LIMIT $limit" 117 ); 118 $query->execute; 119 120 $dbh->do("DROP TABLE IF EXISTS mymountedvol"); 121 122 my @rows; 123 while (my $row = $query->fetchrow_hashref) { 124 push @rows, $row; 125 } 126 $query->finish; 127 128 exit unless scalar @rows; 129 130 print "replicatePending MULTI\n\n"; 131 132 foreach my $obj (@rows) { 133 if (defined $verbose) { 134 require Data::Dumper; 135 print Data::Dumper::Dumper($obj); 136 } 137 138 my $so_id = $obj->{so_id}; 139 my $key = $obj->{ext_id}; 140 my $has = $obj->{instances}; 141 my $vol_name = $obj->{volume_name}; 142 my $vol_host = $obj->{volume_host}; 143 my $available = $obj->{available_instances} || 0; 144 my $need_recovery = $obj->{need_recovery}; 145 my $recoverable = $obj->{recoverable}; 146 # if the copies xattr is unset and the object has 2 or more instances, we 147 # will assume a target of 2 copies 148 my $copies = $obj->{copies} || 2; 149 150 # objects with only a single instance that are offline are unrecoverable so 151 # we don't need to handle that special case 152 # next unless $need_recovery; 153 unless ($recoverable) { 154 warn "so_id: $so_id key: \'$key\' ", 155 "can not be recovered - no available instances\n"; 156 next; 157 } 158 159 my $need = $copies - $available; 160 $need = 0 if $need < 0; 161 162 next unless $need; 163 164 my %md = ( 165 key => $key, 166 need_copies => $need, 167 volume_name => $vol_name, 168 volume_host => $vol_host, 169 ); 170 171 print_metadata("replicatePending", \%md); 172 print "\n"; 173 } 174 175 return 1; 176 } 177 178 179 sub removal 72 180 { 73 my $query = $dbh->prepare("CREATE TEMPORARY TABLE mymountedvol LIKE mountedvol"); 181 # so_id, ext_id, instances, available_instances, need_recovery, recoverable 182 $dbh->do("CREATE TEMPORARY TABLE mymountedvol LIKE mountedvol"); 183 $dbh->do("INSERT INTO mymountedvol SELECT * FROM mountedvol"); 184 $dbh->do("CREATE TEMPORARY TABLE myvolume LIKE volume"); 185 $dbh->do("INSERT INTO myvolume SELECT * FROM volume"); 186 187 my $query = $dbh->prepare( 188 ); 74 189 $query->execute; 190 191 $dbh->do("DROP TABLE IF EXISTS mymountedvol"); 192 193 my @rows; 194 while (my $row = $query->fetchrow_hashref) { 195 push @rows, $row; 196 } 197 $query->finish; 198 199 exit unless scalar @rows; 200 201 print "replicatePending MULTI\n\n"; 202 203 foreach my $obj (@rows) { 204 if (defined $verbose) { 205 require Data::Dumper; 206 print Data::Dumper::Dumper($obj); 207 } 208 209 my $so_id = $obj->{so_id}; 210 my $key = $obj->{ext_id}; 211 my $has = $obj->{instances}; 212 my $vol_name = $obj->{volume_name}; 213 my $vol_host = $obj->{volume_host}; 214 my $available = $obj->{available_instances} || 0; 215 my $need_recovery = $obj->{need_recovery}; 216 my $recoverable = $obj->{recoverable}; 217 # if the copies xattr is unset and the object has 2 or more instances, we 218 # will assume a target of 2 copies 219 my $copies = $obj->{copies} || 2; 220 221 # objects with only a single instance that are offline are unrecoverable so 222 # we don't need to handle that special case 223 # next unless $need_recovery; 224 unless ($recoverable) { 225 warn "so_id: $so_id key: \'$key\' ", 226 "can not be recovered - no available instances\n"; 227 next; 228 } 229 230 my $need = $copies - $available; 231 $need = 0 if $need < 0; 232 233 next unless $need; 234 235 my %md = ( 236 key => $key, 237 need_copies => $need, 238 volume_name => $vol_name, 239 volume_host => $vol_host, 240 ); 241 242 print_metadata("replicatePending", \%md); 243 print "\n"; 244 } 245 246 return 1; 75 247 } 76 248 77 {78 my $query = $dbh->prepare("INSERT INTO mymountedvol SELECT * FROM mountedvol");79 $query->execute;80 }81 82 {83 my $query = $dbh->prepare("CREATE TEMPORARY TABLE myvolume LIKE volume");84 $query->execute;85 }86 87 {88 my $query = $dbh->prepare("INSERT INTO myvolume SELECT * FROM volume");89 $query->execute;90 }91 92 my $query = $dbh->prepare(93 " SELECT94 storage_object.so_id,95 ext_id,96 count(ins_id) as instances,97 myvolume.name as volume_name,98 myvolume.host as volume_host,99 count(mymountedvol.vol_id) as available_instances,100 count(mymountedvol.vol_id) > 0 as recoverable,101 storage_object_xattr.value as copies102 FROM storage_object103 JOIN instance104 USING(so_id)105 JOIN myvolume106 USING(vol_id)107 LEFT JOIN storage_object_xattr108 ON storage_object.so_id = storage_object_xattr.so_id109 JOIN mymountedvol110 USING(vol_id)111 WHERE mymountedvol.available = 1112 -- WHERE storage_object_xattr.name = 'user.copies'113 GROUP BY so_id114 HAVING available_instances < instances OR instances < copies115 LIMIT $limit" );116 $query->execute;117 118 $dbh->do("DROP TABLE IF EXISTS mymountedvol");119 120 my @rows;121 while (my $row = $query->fetchrow_hashref) {122 push @rows, $row;123 }124 $query->finish;125 126 exit unless scalar @rows;127 128 print "replicatePending MULTI\n\n";129 130 foreach my $obj (@rows) {131 if (defined $verbose) {132 require Data::Dumper;133 print Data::Dumper::Dumper($obj);134 }135 136 my $so_id = $obj->{so_id};137 my $key = $obj->{ext_id};138 my $has = $obj->{instances};139 my $vol_name = $obj->{volume_name};140 my $vol_host = $obj->{volume_host};141 my $available = $obj->{available_instances} || 0;142 my $need_recovery = $obj->{need_recovery};143 my $recoverable = $obj->{recoverable};144 # if the copies xattr is unset and the object has 2 or more instances, we145 # will assume a target of 2 copies146 my $copies = $obj->{copies} || 2;147 148 # objects with only a single instance that are offline are unrecoverable so149 # we don't need to handle that special case150 # next unless $need_recovery;151 unless ($recoverable) {152 warn "so_id: $so_id key: \'$key\' ",153 "can not be recovered - no available instances\n";154 next;155 }156 157 my $need = $copies - $available;158 $need = 0 if $need < 0;159 160 next unless $need;161 162 my %md = (163 key => $key,164 need_copies => $need,165 volume_name => $vol_name,166 volume_host => $vol_host,167 );168 169 print_metadata("replicatePending", \%md);170 print "\n";171 }172 249 173 250 sub print_metadata
Note:
See TracChangeset
for help on using the changeset viewer.
