Append an entry for the given offset/location pair to the index.
Append an entry for the given offset/location pair to the index. This entry must have a larger offset than all subsequent entries.
Close the index
Delete this index file
The number of entries in this index
Get the nth offset mapping from the index
Get the nth offset mapping from the index
The entry number in the index
The offset/position pair at that entry
Flush the data in the index to disk
True iff there are no more slots available in this index
Find the largest offset less than or equal to the given targetOffset and return a pair holding this offset and it's corresponding physical file position.
Find the largest offset less than or equal to the given targetOffset and return a pair holding this offset and it's corresponding physical file position.
The offset to look up.
The offset found and the corresponding file position for this offset. If the target offset is smaller than the least entry in the index (or the index is empty), the pair (baseOffset, 0) is returned.
The maximum number of eight-byte entries this index can hold
The last entry in the index
Rename the file that backs this offset index
Rename the file that backs this offset index
true iff the rename was successful
Reset the size of the memory map and the underneath file.
Reset the size of the memory map and the underneath file. This is used in two kinds of cases: (1) in trimToValidSize() which is called at closing the segment or new segment being rolled; (2) at loading segments from disk or truncating back to an old segment where a new log segment became active; we want to reset the index size to maximum index size to avoid rolling new segment.
Do a basic sanity check on this index to detect obvious problems
Do a basic sanity check on this index to detect obvious problems
if any problems are found
The number of bytes actually used by this index
Trim this segment to fit just the valid entries, deleting all trailing unwritten bytes from the file.
Truncate the entire index, deleting all entries
Remove all entries from the index which have an offset greater than or equal to the given offset.
Remove all entries from the index which have an offset greater than or equal to the given offset. Truncating to an offset larger than the largest in the index has no effect.
An index that maps offsets to physical file locations for a particular log segment. This index may be sparse: that is it may not hold an entry for all messages in the log.
The index is stored in a file that is pre-allocated to hold a fixed maximum number of 8-byte entries.
The index supports lookups against a memory-map of this file. These lookups are done using a simple binary search variant to locate the offset/location pair for the greatest offset less than or equal to the target offset.
Index files can be opened in two ways: either as an empty, mutable index that allows appends or an immutable read-only index file that has previously been populated. The makeReadOnly method will turn a mutable file into an immutable one and truncate off any extra bytes. This is done when the index file is rolled over.
No attempt is made to checksum the contents of this file, in the event of a crash it is rebuilt.
The file format is a series of entries. The physical format is a 4 byte "relative" offset and a 4 byte file location for the message with that offset. The offset stored is relative to the base offset of the index file. So, for example, if the base offset was 50, then the offset 55 would be stored as 5. Using relative offsets in this way let's us use only 4 bytes for the offset.
The frequency of entries is up to the user of this class.
All external APIs translate from relative offsets to full offsets, so users of this class do not interact with the internal storage format.