NRTCachingDirectory

open class NRTCachingDirectory(delegate: Directory, maxMergeSizeMB: Double, maxCachedMB: Double) : FilterDirectory, Accountable

Wraps a RAM-resident directory around any provided delegate directory, to be used during NRT search.

This class is likely only useful in a near-real-time context, where indexing rate is lowish but reopen rate is highish, resulting in many tiny files being written. This directory keeps such segments (as well as the segments produced by merging them, as long as they are small enough), in RAM.

This is safe to use: when your app calls {IndexWriter#commit}, all cached files will be flushed from the cached and sync'd.

Here's a simple example usage:

Directory fsDir = FSDirectory.open(new File("/path/to/index").toPath());
NRTCachingDirectory cachedFSDir = new NRTCachingDirectory(fsDir, 5.0, 60.0);
IndexWriterConfig conf = new IndexWriterConfig(analyzer);
IndexWriter writer = new IndexWriter(cachedFSDir, conf);

This will cache all newly flushed segments, all merges whose expected segment size is {@code <= 5 MB}, unless the net cached bytes exceed 60 MB at which point all writes will not be cached (until the net bytes fall below 60 MB).

Constructors

Link copied to clipboard
constructor(delegate: Directory, maxMergeSizeMB: Double, maxCachedMB: Double)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns nested resources of this class. The result should be a point-in-time snapshot (to avoid race conditions).

Link copied to clipboard

Return the wrapped Directory.

Link copied to clipboard
open override val pendingDeletions: MutableSet<String>

Functions

Link copied to clipboard
open override fun close()

Close this directory, which flushes any cached files to the delegate and then closes the delegate.

Link copied to clipboard
open fun copyFrom(from: Directory, src: String, dest: String, context: IOContext)

Copies an existing src file from directory from to a non-existent file dest in this directory. The given IOContext is only used for opening the destination file.

Link copied to clipboard
open override fun createOutput(name: String, context: IOContext): IndexOutput

Creates a new, empty file in the directory and returns an IndexOutput instance for appending data to this file.

Link copied to clipboard
open override fun createTempOutput(prefix: String, suffix: String, context: IOContext): IndexOutput

Creates a new, empty, temporary file in the directory and returns an IndexOutput instance for appending data to this file.

Link copied to clipboard
open override fun deleteFile(name: String)

Removes an existing file in the directory.

Link copied to clipboard
open override fun ensureOpen()

Ensures this directory is still open.

Link copied to clipboard
open override fun fileLength(name: String): Long

Returns the byte length of a file in the directory.

Link copied to clipboard
Link copied to clipboard
open override fun listAll(): Array<String>

Returns names of all files stored in this directory. The output must be in sorted (UTF-16, java's String.compareTo) order.

Link copied to clipboard
Link copied to clipboard
open override fun obtainLock(name: String): Lock

Acquires and returns a Lock for a file with the given name.

Link copied to clipboard

Opens a checksum-computing stream for reading an existing file.

Link copied to clipboard
open override fun openInput(name: String, context: IOContext): IndexInput

Opens a stream for reading an existing file.

Link copied to clipboard
open override fun ramBytesUsed(): Long

Return the memory usage of this object in bytes. Negative values are illegal.

Link copied to clipboard
open override fun rename(source: String, dest: String)

Renames source file to dest file where dest must not already exist in the directory.

Link copied to clipboard
open override fun sync(names: MutableCollection<String>)

Ensures that any writes to these files are moved to stable storage (made durable).

Link copied to clipboard
open override fun syncMetaData()

Ensures that directory metadata, such as recent file renames, are moved to stable storage.

Link copied to clipboard
open override fun toString(): String