You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2013/02/21 16:39:31 UTC
svn commit: r1448684 - in /directory/apacheds/trunk:
core/src/main/java/org/apache/directory/server/core/
jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/
jdbm-partition/src/test/java/org/apache/directory/server/...
Author: elecharny
Date: Thu Feb 21 15:39:30 2013
New Revision: 1448684
URL: http://svn.apache.org/r1448684
Log:
o Removed the useless SynchWorker : we now use the JDBM transaction manager instead.
o Correctly flush the data on disk periodically
o Substring, <=, >= index now return 10 instead of the number of elements in the index. That save us a hell lot of processing when a substring is used in a filter.
o Removed a printStackTrace
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java
directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=1448684&r1=1448683&r2=1448684&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Thu Feb 21 15:39:30 2013
@@ -203,9 +203,6 @@ public class DefaultDirectoryService imp
/** */
private Thread workerThread;
- /** The sync worker thread */
- private SynchWorker worker = new SynchWorker();
-
/** The default timeLimit : 100 entries */
public static final int MAX_SIZE_LIMIT_DEFAULT = 100;
@@ -298,51 +295,6 @@ public class DefaultDirectoryService imp
/** The Subtree evaluator instance */
private SubtreeEvaluator evaluator;
- /**
- * The synchronizer thread. It flush data on disk periodically.
- */
- class SynchWorker implements Runnable
- {
- final Object lock = new Object();
-
- /** A flag to stop the thread */
- boolean stop;
-
-
- /**
- * The main loop
- */
- public void run()
- {
- while ( !stop )
- {
- synchronized ( lock )
- {
- try
- {
- lock.wait( syncPeriodMillis );
- }
- catch ( InterruptedException e )
- {
- LOG.warn( "SynchWorker failed to wait on lock.", e );
- }
- }
-
- try
- {
- // Protect this section against concurrent access
- getOperationManager().lockWrite();
- partitionNexus.sync();
- getOperationManager().unlockWrite();
- }
- catch ( Exception e )
- {
- LOG.error( I18n.err( I18n.ERR_74 ), e );
- }
- }
- }
- }
-
// ------------------------------------------------------------------------
// Constructor
@@ -1275,13 +1227,6 @@ public class DefaultDirectoryService imp
initialize();
showSecurityWarnings();
- // Start the sync thread if required
- if ( syncPeriodMillis > 0 )
- {
- workerThread = new Thread( worker, "SynchWorkerThread" );
- workerThread.start();
- }
-
// load the last stored valid CSN value
LookupOperationContext loc = new LookupOperationContext( getAdminSession(), systemPartition.getSuffixDn(),
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
@@ -1319,6 +1264,8 @@ public class DefaultDirectoryService imp
public synchronized void shutdown() throws Exception
{
+ LOG.debug( "+++ DirectoryService Shutdown required" );
+
if ( !started )
{
return;
@@ -1327,29 +1274,13 @@ public class DefaultDirectoryService imp
// --------------------------------------------------------------------
// Shutdown the sync thread
// --------------------------------------------------------------------
- if ( workerThread != null )
- {
- worker.stop = true;
-
- synchronized ( worker.lock )
- {
- worker.lock.notify();
- }
-
- while ( workerThread.isAlive() )
- {
- LOG.info( "Waiting for SynchWorkerThread to die." );
- workerThread.join( 500 );
- }
- }
- else
- {
- partitionNexus.sync();
- }
+ LOG.debug( "--- Syncing the nexus " );
+ partitionNexus.sync();
// --------------------------------------------------------------------
// Shutdown the changelog
// --------------------------------------------------------------------
+ LOG.debug( "--- Syncing the changeLog " );
changeLog.sync();
changeLog.destroy();
@@ -1358,6 +1289,7 @@ public class DefaultDirectoryService imp
// --------------------------------------------------------------------
if ( journal.isEnabled() )
{
+ LOG.debug( "--- Destroying the journal " );
journal.destroy();
}
@@ -1365,11 +1297,19 @@ public class DefaultDirectoryService imp
// Shutdown the partition
// --------------------------------------------------------------------
+ LOG.debug( "--- Destroying the nexus" );
partitionNexus.destroy();
+ // Last flush...
+ LOG.debug( "--- Flushing everything before quitting" );
+ getOperationManager().lockWrite();
+ partitionNexus.sync();
+ getOperationManager().unlockWrite();
+
// --------------------------------------------------------------------
// And shutdown the server
// --------------------------------------------------------------------
+ LOG.debug( "--- Deleting the cache service" );
cacheService.destroy();
if ( lockFile != null )
@@ -1385,6 +1325,7 @@ public class DefaultDirectoryService imp
}
}
+ LOG.debug( "+++ DirectoryService stopped" );
started = false;
}
Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=1448684&r1=1448683&r2=1448684&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java Thu Feb 21 15:39:30 2013
@@ -679,20 +679,25 @@ public class JdbmIndex<K, V> extends Abs
*/
public synchronized void sync() throws IOException
{
- commit( recMan );
+ // Commit
+ recMan.commit();
- BaseRecordManager baseRecordManager = null;
-
- if ( recMan instanceof CacheRecordManager )
- {
- baseRecordManager = ( ( BaseRecordManager ) ( ( CacheRecordManager ) recMan ).getRecordManager() );
- }
- else
+ // And flush the journal
+ if ( ( commitNumber.get() % 4000 ) == 0 )
{
- baseRecordManager = ( ( BaseRecordManager ) recMan );
- }
+ BaseRecordManager baseRecordManager = null;
+
+ if ( recMan instanceof CacheRecordManager )
+ {
+ baseRecordManager = ( ( BaseRecordManager ) ( ( CacheRecordManager ) recMan ).getRecordManager() );
+ }
+ else
+ {
+ baseRecordManager = ( ( BaseRecordManager ) recMan );
+ }
- baseRecordManager.getTransactionManager().synchronizeLog();
+ baseRecordManager.getTransactionManager().synchronizeLog();
+ }
}
@@ -719,9 +724,9 @@ public class JdbmIndex<K, V> extends Abs
*/
private void commit( RecordManager recordManager ) throws IOException
{
- if ( commitNumber.incrementAndGet() % 4000 == 0 )
+ if ( commitNumber.incrementAndGet() % 2000 == 0 )
{
- recordManager.commit();
+ sync();
}
}
Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?rev=1448684&r1=1448683&r2=1448684&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java Thu Feb 21 15:39:30 2013
@@ -318,14 +318,8 @@ public class JdbmPartition extends Abstr
idx.sync();
}
+ // Sync the master table
( ( JdbmMasterTable ) master ).sync();
- recMan.commit();
-
- if ( recMan instanceof CacheRecordManager )
- {
- ( ( BaseRecordManager ) ( ( CacheRecordManager ) recMan ).getRecordManager() ).getTransactionManager()
- .synchronizeLog();
- }
}
Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=1448684&r1=1448683&r2=1448684&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java Thu Feb 21 15:39:30 2013
@@ -29,6 +29,8 @@ import jdbm.btree.BTree;
import jdbm.helper.Serializer;
import jdbm.helper.Tuple;
import jdbm.helper.TupleBrowser;
+import jdbm.recman.BaseRecordManager;
+import jdbm.recman.CacheRecordManager;
import org.apache.directory.api.ldap.model.cursor.Cursor;
import org.apache.directory.api.ldap.model.cursor.EmptyCursor;
@@ -250,7 +252,7 @@ public class JdbmTable<K, V> extends Abs
public int greaterThanCount( K key ) throws IOException
{
// take a best guess
- return count;
+ return Math.min( count, 10 );
}
@@ -260,7 +262,7 @@ public class JdbmTable<K, V> extends Abs
public int lessThanCount( K key ) throws IOException
{
// take a best guess
- return count;
+ return Math.min( count, 10 );
}
@@ -956,7 +958,26 @@ public class JdbmTable<K, V> extends Abs
{
long recId = recMan.getNamedObject( name + SZSUFFIX );
recMan.update( recId, count );
- commit( recMan );
+
+ // Commit
+ recMan.commit();
+
+ // And flush the journal
+ if ( ( commitNumber.get() % 4000 ) == 0 )
+ {
+ BaseRecordManager baseRecordManager = null;
+
+ if ( recMan instanceof CacheRecordManager )
+ {
+ baseRecordManager = ( ( BaseRecordManager ) ( ( CacheRecordManager ) recMan ).getRecordManager() );
+ }
+ else
+ {
+ baseRecordManager = ( ( BaseRecordManager ) recMan );
+ }
+
+ baseRecordManager.getTransactionManager().synchronizeLog();
+ }
}
@@ -1143,9 +1164,9 @@ public class JdbmTable<K, V> extends Abs
*/
private void commit( RecordManager recordManager ) throws IOException
{
- if ( commitNumber.incrementAndGet() % 4000 == 0 )
+ if ( commitNumber.incrementAndGet() % 2000 == 0 )
{
- recordManager.commit();
+ sync();
}
}
}
Modified: directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java?rev=1448684&r1=1448683&r2=1448684&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndexTest.java Thu Feb 21 15:39:30 2013
@@ -336,7 +336,8 @@ public class JdbmIndexTest
idx.add( String.valueOf( ch ), Strings.getUUID( ch ) );
}
- assertEquals( 26, idx.greaterThanCount( "a" ) );
+ // We should not go above the magic limit of 10
+ assertEquals( 10, idx.greaterThanCount( "a" ) );
}
@@ -351,7 +352,8 @@ public class JdbmIndexTest
idx.add( String.valueOf( ch ), Strings.getUUID( ch ) );
}
- assertEquals( 26, idx.lessThanCount( "z" ) );
+ // We should not go above the magic limit of 10
+ assertEquals( 10, idx.lessThanCount( "z" ) );
}
Modified: directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=1448684&r1=1448683&r2=1448684&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java Thu Feb 21 15:39:30 2013
@@ -453,8 +453,8 @@ public class JdbmTableWithDuplicatesTest
* case guesses are allowed.
*/
- assertEquals( SIZE, table.lessThanCount( "5" ) );
- assertEquals( SIZE, table.greaterThanCount( "5" ) );
+ assertEquals( 10, table.lessThanCount( "5" ) );
+ assertEquals( 10, table.greaterThanCount( "5" ) );
}
Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java?rev=1448684&r1=1448683&r2=1448684&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java Thu Feb 21 15:39:30 2013
@@ -787,7 +787,6 @@ public abstract class AbstractBTreeParti
}
catch ( Exception e )
{
- e.printStackTrace();
throw new LdapException( e );
}
}