use of org.exist.util.LockException in project exist by eXist-db.
the class RawNodeIterator method seek.
@Override
public final void seek(final NodeHandle node) throws IOException {
try (final ManagedLock<ReentrantLock> domFileLock = lockManager.acquireBtreeReadLock(db.getLockName())) {
RecordPos rec = null;
if (StorageAddress.hasAddress(node.getInternalAddress())) {
rec = db.findRecord(node.getInternalAddress());
}
if (rec == null) {
try {
final long address = db.findValue(broker, new NodeProxy(node));
if (address == BTree.KEY_NOT_FOUND) {
throw new IOException("Node not found.");
}
rec = db.findRecord(address);
} catch (final BTreeException e) {
throw new IOException("Node not found: " + e.getMessage());
}
}
pageNum = rec.getPage().getPageNum();
// Position the stream at the very beginning of the record
offset = rec.offset - DOMFile.LENGTH_TID;
page = rec.getPage();
} catch (final LockException e) {
throw new IOException("Exception while scanning document: " + e.getMessage());
}
}
use of org.exist.util.LockException in project exist by eXist-db.
the class ExistDocument method resourceCopyMove.
/**
* Copy document or collection in database.
*/
void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) throws EXistException {
if (LOG.isDebugEnabled()) {
LOG.debug("{} {} to {} named {}", String.valueOf(mode), xmldbUri, destCollectionUri, newName);
}
XmldbURI newNameUri = null;
try {
newNameUri = XmldbURI.xmldbUriFor(newName);
} catch (URISyntaxException ex) {
LOG.error(ex);
throw new EXistException(ex.getMessage());
}
// use WRITE_LOCK if moving or if src and dest collection are the same
final LockMode srcCollectionLockMode = mode == Mode.MOVE || destCollectionUri.equals(xmldbUri.removeLastSegment()) ? LockMode.WRITE_LOCK : LockMode.READ_LOCK;
DocumentImpl srcDocument = null;
// Need to split path into collection and document name
final XmldbURI srcCollectionUri = xmldbUri.removeLastSegment();
final XmldbURI srdDocumentUri = xmldbUri.lastSegment();
final TransactionManager txnManager = brokerPool.getTransactionManager();
try (final DBBroker broker = brokerPool.get(Optional.ofNullable(subject));
final Txn txn = txnManager.beginTransaction();
final Collection srcCollection = broker.openCollection(srcCollectionUri, srcCollectionLockMode)) {
// Open collection if possible, else abort
if (srcCollection == null) {
txnManager.abort(txn);
// TODO throw
return;
}
// Open document if possible, else abort
srcDocument = srcCollection.getDocument(broker, srdDocumentUri);
if (srcDocument == null) {
LOG.debug("No resource found for path: {}", xmldbUri);
txnManager.abort(txn);
return;
}
// Open collection if possible, else abort
try (final Collection destCollection = broker.openCollection(destCollectionUri, LockMode.WRITE_LOCK)) {
if (destCollection == null) {
LOG.debug("Destination collection {} does not exist.", xmldbUri);
txnManager.abort(txn);
return;
}
// Perform actial move/copy
if (mode == Mode.COPY) {
broker.copyResource(txn, srcDocument, destCollection, newNameUri);
} else {
broker.moveResource(txn, srcDocument, destCollection, newNameUri);
}
// Commit change
txnManager.commit(txn);
if (LOG.isDebugEnabled()) {
LOG.debug("Document {}d successfully", mode);
}
}
} catch (LockException e) {
LOG.error("Resource is locked.", e);
throw new EXistException(e.getMessage());
} catch (EXistException e) {
LOG.error(e);
throw e;
} catch (IOException | PermissionDeniedException | TriggerException e) {
LOG.error(e);
throw new EXistException(e.getMessage());
} finally {
if (LOG.isDebugEnabled()) {
LOG.debug("Finished {}", mode);
}
}
}
use of org.exist.util.LockException in project exist by eXist-db.
the class NativeStructuralIndexWorker method removeQNamesForDoc.
protected void removeQNamesForDoc(DocumentImpl doc) {
final byte[] fromKey = computeDocKey(doc.getDocId());
final byte[] toKey = computeDocKey(doc.getDocId() + 1);
final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
try (final ManagedLock<ReentrantLock> btreeLock = index.lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
index.btree.remove(query, null);
} catch (final LockException e) {
NativeStructuralIndex.LOG.warn("Failed to lock structural index: {}", e.getMessage(), e);
} catch (final Exception e) {
NativeStructuralIndex.LOG.warn("Exception caught while reading structural index for document {}: {}", doc.getURI(), e.getMessage(), e);
}
}
use of org.exist.util.LockException in project exist by eXist-db.
the class NativeStructuralIndexWorker method removeCollection.
@Override
public void removeCollection(Collection collection, DBBroker broker, boolean reindex) throws PermissionDeniedException {
try {
for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
final DocumentImpl doc = i.next();
removeDocument(doc);
}
} catch (final LockException e) {
LOG.error(e);
}
}
use of org.exist.util.LockException in project exist by eXist-db.
the class NativeStructuralIndexWorker method findDescendantsByTagName.
public NodeSet findDescendantsByTagName(byte type, QName qname, int axis, DocumentSet docs, NodeSet contextSet, int contextId, Expression parent) {
final NewArrayNodeSet result = new NewArrayNodeSet();
final FindDescendantsCallback callback = new FindDescendantsCallback(type, axis, qname, contextId, result, parent);
try (final ManagedLock<ReentrantLock> btreeLock = index.lockManager.acquireBtreeReadLock(index.btree.getLockName())) {
for (final NodeProxy ancestor : contextSet) {
final DocumentImpl doc = ancestor.getOwnerDocument();
final NodeId ancestorId = ancestor.getNodeId();
callback.setAncestor(doc, ancestor);
final byte[] fromKey;
final byte[] toKey;
if (ancestorId == NodeId.DOCUMENT_NODE) {
fromKey = computeKey(type, qname, doc.getDocId());
toKey = computeKey(type, qname, doc.getDocId() + 1);
} else {
fromKey = computeKey(type, qname, doc.getDocId(), ancestorId);
toKey = computeKey(type, qname, doc.getDocId(), ancestorId.nextSibling());
}
final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
try {
index.btree.query(query, callback);
} catch (final Exception e) {
NativeStructuralIndex.LOG.error("Error while searching structural index: {}", e.getMessage(), e);
}
}
} catch (final LockException e) {
NativeStructuralIndex.LOG.warn("Lock problem while searching structural index: {}", e.getMessage(), e);
}
result.updateNoSort();
return result;
}
Aggregations