I am using db4o 8.0.
The db4odatabase file size is 21MB.
The database has following Objects in it.
User : There is 1 user in db.
PostedMessage : There are 10000 postedMessages in db.
I delete all 10000 PostedMessages. Then I try to defragment the db4o database. Following code is used for Defragmentation.
private void processDefrag() {
try {
String dbpath = "D:\\db4oDatabase";
IdMapping mapping = new InMemoryIdMapping();
//new DatabaseIdMapping(dbpath); //use this if heap overflows
DefragmentConfig config = new DefragmentConfig(dbpath, dbpath+".bak", mapping);
config.storedClassFilter(new AvailableClassFilter());
config.forceBackupDelete(false);
config.objectCommitFrequency(1000);
Defragment.defrag(config);
System.out.println("Defrag completed");
} catch (IOException ex) {
ex.printStackTrace();
}
}
My expectation is that the db4oDatabase file size will go back to 21 Kb. And the db4oDatabase will still contain the 1 User object in it. However, after running the above code, the db4odatabase becomes completely empty. Why is it happening like that?
How can I avoid losing the other objects which were not deleted (in this case the 1 User object)? What is the right way of doing defragmentation on db4o database?
If it’s not accepting the class because it can’t find it, you might try writing a
StoredClassFilterof your own that just accepts allStoredClassobjects.Then:
This will work unless the defrag process just deletes everything without a
StoredClassautomatically. If this is the case, we may need to figure out why theUserclass doesn’t have a correspondingStoredClassinstance for the container.