Search in sources :

Example 6 with TerminatedException

use of org.exist.xquery.TerminatedException in project exist by eXist-db.

the class ConsistencyCheckTask method execute.

@Override
public void execute(final DBBroker broker, final Txn transaction) throws EXistException {
    final Agent agentInstance = AgentFactory.getInstance();
    final BrokerPool brokerPool = broker.getBrokerPool();
    final TaskStatus endStatus = new TaskStatus(TaskStatus.Status.STOPPED_OK);
    agentInstance.changeStatus(brokerPool, new TaskStatus(TaskStatus.Status.INIT));
    if (paused) {
        LOG.info("Consistency check is paused.");
        agentInstance.changeStatus(brokerPool, new TaskStatus(TaskStatus.Status.PAUSED));
        return;
    }
    brokerPool.getProcessMonitor().startJob(ProcessMonitor.ACTION_BACKUP, null, monitor);
    PrintWriter report = null;
    try {
        boolean doBackup = createBackup;
        // TODO: don't use the direct access feature for now. needs more testing
        List<ErrorReport> errors = null;
        if (!incremental || incrementalCheck) {
            LOG.info("Starting consistency check...");
            report = openLog();
            final CheckCallback cb = new CheckCallback(report);
            final ConsistencyCheck check = new ConsistencyCheck(broker, transaction, false, checkDocs);
            agentInstance.changeStatus(brokerPool, new TaskStatus(TaskStatus.Status.RUNNING_CHECK));
            errors = check.checkAll(cb);
            if (!errors.isEmpty()) {
                endStatus.setStatus(TaskStatus.Status.STOPPED_ERROR);
                endStatus.setReason(errors);
                LOG.error("Errors found: {}", errors.size());
                doBackup = true;
                if (fatalErrorsFound(errors)) {
                    LOG.error("Fatal errors were found: pausing the consistency check task.");
                    paused = true;
                }
            }
            LOG.info("Finished consistency check");
        }
        if (doBackup) {
            LOG.info("Starting backup...");
            final SystemExport sysexport = new SystemExport(broker, transaction, logCallback, monitor, false);
            lastExportedBackup = sysexport.export(exportDir, incremental, maxInc, createZip, errors);
            agentInstance.changeStatus(brokerPool, new TaskStatus(TaskStatus.Status.RUNNING_BACKUP));
            if (lastExportedBackup != null) {
                LOG.info("Created backup to file: {}", lastExportedBackup.toAbsolutePath().toString());
            }
            LOG.info("Finished backup");
        }
    } catch (final TerminatedException | PermissionDeniedException e) {
        throw new EXistException(e.getMessage(), e);
    } finally {
        if (report != null) {
            report.close();
        }
        agentInstance.changeStatus(brokerPool, endStatus);
        brokerPool.getProcessMonitor().endJob();
    }
}
Also used : Agent(org.exist.management.Agent) EXistException(org.exist.EXistException) TaskStatus(org.exist.management.TaskStatus) ConsistencyCheck(org.exist.backup.ConsistencyCheck) ErrorReport(org.exist.backup.ErrorReport) PermissionDeniedException(org.exist.security.PermissionDeniedException) SystemExport(org.exist.backup.SystemExport) TerminatedException(org.exist.xquery.TerminatedException) PrintWriter(java.io.PrintWriter)

Example 7 with TerminatedException

use of org.exist.xquery.TerminatedException in project exist by eXist-db.

the class SortIndexWorker method remove.

