public class Store extends AbstractIndexShardComponent implements Closeable, RefCounted
Note: If you use a store it's reference count should be increased before using it by calling #incRef and a corresponding #decRef must be called in a try/finally block to release the store again ie.:
store.incRef(); try { // use the store... } finally { store.decRef(); }
Modifier and Type | Class and Description |
---|---|
static class |
Store.LegacyChecksums |
static class |
Store.MetadataSnapshot
Represents a snapshot of the current directory build from the latest Lucene commit.
|
static interface |
Store.OnClose
A listener that is executed once the store is closed and all references to it are released
|
static class |
Store.RecoveryDiff
A class representing the diff between a recovery source and recovery target
|
Modifier and Type | Field and Description |
---|---|
static String |
CHECKSUMS_PREFIX |
static String |
INDEX_STORE_STATS_REFRESH_INTERVAL |
deprecationLogger, indexSettings, logger, shardId
Constructor and Description |
---|
Store(ShardId shardId,
IndexSettingsService indexSettingsService,
DirectoryService directoryService,
ShardLock shardLock,
Store.OnClose onClose) |
Store(ShardId shardId,
Settings indexSettings,
DirectoryService directoryService,
ShardLock shardLock) |
Store(ShardId shardId,
Settings indexSettings,
DirectoryService directoryService,
ShardLock shardLock,
Store.OnClose onClose) |
Modifier and Type | Method and Description |
---|---|
static boolean |
canOpenIndex(ESLogger logger,
Path indexLocation)
Returns
true iff the given location contains an index an the index
can be successfully opened. |
static void |
checkIntegrity(StoreFileMetaData md,
org.apache.lucene.store.Directory directory) |
boolean |
checkIntegrityNoException(StoreFileMetaData md) |
static boolean |
checkIntegrityNoException(StoreFileMetaData md,
org.apache.lucene.store.Directory directory) |
void |
cleanupAndVerify(String reason,
Store.MetadataSnapshot sourceMetaData)
This method deletes every file in this store that is not contained in the given source meta data or is a
legacy checksum file.
|
void |
close() |
org.apache.lucene.store.IndexOutput |
createVerifyingOutput(String fileName,
StoreFileMetaData metadata,
org.apache.lucene.store.IOContext context)
The returned IndexOutput might validate the files checksum if the file has been written with a newer lucene version
and the metadata holds the necessary information to detect that it was been written by Lucene 4.8 or newer.
|
void |
decRef()
Decreases the refCount of this Store instance.If the refCount drops to 0, then this
store is closed.
|
void |
deleteQuiet(String... files) |
static String |
digestToString(long digest)
Produces a string representation of the given digest value.
|
org.apache.lucene.store.Directory |
directory() |
void |
failIfCorrupted() |
Store.MetadataSnapshot |
getMetadata()
Returns a new MetadataSnapshot for the latest commit in this store.
|
Store.MetadataSnapshot |
getMetadata(org.apache.lucene.index.IndexCommit commit)
Returns a new MetadataSnapshot for the given commit.
|
Store.MetadataSnapshot |
getMetadataOrEmpty()
Returns a new MetadataSnapshot for the latest commit in this store or
an empty snapshot if no index exists or can not be opened.
|
void |
incRef()
Increments the refCount of this Store instance.
|
static boolean |
isAutogenerated(String name)
Returns true if the file is auto-generated by the store and shouldn't be deleted during cleanup.
|
static boolean |
isChecksum(String name) |
boolean |
isMarkedCorrupted() |
void |
markStoreCorrupted(IOException exception)
Marks this store as corrupted.
|
org.apache.lucene.store.IndexInput |
openVerifyingInput(String filename,
org.apache.lucene.store.IOContext context,
StoreFileMetaData metadata) |
org.apache.lucene.index.SegmentInfos |
readLastCommittedSegmentsInfo()
Returns the last committed segments info for this store
|
static Store.MetadataSnapshot |
readMetadataSnapshot(Path indexLocation,
ESLogger logger)
Reads a MetadataSnapshot from the given index locations or returns an empty snapshot if it can't be read.
|
int |
refCount()
Returns the current reference count.
|
void |
removeCorruptionMarker()
Deletes all corruption markers from this store.
|
void |
renameFile(String from,
String to) |
void |
renameTempFilesSafe(Map<String,String> tempFileMap)
Renames all the given files form the key of the map to the
value of the map.
|
StoreStats |
stats() |
boolean |
tryIncRef()
Tries to increment the refCount of this Store instance.
|
static void |
tryOpenIndex(Path indexLocation)
Tries to open an index for the given location.
|
static void |
verify(org.apache.lucene.store.IndexInput input) |
static void |
verify(org.apache.lucene.store.IndexOutput output) |
indexSettings, nodeName, shardId
public static final String INDEX_STORE_STATS_REFRESH_INTERVAL
public static final String CHECKSUMS_PREFIX
public Store(ShardId shardId, Settings indexSettings, DirectoryService directoryService, ShardLock shardLock) throws IOException
IOException
@Inject public Store(ShardId shardId, IndexSettingsService indexSettingsService, DirectoryService directoryService, ShardLock shardLock, Store.OnClose onClose) throws IOException
IOException
public Store(ShardId shardId, Settings indexSettings, DirectoryService directoryService, ShardLock shardLock, Store.OnClose onClose) throws IOException
IOException
public org.apache.lucene.store.Directory directory()
public org.apache.lucene.index.SegmentInfos readLastCommittedSegmentsInfo() throws IOException
IOException
- if the index is corrupted or the segments file is not presentpublic Store.MetadataSnapshot getMetadataOrEmpty() throws IOException
org.apache.lucene.index.CorruptIndexException
- if the lucene index is corrupted. This can be caused by a checksum mismatch or an
unexpected exception when opening the index reading the segments file.org.apache.lucene.index.IndexFormatTooOldException
- if the lucene index is too old to be opened.org.apache.lucene.index.IndexFormatTooNewException
- if the lucene index is too new to be opened.IOException
public Store.MetadataSnapshot getMetadata() throws IOException
org.apache.lucene.index.CorruptIndexException
- if the lucene index is corrupted. This can be caused by a checksum mismatch or an
unexpected exception when opening the index reading the segments file.org.apache.lucene.index.IndexFormatTooOldException
- if the lucene index is too old to be opened.org.apache.lucene.index.IndexFormatTooNewException
- if the lucene index is too new to be opened.FileNotFoundException
- if one or more files referenced by a commit are not present.NoSuchFileException
- if one or more files referenced by a commit are not present.org.apache.lucene.index.IndexNotFoundException
- if no index / valid commit-point can be found in this storeIOException
public Store.MetadataSnapshot getMetadata(org.apache.lucene.index.IndexCommit commit) throws IOException
null
the latest commit point is used.org.apache.lucene.index.CorruptIndexException
- if the lucene index is corrupted. This can be caused by a checksum mismatch or an
unexpected exception when opening the index reading the segments file.org.apache.lucene.index.IndexFormatTooOldException
- if the lucene index is too old to be opened.org.apache.lucene.index.IndexFormatTooNewException
- if the lucene index is too new to be opened.FileNotFoundException
- if one or more files referenced by a commit are not present.NoSuchFileException
- if one or more files referenced by a commit are not present.org.apache.lucene.index.IndexNotFoundException
- if the commit point can't be found in this storeIOException
public void renameTempFilesSafe(Map<String,String> tempFileMap) throws IOException
IOException
public StoreStats stats() throws IOException
IOException
public void renameFile(String from, String to) throws IOException
IOException
public final void incRef()
decRef()
, in a finally clause; otherwise the store may never be closed. Note that
close()
simply calls decRef(), which means that the Store will not really be closed until decRef()
has been called for all outstanding references.
Note: Close can safely be called multiple times.
incRef
in interface RefCounted
org.apache.lucene.store.AlreadyClosedException
- iff the reference counter can not be incremented.decRef()
,
tryIncRef()
public final boolean tryIncRef()
decRef()
, in a finally clause; otherwise the store may never be closed. Note that
close()
simply calls decRef(), which means that the Store will not really be closed until decRef()
has been called for all outstanding references.
Note: Close can safely be called multiple times.
tryIncRef
in interface RefCounted
decRef()
,
incRef()
public final void decRef()
decRef
in interface RefCounted
incRef()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public static Store.MetadataSnapshot readMetadataSnapshot(Path indexLocation, ESLogger logger) throws IOException
IOException
- if the index we try to read is corruptedpublic static boolean canOpenIndex(ESLogger logger, Path indexLocation) throws IOException
true
iff the given location contains an index an the index
can be successfully opened. This includes reading the segment infos and possible
corruption markers.IOException
public static void tryOpenIndex(Path indexLocation) throws IOException
IOException
public org.apache.lucene.store.IndexOutput createVerifyingOutput(String fileName, StoreFileMetaData metadata, org.apache.lucene.store.IOContext context) throws IOException
Note: Checksums are calculated nevertheless since lucene does it by default sicne version 4.8.0. This method only adds the verification against the checksum in the given metadata and does not add any significant overhead.
IOException
public static void verify(org.apache.lucene.store.IndexOutput output) throws IOException
IOException
public org.apache.lucene.store.IndexInput openVerifyingInput(String filename, org.apache.lucene.store.IOContext context, StoreFileMetaData metadata) throws IOException
IOException
public static void verify(org.apache.lucene.store.IndexInput input) throws IOException
IOException
public boolean checkIntegrityNoException(StoreFileMetaData md)
public static boolean checkIntegrityNoException(StoreFileMetaData md, org.apache.lucene.store.Directory directory)
public static void checkIntegrity(StoreFileMetaData md, org.apache.lucene.store.Directory directory) throws IOException
IOException
public boolean isMarkedCorrupted() throws IOException
IOException
public void removeCorruptionMarker() throws IOException
IOException
public void failIfCorrupted() throws IOException
IOException
public void cleanupAndVerify(String reason, Store.MetadataSnapshot sourceMetaData) throws IOException
reason
- the reason for this cleanup operation logged for each deleted filesourceMetaData
- the metadata used for cleanup. all files in this metadata should be kept around.IOException
- if an IOException occursIllegalStateException
- if the latest snapshot in this store differs from the given one after the cleanup.public int refCount()
public static boolean isChecksum(String name)
public static boolean isAutogenerated(String name)
public static String digestToString(long digest)
public void deleteQuiet(String... files)
public void markStoreCorrupted(IOException exception) throws IOException
isMarkedCorrupted()
will return true
.IOException
Copyright © 2009–2016. All rights reserved.