Package com.arcadedb.index.lsm
Class LSMTreeIndexAbstract
- java.lang.Object
-
- com.arcadedb.engine.PaginatedComponent
-
- com.arcadedb.index.lsm.LSMTreeIndexAbstract
-
- Direct Known Subclasses:
LSMTreeIndexCompacted
,LSMTreeIndexMutable
public abstract class LSMTreeIndexAbstract extends PaginatedComponent
Abstract class for LSM-based indexes. The first page contains 2 bytes to store key and value types. The pages are populated from the head of the page with the pointers to the pair key/value that starts from the tail. A page is full when there is no space between the head (key pointers) and the tail (key/value pairs).
When a page is full, another page is created, waiting for a compaction.
HEADER ROOT PAGE (1st) = [offsetFreeKeyValueContent(int:4),numberOfEntries(int:4),mutable(boolean:1),compactedPageNumberOfSeries(int:4),subIndexFileId(int:4),numberOfKeys(byte:1),keyType(byte:1)*]
HEADER Nst PAGE = [offsetFreeKeyValueContent(int:4),numberOfEntries(int:4),mutable(boolean:1),compactedPageNumberOfSeries(int:4)]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LSMTreeIndexAbstract.COMPACTING_STATUS
protected static class
LSMTreeIndexAbstract.LookupResult
static class
LSMTreeIndexAbstract.NULL_STRATEGY
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
binaryKeyTypes
protected BinaryComparator
comparator
static int
DEF_PAGE_SIZE
protected static LSMTreeIndexAbstract.LookupResult
HIGHER
protected Type[]
keyTypes
protected static LSMTreeIndexAbstract.LookupResult
LOWER
protected LSMTreeIndex
mainIndex
protected LSMTreeIndexAbstract.NULL_STRATEGY
nullStrategy
RID
REMOVED_ENTRY_RID
protected BinarySerializer
serializer
protected static String
TEMP_EXT
protected boolean
unique
protected static byte
valueType
-
Constructor Summary
Constructors Modifier Constructor Description protected
LSMTreeIndexAbstract(LSMTreeIndex mainIndex, DatabaseInternal database, String name, boolean unique, String filePath, int id, PaginatedFile.MODE mode, int pageSize, int version)
Called at load time (1st page only).protected
LSMTreeIndexAbstract(LSMTreeIndex mainIndex, DatabaseInternal database, String name, boolean unique, String filePath, String ext, byte[] keyTypes, int pageSize, int version)
Called at cloning time.protected
LSMTreeIndexAbstract(LSMTreeIndex mainIndex, DatabaseInternal database, String name, boolean unique, String filePath, String ext, PaginatedFile.MODE mode, Type[] keyTypes, int pageSize, int version, LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy)
Called at creation time.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Object[]
checkForNulls(Object[] keys)
protected int
compareKey(Binary currentPageBuffer, int startIndexArray, Object[] keys, int mid, int count)
protected abstract LSMTreeIndexAbstract.LookupResult
compareKey(Binary currentPageBuffer, int startIndexArray, Object[] convertedKeys, int mid, int count, int purpose)
static int
compareKeys(BinaryComparator comparator, byte[] keyTypes, Object[] keys1, Object[] keys2)
protected Object[]
convertKeys(Object[] keys, byte[] keyTypes)
void
drop()
protected int
getCount(BasePage currentPage)
int
getFileId()
protected int
getHeaderSize(int pageNum)
protected Object[]
getKeyInPagePosition(int pageNum, Binary currentPageBuffer, int position)
byte[]
getKeyTypes()
Object
getMainComponent()
LSMTreeIndexAbstract.NULL_STRATEGY
getNullStrategy()
protected RID
getOriginalRID(RID rid)
protected Object[]
getPageBound(BasePage currentPage, Binary currentPageBuffer)
PaginatedComponent
getPaginatedComponent()
protected int
getSerializedKeySize(Binary buffer, int keyLength)
Reads the keys and returns the serialized size.Map<String,Long>
getStats()
protected int
getValuesFreePosition(BasePage currentPage)
boolean
isDeletedEntry(RID rid)
static boolean
isKeyNull(Object[] keys)
protected boolean
isMutable(BasePage currentPage)
boolean
isUnique()
protected LSMTreeIndexAbstract.LookupResult
lookupInPage(int pageNum, int count, Binary currentPageBuffer, Object[] convertedKeys, int purpose)
Lookups for an entry in the index by using dichotomy search.protected boolean
lookupInPageAndAddInResultset(BasePage currentPage, Binary currentPageBuffer, int count, Object[] originalKeys, Object[] convertedKeys, int limit, Set<IndexCursorEntry> set, Set<RID> removedRIDs)
protected RID[]
readEntryValues(Binary buffer)
void
removeTempSuffix()
protected void
setCount(MutablePage currentPage, int newCount)
protected void
setMutable(MutablePage currentPage, boolean mutable)
protected void
setValuesFreePosition(MutablePage currentPage, int newValuesFreePosition)
String
toString()
protected void
writeEntry(Binary buffer, Object[] keys, Object rid)
protected void
writeEntry(Binary buffer, Object[] keys, Object[] rids)
-
Methods inherited from class com.arcadedb.engine.PaginatedComponent
close, getDatabase, getId, getName, getOSFile, getPageSize, getTotalPages, getVersion, onAfterCommit, onAfterLoad, setPageCount
-
-
-
-
Field Detail
-
DEF_PAGE_SIZE
public static final int DEF_PAGE_SIZE
- See Also:
- Constant Field Values
-
REMOVED_ENTRY_RID
public final RID REMOVED_ENTRY_RID
-
TEMP_EXT
protected static final String TEMP_EXT
- See Also:
- Constant Field Values
-
LOWER
protected static final LSMTreeIndexAbstract.LookupResult LOWER
-
HIGHER
protected static final LSMTreeIndexAbstract.LookupResult HIGHER
-
valueType
protected static final byte valueType
- See Also:
- Constant Field Values
-
mainIndex
protected LSMTreeIndex mainIndex
-
comparator
protected final BinaryComparator comparator
-
serializer
protected final BinarySerializer serializer
-
unique
protected final boolean unique
-
keyTypes
protected Type[] keyTypes
-
binaryKeyTypes
protected byte[] binaryKeyTypes
-
nullStrategy
protected LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy
-
-
Constructor Detail
-
LSMTreeIndexAbstract
protected LSMTreeIndexAbstract(LSMTreeIndex mainIndex, DatabaseInternal database, String name, boolean unique, String filePath, String ext, PaginatedFile.MODE mode, Type[] keyTypes, int pageSize, int version, LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy) throws IOException
Called at creation time.- Throws:
IOException
-
LSMTreeIndexAbstract
protected LSMTreeIndexAbstract(LSMTreeIndex mainIndex, DatabaseInternal database, String name, boolean unique, String filePath, String ext, byte[] keyTypes, int pageSize, int version) throws IOException
Called at cloning time.- Throws:
IOException
-
LSMTreeIndexAbstract
protected LSMTreeIndexAbstract(LSMTreeIndex mainIndex, DatabaseInternal database, String name, boolean unique, String filePath, int id, PaginatedFile.MODE mode, int pageSize, int version) throws IOException
Called at load time (1st page only).- Throws:
IOException
-
-
Method Detail
-
compareKey
protected abstract LSMTreeIndexAbstract.LookupResult compareKey(Binary currentPageBuffer, int startIndexArray, Object[] convertedKeys, int mid, int count, int purpose)
- Parameters:
purpose
- 0 = exists, 1 = retrieve, 2 = ascending iterator, 3 = descending iterator
-
getPaginatedComponent
public PaginatedComponent getPaginatedComponent()
-
isUnique
public boolean isUnique()
-
getFileId
public int getFileId()
-
getNullStrategy
public LSMTreeIndexAbstract.NULL_STRATEGY getNullStrategy()
-
getKeyTypes
public byte[] getKeyTypes()
-
isDeletedEntry
public boolean isDeletedEntry(RID rid)
-
removeTempSuffix
public void removeTempSuffix()
-
drop
public void drop() throws IOException
- Throws:
IOException
-
getMainComponent
public Object getMainComponent()
- Overrides:
getMainComponent
in classPaginatedComponent
-
lookupInPage
protected LSMTreeIndexAbstract.LookupResult lookupInPage(int pageNum, int count, Binary currentPageBuffer, Object[] convertedKeys, int purpose)
Lookups for an entry in the index by using dichotomy search.- Parameters:
purpose
- 0 = exists, 1 = retrieve, 2 = ascending iterator, 3 = descending iterator- Returns:
- LookupResult object, never null
-
getSerializedKeySize
protected int getSerializedKeySize(Binary buffer, int keyLength)
Reads the keys and returns the serialized size.
-
getKeyInPagePosition
protected Object[] getKeyInPagePosition(int pageNum, Binary currentPageBuffer, int position)
-
compareKey
protected int compareKey(Binary currentPageBuffer, int startIndexArray, Object[] keys, int mid, int count)
-
getHeaderSize
protected int getHeaderSize(int pageNum)
-
compareKeys
public static int compareKeys(BinaryComparator comparator, byte[] keyTypes, Object[] keys1, Object[] keys2)
-
getCount
protected int getCount(BasePage currentPage)
-
setCount
protected void setCount(MutablePage currentPage, int newCount)
-
isMutable
protected boolean isMutable(BasePage currentPage)
-
setMutable
protected void setMutable(MutablePage currentPage, boolean mutable)
-
isKeyNull
public static boolean isKeyNull(Object[] keys)
-
lookupInPageAndAddInResultset
protected boolean lookupInPageAndAddInResultset(BasePage currentPage, Binary currentPageBuffer, int count, Object[] originalKeys, Object[] convertedKeys, int limit, Set<IndexCursorEntry> set, Set<RID> removedRIDs)
-
getValuesFreePosition
protected int getValuesFreePosition(BasePage currentPage)
-
setValuesFreePosition
protected void setValuesFreePosition(MutablePage currentPage, int newValuesFreePosition)
-
-