synchronized (StorageCoreController.class) {
try {
this.idGenerator = new IDGenerator(10);
} catch (Exception e) {
throw new StorageException("Can't create ID Generator", e);
}
boolean createNewStorage = false;
if (this.storageDir == null) {
File storeDir = new File(this.storageDirectory);
File storageLog = new File(storeDir.getAbsolutePath()
+ System.getProperty("file.separator") + STORAGELOG);
try {
if (storeDir.isDirectory() && !storageLog.exists()) {
if (createLuceneStorageLog(storeDir)) {
this.storageDir = FSDirectory.getDirectory(
storeDir, true);
createNewStorage = true;
} else
throw new StorageException(
"could not create storage lock file in "
+ this.storageDirectory);
} else
this.storageDir = FSDirectory.getDirectory(storeDir,
false);
} catch (IOException e) {
storageLog.delete();
throw new StorageException(e);
}
this.storageBufferSize = this.storageBufferSize < DEFAULT_STORAGE_BUFFER_SIZE ? DEFAULT_STORAGE_BUFFER_SIZE
: this.storageBufferSize;
this.storagePersistFactor = this.storagePersistFactor < DEFAULT_STORAGE_PERSIST_FACTOR ? DEFAULT_STORAGE_PERSIST_FACTOR
: this.storagePersistFactor;
}else
createNewStorage = true;
this.currentBuffer = new StorageBuffer(this.storageBufferSize);
try{
this.modifier = createStorageModifier(createNewStorage);
this.searcher = new IndexSearcher(this.storageDir);
}catch (Exception e) {
throw new StorageException("Can not create Searcher/Modifier -- "+e.getMessage(),e);
}
if(createNewStorage)
createAdminAccount();
if(!this.recover)
return;
try{
tryRecover();
}catch (Exception e) {
LOG.fatal("Recovering failed",e);
throw new StorageException("Recovering failed -- "+e.getMessage(),e);
}
this.recoverController = createRecoverController(false,false);
try{
this.recoverController.initialize();
}catch (Exception e) {
LOG.fatal("Can not initialize recover controller",e);
throw new StorageException("Can not initialize recover controller -- "+e.getMessage(),e);
}
}
}