private void remove(final DocumentImpl doc, final short id) throws LockException, EXistException {
    try (final ManagedLock<ReentrantLock> btreeLock = lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
        final byte[] fromKey = computeKey(id, doc.getDocId());
        final byte[] toKey = computeKey(id, doc.getDocId() + 1);
        final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
        index.btree.remove(query, null);
    } catch (final BTreeException | TerminatedException | IOException e) {
        throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BTreeException(org.exist.storage.btree.BTreeException) IndexQuery(org.exist.storage.btree.IndexQuery) Value(org.exist.storage.btree.Value) IOException(java.io.IOException) EXistException(org.exist.EXistException) TerminatedException(org.exist.xquery.TerminatedException)

Example 8 with TerminatedException

use of org.exist.xquery.TerminatedException in project exist by eXist-db.

the class SortIndexWorker method getOrRegisterId.

/**
 * Register the given index name and return a short id for it.
 *
 * @param name the name of the index
 *
 * @return a unique id to be used for the index entries
 *
 * @throws EXistException if an error occurs with the database
 * @throws LockException if a locking error occurs
 */
private short getOrRegisterId(final String name) throws EXistException, LockException {
    short id = getId(name);
    if (id < 0) {
        final byte[] fromKey = { 1 };
        final byte[] endKey = { 2 };
        final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(endKey));
        try (final ManagedLock<ReentrantLock> btreeLock = lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
            final FindIdCallback callback = new FindIdCallback(false);
            index.btree.query(query, callback);
            id = (short) (callback.max + 1);
            registerId(id, name);
        } catch (final IOException | TerminatedException | BTreeException e) {
            throw new EXistException("Exception caught while reading sort index: " + e.getMessage(), e);
        }
    }
    return id;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BTreeException(org.exist.storage.btree.BTreeException) IndexQuery(org.exist.storage.btree.IndexQuery) Value(org.exist.storage.btree.Value) IOException(java.io.IOException) EXistException(org.exist.EXistException) TerminatedException(org.exist.xquery.TerminatedException)

Example 9 with TerminatedException

use of org.exist.xquery.TerminatedException in project exist by eXist-db.

the class DebuggeeJointImpl method expressionStart.

/* (non-Javadoc)
	 * @see org.exist.debuggee.DebuggeeJoint#expressionStart(org.exist.xquery.Expression)
	 */
public void expressionStart(Expression expr) throws TerminatedException {
    if (LOG.isDebugEnabled())
        LOG.debug("" + expr.getLine() + " expr = " + expr.toString());
    if (compiledXQuery == null)
        return;
    if (firstExpression == null)
        firstExpression = expr;
    stack.set(stackDepth, expr);
    String fileName = Command.getFileuri(expr.getSource());
    Integer lineNo = expr.getLine();
    // check breakpoint
    for (Breakpoint breakpoint : activeBreakpoints) {
        if (breakpoint.getFilename().equals(fileName) && breakpoint.getType().equals(Breakpoint.TYPE_LINE)) {
            if (breakpoint.getLineno() != lineNo) {
                activeBreakpoints.remove(breakpoint);
            }
        }
    }
    Map<Integer, Breakpoint> fileBreakpoints = null;
    while (true) {
        // didn't receive any command, wait for any
        if (command == null || // the status is break, wait for changes
        command.isStatus(BREAK)) {
            waitCommand();
            continue;
        }
        // wait for connection
        if (command.is(CommandContinuation.INIT) && command.isStatus(STARTING)) {
            Init init = (Init) command;
            init.getSession().setAttribute("joint", this);
            init.setFileURI(compiledXQuery.getSource());
            // break on first line
            command.setStatus(BREAK);
        }
        // disconnected
        if (compiledXQuery == null)
            return;
        // stop command, terminate
        if (command.is(CommandContinuation.STOP) && !command.isStatus(STOPPED)) {
            command.setStatus(STOPPED);
            sessionClosed(true);
            throw new TerminatedException(expr.getLine(), expr.getColumn(), "Debuggee STOP command.");
        }
        // step-into is done
        if (command.is(CommandContinuation.STEP_INTO) && command.isStatus(RUNNING)) {
            command.setStatus(BREAK);
        // step-over should stop on same call's stack depth
        } else if (command.is(CommandContinuation.STEP_OVER) && command.getCallStackDepth() == stackDepth && command.isStatus(RUNNING)) {
            command.setStatus(BREAK);
        }
        // checking breakpoints
        synchronized (breakpoints) {
            if (filesBreakpoints.containsKey(fileName)) {
                fileBreakpoints = filesBreakpoints.get(fileName);
                if (fileBreakpoints.containsKey(lineNo)) {
                    Breakpoint breakpoint = fileBreakpoints.get(lineNo);
                    if (!activeBreakpoints.contains(breakpoint) && breakpoint.getState() && breakpoint.getType().equals(Breakpoint.TYPE_LINE)) {
                        activeBreakpoints.add(breakpoint);
                        command.setStatus(BREAK);
                    // waitCommand();
                    // break;
                    }
                }
            }
        }
        // RUN command with status RUNNING can be break only on breakpoints
        if (command.getType() >= CommandContinuation.RUN && command.isStatus(RUNNING)) {
            break;
        // any continuation command with status RUNNING
        } else if (command.getType() >= CommandContinuation.RUN && command.isStatus(STARTING)) {
            command.setStatus(RUNNING);
            break;
        }
        waitCommand();
    }
}
Also used : Breakpoint(org.exist.debugger.model.Breakpoint) Init(org.exist.debuggee.dbgp.packets.Init) TerminatedException(org.exist.xquery.TerminatedException)

Example 10 with TerminatedException

use of org.exist.xquery.TerminatedException in project exist by eXist-db.

the class SortIndexWorker method remove.

/**
 * Completely remove the index identified by its name.
 *
 * @param name the name of the index
 *
 * @throws EXistException if an error occurs with the database
 * @throws LockException if a locking error occurs
 */
public void remove(final String name) throws EXistException, LockException {
    final short id = getId(name);
    try (final ManagedLock<ReentrantLock> btreeLock = lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
        final byte[] fromKey = computeKey(id);
        final byte[] toKey = computeKey((short) (id + 1));
        final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
        index.btree.remove(query, null);
        removeId(name);
    } catch (final BTreeException | TerminatedException | IOException e) {
        throw new EXistException("Exception caught while deleting sort index: " + e.getMessage(), e);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BTreeException(org.exist.storage.btree.BTreeException) IndexQuery(org.exist.storage.btree.IndexQuery) Value(org.exist.storage.btree.Value) IOException(java.io.IOException) EXistException(org.exist.EXistException) TerminatedException(org.exist.xquery.TerminatedException)

Aggregations

TerminatedException (org.exist.xquery.TerminatedException)19 EXistException (org.exist.EXistException)9 IOException (java.io.IOException)8 ReentrantLock (java.util.concurrent.locks.ReentrantLock)8 PermissionDeniedException (org.exist.security.PermissionDeniedException)6 BTreeException (org.exist.storage.btree.BTreeException)6 IndexQuery (org.exist.storage.btree.IndexQuery)6 Value (org.exist.storage.btree.Value)6 XMLStreamException (javax.xml.stream.XMLStreamException)3 PooledObject (org.apache.commons.pool2.PooledObject)3 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)3 Collection (org.exist.collections.Collection)3 DOMTransaction (org.exist.storage.dom.DOMTransaction)3 XmldbURI (org.exist.xmldb.XmldbURI)3 XPathException (org.exist.xquery.XPathException)3 DateTimeValue (org.exist.xquery.value.DateTimeValue)3 Path (java.nio.file.Path)2 ACLPermission (org.exist.security.ACLPermission)2 Permission (org.exist.security.Permission)2 DBBroker (org.exist.storage.DBBroker)2