Search in sources :

Example 1 with NativeStructuralIndexWorker

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();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) LockManager(org.exist.storage.lock.LockManager) DBBroker(org.exist.storage.DBBroker) StructuralIndex(org.exist.indexing.StructuralIndex) Index(org.exist.indexing.Index) NativeBroker(org.exist.storage.NativeBroker) NativeStructuralIndexWorker(org.exist.storage.structural.NativeStructuralIndexWorker) StartException(org.exist.start.StartException) EXistException(org.exist.EXistException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException)

Aggregations

ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 EXistException (org.exist.EXistException)1 Index (org.exist.indexing.Index)1 StructuralIndex (org.exist.indexing.StructuralIndex)1 StartException (org.exist.start.StartException)1 DBBroker (org.exist.storage.DBBroker)1 NativeBroker (org.exist.storage.NativeBroker)1 LockManager (org.exist.storage.lock.LockManager)1 NativeStructuralIndexWorker (org.exist.storage.structural.NativeStructuralIndexWorker)1 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)1