public class IndexData
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private class |
IndexData.AddRowPendingChange
PendingChange for a row addition.
|
private static class |
IndexData.BinaryColumnDescriptor
ColumnDescriptor for BINARY columns.
|
private static class |
IndexData.BooleanColumnDescriptor
ColumnDescriptor for boolean columns.
|
private static class |
IndexData.ByteColumnDescriptor
ColumnDescriptor for byte based columns.
|
static class |
IndexData.ColumnDescriptor
Information about the columns in an index.
|
protected static class |
IndexData.DataPage
Object used to maintain state about an Index page.
|
static class |
IndexData.Entry
A single leaf entry in an index (points to a single row)
|
class |
IndexData.EntryCursor
Utility class to traverse the entries in the Index.
|
static class |
IndexData.EntryType
type attributes for Entries which simplify comparisons
|
private static class |
IndexData.FixedPointColumnDescriptor
ColumnDescriptor for new-style fixed point based columns.
|
private static class |
IndexData.FloatingPointColumnDescriptor
ColumnDescriptor for floating point based columns.
|
private static class |
IndexData.GenLegTextColumnDescriptor
ColumnDescriptor for "general legacy" sort order text based columns.
|
private static class |
IndexData.GenTextColumnDescriptor
ColumnDescriptor for "general" sort order (2010+) text based columns.
|
private static class |
IndexData.GuidColumnDescriptor
ColumnDescriptor for guid columns.
|
private static class |
IndexData.IntegerColumnDescriptor
ColumnDescriptor for integer based columns.
|
private static class |
IndexData.LegacyFixedPointColumnDescriptor
ColumnDescriptor for fixed point based columns (legacy sort order).
|
private static class |
IndexData.NodeEntry
A single node entry in an index (points to a sub-page in the index)
|
static class |
IndexData.PendingChange
Utility class which maintains information about a pending index update.
|
private static class |
IndexData.Position
Simple value object for maintaining some cursor state.
|
private class |
IndexData.ReadOnlyColumnDescriptor
ColumnDescriptor for columns which we cannot currently write.
|
private static class |
IndexData.RootDataPage
Simple implementation of a DataPage
|
private class |
IndexData.UpdateRowPendingChange
PendingChange for a row update (which is essentially a deletion followed
by an addition).
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.List<IndexData.ColumnDescriptor> |
_columns
List of columns and flags
|
private ByteUtil.ByteStream |
_entryBuffer
temp buffer used to create index entries
|
private TempBufferHolder |
_indexBufferH
temp buffer used to read/write the index pages
|
private java.util.List<Index> |
_indexes
the logical indexes which this index data backs
|
private byte |
_indexFlags
flags for this index
|
private boolean |
_initialized
true if the index entries have been initialized,
false otherwise |
private int |
_maxPageEntrySize
max size for all the entries written to a given index data page
|
private int |
_modCount
modification count for the table, keeps cursors up-to-date
|
private java.lang.String |
_name
name, generated on demand
|
private int |
_number
0-based index data number
|
private UsageMap |
_ownedPages
Usage map of pages that this index owns
|
private IndexPageCache |
_pageCache
Cache which manages the index pages
|
private boolean |
_primaryKey
whether or not this index data is backing a primary key logical index
|
private int |
_rootPageNumber
Page number of the root index data
|
private TableImpl |
_table
owning table
|
private int |
_uniqueEntryCount
The number of unique entries which have been added to this index.
|
private int |
_uniqueEntryCountOffset
offset within the tableDefinition buffer of the uniqueEntryCount for
this index
|
private java.lang.String |
_unsupportedReason
if non-null, the reason why we cannot create entries for this index
|
static byte |
ASCENDING_COLUMN_FLAG |
static java.util.Comparator<byte[]> |
BYTE_CODE_COMPARATOR |
(package private) static short |
COLUMN_UNUSED |
protected static byte[] |
EMPTY_PREFIX |
private static java.nio.ByteOrder |
ENTRY_BYTE_ORDER |
static IndexData.Entry |
FIRST_ENTRY
special entry which is less than any other entry
|
static byte |
IGNORE_NULLS_INDEX_FLAG |
protected static int |
INVALID_INDEX_PAGE_NUMBER |
static IndexData.Entry |
LAST_ENTRY
special entry which is greater than any other entry
|
protected static org.apache.commons.logging.Log |
LOG |
private static int |
MAGIC_INDEX_NUMBER |
static int |
MAX_COLUMNS
Max number of columns in an index
|
static java.lang.Object |
MAX_VALUE
special object which will always be greater than any other value, when
searching for an index entry range in a multi-value index
|
static java.lang.Object |
MIN_VALUE
special object which will always be greater than any other value, when
searching for an index entry range in a multi-value index
|
private static IndexData.DataPage |
NEW_ROOT_DATA_PAGE |
static byte |
SPECIAL_INDEX_FLAG |
static byte |
UNIQUE_INDEX_FLAG |
static byte |
UNKNOWN_INDEX_FLAG |
| Modifier | Constructor and Description |
|---|---|
protected |
IndexData(TableImpl table,
int number,
int uniqueEntryCount,
int uniqueEntryCountOffset) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
addIndex(Index index)
Adds a logical index which this data is backing.
|
(package private) void |
addOwnedPage(int pageNumber) |
private static int |
calcMaxPageEntrySize(JetFormat format)
Returns the maximum amount of entry data which can be encoded on any
index page.
|
private void |
commitAddRow(IndexData.Entry newEntry,
IndexData.DataPage dataPage,
int idx,
boolean isDupeEntry,
IndexData.Entry oldEntry)
Completes a prepared row addition.
|
static void |
commitAll(IndexData.PendingChange change) |
java.lang.Object[] |
constructIndexRow(java.util.Map<java.lang.String,?> row)
Constructs an array of values appropriate for this index from the given
column values.
|
java.lang.Object[] |
constructIndexRow(java.lang.String colName,
java.lang.Object value)
Constructs an array of values appropriate for this index from the given
column value.
|
java.lang.Object[] |
constructIndexRowFromEntry(java.lang.Object... values)
Constructs an array of values appropriate for this index from the given
column values, expected to match the columns for this index.
|
private int |
countNullValues(java.lang.Object[] values)
Determines the number of
null values for this index from the
given row. |
static IndexData |
create(TableImpl table,
java.nio.ByteBuffer tableBuffer,
int number,
JetFormat format)
Creates an IndexData appropriate for the given table, using information
from the given table definition buffer.
|
private byte[] |
createEntryBytes(java.lang.Object[] values)
Creates the entry bytes for a row of values.
|
private static IndexData.Entry |
createSpecialEntry(RowIdImpl rowId)
Creates one of the special index entries.
|
IndexData.EntryCursor |
cursor()
Gets a new cursor for this index.
|
IndexData.EntryCursor |
cursor(java.lang.Object[] startRow,
boolean startInclusive,
java.lang.Object[] endRow,
boolean endInclusive)
Gets a new cursor for this index, narrowed to the range defined by the
given startRow and endRow.
|
void |
deleteRow(java.lang.Object[] row,
RowIdImpl rowId)
Removes a row from this index
|
private IndexData.Entry |
deleteRowImpl(java.lang.Object[] row,
RowIdImpl rowId) |
private static IndexData.EntryType |
determineEntryType(byte[] entryBytes,
RowIdImpl rowId)
Returns the EntryType based on the given entry info.
|
private static byte[] |
encodeNumberColumnValue(java.lang.Object value,
ColumnImpl column)
Writes the value of the given column type to a byte array and returns it.
|
protected IndexData.DataPage |
findDataPage(IndexData.Entry entry)
Finds the data page for the given entry.
|
private IndexData.Position |
findEntryPosition(IndexData.Entry entry) |
private static byte[] |
flipBytes(byte[] value)
Flips all the bits in the byte array.
|
(package private) static byte[] |
flipBytes(byte[] value,
int offset,
int length)
Flips the bits in the specified bytes in the byte array.
|
private static byte[] |
flipFirstBitInByte(byte[] value,
int index)
Flips the first bit in the byte at the given index.
|
java.util.List<IndexData.ColumnDescriptor> |
getColumns()
Returns the Columns for this index (unmodifiable)
|
protected IndexData.DataPage |
getDataPage(int pageNumber)
Gets the data page for the pageNumber.
|
int |
getEntryCount()
Returns the number of index entries in the index.
|
JetFormat |
getFormat() |
int |
getIndexDataNumber() |
java.util.List<Index> |
getIndexes() |
byte |
getIndexFlags() |
protected int |
getMaxPageEntrySize() |
java.lang.String |
getName() |
private IndexData.Position |
getNextPosition(IndexData.Position curPos) |
int |
getOwnedPageCount()
Returns the number of database pages owned by this index data.
|
PageChannel |
getPageChannel() |
private IndexData.Position |
getPreviousPosition(IndexData.Position curPos)
Returns the Position before the given one, or
null if none. |
Index |
getPrimaryIndex() |
protected int |
getRootPageNumber() |
TableImpl |
getTable() |
private java.nio.ByteBuffer |
getTempEntryBuffer(java.nio.ByteBuffer indexPage,
int entryLen,
byte[] valuePrefix,
TempBufferHolder tmpEntryBufferH)
Returns an entry buffer containing the relevant data for an entry given
the valuePrefix.
|
int |
getUniqueEntryCount() |
int |
getUniqueEntryCountOffset() |
(package private) java.lang.String |
getUnsupportedReason() |
void |
initialize()
Forces initialization of this index (actual parsing of index pages).
|
protected boolean |
isBackingPrimaryKey() |
boolean |
isInitialized()
Whether or not the complete index state has been read.
|
private boolean |
isLeafPage(java.nio.ByteBuffer buffer)
Determines if the given index page is a leaf or node page.
|
boolean |
isUnique()
Whether or not index entries must be unique.
|
protected static int |
missingIndexToInsertionPoint(int idx)
Returns the valid insertion point for an index indicating a missing
entry.
|
private IndexData.ColumnDescriptor |
newColumnDescriptor(ColumnImpl col,
byte flags)
Constructs a ColumnDescriptor of the relevant type for the given Column.
|
private static IndexData.Entry |
newEntry(java.nio.ByteBuffer buffer,
int entryLength,
boolean isLeaf)
Returns a new Entry of the correct type for the given data and page type.
|
private IndexData.PendingChange |
prepareAddEntry(IndexData.Entry newEntry,
boolean isNullEntry,
java.lang.Object[] row,
IndexData.AddRowPendingChange change)
Adds an entry to the correct index dataPage, maintaining the order.
|
private IndexData.PendingChange |
prepareAddRow(java.lang.Object[] row,
RowIdImpl rowId,
IndexData.AddRowPendingChange change) |
IndexData.PendingChange |
prepareAddRow(java.lang.Object[] row,
RowIdImpl rowId,
IndexData.PendingChange nextChange)
Prepares to add a row to this index.
|
IndexData.PendingChange |
prepareUpdateRow(java.lang.Object[] oldRow,
RowIdImpl rowId,
java.lang.Object[] newRow,
IndexData.PendingChange nextChange)
Prepares to update a row in this index.
|
void |
read(java.nio.ByteBuffer tableBuffer,
java.util.List<ColumnImpl> availableColumns)
Read the rest of the index info from a tableBuffer
|
protected void |
readDataPage(IndexData.DataPage dataPage)
Reads an index page, populating the correct collection based on the page
type (node or leaf).
|
private IndexData.Entry |
removeEntry(IndexData.Entry oldEntry)
Removes an entry from the relevant index dataPage, maintaining the order.
|
static void |
rollbackAll(IndexData.PendingChange change) |
private void |
rollbackDeletedRow(IndexData.Entry removedEntry)
Undoes a previous row deletion.
|
private void |
setUnsupportedReason(java.lang.String reason,
ColumnImpl col) |
boolean |
shouldIgnoreNulls()
Whether or not
null values are actually recorded in the index. |
java.lang.String |
toString() |
void |
update()
Writes the current index state to the database.
|
void |
validate()
Used by unit tests to validate the internal status of the index.
|
(package private) java.lang.String |
withErrorContext(java.lang.String msg) |
private static java.lang.String |
withErrorContext(java.lang.String msg,
DatabaseImpl db,
java.lang.String tableName,
java.lang.String idxName) |
protected static void |
writeDataPage(java.nio.ByteBuffer buffer,
IndexData.DataPage dataPage,
int tdefPageNumber,
JetFormat format)
Writes the data page info to the given buffer.
|
protected void |
writeDataPage(IndexData.DataPage dataPage)
Write the given index page out to a buffer
|
protected static void |
writeDefinitions(TableCreator creator,
java.nio.ByteBuffer buffer)
Writes the index definitions into a table definition buffer.
|
private static void |
writeGeneralBinaryEntry(byte[] valueBytes,
boolean isAsc,
ByteUtil.ByteStream bout)
Writes a binary value using the general binary entry encoding rules.
|
protected static void |
writeRowCountDefinitions(TableCreator creator,
java.nio.ByteBuffer buffer)
Writes the index row count definitions into a table definition buffer.
|
protected static final org.apache.commons.logging.Log LOG
public static final IndexData.Entry FIRST_ENTRY
public static final IndexData.Entry LAST_ENTRY
public static final java.lang.Object MAX_VALUE
public static final java.lang.Object MIN_VALUE
private static final IndexData.DataPage NEW_ROOT_DATA_PAGE
protected static final int INVALID_INDEX_PAGE_NUMBER
public static final int MAX_COLUMNS
protected static final byte[] EMPTY_PREFIX
static final short COLUMN_UNUSED
public static final byte ASCENDING_COLUMN_FLAG
public static final byte UNIQUE_INDEX_FLAG
public static final byte IGNORE_NULLS_INDEX_FLAG
public static final byte SPECIAL_INDEX_FLAG
public static final byte UNKNOWN_INDEX_FLAG
private static final int MAGIC_INDEX_NUMBER
private static final java.nio.ByteOrder ENTRY_BYTE_ORDER
public static final java.util.Comparator<byte[]> BYTE_CODE_COMPARATOR
private java.lang.String _name
private final TableImpl _table
private final int _number
private int _rootPageNumber
private final int _uniqueEntryCountOffset
private int _uniqueEntryCount
private final java.util.List<IndexData.ColumnDescriptor> _columns
private final java.util.List<Index> _indexes
private byte _indexFlags
private UsageMap _ownedPages
private boolean _initialized
true if the index entries have been initialized,
false otherwiseprivate int _modCount
private final TempBufferHolder _indexBufferH
private ByteUtil.ByteStream _entryBuffer
private final int _maxPageEntrySize
private boolean _primaryKey
private java.lang.String _unsupportedReason
private final IndexPageCache _pageCache
protected IndexData(TableImpl table, int number, int uniqueEntryCount, int uniqueEntryCountOffset)
public static IndexData create(TableImpl table, java.nio.ByteBuffer tableBuffer, int number, JetFormat format) throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getName()
public TableImpl getTable()
public JetFormat getFormat()
public PageChannel getPageChannel()
public Index getPrimaryIndex()
public java.util.List<Index> getIndexes()
void addIndex(Index index)
public byte getIndexFlags()
public int getIndexDataNumber()
public int getUniqueEntryCount()
public int getUniqueEntryCountOffset()
protected boolean isBackingPrimaryKey()
public boolean shouldIgnoreNulls()
null values are actually recorded in the index.public boolean isUnique()
Some notes about uniqueness:
null entries
invalid for a unique indexpublic java.util.List<IndexData.ColumnDescriptor> getColumns()
public boolean isInitialized()
protected int getRootPageNumber()
private void setUnsupportedReason(java.lang.String reason,
ColumnImpl col)
java.lang.String getUnsupportedReason()
protected int getMaxPageEntrySize()
public int getOwnedPageCount()
void addOwnedPage(int pageNumber)
throws java.io.IOException
java.io.IOExceptionpublic void validate()
throws java.io.IOException
java.io.IOExceptionpublic int getEntryCount()
throws java.io.IOException
Forces index initialization.
java.io.IOExceptionpublic void initialize()
throws java.io.IOException
java.io.IOExceptionpublic void update()
throws java.io.IOException
Forces index initialization.
java.io.IOExceptionpublic void read(java.nio.ByteBuffer tableBuffer,
java.util.List<ColumnImpl> availableColumns)
throws java.io.IOException
tableBuffer - table definition buffer to read from initial infoavailableColumns - Columns that this index may usejava.io.IOExceptionprotected static void writeRowCountDefinitions(TableCreator creator, java.nio.ByteBuffer buffer)
creator - description of the indexes to writebuffer - Buffer to write toprotected static void writeDefinitions(TableCreator creator, java.nio.ByteBuffer buffer) throws java.io.IOException
creator - description of the indexes to writebuffer - Buffer to write tojava.io.IOExceptionpublic IndexData.PendingChange prepareAddRow(java.lang.Object[] row, RowIdImpl rowId, IndexData.PendingChange nextChange) throws java.io.IOException
Forces index initialization.
row - Row to addrowId - rowId of the row to be addedjava.io.IOExceptionprivate IndexData.PendingChange prepareAddRow(java.lang.Object[] row, RowIdImpl rowId, IndexData.AddRowPendingChange change) throws java.io.IOException
java.io.IOExceptionprivate IndexData.PendingChange prepareAddEntry(IndexData.Entry newEntry, boolean isNullEntry, java.lang.Object[] row, IndexData.AddRowPendingChange change) throws java.io.IOException
java.io.IOExceptionprivate void commitAddRow(IndexData.Entry newEntry, IndexData.DataPage dataPage, int idx, boolean isDupeEntry, IndexData.Entry oldEntry) throws java.io.IOException
java.io.IOExceptionpublic IndexData.PendingChange prepareUpdateRow(java.lang.Object[] oldRow, RowIdImpl rowId, java.lang.Object[] newRow, IndexData.PendingChange nextChange) throws java.io.IOException
Forces index initialization.
oldRow - Row to be removednewRow - Row to be addedrowId - rowId of the row to be updatedjava.io.IOExceptionpublic void deleteRow(java.lang.Object[] row,
RowIdImpl rowId)
throws java.io.IOException
Forces index initialization.
row - Row to removerowId - rowId of the row to be removedjava.io.IOExceptionprivate IndexData.Entry deleteRowImpl(java.lang.Object[] row, RowIdImpl rowId) throws java.io.IOException
java.io.IOExceptionprivate void rollbackDeletedRow(IndexData.Entry removedEntry) throws java.io.IOException
java.io.IOExceptionprivate IndexData.Entry removeEntry(IndexData.Entry oldEntry) throws java.io.IOException
java.io.IOExceptionpublic static void commitAll(IndexData.PendingChange change) throws java.io.IOException
java.io.IOExceptionpublic static void rollbackAll(IndexData.PendingChange change) throws java.io.IOException
java.io.IOExceptionpublic IndexData.EntryCursor cursor() throws java.io.IOException
Forces index initialization.
java.io.IOExceptionpublic IndexData.EntryCursor cursor(java.lang.Object[] startRow, boolean startInclusive, java.lang.Object[] endRow, boolean endInclusive) throws java.io.IOException
Forces index initialization.
startRow - the first row of data for the cursor, or null for
the first entrystartInclusive - whether or not startRow is inclusive or exclusiveendRow - the last row of data for the cursor, or null for
the last entryendInclusive - whether or not endRow is inclusive or exclusivejava.io.IOExceptionprivate IndexData.Position findEntryPosition(IndexData.Entry entry) throws java.io.IOException
java.io.IOExceptionprivate IndexData.Position getNextPosition(IndexData.Position curPos) throws java.io.IOException
java.io.IOExceptionprivate IndexData.Position getPreviousPosition(IndexData.Position curPos) throws java.io.IOException
null if none.java.io.IOExceptionprotected static int missingIndexToInsertionPoint(int idx)
public java.lang.Object[] constructIndexRowFromEntry(java.lang.Object... values)
java.lang.IllegalArgumentException - if the wrong number of values are
providedpublic java.lang.Object[] constructIndexRow(java.lang.String colName,
java.lang.Object value)
null if not all
columns for this index were providedpublic java.lang.Object[] constructIndexRow(java.util.Map<java.lang.String,?> row)
null if not all
columns for this index were providedpublic java.lang.String toString()
toString in class java.lang.Objectprotected void writeDataPage(IndexData.DataPage dataPage) throws java.io.IOException
java.io.IOExceptionprotected static void writeDataPage(java.nio.ByteBuffer buffer,
IndexData.DataPage dataPage,
int tdefPageNumber,
JetFormat format)
throws java.io.IOException
java.io.IOExceptionprotected void readDataPage(IndexData.DataPage dataPage) throws java.io.IOException
java.io.IOExceptionprivate static IndexData.Entry newEntry(java.nio.ByteBuffer buffer, int entryLength, boolean isLeaf) throws java.io.IOException
java.io.IOExceptionprivate java.nio.ByteBuffer getTempEntryBuffer(java.nio.ByteBuffer indexPage,
int entryLen,
byte[] valuePrefix,
TempBufferHolder tmpEntryBufferH)
private boolean isLeafPage(java.nio.ByteBuffer buffer)
throws java.io.IOException
java.io.IOExceptionprivate int countNullValues(java.lang.Object[] values)
null values for this index from the
given row.private byte[] createEntryBytes(java.lang.Object[] values)
throws java.io.IOException
java.io.IOExceptionprotected IndexData.DataPage findDataPage(IndexData.Entry entry) throws java.io.IOException
java.io.IOExceptionprotected IndexData.DataPage getDataPage(int pageNumber) throws java.io.IOException
java.io.IOExceptionprivate static byte[] flipFirstBitInByte(byte[] value,
int index)
private static byte[] flipBytes(byte[] value)
static byte[] flipBytes(byte[] value,
int offset,
int length)
private static byte[] encodeNumberColumnValue(java.lang.Object value,
ColumnImpl column)
throws java.io.IOException
java.io.IOExceptionprivate static void writeGeneralBinaryEntry(byte[] valueBytes,
boolean isAsc,
ByteUtil.ByteStream bout)
private static IndexData.Entry createSpecialEntry(RowIdImpl rowId)
private IndexData.ColumnDescriptor newColumnDescriptor(ColumnImpl col, byte flags) throws java.io.IOException
java.io.IOExceptionprivate static IndexData.EntryType determineEntryType(byte[] entryBytes, RowIdImpl rowId)
private static int calcMaxPageEntrySize(JetFormat format)
java.lang.String withErrorContext(java.lang.String msg)
private static java.lang.String withErrorContext(java.lang.String msg,
DatabaseImpl db,
java.lang.String tableName,
java.lang.String idxName)