public abstract class BPlusTree<L,T extends L> extends DataStructure implements IgniteTree<L,T>
Modifier and Type | Class and Description |
---|---|
class |
BPlusTree.Get
Get operation.
|
class |
BPlusTree.Insert |
class |
BPlusTree.Invoke
Invoke operation.
|
class |
BPlusTree.Put
Put operation.
|
class |
BPlusTree.Replace |
static class |
BPlusTree.Result
Operation result.
|
class |
BPlusTree.Search |
static interface |
BPlusTree.TreeRowClosure<L,T extends L>
A generic visitor-style interface for performing filtering/modifications/miscellaneous operations on the tree.
|
static interface |
BPlusTree.TreeVisitorClosure<L,T extends L>
A generic visitor-style interface for performing inspection/modification operations on the tree.
|
IgniteTree.InvokeClosure<T>, IgniteTree.OperationType
Modifier and Type | Field and Description |
---|---|
static String |
CONC_DESTROY_MSG
Destroy msg.
|
static int |
IGNITE_BPLUS_TREE_LOCK_RETRIES_DEFAULT |
protected long |
metaPageId |
static ThreadLocal<Boolean> |
suspendFailureDiagnostic |
static PageHandlerWrapper<BPlusTree.Result> |
testHndWrapper
Wrapper for tree pages operations.
|
Modifier | Constructor and Description |
---|---|
protected |
BPlusTree(String name,
int cacheGrpId,
String grpName,
PageMemory pageMem,
IgniteWriteAheadLogManager wal,
AtomicLong globalRmvId,
long metaPageId,
ReuseList reuseList,
byte pageFlag,
@Nullable FailureProcessor failureProcessor,
@Nullable PageLockListener lsnr,
PageIoResolver pageIoRslvr) |
protected |
BPlusTree(String name,
int cacheGrpId,
String cacheGrpName,
PageMemory pageMem,
IgniteWriteAheadLogManager wal,
AtomicLong globalRmvId,
long metaPageId,
ReuseList reuseList,
IOVersions<? extends BPlusInnerIO<L>> innerIos,
IOVersions<? extends BPlusLeafIO<L>> leafIos,
byte pageFlag,
@Nullable FailureProcessor failureProcessor,
@Nullable PageLockListener lockLsnr) |
Modifier and Type | Method and Description |
---|---|
protected long |
acquirePage(long pageId) |
protected void |
checkDestroyed()
Check if the tree is getting destroyed.
|
protected abstract int |
compare(BPlusIO<L> io,
long pageAddr,
int idx,
L row) |
protected int |
compare(int lvl,
BPlusIO<L> io,
long pageAddr,
int idx,
L row) |
protected CorruptedTreeException |
corruptedTreeException(String msg,
Throwable cause,
int grpId,
long... pageIds)
Construct the exception and invoke failure processor.
|
long |
destroy()
Destroys tree.
|
long |
destroy(IgniteInClosure<L> c,
boolean forceDestroy)
Destroys tree.
|
protected long |
destroyDownPages(LongListReuseBag bag,
long pageId,
int lvl,
IgniteInClosure<L> c,
AtomicLong lockHoldStartTime,
long lockMaxTime,
Deque<GridTuple3<Long,Long,Long>> lockedPages)
Recursively destroys tree pages.
|
void |
enableSequentialWriteMode()
Flag for enabling single-threaded append-only tree creation.
|
GridCursor<T> |
find(L lower,
L upper)
Returns a cursor from lower to upper bounds inclusive.
|
GridCursor<T> |
find(L lower,
L upper,
BPlusTree.TreeRowClosure<L,T> c,
Object x) |
GridCursor<T> |
find(L lower,
L upper,
Object x)
Returns a cursor from lower to upper bounds inclusive.
|
T |
findFirst()
Returns a value mapped to the lowest key, or
null if tree is empty |
T |
findFirst(BPlusTree.TreeRowClosure<L,T> filter)
Returns a value mapped to the lowest key, or
null if tree is empty or no entry matches the passed filter. |
T |
findLast()
Returns a value mapped to the greatest key, or
null if tree is empty |
T |
findLast(BPlusTree.TreeRowClosure<L,T> c)
Returns a value mapped to the greatest key, or
null if tree is empty or no entry matches the passed filter. |
T |
findOne(L row)
Returns the value to which the specified key is mapped, or
null if this tree contains no mapping for the
key. |
<R> R |
findOne(L row,
BPlusTree.TreeRowClosure<L,T> c,
Object x) |
<R> R |
findOne(L row,
Object x) |
protected Iterable<Long> |
getFirstPageIds(long pageAddr) |
protected int |
getLockRetries() |
long |
getMetaPageId()
Returns meta page id.
|
String |
getName() |
T |
getRow(BPlusIO<L> io,
long pageAddr,
int idx)
Get a full detached data row.
|
abstract T |
getRow(BPlusIO<L> io,
long pageAddr,
int idx,
Object x)
Get data row.
|
protected void |
initTree(boolean initNew)
Initialize new tree.
|
protected void |
initTree(boolean initNew,
int inlineSize)
Initialize new tree.
|
static void |
interruptAll()
Interrupt all operations on all threads and all indexes.
|
void |
invoke(L row,
Object z,
IgniteTree.InvokeClosure<T> c) |
boolean |
isEmpty() |
void |
iterate(L lower,
L upper,
BPlusTree.TreeRowClosure<L,T> c) |
protected BPlusInnerIO<L> |
latestInnerIO() |
protected BPlusLeafIO<L> |
latestLeafIO() |
boolean |
markDestroyed() |
protected long |
maxLockHoldTime()
Maximum time for which tree destroy process is allowed to hold the lock, after this time exceeds,
temporaryReleaseLock() is called and hold time is reset. |
String |
printTree()
For debug.
|
protected void |
processFailure(FailureType failureType,
Throwable e)
Processes failure with failure processor.
|
T |
put(T row)
Put value in this tree.
|
boolean |
putx(T row) |
protected <X,R> R |
read(long pageId,
long page,
PageHandler<X,R> h,
X arg,
int intArg,
R lockFailed) |
protected <X,R> R |
read(long pageId,
PageHandler<X,R> h,
X arg,
int intArg,
R lockFailed) |
T |
remove(L row)
Removes the mapping for a key from this tree if it is present.
|
boolean |
removex(L row) |
int |
rootLevel() |
protected void |
setIos(IOVersions<? extends BPlusInnerIO<L>> innerIos,
IOVersions<? extends BPlusLeafIO<L>> leafIos) |
long |
size()
Returns number of elements in the tree by scanning pages of the bottom (leaf) level.
|
long |
size(@Nullable BPlusTree.TreeRowClosure<L,T> filter)
Returns number of elements in the tree that match the filter by scanning through the pages of the leaf level.
|
protected IoStatisticsHolder |
statisticsHolder() |
protected void |
temporaryReleaseLock()
Releases the lock that is held by long tree destroy process for a short period of time and acquires it again,
allowing other processes to acquire it.
|
String |
toString() |
static String |
treeName(String instance,
String type) |
void |
validateTree() |
void |
visit(L lower,
L upper,
BPlusTree.TreeVisitorClosure<L,T> c) |
acquirePage, allocatePage, allocatePage, allocatePageNoReuse, groupId, init, needWalDeltaRecord, pageSize, randomInt, read, read, readLock, readUnlock, recyclePage, releasePage, tryWriteLock, write, write, write, write, writeLock, writeUnlock, writeUnlock
public static PageHandlerWrapper<BPlusTree.Result> testHndWrapper
public static final ThreadLocal<Boolean> suspendFailureDiagnostic
public static final String CONC_DESTROY_MSG
public static final int IGNITE_BPLUS_TREE_LOCK_RETRIES_DEFAULT
protected final long metaPageId
protected BPlusTree(String name, int cacheGrpId, String cacheGrpName, PageMemory pageMem, IgniteWriteAheadLogManager wal, AtomicLong globalRmvId, long metaPageId, ReuseList reuseList, IOVersions<? extends BPlusInnerIO<L>> innerIos, IOVersions<? extends BPlusLeafIO<L>> leafIos, byte pageFlag, @Nullable @Nullable FailureProcessor failureProcessor, @Nullable @Nullable PageLockListener lockLsnr) throws IgniteCheckedException
name
- Tree name.cacheGrpId
- Cache group ID.cacheGrpName
- Cache group name.pageMem
- Page memory.wal
- Write ahead log manager.globalRmvId
- Remove ID.metaPageId
- Meta page ID.reuseList
- Reuse list.innerIos
- Inner IO versions.leafIos
- Leaf IO versions.pageFlag
- Default flag value for allocated pages.failureProcessor
- if the tree is corrupted.IgniteCheckedException
- If failed.protected BPlusTree(String name, int cacheGrpId, String grpName, PageMemory pageMem, IgniteWriteAheadLogManager wal, AtomicLong globalRmvId, long metaPageId, ReuseList reuseList, byte pageFlag, @Nullable @Nullable FailureProcessor failureProcessor, @Nullable @Nullable PageLockListener lsnr, PageIoResolver pageIoRslvr) throws IgniteCheckedException
name
- Tree name.cacheGrpId
- Cache ID.grpName
- Cache group name.pageMem
- Page memory.wal
- Write ahead log manager.globalRmvId
- Remove ID.metaPageId
- Meta page ID.reuseList
- Reuse list.pageFlag
- Default flag value for allocated pages.failureProcessor
- if the tree is corrupted.IgniteCheckedException
- If failed.protected void setIos(IOVersions<? extends BPlusInnerIO<L>> innerIos, IOVersions<? extends BPlusLeafIO<L>> leafIos)
innerIos
- Inner IO versions.leafIos
- Leaf IO versions.public final String getName()
public void enableSequentialWriteMode()
protected final void initTree(boolean initNew) throws IgniteCheckedException
initNew
- True
if new tree should be created.IgniteCheckedException
- If failed.protected final void initTree(boolean initNew, int inlineSize) throws IgniteCheckedException
initNew
- True
if new tree should be created.inlineSize
- Inline size.IgniteCheckedException
- If failed.protected final void checkDestroyed() throws IgniteCheckedException
IgniteCheckedException
public final GridCursor<T> find(L lower, L upper) throws IgniteCheckedException
find
in interface IgniteTree<L,T extends L>
lower
- Lower bound or null
if unbounded.upper
- Upper bound or null
if unbounded.IgniteCheckedException
- If failed.public final GridCursor<T> find(L lower, L upper, Object x) throws IgniteCheckedException
find
in interface IgniteTree<L,T extends L>
lower
- Lower bound or null
if unbounded.upper
- Upper bound or null
if unbounded.x
- Implementation specific argument, null
always means that we need to return full detached
data row.IgniteCheckedException
- If failed.public GridCursor<T> find(L lower, L upper, BPlusTree.TreeRowClosure<L,T> c, Object x) throws IgniteCheckedException
lower
- Lower bound inclusive or null
if unbounded.upper
- Upper bound inclusive or null
if unbounded.c
- Filter closure.x
- Implementation specific argument, null
always means that we need to return full detached data row.IgniteCheckedException
- If failed.public void iterate(L lower, L upper, BPlusTree.TreeRowClosure<L,T> c) throws IgniteCheckedException
lower
- Lower bound inclusive.upper
- Upper bound inclusive.c
- Closure applied for all found items, iteration is stopped if closure returns false
.IgniteCheckedException
- If failed.public void visit(L lower, L upper, BPlusTree.TreeVisitorClosure<L,T> c) throws IgniteCheckedException
lower
- Lower bound inclusive.upper
- Upper bound inclusive.c
- Closure applied for all found items.IgniteCheckedException
- If failed.public T findFirst() throws IgniteCheckedException
null
if tree is emptyfindFirst
in interface IgniteTree<L,T extends L>
IgniteCheckedException
- If failed.public T findFirst(BPlusTree.TreeRowClosure<L,T> filter) throws IgniteCheckedException
null
if tree is empty or no entry matches the passed filter.filter
- Filter closure.IgniteCheckedException
- If failed.public T findLast() throws IgniteCheckedException
null
if tree is emptyfindLast
in interface IgniteTree<L,T extends L>
IgniteCheckedException
- If failed.public T findLast(BPlusTree.TreeRowClosure<L,T> c) throws IgniteCheckedException
null
if tree is empty or no entry matches the passed filter.c
- Filter closure.IgniteCheckedException
- If failed.public final <R> R findOne(L row, Object x) throws IgniteCheckedException
row
- Lookup row for exact match.x
- Implementation specific argument, null
always means that we need to return full detached data row.null
IgniteCheckedException
- If failed.public final <R> R findOne(L row, BPlusTree.TreeRowClosure<L,T> c, Object x) throws IgniteCheckedException
row
- Lookup row for exact match.x
- Implementation specific argument, null
always means that we need to return full detached data row.null
.IgniteCheckedException
- If failed.public final T findOne(L row) throws IgniteCheckedException
IgniteTree
null
if this tree contains no mapping for the
key.findOne
in interface IgniteTree<L,T extends L>
row
- Lookup row for exact match.IgniteCheckedException
- If failed.public static String treeName(String instance, String type)
instance
- Instance name.type
- Tree type.public final String printTree() throws IgniteCheckedException
String
.IgniteCheckedException
- If failed.public final void validateTree() throws IgniteCheckedException
IgniteCheckedException
- If failed.public static void interruptAll()
public final T remove(L row) throws IgniteCheckedException
IgniteTree
remove
in interface IgniteTree<L,T extends L>
row
- Lookup row.IgniteCheckedException
- If failed.public final boolean removex(L row) throws IgniteCheckedException
row
- Lookup row.True
if removed row.IgniteCheckedException
- If failed.public void invoke(L row, Object z, IgniteTree.InvokeClosure<T> c) throws IgniteCheckedException
invoke
in interface IgniteTree<L,T extends L>
row
- Key.z
- Implementation specific argument, null
always means that we need a full detached data row.c
- Closure.IgniteCheckedException
- If failed.public final int rootLevel() throws IgniteCheckedException
IgniteCheckedException
- If failed.public final boolean isEmpty() throws IgniteCheckedException
True
in case the tree is empty.IgniteCheckedException
- If failed.public final long size() throws IgniteCheckedException
size
in interface IgniteTree<L,T extends L>
IgniteCheckedException
- If failed.public long size(@Nullable @Nullable BPlusTree.TreeRowClosure<L,T> filter) throws IgniteCheckedException
filter
- The filter to use or null to count all elements.IgniteCheckedException
- If failed.public final T put(T row) throws IgniteCheckedException
put
in interface IgniteTree<L,T extends L>
row
- Value to be associated with the specified key.IgniteCheckedException
- If failed.public boolean putx(T row) throws IgniteCheckedException
row
- New value.True
if replaced existing row.IgniteCheckedException
- If failed.protected void temporaryReleaseLock()
protected long maxLockHoldTime()
temporaryReleaseLock()
is called and hold time is reset.public final long destroy() throws IgniteCheckedException
0
, otherwise it should return at least 2
(for meta page and root page), unless this tree is
used as metadata storage, or -1
if we don't have a reuse list and did not do recycling at all.IgniteCheckedException
- If failed.public final long destroy(IgniteInClosure<L> c, boolean forceDestroy) throws IgniteCheckedException
c
- Visitor closure. Visits only leaf pages.forceDestroy
- Whether to proceed with destroying, even if tree is already marked as destroyed (see
markDestroyed()
).0
, otherwise it should return at least 2
(for meta page and root page), unless this tree is
used as metadata storage, or -1
if we don't have a reuse list and did not do recycling at all.IgniteCheckedException
- If failed.protected long destroyDownPages(LongListReuseBag bag, long pageId, int lvl, IgniteInClosure<L> c, AtomicLong lockHoldStartTime, long lockMaxTime, Deque<GridTuple3<Long,Long,Long>> lockedPages) throws IgniteCheckedException
pageId
and root level as lvl
.bag
- Reuse bag.pageId
- Page id.lvl
- Current level of tree.c
- Visitor closure. Visits only leaf pages.lockHoldStartTime
- When lock has been aquired last time.lockMaxTime
- Maximum time to hold the lock.lockedPages
- Deque of locked pages. Is used to release write-locked pages when temporary releasing
checkpoint read lock.IgniteCheckedException
- If failed.public boolean markDestroyed()
True
if state was changed.protected Iterable<Long> getFirstPageIds(long pageAddr)
pageAddr
- Meta page address.protected final BPlusInnerIO<L> latestInnerIO()
protected final BPlusLeafIO<L> latestLeafIO()
protected abstract int compare(BPlusIO<L> io, long pageAddr, int idx, L row) throws IgniteCheckedException
io
- IO.pageAddr
- Page address.idx
- Index of row in the given buffer.row
- Lookup row.Comparator.compare(Object, Object)
.IgniteCheckedException
- If failed.protected int compare(int lvl, BPlusIO<L> io, long pageAddr, int idx, L row) throws IgniteCheckedException
lvl
- Level.io
- IO.pageAddr
- Page address.idx
- Index of row in the given buffer.row
- Lookup row.Comparator.compare(Object, Object)
.IgniteCheckedException
- If failed.public final T getRow(BPlusIO<L> io, long pageAddr, int idx) throws IgniteCheckedException
io
- IO.pageAddr
- Page address.idx
- Index.IgniteCheckedException
- If failed.public abstract T getRow(BPlusIO<L> io, long pageAddr, int idx, Object x) throws IgniteCheckedException
canGetRowFromInner
is true
.io
- IO.pageAddr
- Page address.idx
- Index.x
- Implementation specific argument, null
always means that we need to return full detached data row.IgniteCheckedException
- If failed.protected int getLockRetries()
protected final long acquirePage(long pageId) throws IgniteCheckedException
pageId
- Page ID.IgniteCheckedException
- If failed.protected final <X,R> R read(long pageId, PageHandler<X,R> h, X arg, int intArg, R lockFailed) throws IgniteCheckedException
pageId
- Page ID.h
- Handler.arg
- Argument.intArg
- Argument of type int
.lockFailed
- Result in case of lock failure due to page recycling.IgniteCheckedException
- If failed.protected final <X,R> R read(long pageId, long page, PageHandler<X,R> h, X arg, int intArg, R lockFailed) throws IgniteCheckedException
pageId
- Page ID.page
- Page pointer.h
- Handler.arg
- Argument.intArg
- Argument of type int
.lockFailed
- Result in case of lock failure due to page recycling.IgniteCheckedException
- If failed.protected IoStatisticsHolder statisticsHolder()
protected CorruptedTreeException corruptedTreeException(String msg, Throwable cause, int grpId, long... pageIds)
msg
- Message.cause
- Cause.grpId
- Group id.pageIds
- Pages ids.protected void processFailure(FailureType failureType, Throwable e)
failureType
- Failure type.e
- Exception.public long getMetaPageId()
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.10.0 Release Date : March 10 2021