Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
SegmentInfos.h
Go to the documentation of this file.
1
2// Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3// Distributable under the terms of either the Apache License (Version 2.0)
4// or the GNU Lesser General Public License.
6
7#ifndef SEGMENTINFOS_H
8#define SEGMENTINFOS_H
9
11
12namespace Lucene {
13
15class LPPAPI SegmentInfos : public SegmentInfoCollection {
16public:
18 virtual ~SegmentInfos();
19
21
22public:
24 static const int32_t FORMAT;
25
30 static const int32_t FORMAT_LOCKLESS;
31
33 static const int32_t FORMAT_SINGLE_NORM_FILE;
34
36 static const int32_t FORMAT_SHARED_DOC_STORE;
37
39 static const int32_t FORMAT_CHECKSUM;
40
42 static const int32_t FORMAT_DEL_COUNT;
43
46 static const int32_t FORMAT_HAS_PROX;
47
49 static const int32_t FORMAT_USER_DATA;
50
52 static const int32_t FORMAT_DIAGNOSTICS;
53
55 static const int32_t CURRENT_FORMAT;
56
57 int32_t counter; // used to name new segments
58
59private:
61 static int32_t defaultGenFileRetryCount;
62 static int32_t defaultGenFileRetryPauseMsec;
63 static int32_t defaultGenLookaheadCount;
64
67 int64_t version;
68
69 int64_t generation; // generation of the "segments_N" for the next commit
70
71 int64_t lastGeneration; // generation of the "segments_N" file we last successfully read
72 // or wrote; this is normally the same as generation except if
73 // there was an exception that had interrupted a commit
74
75 MapStringString userData; // Opaque map<string, string> that user can specify during IndexWriter::commit
76
77 static MapStringString singletonUserData;
78
79 static InfoStreamPtr infoStream;
80 ChecksumIndexOutputPtr pendingSegnOutput;
81
82public:
83 SegmentInfoPtr info(int32_t i);
86
88 void read(const DirectoryPtr& directory, const String& segmentFileName);
89
91 void read(const DirectoryPtr& directory);
92
95
97 int64_t getVersion();
98 int64_t getGeneration();
100
103 SegmentInfosPtr range(int32_t first, int32_t last);
104
107
108 void rollbackCommit(const DirectoryPtr& dir);
109
114 void prepareCommit(const DirectoryPtr& dir);
115
118 HashSet<String> files(const DirectoryPtr& dir, bool includeSegmentsFile);
119
120 void finishCommit(const DirectoryPtr& dir);
121
123 void commit(const DirectoryPtr& dir);
124
125 String segString(const DirectoryPtr& directory);
126 MapStringString getUserData();
127 void setUserData(MapStringString data);
128
131 void replace(const SegmentInfosPtr& other);
132
134
136 static int64_t getCurrentSegmentGeneration(const DirectoryPtr& directory);
138 static String getCurrentSegmentFileName(const DirectoryPtr& directory);
139 static int64_t generationFromSegmentsFileName(const String& fileName);
140
142 static int64_t readCurrentVersion(const DirectoryPtr& directory);
143
145 static MapStringString readCurrentUserData(const DirectoryPtr& directory);
146
148 static void setInfoStream(const InfoStreamPtr& infoStream);
149
152 static void setDefaultGenFileRetryCount(int32_t count);
153
156
158 static void setDefaultGenFileRetryPauseMsec(int32_t msec);
159
162
165 static void setDefaultGenLookaheadCount(int32_t count);
166
169
172
173 static void message(const String& message);
174
175protected:
176 void write(const DirectoryPtr& directory);
177
178 friend class FindSegmentsFile;
179};
180
181}
182
183#endif
#define LUCENE_CLASS(Name)
Definition LuceneObject.h:24
Utility template class to handle hash set collections that can be safely copied and shared.
Definition HashSet.h:17
A collection of SegmentInfo objects to be used as a base class for SegmentInfos.
Definition SegmentInfoCollection.h:15
A collection of SegmentInfo objects with methods for operating on those segments in relation to the f...
Definition SegmentInfos.h:15
static void setDefaultGenFileRetryCount(int32_t count)
Set how many times to try loading the segments.gen file contents to determine current segment generat...
static int32_t getDefaultGenLookahedCount()
static const int32_t FORMAT
The file format version, a negative number. Works since counter, the old 1st entry,...
Definition SegmentInfos.h:24
static int64_t generationFromSegmentsFileName(const String &fileName)
static int32_t getDefaultGenFileRetryCount()
void commit(const DirectoryPtr &dir)
Writes & syncs to the Directory dir, taking care to remove the segments file on exception.
bool hasExternalSegments(const DirectoryPtr &dir)
static const int32_t FORMAT_LOCKLESS
This format adds details used for lockless commits. It differs slightly from the previous format in t...
Definition SegmentInfos.h:30
static const int32_t FORMAT_SHARED_DOC_STORE
This format allows multiple segments to share a single vectors and stored fields file.
Definition SegmentInfos.h:36
int64_t getVersion()
Version number when this SegmentInfos was generated.
static const int32_t FORMAT_SINGLE_NORM_FILE
This format adds a "hasSingleNormFile" flag into each segment info.
Definition SegmentInfos.h:33
static const int32_t FORMAT_HAS_PROX
This format adds the boolean hasProx to record if any fields in the segment store prox information (i...
Definition SegmentInfos.h:46
static void setDefaultGenFileRetryPauseMsec(int32_t msec)
Set how many milliseconds to pause in between attempts to load the segments.gen file.
void write(const DirectoryPtr &directory)
static int64_t getCurrentSegmentGeneration(HashSet< String > files)
static MapStringString readCurrentUserData(const DirectoryPtr &directory)
Returns userData from latest segments file.
static void setDefaultGenLookaheadCount(int32_t count)
Set how many times to try incrementing the gen when loading the segments file. This only runs if the ...
static String getCurrentSegmentFileName(const DirectoryPtr &directory)
void rollbackCommit(const DirectoryPtr &dir)
String getNextSegmentFileName()
void finishCommit(const DirectoryPtr &dir)
static int64_t getCurrentSegmentGeneration(const DirectoryPtr &directory)
static InfoStreamPtr getInfoStream()
void read(const DirectoryPtr &directory, const String &segmentFileName)
Read a particular segmentFileName. Note that this may throw an IOException if a commit is in process.
void replace(const SegmentInfosPtr &other)
Replaces all segments in this instance, but keeps generation, version, counter so that future commits...
String segString(const DirectoryPtr &directory)
void setUserData(MapStringString data)
SegmentInfosPtr range(int32_t first, int32_t last)
Returns a new SegmentInfos containing the SegmentInfo instances in the specified range first (inclusi...
virtual LuceneObjectPtr clone(const LuceneObjectPtr &other=LuceneObjectPtr())
Returns a copy of this instance, also copying each SegmentInfo.
static const int32_t FORMAT_DEL_COUNT
This format adds the deletion count for each segment. This way IndexWriter can efficiently report num...
Definition SegmentInfos.h:42
HashSet< String > files(const DirectoryPtr &dir, bool includeSegmentsFile)
Returns all file names referenced by SegmentInfo instances matching the provided Directory (ie files ...
int32_t counter
Definition SegmentInfos.h:57
void read(const DirectoryPtr &directory)
This version of read uses the retry logic (for lock-less commits) to find the right segments file to ...
static void message(const String &message)
static void setInfoStream(const InfoStreamPtr &infoStream)
If non-null, information about retries when loading the segments file will be printed to this.
int64_t getLastGeneration()
static const int32_t FORMAT_CHECKSUM
This format adds a checksum at the end of the file to ensure all bytes were successfully written.
Definition SegmentInfos.h:39
static int32_t getDefaultGenFileRetryPauseMsec()
MapStringString getUserData()
static int64_t readCurrentVersion(const DirectoryPtr &directory)
Current version number from segments file.
SegmentInfoPtr info(int32_t i)
void updateGeneration(const SegmentInfosPtr &other)
Carry over generation numbers from another SegmentInfos.
String getCurrentSegmentFileName()
static String getCurrentSegmentFileName(HashSet< String > files)
static const int32_t FORMAT_DIAGNOSTICS
This format adds optional per-segment string diagnostics storage, and switches userData to Map.
Definition SegmentInfos.h:52
void prepareCommit(const DirectoryPtr &dir)
Call this to start a commit. This writes the new segments file, but writes an invalid checksum at the...
static const int32_t CURRENT_FORMAT
This must always point to the most recent file format.
Definition SegmentInfos.h:55
static const int32_t FORMAT_USER_DATA
This format adds optional commit userData storage.
Definition SegmentInfos.h:49
Definition AbstractAllTermDocs.h:12
boost::shared_ptr< InfoStream > InfoStreamPtr
Definition LuceneTypes.h:532
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition LuceneTypes.h:539
boost::shared_ptr< SegmentInfo > SegmentInfoPtr
Definition LuceneTypes.h:208
boost::shared_ptr< ChecksumIndexOutput > ChecksumIndexOutputPtr
Definition LuceneTypes.h:488
boost::shared_ptr< Directory > DirectoryPtr
Definition LuceneTypes.h:489
boost::shared_ptr< SegmentInfos > SegmentInfosPtr
Definition LuceneTypes.h:210

clucene.sourceforge.net