IndexRebuildThread.java revision a395dd575518d9e5280fc5d5d5ef47c61b174647
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
*/
/**
* A thread to do the actual work of rebuilding an index.
*/
public class IndexRebuildThread extends DirectoryThread
{
/**
* The tracer object for the debug logger.
*/
/**
* The entry container.
*/
/**
*/
/**
* The attribute indexType to rebuild.
*/
/**
* The VLV index to rebuild.
*/
/**
* The indexType to rebuild.
*/
/**
* The ID2ENTRY database.
*/
/**
* The number of total entries to rebuild. An negative value indicates this
* value is not yet known.
*/
long totalEntries = -1;
/**
* The number of entries processed.
*/
long processedEntries = 0;
/**
* The number of entries rebuilt successfully.
*/
long rebuiltEntries = 0;
/**
* The number of entries rebuilt with possible duplicates.
*/
long duplicatedEntries = 0;
/**
* The number of entries that were skipped because they were not applicable
* for the indexType or because an error occurred.
*/
long skippedEntries = 0;
/**
* The types of internal indexes that are rebuildable.
*/
enum IndexType
{
}
/**
* Construct a new index rebuild thread to rebuild a system index.
*
* @param ec The entry container to rebuild in.
* @param index The index type to rebuild.
*/
{
}
/**
* Construct a new index rebuild thread to rebuild an index.
*
* @param ec The entry container to rebuild in.
* @param index The index to rebuild.
*/
{
}
/**
* Construct a new index rebuild thread to rebuild an attribute index.
*
* @param ec The entry container to rebuild in.
* @param index The attribute index to rebuild.
*/
{
}
/**
* Construct a new index rebuild thread to rebuild an VLV index.
*
* @param ec The entry container to rebuild in.
* @param vlvIndex The VLV index to rebuild.
*/
{
}
/**
* Clear the database and prep it for the rebuild.
*
* @throws DatabaseException if a JE databse error occurs while clearing
* the database being rebuilt.
*/
public void clearDatabase() throws DatabaseException
{
{
//TODO: throw error
if(debugEnabled())
{
"terminated.");
}
return;
}
{
//TODO: throw error
if(debugEnabled())
{
"terminated.");
}
return;
}
{
//TODO: throw error
if(debugEnabled())
{
}
return;
}
{
//TODO: throw error
if(debugEnabled())
{
"terminated.");
}
return;
}
switch(indexType)
{
case DN2ID :
break;
case DN2URI :
break;
case ID2CHILDREN :
break;
case ID2SUBTREE :
break;
case ATTRIBUTEINDEX :
attrIndex.setRebuildStatus(true);
break;
case VLVINDEX :
vlvIndex.setRebuildStatus(true);
break;
case INDEX :
index.setRebuildStatus(true);
}
}
/**
* Start the rebuild process.
*/
public void run()
{
{
//TODO: throw error
if(debugEnabled())
{
"terminated.");
}
return;
}
{
//TODO: throw error
if(debugEnabled())
{
"terminated.");
}
return;
}
{
//TODO: throw error
if(debugEnabled())
{
}
return;
}
{
//TODO: throw error
if(debugEnabled())
{
"terminated.");
}
return;
}
try
{
switch(indexType)
{
case DN2ID : rebuildDN2ID();
break;
case DN2URI : rebuildDN2URI();
break;
case ID2CHILDREN : rebuildID2Children();
break;
case ID2SUBTREE : rebuildID2Subtree();
break;
break;
break;
}
if(debugEnabled())
{
}
}
catch(Exception e)
{
this.getName(), stackTraceToSingleLineString(e));
if(debugEnabled())
{
}
}
}
/**
* Rebuild an interal DN2ID database.
*
* @throws DatabaseException If an error occurs during the rebuild.
*/
private void rebuildDN2ID() throws DatabaseException
{
if(debugEnabled())
{
}
//Iterate through the id2entry database and insert associated dn2id
//records.
try
{
{
try
{
// Insert into dn2id.
{
}
else
{
// The entry ID already exists in the database.
// This could happen if some other process got to this entry
// before we did. Since the backend should be offline, this
// might be a problem.
if(debugEnabled())
{
"into the DN2ID database because it already exists.",
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
}
finally
{
}
}
/**
* Rebuild the ID2URI internal database.
*
* @throws DatabaseException if an error occurs during rebuild.
*/
private void rebuildDN2URI() throws DatabaseException
{
if(debugEnabled())
{
}
//Iterate through the id2entry database and insert associated dn2uri
//records.
try
{
{
try
{
// Insert into dn2uri.
{
}
else
{
// The entry DN and URIs already exists in the database.
// This could happen if some other process got to this entry
// before we did. Since the backend should be offline, this
// might be a problem.
if(debugEnabled())
{
"into the DN2URI database because it already exists.",
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
}
finally
{
}
}
/**
* Rebuild the ID2Subtree internal index. This depends on the DN2ID and DN2URI
* databases being complete.
*
* @throws DatabaseException if an error occurs during rebuild.
*/
private void rebuildID2Children() throws DatabaseException
{
if(debugEnabled())
{
id2children.getName());
}
//Iterate through the id2entry database and insert associated dn2children
//records.
try
{
{
try
{
// Check that the parent entry exists.
{
// Check for referral entries above the target.
// Read the parent ID from dn2id.
{
// Insert into id2children for parent ID.
entryID))
{
}
else
{
// The entry already exists in the database.
// This could happen if some other process got to this entry
// before we did. Since the backend should be offline, this
// might be a problem.
if(debugEnabled())
{
"ID %d into the DN2Subtree database because it already " +
"exists.",
}
}
}
else
{
throw new JebException(msg);
}
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
id2children.setRebuildStatus(false);
}
finally
{
}
}
/**
* Rebuild the ID2Subtree internal index. This depends on the DN2ID and DN2URI
* databases being complete.
*
* @throws DatabaseException if an error occurs during rebuild.
*/
private void rebuildID2Subtree() throws DatabaseException
{
if(debugEnabled())
{
id2subtree.getName());
}
//Iterate through the id2entry database and insert associated dn2subtree
//records.
try
{
{
try
{
// Check that the parent entry exists.
{
boolean success = true;
// Check for referral entries above the target.
// Read the parent ID from dn2id.
{
// Insert into id2subtree for parent ID.
entryID))
{
success = false;
}
// Iterate up through the superior entries, starting above the
// parent.
{
// Read the ID from dn2id.
{
// Insert into id2subtree for this node.
entryID))
{
success = false;
}
}
else
{
throw new JebException(msg);
}
}
}
else
{
throw new JebException(msg);
}
if(success)
{
}
else
{
// The entry already exists in the database.
// This could happen if some other process got to this entry
// before we did. Since the backend should be offline, this
// might be a problem.
if(debugEnabled())
{
"%d into the DN2Subtree database because it already " +
}
}
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
id2subtree.setRebuildStatus(false);
}
finally
{
}
}
/**
* Rebuild the attribute index.
*
* @param index The indexType to rebuild.
* @throws DatabaseException if an error occurs during rebuild.
*/
throws DatabaseException
{
if(debugEnabled())
{
}
//Iterate through the id2entry database and insert associated indexType
//records.
try
{
{
try
{
// Insert into attribute indexType.
{
}
else
{
// The entry already exists in one or more entry sets.
// This could happen if some other process got to this entry
// before we did. Since the backend should be offline, this
// might be a problem.
if(debugEnabled())
{
"into the DN2Subtree database because it already " +
"exists.",
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
index.setRebuildStatus(false);
}
finally
{
}
}
/**
* Rebuild the VLV index.
*
* @param vlvIndex The VLV index to rebuild.
* @throws DatabaseException if an error occurs during rebuild.
*/
throws DatabaseException
{
//Iterate through the id2entry database and insert associated indexType
//records.
try
{
{
try
{
// Insert into attribute indexType.
{
}
else
{
// The entry already exists in one or more entry sets.
// This could happen if some other process got to this entry
// before we did. Since the backend should be offline, this
// might be a problem.
if(debugEnabled())
{
"into the VLV index %s because it already " +
"exists.",
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
vlvIndex.setRebuildStatus(false);
}
finally
{
}
}
/**
* Rebuild the partial attribute index.
*
* @param index The indexType to rebuild.
* @throws DatabaseException if an error occurs during rebuild.
*/
throws DatabaseException
{
if(debugEnabled())
{
}
//Iterate through the id2entry database and insert associated indexType
//records.
try
{
{
try
{
// Insert into attribute indexType.
{
}
else
{
// The entry already exists in one or more entry sets.
// This could happen if some other process got to this entry
// before we did. Since the backend should be offline, this
// might be a problem.
if(debugEnabled())
{
"into the DN2Subtree database because it already " +
"exists.",
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
index.setRebuildStatus(false);
}
finally
{
}
}
/**
* Get the total entries to process in the rebuild.
*
* @return The total entries to process.
* @throws DatabaseException if an error occurs while getting the total
* number of entries to process.
*/
public long getTotalEntries() throws DatabaseException
{
//If total entries is not calculated yet, do it now.
if(totalEntries < 0)
{
}
return totalEntries;
}
/**
* Get the number of entries processed in the rebuild.
*
* @return The total entries processed.
*/
public long getProcessedEntries()
{
return processedEntries;
}
/**
* Get the number of entries successfully rebuilt.
*
* @return The number of entries successfully rebuilt.
*/
public long getRebuiltEntries()
{
return rebuiltEntries;
}
/**
* Get the number of entries that encountered duplicated indexType values in
* the rebuild process.
*
* @return The number of entries that encountered duplicated indexType values
* in the rebuild process.
*/
public long getDuplicatedEntries()
{
return duplicatedEntries;
}
/**
* Get the number of entries skipped because they were either not applicable
* or an error occurred during the process.
*
* @return The number of entries skipped.
*/
public long getSkippedEntries()
{
return skippedEntries;
}
/**
* Get the index type being rebuilt by this thread.
*
* @return The index type being rebuilt by this thread.
*/
public IndexType getIndexType()
{
return indexType;
}
}