mikemccand commented on a change in pull request #1397: LUCENE-9304: Refactor DWPTPool to pool DWPT directly URL: https://github.com/apache/lucene-solr/pull/1397#discussion_r403703730
########## File path: lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java ########## @@ -600,5 +608,81 @@ public String toString() { + ", segment=" + (segmentInfo != null ? segmentInfo.name : "null") + ", aborted=" + aborted + ", numDocsInRAM=" + numDocsInRAM + ", deleteQueue=" + deleteQueue + "]"; } - + + + /** + * Returns true iff this DWPT is marked as flush pending + */ + boolean isFlushPending() { + return flushPending.get() == Boolean.TRUE; + } + + /** + * Sets this DWPT as flush pending. This can only be set once. + */ + void setFlushPending() { + flushPending.set(Boolean.TRUE); + } + + + /** + * Returns the last committed bytes for this DWPT. This method can be called + * without acquiring the DWPTs lock. + */ + long getLastCommittedBytesUsed() { + return lastCommittedBytesUsed; + } + + /** + * Commits the current {@link #bytesUsed()} and stores it's value for later reuse. + * The last committed bytes used can be retrieved via {@link #getLastCommittedBytesUsed()} + * @return the delta between the current {@link #bytesUsed()} and the current {@link #getLastCommittedBytesUsed()} + */ + long commitLastBytesUsed() { + assert isHeldByCurrentThread(); + long delta = bytesUsed() - lastCommittedBytesUsed; + lastCommittedBytesUsed += delta; + return delta; + } + + /** + * Locks this DWPT for exclusive access. + * @see ReentrantLock#lock() + */ + void lock() { + lock.lock(); + } + + /** + * Acquires the DWPTs lock only if it is not held by another thread at the time + * of invocation. + * @return true if the lock was acquired. + * @see ReentrantLock#tryLock() + */ + boolean tryLock() { + return lock.tryLock(); + } + + /** + * Returns true if the DWPTs lock is held by the current thread + * @see ReentrantLock#isHeldByCurrentThread() + */ + boolean isHeldByCurrentThread() { + return lock.isHeldByCurrentThread(); + } + + /** + * Unlocks the DWPTs lock Review comment: Here too. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org