- Timestamp:
- Jun 25, 2009, 2:00:56 PM (17 years ago)
- Location:
- branches/eam_branches/20090522
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
Nebulous-Server (modified) (1 prop)
-
Nebulous-Server/scripts/dirize.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090522
- Property svn:mergeinfo changed
-
branches/eam_branches/20090522/Nebulous-Server
- Property svn:mergeinfo changed
-
branches/eam_branches/20090522/Nebulous-Server/scripts/dirize.pl
r23952 r24557 1 1 #!/usr/bin/env perl 2 3 # query to check for duplicate directory entries 4 # select count(*) from (select so.so_id, so.ext_id, so.dir_id from storage_object as so join (select dir_id, dirname, parent_id, count(*) from directory group by dirname, parent_id having count(*) > 1) as foo on so.dir_id = foo.dir_id) as foo; 2 5 3 6 use strict; … … 23 26 my $db = $neb->_db_for_index(0); 24 27 25 my $n ;26 {27 my $query = $db->prepare("SELECT COUNT(*) as n FROM storage_object");28 $query->execute;29 $n = $query->fetchrow_hashref->{'n'};30 }28 my $n = 0; 29 #{ 30 # my $query = $db->prepare("SELECT COUNT(*) as n FROM storage_object"); 31 # $query->execute; 32 # $n = $query->fetchrow_hashref->{'n'}; 33 #} 31 34 32 my $query = $db->prepare_cached("SELECT so_id, ext_id, dir_id FROM storage_object AS so WHERE so.dir_id = 0 LIMIT 1000"); 35 # repair directory duplication 36 #my $query = $db->prepare_cached("select so.so_id, so.ext_id, so.dir_id from storage_object as so join (select dir_id, dirname, parent_id, count(*) from directory group by dirname, parent_id having count(*) > 1) as foo on so.dir_id = foo.dir_id limit 1000"); 37 38 # initial directory fill in 39 my $work_query = $db->prepare_cached("SELECT so_id, ext_id, dir_id FROM storage_object AS so WHERE so.dir_id = 0 LIMIT 1000"); 40 41 my $update_query = $db->prepare_cached("UPDATE storage_object SET ext_id_basename = ?, dir_id = ? WHERE so_id = ?"); 42 43 # turn of fkeys, otherwise we can change storage_object.dir_id to a 44 # non-existant value 45 $db->do("SET FOREIGN_KEY_CHECKS=0"); 46 #$db->do("UPDATE storage_object SET dir_id = 0"); 47 48 # completely reset the directory table 49 #$db->do("DELETE FROM directory"); 50 #$db->do("ALTER TABLE directory AUTO_INCREMENT = 1"); 51 # make sure these duplicates can't happen again 52 #$db->do("alter table directory add unique key(dirname,parent_id)"); 53 # seed the root ('/') directory 54 #$db->do("INSERT INTO directory VALUES(1, '/', 1)"); 33 55 34 56 my $i = 0; 35 while ($query->execute and $query->rows) { 36 print "foo\n"; 37 while (my $row = $query->fetchrow_hashref) { 57 while ($work_query->execute and $work_query->rows) { 58 while (my $row = $work_query->fetchrow_hashref) { 38 59 $i++; 39 60 my $key = parse_neb_key($row->{'ext_id'}); … … 41 62 42 63 #printf("dirizing %20s basename: %20s parent_id %10d\n", $key, basename($row->{'ext_id'}), $parent_id); 43 printf("$i/$ndirizing %s\n", $key->path);64 # printf("$i dirizing %s\n", $key->path); 44 65 45 my $q = $db->prepare_cached("UPDATE storage_object SET ext_id_basename = ?, dir_id = ? WHERE so_id = ?"); 46 $q->execute(basename($row->{'ext_id'}), $parent_id, $row->{'so_id'}); 47 $db->commit; 66 $update_query->execute(basename($row->{'ext_id'}), $parent_id, $row->{'so_id'}); 48 67 } 49 $query->finish; 68 $db->commit; 69 printf("### COMMIT ###\n"); 70 $work_query->finish; 71 printf("dirized $i\n"); 50 72 } 73 74 $db->do("SET FOREIGN_KEY_CHECKS=1"); 75 $db->commit;
Note:
See TracChangeset
for help on using the changeset viewer.
