in bulkloader/src/main/java/org/apache/directory/mavibot/btree/MavibotPartitionBuilder.java [804:991]
public void buildPartition()
{
// First, we load the Schema, as we will check the entries before
// injecting them into the partition
try
{
System.out.println( "Loading schema using JarLdifSchemaLoader" );
JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
schemaManager = new DefaultSchemaManager( loader );
schemaManager.loadAllEnabled();
dnFactory = new DefaultDnFactory( schemaManager, null );
cacheService = new CacheService();
InstanceLayout instanceLayout = new InstanceLayout( outputDir );
cacheService.initialize( instanceLayout );
}
catch ( Exception e )
{
e.printStackTrace();
LOG.warn( "Failed to initialize the schema manager", e );
return;
}
// Now, read all the DNs, and sort them
Set<DnTuple> sortedDnSet = null;
try
{
long sortT0 = System.currentTimeMillis();
System.out.println( "Sorting the LDIF data..." );
sortedDnSet = getDnTuples();
long sortT1 = System.currentTimeMillis();
totalEntries = sortedDnSet.size();
System.out.println( "Completed sorting, total number of entries " + totalEntries +
", time taken : " + ( sortT1 - sortT0 ) + "ms" );
}
catch ( Exception e )
{
e.printStackTrace();
LOG.warn( "Failed to parse the given LDIF file ", e );
return;
}
if ( ( sortedDnSet == null ) || ( sortedDnSet.isEmpty() ) )
{
String message = "No entries found in the given LDIF file, aborting bulk load";
System.out.println( message );
LOG.info( message );
}
MavibotPartition partition = null;
try
{
long partT0 = System.currentTimeMillis();
System.out.print( "Creating partition..." );
partition = new MavibotPartition( schemaManager, dnFactory );
partition.setId( "builder" );
partition.setSuffixDn( suffixDn );
File dir = new File( outputDir );
partition.setPartitionPath( dir.toURI() );
partition.setCacheService( cacheService );
for( String atName : indexAttributes )
{
schemaManager.lookupAttributeTypeRegistry( atName );
partition.addIndex( new MavibotIndex( atName, false ) );
}
partition.initialize();
masterTableName = partition.getMasterTable().getName();
rm = partition.getRecordMan();
long partT1 = System.currentTimeMillis();
System.out.println( ", time taken : " + ( partT1 - partT0 ) + "ms" );
}
catch ( Exception e )
{
e.printStackTrace();
LOG.warn( "Failed to initialize the partition", e );
return;
}
try
{
long masterT0 = System.currentTimeMillis();
System.out.print( "Building master table..." );
buildMasterTable( sortedDnSet );
long masterT1 = System.currentTimeMillis();
System.out.println( ", time taken : " + ( masterT1 - masterT0 ) + "ms" );
}
catch( Exception e )
{
e.printStackTrace();
LOG.warn( "Failed to build master table", e );
e.printStackTrace();
return;
}
Iterator<String> userIndexItr = partition.getUserIndices();
try
{
// the RecordManager must be re-initialized cause we are
// setting the "values" of leaves to null while building
// the tree to avoid OOM errors
partition.destroy();
rm = new RecordManager( new File( partition.getPartitionPath() ).getAbsolutePath() );
long rdnT0 = System.currentTimeMillis();
System.out.print( "Building RDN index." );
buildRdnIndex( sortedDnSet );
long rdnT1 = System.currentTimeMillis();
System.out.println( ", time taken : " + ( rdnT1 - rdnT0 ) + "ms" );
}
catch( Exception e )
{
e.printStackTrace();
LOG.warn( "Failed to build the RDN index", e );
return;
}
// not needed anymore
System.out.println( "Clearing the sorted DN set." );
sortedDnSet.clear();
for( Index<?, String> id : partition.getAllIndices() )
{
// RDN and presence indices are built separately
String oid = id.getAttribute().getOid();
if( ApacheSchemaConstants.APACHE_RDN_AT_OID.equals( oid )
|| ApacheSchemaConstants.APACHE_PRESENCE_AT_OID.equals( oid ) )
{
continue;
}
String ignoreVal = null;
if( SchemaConstants.OBJECT_CLASS_AT_OID.equals( oid ) )
{
// should be a normalized val
ignoreVal = "top";
}
try
{
long indexT0 = System.currentTimeMillis();
System.out.print("Building index " + id.getAttribute().getName() );
buildIndex( id, ignoreVal );
long indexT1 = System.currentTimeMillis();
System.out.println( ", time taken : " + ( indexT1 - indexT0 ) + "ms" );
}
catch( Exception e )
{
e.printStackTrace();
LOG.warn( "Failed to build the index " + id.getAttribute().getName() );
LOG.warn( "", e );
return;
}
}
try
{
System.out.print( "Building presence index..." );
long presenceT0 = System.currentTimeMillis();
buildPresenceIndex( userIndexItr );
long presenceT1 = System.currentTimeMillis();
System.out.println( ", time taken : " + ( presenceT1 - presenceT0 ) + "ms" );
}
catch( Exception e )
{
e.printStackTrace();
LOG.warn( "Failed to build the presence index." );
LOG.warn( "", e );
return;
}
System.out.println( "Patition building complete." );
}