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();
}
}
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);
}
}
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;
}
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();
}
}
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);
}
}
Aggregations