directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r948522 - in /directory/apacheds/trunk/jdbm-store/src: main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Date Wed, 26 May 2010 18:29:23 GMT
Author: kayyagari
Date: Wed May 26 18:29:22 2010
New Revision: 948522

URL: http://svn.apache.org/viewvc?rev=948522&view=rev
Log:
fix for DIRSERVER-1417

Modified:
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=948522&r1=948521&r2=948522&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
Wed May 26 18:29:22 2010
@@ -21,6 +21,7 @@ package org.apache.directory.server.core
 
 
 import java.io.File;
+import java.io.FilenameFilter;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -128,6 +129,8 @@ public class JdbmStore<E> extends Abstra
         setupSystemIndices();
         setupUserIndices();
 
+        deleteUnusedIndexFiles();
+        
         // We are done !
         initialized = true;
     }
@@ -274,4 +277,57 @@ public class JdbmStore<E> extends Abstra
         return jdbmIndex;
     }
 
+    
+    /**
+     * removes any unused/removed attribute index files present under the partition's
+     * working directory
+     */
+    private void deleteUnusedIndexFiles()
+    {
+        final String jdbmDbFileExtn = ".db";
+        
+        FilenameFilter filter = new FilenameFilter()
+        {
+            
+            public boolean accept( File dir, String name )
+            {
+                // really important to filter master.db and master.lg files
+                return ( name.endsWith( jdbmDbFileExtn ) && !name.startsWith( "master."
) );
+            }
+        };
+        
+        File[] dbFiles = getPartitionDir().listFiles( filter );
+        
+        List<String> allIndices = new ArrayList<String>();
+        for( Index i : systemIndices.values() )
+        {
+            allIndices.addAll( i.getAttribute().getNames() );
+        }
+        
+        for( Index i : userIndices.values() )
+        {
+            allIndices.addAll( i.getAttribute().getNames() );
+        }
+        
+        for( File file : dbFiles )
+        {
+            String name = file.getName();
+            // take the part after removing .db from the  
+            name = name.substring( 0, name.lastIndexOf( jdbmDbFileExtn ) );
+            
+            // remove the file if not found in the list of names of indices
+            if( !allIndices.contains( name ) )
+            {
+                boolean deleted = file.delete();
+                if( deleted )
+                {
+                    LOG.info( "Deleted unused index file {}", file.getAbsolutePath() );
+                }
+                else
+                {
+                    LOG.warn( "Failed to delete unused index file {}", file.getAbsolutePath()
);
+                }
+            }
+        }
+    }
 }

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=948522&r1=948521&r2=948522&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
Wed May 26 18:29:22 2010
@@ -889,4 +889,42 @@ public class JdbmStoreTest
         store.modify( dn, mods );
         assertEquals( attribVal, lookedup.get( "ou" ).get().getString() );
     }
+    
+    
+    @Test
+    public void testDeleteUnusedIndexFiles() throws Exception
+    {
+        File ouIndexDbFile = new File( wkdir, "ou.db" );
+        File uuidIndexDbFile = new File( wkdir, "entryUUID.db" );
+        
+        assertTrue( ouIndexDbFile.exists() );
+        assertTrue( uuidIndexDbFile.exists() );
+        
+        // destroy the store to manually start the init phase
+        // by keeping the same work dir
+        store.destroy();
+        
+        // just assert again that ou and entryUUID files exist even after destroying the
store
+        assertTrue( ouIndexDbFile.exists() );
+        assertTrue( uuidIndexDbFile.exists() );
+        
+        store = new JdbmStore<Entry>();
+        store.setId( "example" );
+        store.setCacheSize( 10 );
+        store.setPartitionDir( wkdir );
+        store.setSyncOnWrite( false );
+        // do not add ou index this time
+        store.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) );
+
+        
+        DN suffixDn = new DN( "o=Good Times Co." );
+        suffixDn.normalize( schemaManager.getNormalizerMapping() );
+        store.setSuffixDn( suffixDn );
+        // init the store to call deleteUnusedIndexFiles() method
+        store.init( schemaManager );
+
+        assertFalse( ouIndexDbFile.exists() );
+        assertTrue( uuidIndexDbFile.exists() );
+    }
+    
 }



Mime
View raw message