Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r10928: LJSUP-9636 (make moveucluster more rigor...

Committer: ailyin
LJSUP-9636 (make moveucluster more rigorous checking tables)
U   trunk/cgi-bin/LJ/UserManage.pm
Modified: trunk/cgi-bin/LJ/UserManage.pm
===================================================================
--- trunk/cgi-bin/LJ/UserManage.pm	2011-08-26 03:41:51 UTC (rev 10927)
+++ trunk/cgi-bin/LJ/UserManage.pm	2011-08-26 03:50:45 UTC (rev 10928)
@@ -46,7 +46,7 @@
     'eventratescounters' => { 'copy_policy' => 'chunks', 'userid' => 'journalid', 'id' => 'itemid' },
     'friending_actions_q' => { 'userid' => 'userid', 'id' => 'rec_id', 'copy_policy' => 'chunks' },
     'friendgroup2' => { 'copy_policy' => 'whole' },
-    'friendstimes' => { 'copy_policy' => 'whole', id => 'userid' },
+    'friendstimes' => { 'copy_policy' => 'whole' },
     'fotki_albums' => { 'copy_policy' => 'chunks', 'id' => 'album_id' },
     'fotki_photos' => { 'copy_policy' => 'chunks', 'id' => 'photo_id' },
     'fotki_photos_data' => { 'copy_policy' => 'chunks', 'id' => 'photo_id' },
@@ -394,6 +394,66 @@
             join("\n", map { "   $_" } @unspecified_tables) . "\n";
         die $message;
     }
+
+    foreach my $table (@tables) {
+        my $info = $table_info{$table};
+
+        # if $info is not a reference, it only can be equal to 'ignore'
+        next if ref $info eq '' && $info eq 'ignore';
+        die "invalid info '$info' for table $table\n" if ref $info eq '';
+
+        # now, require that it is a hashref
+        unless ( ref $info eq 'HASH' ) {
+            my $type = ref $info;
+            die "invalid info type for table $table: $type\n";
+        }
+
+        my $copy_policy = $info->{'copy_policy'};
+        unless ($copy_policy) {
+            die "no copy policy found for table $table\n";
+        }
+
+        # if it's code, assume it knows what it's doing
+        unless ( ref $copy_policy eq 'CODE' ) {
+            my %valid_policy = map { $_ => 1 } qw( whole chunks regen_id );
+
+            unless ( $valid_policy{$copy_policy} ) {
+                die "invalid copy policy $copy_policy for table $table\n";
+            }
+
+            my $rows = $dbh->selectall_arrayref(
+                "DESCRIBE $table",
+                { 'Slice' => {} },
+            );
+
+            my %column_present = map { $_->{'Field'} => 1 } @$rows;
+
+            my $userid_col = $info->{'userid'} || 'userid';
+            die "userid column '$userid_col' not found in table $table\n"
+                unless $column_present{$userid_col};
+
+            unless ( $copy_policy eq 'whole' ) {
+                my $id_col = $info->{'id'};
+
+                die "id column is required for copy policy $copy_policy\n"
+                    unless $id_col;
+
+                die "id column '$id_col' not found in table $table\n"
+                    unless $column_present{$id_col};
+            }
+        }
+
+        # in the most cases, purge policy is exactly the same as
+        # the copy policy, so we don't bother checking it as rigorously
+        my $purge_policy = $info->{'purge_policy'} || $copy_policy;
+        unless (    ref $purge_policy eq 'CODE'
+                 || $purge_policy eq $copy_policy )
+        {
+            warn "purge policy for table $table ('$purge_policy') differs " .
+                 "from the copy policy ('$copy_policy'), " .
+                 "not checking details\n";
+        }
+    }
 }
  
 1;

Tags: andy, ljcom, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments