/** * Closes the given resource, suppresses any new exception, and then throws the original * exception. * * @param c optional * @param e required */ static RuntimeException fail(AutoCloseable c, Throwable e) { if (c != null) { try { c.close(); } catch (Throwable e2) { Utils.suppress(e, e2); } } throw Utils.rethrow(e); }
@Override public void notify(EventType type, String message, Object... args) { try { if (mLogger.isLoggable(type.level)) { String msg = type.category + ": " + String.format(message, args); LogRecord record = new LogRecord(type.level, msg); record.setSourceClassName(null); record.setSourceMethodName(null); for (Object obj : args) { if (obj instanceof Throwable) { Throwable thrown = record.getThrown(); if (thrown != null) { Utils.suppress(thrown, (Throwable) obj); } else { record.setThrown((Throwable) obj); } } } mLogger.log(record); } } catch (Throwable e) { // Ignore, and so this listener is safe for the caller. } } }
static RuntimeException lockCleanup(Throwable e, Transaction txn, LockResult result) { if (result.isAcquired()) { try { txn.unlock(); } catch (Throwable e2) { Utils.suppress(e, e2); } } throw Utils.rethrow(e); }
@Override public Node allocLatchedNode(LocalDatabase db, int mode) throws IOException { long nodeId = allocPage(); try { Node node = db.allocLatchedNode(nodeId, mode); node.mId = nodeId; return node; } catch (Throwable e) { try { recyclePage(nodeId); } catch (Throwable e2) { Utils.suppress(e, e2); } throw e; } }
@Override public _Node allocLatchedNode(_LocalDatabase db, int mode) throws IOException { long nodeId = allocPage(); try { _Node node = db.allocLatchedNode(nodeId, mode); node.mId = nodeId; return node; } catch (Throwable e) { try { recyclePage(nodeId); } catch (Throwable e2) { Utils.suppress(e, e2); } throw e; } }
@Override public Node allocLatchedNode(LocalDatabase db, int mode) throws IOException { long nodeId = allocPage(); try { Node node = db.allocLatchedNode(nodeId, mode); node.mId = nodeId; return node; } catch (Throwable e) { try { recyclePage(nodeId); } catch (Throwable e2) { Utils.suppress(e, e2); } throw e; } }
@Override public _Node allocLatchedNode(_LocalDatabase db, int mode) throws IOException { long nodeId = allocPage(); try { _Node node = db.allocLatchedNode(nodeId, mode); node.mId = nodeId; return node; } catch (Throwable e) { try { recyclePage(nodeId); } catch (Throwable e2) { Utils.suppress(e, e2); } throw e; } }
/** * Should be called after the cursor id has been assigned, with the commit lock held. */ void registerCursor(_Tree cursorRegistry, _TreeCursor cursor) throws IOException { try { byte[] cursorIdBytes = new byte[8]; encodeLongBE(cursorIdBytes, 0, cursor.mCursorId); cursorRegistry.store(Transaction.BOGUS, cursorIdBytes, cursor.mTree.mIdBytes); } catch (Throwable e) { try { cursor.unregister(); } catch (Throwable e2) { suppress(e, e2); } throw e; } }
/** * Should be called after the cursor id has been assigned, with the commit lock held. */ void registerCursor(Tree cursorRegistry, TreeCursor cursor) throws IOException { try { byte[] cursorIdBytes = new byte[8]; encodeLongBE(cursorIdBytes, 0, cursor.mCursorId); cursorRegistry.store(Transaction.BOGUS, cursorIdBytes, cursor.mTree.mIdBytes); } catch (Throwable e) { try { cursor.unregister(); } catch (Throwable e2) { suppress(e, e2); } throw e; } }
private void cleanupSplit(Throwable cause, Node newNode, Split split) { if (split != null) { cleanupFragments(cause, split.fragmentedKey()); } try { // No need to prepare for delete because node contents are unreferenced. getDatabase().finishDeleteNode(newNode); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } }
private void cleanupSplit(Throwable cause, _Node newNode, _Split split) { if (split != null) { cleanupFragments(cause, split.fragmentedKey()); } try { // No need to prepare for delete because node contents are unreferenced. getDatabase().finishDeleteNode(newNode); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } }
private void cleanupSplit(Throwable cause, _Node newNode, _Split split) { if (split != null) { cleanupFragments(cause, split.fragmentedKey()); } try { // No need to prepare for delete because node contents are unreferenced. getDatabase().finishDeleteNode(newNode); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } }
private void cleanupSplit(Throwable cause, Node newNode, Split split) { if (split != null) { cleanupFragments(cause, split.fragmentedKey()); } try { // No need to prepare for delete because node contents are unreferenced. getDatabase().finishDeleteNode(newNode); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } }
private void cleanupFragments(Throwable cause, byte[] fragmented) { if (fragmented != null) { long copy = p_transfer(fragmented); try { getDatabase().deleteFragments(copy, 0, fragmented.length); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } finally { p_delete(copy); } } }
private void cleanupFragments(Throwable cause, byte[] fragmented) { if (fragmented != null) { /*P*/ byte[] copy = p_transfer(fragmented); try { getDatabase().deleteFragments(copy, 0, fragmented.length); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } finally { p_delete(copy); } } }
void cleanupFragments(Throwable cause, byte[] fragmented) { if (fragmented != null) { /*P*/ byte[] copy = p_transfer(fragmented, false); try { getDatabase().deleteFragments(copy, 0, fragmented.length); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } finally { p_delete(copy); } } }
void cleanupFragments(Throwable cause, byte[] fragmented) { if (fragmented != null) { long copy = p_transfer(fragmented, false); try { getDatabase().deleteFragments(copy, 0, fragmented.length); } catch (Throwable e) { Utils.suppress(cause, e); panic(cause); } finally { p_delete(copy); } } }
/** * Mark an unmapped node as dirty. Caller must hold commit lock and exclusive latch on * node. Method does nothing if node is already dirty. Latch is never released by this * method, even if an exception is thrown. */ void markUnmappedDirty(_Node node) throws IOException { if (node.mCachedState != mCommitState) { node.write(mPageDb); long newId = mPageDb.allocPage(); long oldId = node.mId; try { mPageDb.deletePage(oldId); } catch (Throwable e) { try { mPageDb.recyclePage(newId); } catch (Throwable e2) { // Panic. Utils.suppress(e, e2); close(e); } throw e; } dirty(node, newId); } }
/** * Mark an unmapped node as dirty. Caller must hold commit lock and exclusive latch on * node. Method does nothing if node is already dirty. Latch is never released by this * method, even if an exception is thrown. */ void markUnmappedDirty(Node node) throws IOException { if (node.mCachedState != mCommitState) { node.write(mPageDb); long newId = mPageDb.allocPage(); long oldId = node.mId; try { mPageDb.deletePage(oldId); } catch (Throwable e) { try { mPageDb.recyclePage(newId); } catch (Throwable e2) { // Panic. Utils.suppress(e, e2); close(e); } throw e; } dirty(node, newId); } }
/** * Mark an unmapped node as dirty. Caller must hold commit lock and exclusive latch on * node. Method does nothing if node is already dirty. Latch is never released by this * method, even if an exception is thrown. */ void markUnmappedDirty(Node node) throws IOException { if (node.mCachedState != mCommitState) { node.write(mPageDb); long newId = mPageDb.allocPage(); long oldId = node.mId; try { // No need to force delete when dirtying. Caller is responsible for cleaning up. mPageDb.deletePage(oldId, false); } catch (Throwable e) { try { mPageDb.recyclePage(newId); } catch (Throwable e2) { // Panic. Utils.suppress(e, e2); close(e); } throw e; } dirty(node, newId); } }