* of the existing DBs, while removing outdated one's.
*
* @throws BabuDBException
*/
public void reset() throws BabuDBException {
DatabaseManagerInternal dbman = dbs.getDatabaseManager();
assert (dbman != null) : "The DatabaseManager is not available!";
ObjectInputStream ois = null;
try {
List<Integer> ids = new LinkedList<Integer>();
if (configFile.exists()) {
ois = new ObjectInputStream(new FileInputStream(configFile));
final int dbFormatVer = ois.readInt();
if (dbFormatVer != BABUDB_DB_FORMAT_VERSION) {
throw new BabuDBException(ErrorCode.IO_ERROR, "on-disk format (version " + dbFormatVer
+ ") is incompatible with this BabuDB release " + "(uses on-disk format version "
+ BABUDB_DB_FORMAT_VERSION + ")");
}
final int numDB = ois.readInt();
dbman.setNextDBId(ois.readInt());
for (int i = 0; i < numDB; i++) {
Logging.logMessage(Logging.LEVEL_DEBUG, this, "loading DB...");
final String dbName = (String) ois.readObject();
final int dbId = ois.readInt();
final int numIndex = ois.readInt();
ByteRangeComparator[] comps = new ByteRangeComparator[numIndex];
for (int idx = 0; idx < numIndex; idx++) {
final String className = (String) ois.readObject();
ByteRangeComparator comp = dbman.getComparatorInstances().get(className);
if (comp == null) {
Class<?> clazz = Class.forName(className);
comp = (ByteRangeComparator) clazz.newInstance();
dbman.getComparatorInstances().put(className, comp);
}
assert (comp != null);
comps[idx] = comp;
}
ids.add(dbId);
DatabaseInternal db;
try {
// reset existing DBs
db = dbman.getDatabase(dbId);
db.setLSMDB(new LSMDatabase(dbName, dbId, dbs.getConfig().getBaseDir()
+ dbName + File.separatorChar, numIndex, true, comps,
dbs.getConfig().getCompression(),
dbs.getConfig().getMaxNumRecordsPerBlock(),
dbs.getConfig().getMaxBlockFileSize(),
dbs.getConfig().getDisableMMap(),
dbs.getConfig().getMMapLimit()));
} catch (BabuDBException e) {
db = new DatabaseImpl(dbs, new LSMDatabase(dbName, dbId,
dbs.getConfig().getBaseDir() + dbName + File.separatorChar,
numIndex, true, comps, dbs.getConfig().getCompression(),
dbs.getConfig().getMaxNumRecordsPerBlock(),
dbs.getConfig().getMaxBlockFileSize(),
dbs.getConfig().getDisableMMap(),
dbs.getConfig().getMMapLimit()));
dbman.putDatabase(db);
}
Logging.logMessage(Logging.LEVEL_INFO, this, "loaded DB %s" + " successfully. [LSN %s]",
dbName, db.getLSMDB().getOndiskLSN());
}
}
// delete remaining outdated DBs
Set<Integer> outdatedIds = dbman.getAllDatabaseIds();
outdatedIds.removeAll(ids);
if (outdatedIds.size() > 0) {
for (int id : outdatedIds) {
dbman.removeDatabaseById(id);
}
}
} catch (InstantiationException ex) {
throw new BabuDBException(ErrorCode.IO_ERROR, "cannot instantiate comparator", ex);
} catch (IllegalAccessException ex) {