DefragmentConfig class allows you fine-tune the defragmentation process. This topic discusses different settings available through DefragmentConfig.
The path to the file to be defragmented. Can be specified in the constructor:
configuration
= new DefragmentConfig(origPath)
configuration = new DefragmentConfig(origPath, backupPath)
The path to the backup of the original file. If this file exists before the defragmentation, an IOException will be thrown and no action taken.
If you want the backup file to be deleted automatically before the defragment run, specify:
.NET:
configuration.ForceBackupDelete(true)
You can also specify the desired Mapping to be used internally:
configuration = new DefragmentConfig(origPath, backupPath, mapping)
mapping
is an object of a class implementing ContextIDMapping interface. Mapping is
used to keep track of objects moved during defragmentation. Db4o provides 2
mapping classes.
TreeIDMapping - default in-memory mapping. Will increase the memory usage, but is a faster alternative. Set up objectCommitFrequency to control memory usage.
BTreeIDMapping - mapping is done in a separate file using B-tree method. Reduces the memory usage, but is a much slower option.
Defragmentation
process uses StoredClassFilter accept
method to define which
classes should be left in a database after the defragmentation. By default, all
classes are left. However, you can use AvailableClassFilter to get rid of the
deleted classes instances:
.NET:
configuration.StoredClassFilter(new
AvailableClassFilter())
In this case only the classes known to the classloader will be left in the database, the rest will be deleted.
For db4o configurations that influence low-level file layout details, it is important to provide the defragmentation process with the copy of db4o configuration:
.NET:
configuration.Db4oConfig(db4oConfiguration)
For more information about db4o configuration see Configuration.
Commit frequency sets the number of processed objects that should trigger an immediate commit of the target file. By default, frequency = 0 and commit never happens.
.NET:
configuration.ObjectCommitFrequency(frequency)
This method can be used to reduce memory usage during defragmentation.
You can upgrade your database file together with the defragmentation:
.NET:
configuration.pgradeFile(tempFile)
This method can be used to reduce memory usage during defragmentation, however it will make it slower.