use of org.exist.storage.structural.NativeStructuralIndexWorker in project exist by eXist-db.
the class Repair method repair.
public void repair(String id) {
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
BTree btree = null;
if ("collections".equals(id)) {
btree = ((NativeBroker) broker).getStorage(NativeBroker.COLLECTIONS_DBX_ID);
} else if ("dom".equals(id)) {
btree = ((NativeBroker) broker).getStorage(NativeBroker.DOM_DBX_ID);
} else if ("range".equals(id)) {
btree = ((NativeBroker) broker).getStorage(NativeBroker.VALUES_DBX_ID);
} else if ("structure".equals(id)) {
NativeStructuralIndexWorker index = (NativeStructuralIndexWorker) broker.getIndexController().getWorkerByIndexName(StructuralIndex.STRUCTURAL_INDEX_ID);
btree = index.getStorage();
} else {
// use index id defined in conf.xml
Index index = pool.getIndexManager().getIndexByName(id);
if (index != null) {
btree = index.getStorage();
}
}
if (btree == null) {
System.console().printf("Unkown index: %s\n", id);
return;
}
final LockManager lockManager = broker.getBrokerPool().getLockManager();
try (final ManagedLock<ReentrantLock> btreeLock = lockManager.acquireBtreeWriteLock(btree.getLockName())) {
System.console().printf("Rebuilding %15s ...", FileUtils.fileName(btree.getFile()));
btree.rebuild();
System.out.println("Done");
}
} catch (Exception e) {
System.console().printf("An exception occurred during repair: %s\n", e.getMessage());
e.printStackTrace();
}
}
Aggregations