Package org.apache.solr.core
Class DirectoryFactory
java.lang.Object
org.apache.solr.core.DirectoryFactory
- All Implemented Interfaces:
Closeable,AutoCloseable,NamedListInitializedPlugin
- Direct Known Subclasses:
CachingDirectoryFactory
public abstract class DirectoryFactory
extends Object
implements NamedListInitializedPlugin, Closeable
Provides access to a Directory implementation. You must release every Directory that you get.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHint about what the directory will be used for. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddCloseListener(org.apache.lucene.store.Directory dir, CachingDirectoryFactory.CloseListener closeListener) Adds a close listener for a Directory.voidcleanupOldIndexDirectories(String dataDirPath, String currentIndexDirPath, boolean afterCoreReload) abstract voidclose()Close this factory and all the Directories it contains.protected abstract org.apache.lucene.store.DirectoryCreates a new Directory for a given path.protected abstract org.apache.lucene.store.LockFactorycreateLockFactory(String rawLockType) Creates a new LockFactory for a given path.protected booleandeleteOldIndexDirectory(String oldDirPath) abstract voiddoneWithDirectory(org.apache.lucene.store.Directory directory) Indicates a Directory will no longer be used, and when its ref count hits 0, it can be closed.static booleanempty(org.apache.lucene.store.Directory dir) Delete the files in the Directoryabstract booleanReturns true if a Directory exists for a given path in the underlying (stable) storage and contains at least one file.abstract org.apache.lucene.store.Directoryget(String path, DirectoryFactory.DirContext dirContext, String rawLockType) Returns the Directory for a given path, using the specified rawLockType.protected org.apache.lucene.store.DirectorygetBaseDir(org.apache.lucene.store.Directory dir) Get the data home folder.abstract voidincRef(org.apache.lucene.store.Directory directory) Increment the number of references to the given Directory.voidbooleanisAbsolute(String path) abstract booleanbooleanvoidmove(org.apache.lucene.store.Directory fromDir, org.apache.lucene.store.Directory toDir, String fileName, org.apache.lucene.store.IOContext ioContext) Override for more efficient moves.Returns a default Update Log instance.Normalize a given path.abstract voidrelease(org.apache.lucene.store.Directory directory) Releases the Directory so that it may be closed when it is no longer referenced.abstract voidThis remove is special in that it may be called even after the factory has been closed.abstract voidThis remove is special in that it may be called even after the factory has been closed.abstract voidremove(org.apache.lucene.store.Directory dir) Removes the Directory's persistent storage.abstract voidremove(org.apache.lucene.store.Directory dir, boolean afterCoreClose) Removes the Directory's persistent storage.voidrenameWithOverwrite(org.apache.lucene.store.Directory dir, String fileName, String toName) booleanIf your implementation can count on delete-on-last-close semantics or throws an exception when trying to remove a file in use, return false (eg NFS).longlongsize(org.apache.lucene.store.Directory directory) static longstatic longsizeOfDirectory(org.apache.lucene.store.Directory directory) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.solr.util.plugin.NamedListInitializedPlugin
init
-
Field Details
-
IOCONTEXT_NO_CACHE
public static final org.apache.lucene.store.IOContext IOCONTEXT_NO_CACHE -
INDEX_W_TIMESTAMP_REGEX
- See Also:
-
dataHomePath
-
LOCK_TYPE_SIMPLE
- See Also:
-
LOCK_TYPE_NATIVE
- See Also:
-
LOCK_TYPE_SINGLE
- See Also:
-
LOCK_TYPE_NONE
- See Also:
-
coreContainer
-
-
Constructor Details
-
DirectoryFactory
public DirectoryFactory()
-
-
Method Details
-
doneWithDirectory
public abstract void doneWithDirectory(org.apache.lucene.store.Directory directory) throws IOException Indicates a Directory will no longer be used, and when its ref count hits 0, it can be closed. On close all directories will be closed whether this has been called or not. This is simply to allow early cleanup.- Throws:
IOException- If there is a low-level I/O error.
-
addCloseListener
public abstract void addCloseListener(org.apache.lucene.store.Directory dir, CachingDirectoryFactory.CloseListener closeListener) Adds a close listener for a Directory. -
close
Close this factory and all the Directories it contains.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- If there is a low-level I/O error.
-
create
protected abstract org.apache.lucene.store.Directory create(String path, org.apache.lucene.store.LockFactory lockFactory) throws IOException Creates a new Directory for a given path.- Throws:
IOException- If there is a low-level I/O error.
-
createLockFactory
protected abstract org.apache.lucene.store.LockFactory createLockFactory(String rawLockType) throws IOException Creates a new LockFactory for a given path.- Parameters:
rawLockType- A string value as passed in config. Every factory should at least support 'none' to disable locking.- Throws:
IOException- If there is a low-level I/O error.
-
exists
Returns true if a Directory exists for a given path in the underlying (stable) storage and contains at least one file. Note that the existence of aDirectoryObject as returned by a previous call to theget(java.lang.String, org.apache.solr.core.DirectoryFactory.DirContext, java.lang.String)method (on the specifiedpath) is not enough to cause this method to return true. Some prior user of that Directory must have written & synced at least one file to that Directory (and at least one file must still exist)- Throws:
IOException- If there is a low-level I/O error.
-
remove
Removes the Directory's persistent storage. For example: A file system impl may remove the on disk directory.- Throws:
IOException- If there is a low-level I/O error.
-
remove
public abstract void remove(org.apache.lucene.store.Directory dir, boolean afterCoreClose) throws IOException Removes the Directory's persistent storage. For example: A file system impl may remove the on disk directory.- Throws:
IOException- If there is a low-level I/O error.
-
remove
This remove is special in that it may be called even after the factory has been closed. Remove only makes sense for persistent directory factories.- Parameters:
path- to removeafterCoreClose- whether to wait until after the core is closed.- Throws:
IOException- If there is a low-level I/O error.
-
remove
This remove is special in that it may be called even after the factory has been closed. Remove only makes sense for persistent directory factories.- Parameters:
path- to remove- Throws:
IOException- If there is a low-level I/O error.
-
size
- Parameters:
directory- to calculate size of- Returns:
- size in bytes
- Throws:
IOException- on low level IO error
-
size
- Parameters:
path- to calculate size of- Returns:
- size in bytes
- Throws:
IOException- on low level IO error
-
move
public void move(org.apache.lucene.store.Directory fromDir, org.apache.lucene.store.Directory toDir, String fileName, org.apache.lucene.store.IOContext ioContext) throws IOException Override for more efficient moves.Intended for use with replication - use carefully - some Directory wrappers will cache files for example.
- Throws:
IOException- If there is a low-level I/O error.
-
renameWithOverwrite
public void renameWithOverwrite(org.apache.lucene.store.Directory dir, String fileName, String toName) throws IOException - Throws:
IOException
-
get
public abstract org.apache.lucene.store.Directory get(String path, DirectoryFactory.DirContext dirContext, String rawLockType) throws IOException Returns the Directory for a given path, using the specified rawLockType. Will return the same Directory instance for the same path.- Throws:
IOException- If there is a low-level I/O error.
-
incRef
public abstract void incRef(org.apache.lucene.store.Directory directory) Increment the number of references to the given Directory. You must call release for every call to this method. -
isPersistent
public abstract boolean isPersistent()- Returns:
- true if data is kept after close.
-
release
Releases the Directory so that it may be closed when it is no longer referenced.- Throws:
IOException- If there is a low-level I/O error.
-
normalize
Normalize a given path.- Parameters:
path- to normalize- Returns:
- normalized path
- Throws:
IOException- on io error
-
isAbsolute
- Parameters:
path- the path to check- Returns:
- true if absolute, as in not relative
-
sizeOfDirectory
- Throws:
IOException
-
sizeOf
public static long sizeOf(org.apache.lucene.store.Directory directory, String file) throws IOException - Throws:
IOException
-
empty
public static boolean empty(org.apache.lucene.store.Directory dir) Delete the files in the Directory -
searchersReserveCommitPoints
public boolean searchersReserveCommitPoints()If your implementation can count on delete-on-last-close semantics or throws an exception when trying to remove a file in use, return false (eg NFS). Otherwise, return true. Defaults to returning false.- Returns:
- true if factory impl requires that Searcher's explicitly reserve commit points.
-
getDataHome
Get the data home folder. If solr.data.home is set, that is used, else base on instanceDir- Parameters:
cd- core descriptor instance- Returns:
- a String with absolute path to data directory
- Throws:
IOException
-
cleanupOldIndexDirectories
public void cleanupOldIndexDirectories(String dataDirPath, String currentIndexDirPath, boolean afterCoreReload) throws IOException - Throws:
IOException
-
deleteOldIndexDirectory
- Throws:
IOException
-
initCoreContainer
-
getBaseDir
protected org.apache.lucene.store.Directory getBaseDir(org.apache.lucene.store.Directory dir) -
newDefaultUpdateLog
Returns a default Update Log instance. UpdateHandler will invoke this method if the solrconfig / plugin info does not specify any ulog class.
-