|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.lucene.store.Directory
org.apache.lucene.store.NRTCachingDirectory
public class NRTCachingDirectory
Wraps a RAMDirectory
around any provided delegate directory, to
be used during NRT search. Make sure you pull the merge
scheduler using getMergeScheduler() and pass that to your
IndexWriter; this class uses that to keep track of which
merges are being done by which threads, to decide when to
cache each written file.
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.
NOTE: this class is somewhat sneaky in its approach for spying on merges to determine the size of a merge: it records which threads are running which merges by watching ConcurrentMergeScheduler's doMerge method. While this works correctly, likely future versions of this class will take a more general approach.
Here's a simple example usage:
Directory fsDir = FSDirectory.open(new File("/path/to/index"));
NRTCachingDirectory cachedFSDir = new NRTCachingDirectory(fsDir, 5.0, 60.0);
IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_32, analyzer);
conf.setMergeScheduler(cachedFSDir.getMergeScheduler());
IndexWriter writer = new IndexWriter(cachedFSDir, conf);
This will cache all newly flushed segments, all merges whose expected segment size is <= 5 MB, unless the net cached bytes exceeds 60 MB at which point all writes will not be cached (until the net bytes falls below 60 MB).
| Field Summary |
|---|
| Fields inherited from class org.apache.lucene.store.Directory |
|---|
isOpen, lockFactory |
| Constructor Summary | |
|---|---|
NRTCachingDirectory(org.apache.lucene.store.Directory delegate,
double maxMergeSizeMB,
double maxCachedMB)
We will cache a newly created output if 1) it's a flush or a merge and the estimated size of the merged segment is <= maxMergeSizeMB, and 2) the total cached bytes is <= maxCachedMB |
|
| Method Summary | |
|---|---|
void |
clearLock(String name)
|
void |
close()
Close thius directory, which flushes any cached files to the delegate and then closes the delegate. |
org.apache.lucene.store.IndexOutput |
createOutput(String name)
|
void |
deleteFile(String name)
|
protected boolean |
doCacheWrite(String name)
Subclass can override this to customize logic; return true if this file should be written to the RAMDirectory. |
boolean |
fileExists(String name)
|
long |
fileLength(String name)
|
long |
fileModified(String name)
|
org.apache.lucene.store.LockFactory |
getLockFactory()
|
String |
getLockID()
|
org.apache.lucene.index.MergeScheduler |
getMergeScheduler()
|
String[] |
listAll()
|
String[] |
listCachedFiles()
|
org.apache.lucene.store.Lock |
makeLock(String name)
|
org.apache.lucene.store.IndexInput |
openInput(String name)
|
org.apache.lucene.store.IndexInput |
openInput(String name,
int bufferSize)
|
void |
setLockFactory(org.apache.lucene.store.LockFactory lf)
|
long |
sizeInBytes()
Returns how many bytes are being used by the RAMDirectory cache |
void |
sync(Collection<String> fileNames)
|
String |
toString()
|
void |
touchFile(String name)
Deprecated. |
| Methods inherited from class org.apache.lucene.store.Directory |
|---|
copy, copy, ensureOpen, sync |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public NRTCachingDirectory(org.apache.lucene.store.Directory delegate,
double maxMergeSizeMB,
double maxCachedMB)
| Method Detail |
|---|
public org.apache.lucene.store.LockFactory getLockFactory()
getLockFactory in class org.apache.lucene.store.Directory
public void setLockFactory(org.apache.lucene.store.LockFactory lf)
throws IOException
setLockFactory in class org.apache.lucene.store.DirectoryIOExceptionpublic String getLockID()
getLockID in class org.apache.lucene.store.Directorypublic org.apache.lucene.store.Lock makeLock(String name)
makeLock in class org.apache.lucene.store.Directory
public void clearLock(String name)
throws IOException
clearLock in class org.apache.lucene.store.DirectoryIOExceptionpublic String toString()
toString in class org.apache.lucene.store.Directory
public String[] listAll()
throws IOException
listAll in class org.apache.lucene.store.DirectoryIOExceptionpublic long sizeInBytes()
public boolean fileExists(String name)
throws IOException
fileExists in class org.apache.lucene.store.DirectoryIOException
public long fileModified(String name)
throws IOException
fileModified in class org.apache.lucene.store.DirectoryIOException
@Deprecated
public void touchFile(String name)
throws IOException
touchFile in class org.apache.lucene.store.DirectoryIOException
public void deleteFile(String name)
throws IOException
deleteFile in class org.apache.lucene.store.DirectoryIOException
public long fileLength(String name)
throws IOException
fileLength in class org.apache.lucene.store.DirectoryIOExceptionpublic String[] listCachedFiles()
public org.apache.lucene.store.IndexOutput createOutput(String name)
throws IOException
createOutput in class org.apache.lucene.store.DirectoryIOException
public void sync(Collection<String> fileNames)
throws IOException
sync in class org.apache.lucene.store.DirectoryIOException
public org.apache.lucene.store.IndexInput openInput(String name)
throws IOException
openInput in class org.apache.lucene.store.DirectoryIOException
public org.apache.lucene.store.IndexInput openInput(String name,
int bufferSize)
throws IOException
openInput in class org.apache.lucene.store.DirectoryIOException
public void close()
throws IOException
close in interface Closeableclose in class org.apache.lucene.store.DirectoryIOExceptionpublic org.apache.lucene.index.MergeScheduler getMergeScheduler()
protected boolean doCacheWrite(String name)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||