[Fedora-directory-commits] ldapserver/ldap/admin/src/scripts DSMigration.pm.in, 1.17, 1.18 migrate-ds.res, 1.5, 1.6

Richard Allen Megginson (rmeggins) fedora-directory-commits at redhat.com
Fri Oct 5 02:30:09 UTC 2007


Author: rmeggins

Update of /cvs/dirsec/ldapserver/ldap/admin/src/scripts
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv25350/ldapserver/ldap/admin/src/scripts

Modified Files:
	DSMigration.pm.in migrate-ds.res 
Log Message:
Resolves: bug 249366
Bug Description: rhds71 - search filters returns too many entries on interger attributes value greater than 2 to the 31
Reviewed by: nhosoi, nkinder (Thanks!)
Fix Description: This handles the migration part.  The first part is when migrating the schema.  Look for all integer syntax attributes.  This can be tricky if there are SUP attribute types derived from integer syntax attributes.  numSubordinates and hasSubordinates are skipped because they are handled specially by the db code.   The next step is to scan all of the index files in the new db directory.  If any integer indexes are found, they will be removed and recreated.
Platforms tested: RHEL5 x86_64
Flag Day: no
Doc impact: Yes.  Will need to document that this happens during migration if not cross platform.
QA impact: should be covered by regular nightly and manual testing
New Tests integrated into TET: Will need to create some integer indexes and do same platform migration to see if this works



Index: DSMigration.pm.in
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/DSMigration.pm.in,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- DSMigration.pm.in	24 Sep 2007 22:54:47 -0000	1.17
+++ DSMigration.pm.in	5 Oct 2007 02:30:07 -0000	1.18
@@ -311,6 +311,45 @@
     return $tmpldiffile;
 }
 
+sub fixIntegerIndexes {
+    my $mig = shift;
+    my $inst_dir = shift;
+    my $newdbdir = shift;
+
+    if (!$mig->{integerattrs}) {
+        debug(1, "No integer syntax attributes, no indexes fixed\n");
+        return ();
+    }
+
+    # look at each index file in the db dir
+    # if it is on our list of integer attributes,
+    # remove it and re-create it
+    my $dbname = basename($newdbdir);
+    for (glob("$newdbdir/*.db4")) {
+        my $indexname = basename($_, '.db4');
+        if ($mig->{integerattrs}->{lc $indexname}) {
+            $mig->msg($INFO, 'fixing_integer_attr_index', $indexname, $newdbdir);
+            debug(1, "Removing file $_\n");
+            if (! unlink $_) {
+                debug(1, "Error: could not remove file $_: $!\n");
+                return ('error_removing_index_file', $_, $!);
+            }
+            my $cmd = "$inst_dir/db2index -n \"$dbname\" -t \"$indexname\"";
+            debug(1, "Re-creating index file $_: $cmd\n");
+            $? = 0; # clear error condition
+            my $output = `$cmd 2>&1`;
+            if ($?) {
+                return ('error_recreating_index_file', $_, $output);
+            }
+            debug(1, $output);
+        } else {
+            debug(3, "Index $indexname is not for an integer syntax attribute - skipping\n");
+        }
+    }
+
+    return ();
+}
+
 # migrate all of the databases in an instance
 sub migrateDatabases {
     my $mig = shift; # the Migration object
@@ -436,6 +475,15 @@
                 if (@errs = copyDatabaseDirs($srcdir, "$newdbdir")) {
                     return @errs;
                 }
+                # fix up the integer indexes
+                if ($mig->{integerattrs}) {
+                    debug(3, "The schema has some integer attributes\n");
+                    if (@errs = fixIntegerIndexes($mig, $inst_dir, $newdbdir)) {
+                        return @errs;
+                    }
+                } else {
+                    debug(3, "No integer attributes to fix for $newdbdir\n");
+                }
             }
         }
     } while ($ent = $src->nextEntry());
@@ -680,6 +728,12 @@
     '51ns-calendar'        => '51ns-calendar.ldif'
 );
 
+# these indexes are handled specially by the db code
+my %intattrstoskip = (
+    'numsubordinates' => 'numSubordinates',
+    'hassubordinates' => 'hasSubordinates'
+);
+
 sub migrateSchema {
     my $mig = shift; # the Migration object
     my $inst = shift; # the instance name (e.g. slapd-instance)
@@ -700,6 +754,39 @@
         }
     }
 
+    if (!$mig->{crossplatform}) {
+        # now, for all of the new schema, we need to get the list of attribute
+        # types with INTEGER syntax, including derived types (e.g. SUP 'attr')
+        # not required for cross platform because import of the old ldif file
+        # will automatically recreate all indexes
+        my %intattrs = ();
+        for (glob("$newschemadir/*.ldif")) {
+            # read in schema entry from LDIF
+            open( MYSCHEMA, $_ ) || die "Can't open $_: $!";
+            my $in = new Mozilla::LDAP::LDIF(*MYSCHEMA);
+            while (my $ent = readOneEntry $in) {
+                my @attrs = $ent->getValues('attributeTypes');
+                foreach my $attr (@attrs) {
+                    # first see if the attribute definition uses INTEGER syntax
+                    # else see if the super uses INTEGER - note this assumes the attributes
+                    # are listed in the files in SUP order - that is, an attribute does
+                    # not reference a SUP before it is defined
+                    if ($attr =~ / NAME (?:\(\s)?[\']?(\w+)[\']?.* SYNTAX 1.3.6.1.4.1.1466.115.121.1.27[\{\s]/) {
+                        next if ($intattrstoskip{lc $1});
+                        $intattrs{lc $1} = $1;
+                    } elsif (($attr =~ / NAME (?:\(\s)?[\']?(\w+)[\']?.*SUP [\']?(\w+)[\']?/) &&
+                             $intattrs{lc $2}) {
+                        next if ($intattrstoskip{lc $1});
+                        $intattrs{lc $1} = $1;
+                    }
+                }
+            }
+            close MYSCHEMA;
+        }
+        # %intattrs now contains all of the integer valued attributes
+        $mig->{integerattrs} = \%intattrs; # hashref
+    }
+
     return ();
 }
 


Index: migrate-ds.res
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/migrate-ds.res,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- migrate-ds.res	30 Aug 2007 00:06:51 -0000	1.5
+++ migrate-ds.res	5 Oct 2007 02:30:07 -0000	1.6
@@ -22,3 +22,6 @@
 database files are not binary compatible, and the new databases must\
 be initialized from an LDIF export of the old databases.  Please refer\
 to the migration instructions for help with how to do this.\n\n
+fixing_integer_attr_index = The index for the attribute '%s' in the database directory '%s' will be removed and re-created.\n\n
+error_removing_index_file = Could not remove the index file '%s'.  Error: %s\n\n
+error_recreating_index_file = Could not re-create the index file '%s'.  Error: %s\n\n




More information about the Fedora-directory-commits mailing list