recordingPhaseToken = currentPhase.use(); FreeList.Phase recordingPhase = currentPhase; currentPhase = freeList.new Phase(); block.putInt(IDX_PHASE_NUMBER, newPhaseNumber); logger.debug("Writing node pool metaroot for phase: " + newPhaseNumber); recordingPhase.writeToBlock(block, HEADER_SIZE); block.write(); metarootFile.force();
if ( (item < 0) || (item >= currentPhase.getNextItem())) { return false; long index = currentPhase.getTail(); long head = currentPhase.getHead();
/** * Releases a reference to the current phase. When all references have been * released then the phase will no longer be valid. * * @return <code>true</code> when the phase has been completely release, and * <code>false</code> when there are remaining references. */ private synchronized boolean release() { assert getToken() != null:"released() when there is no valid token"; if (refCount == 0) { throw new AssertionError("Attempt to release Phase with refCount == 0."); } if (--refCount == 0) { tokenRef = null; return true; } return false; }
long head = currentPhase.getHead(); currentPhase.setHead(head); currentPhase.incNrValidItems(); long tail = currentPhase.getTail(); long nextItem = currentPhase.getNextItem(); item = nextItem++; currentPhase.setNextItem(nextItem); } else { readTailBlock(getBlockId(tail)); currentPhase.setTail(tail); itemToPhaseSeqMap.putInt(item, currentPhase.getSequenceNumber()); currentPhase.incNrValidItems();
if ( (item < 0) || (item >= currentPhase.getNextItem())) { throw new IllegalArgumentException( "Trying to free item that was never allocated: " + item long head = currentPhase.getHead(); readHeadBlock(getBlockId(head)); currentPhase.setHead(head); currentPhase.decNrValidItems();
freeList.new Phase(committedPhaseToken.getPhase()); } catch (Throwable t) { logger.warn("Exception while rolling back in unmap()", t);
} finally { try { currentPhase = freeList.new Phase(committedPhaseToken.getPhase()); } catch (IOException ex) { throw new SimpleXAResourceException(
/** * Reinitializes the NodePool so that it is empty. This should be called after * constructing a NodePoolImpl when creating a new triple store. * * @param phaseNumber the initial phase number. * @throws IOException if an I/O error occurs. * @throws SimpleXAResourceException if it is inappropriate to call clear() at * this time. */ public synchronized void clear( int phaseNumber ) throws IOException, SimpleXAResourceException { if (currentPhase != null) { throw new IllegalStateException( "NodePool already has a current phase." ); } openMetarootFile(true); try { synchronized (committedPhaseLock) { committedPhaseToken = freeList.new Phase(MIN_NODE).use(); } this.phaseNumber = phaseNumber; phaseIndex = 1; freeList.clear(); } catch (IllegalStateException ex) { throw new SimpleXAResourceException("Cannot initialize free list.", ex); } currentPhase = freeList.new Phase(); }
/** * Removes any unused phases from the phase list. * * {@link #firstHead} and {@link #firstTail} will * be updated to the oldest phase still in use. */ private void removeClosedPhases() { // Caller must be synchronized. assert Thread.holdsLock(this); Phase phase = (Phase) phases.getFirst(); while (!phase.isInUse() && (phases.size() > 1)) { phases.removeFirst(); phase = (Phase) phases.getFirst(); firstHead = phase.getHead(); firstTail = phase.getTail(); } }
public synchronized long getNrValidNodes() { return phase.getNrValidItems(); }
/** * Indicate that this phase is in use. Increments the reference count. * * @return A {@link Token} to represent the phase use. */ public synchronized Token use() { Token token = getToken(); if (token == null) { token = new Token(); tokenRef = new WeakReference(token); } ++refCount; return token; }
/** * Creates a new phase, using a freelist block. * * @param b The block in the freelist to start the new phase in. * @param offset The offset in the block to find the start of the freelist block. * @throws IOException If an I/O error occurred on the free list. */ public Phase(Block b, int offset) throws IOException { freeListPhase = freeList.new Phase(b, offset); currentPhase = this; check(); }
/** * The next item to allocate if the free list is empty or there are no items * between {@link Phase#tail} and {@link #firstHead}. This is also one * greater than the largest item in use. * * @return the next item to allocate if the free list is empty or there are * no items between {@link Phase#tail} and {@link #firstHead}. */ public long getNextItem() { return currentPhase.getNextItem(); }
/** * Create a new token for the encapsulating phase. */ Token() { freeListToken = freeListPhase.use(); }
/** * Writes this PersistableMetaRoot to the specified Block. The ints are * written at the specified offset. * * @param b the Block. * @param offset writes the free list block data at this offset in the block. */ public void writeToBlock(Block b, int offset) { freeListPhase.writeToBlock(b, offset); }
/** * Gets the SharedItem attribute of the FreeList object. This indicates that * the item appears in more than one phase. * * @param item An item in the free list. * @return The SharedItem value */ public synchronized boolean isSharedItem(long item) { return itemToPhaseSeqMap.getInt(item) != currentPhase.getSequenceNumber(); }
public synchronized void refresh() { synchronized (committedPhaseLock) { FreeList.Phase committedPhase = committedPhaseToken.getPhase(); if (phase != committedPhase) { if (token != null) { token.release(); } phase = committedPhase; token = phase.use(); } } }
/** * Gets the NrValidNodes attribute of the XANodePoolImpl object * * @return The NrValidNodes value */ public synchronized long getNrValidNodes() { checkInitialized(); return currentPhase.getNrValidItems(); }