public class CursorImpl
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
CursorImpl.LockStanding
Holds the result of a lockLN operation.
|
static class |
CursorImpl.SearchMode |
static interface |
CursorImpl.WithCursor
Callback object for traverseDbWithCursor.
|
Modifier and Type | Field and Description |
---|---|
static int |
EXACT_KEY |
static int |
FOUND |
static int |
FOUND_LAST |
Constructor and Description |
---|
CursorImpl(DatabaseImpl database,
Locker locker)
Creates a cursor with retainNonTxnLocks=true.
|
CursorImpl(DatabaseImpl databaseImpl,
Locker locker,
boolean retainNonTxnLocks)
Creates a cursor.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
addCursor()
Add to the current cursor.
|
(package private) void |
addCursor(BIN bin) |
boolean |
advanceCursor(DatabaseEntry key,
DatabaseEntry data)
Advance a cursor.
|
void |
checkCursorState(boolean mustBeInitialized)
Check that the cursor is open and optionally if it is initialized.
|
void |
checkEnv() |
void |
clearClosingLocker()
Called when a cursor move operation is complete.
|
CursorImpl |
cloneCursor(boolean addCursor,
CacheMode cacheMode)
Shallow copy.
|
CursorImpl |
cloneCursor(boolean addCursor,
CacheMode cacheMode,
CursorImpl usePosition)
Performs a shallow copy.
|
void |
close() |
void |
close(CursorImpl newCursor)
Close a cursor.
|
void |
criticalEviction() |
OperationStatus |
delete(ReplicationContext repContext)
Delete the item pointed to by the cursor.
|
void |
dump()
dump the cursor for debugging purposes.
|
void |
dump(boolean verbose)
Dump the cursor for debugging purposes.
|
java.lang.String |
dumpToString(boolean verbose) |
void |
dumpTree() |
CursorImpl |
dup(boolean samePosition)
Return a new copy of the cursor.
|
void |
evict()
Evict the LN node at the cursor position.
|
void |
evict(boolean alreadyLatched)
Evict the LN node at the cursor position.
|
BIN |
getBIN() |
BIN |
getBINToBeRemoved() |
CacheMode |
getCacheMode() |
OperationStatus |
getCurrent(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType)
Retrieve the current record.
|
OperationStatus |
getCurrentAlreadyLatched(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType)
Retrieve the current record.
|
byte[] |
getCurrentKey()
Returns the key at the current position, regardless of whether the
record is deleted.
|
LN |
getCurrentLN(LockType lockType)
Retrieve the current LN, return with the target bin unlatched.
|
LN |
getCurrentLNAlreadyLatched(LockType lockType)
Retrieve the current LN, assuming the BIN is already latched.
|
RecordVersion |
getCurrentVersion(boolean allowFetch)
Returns the VLSN and LSN for the record at the current position.
|
int |
getIndex() |
Locker |
getLocker() |
StatGroup |
getLockStats() |
OperationStatus |
getNext(DatabaseEntry foundKey,
DatabaseEntry foundData,
LockType lockType,
boolean forward,
boolean alreadyLatched,
RangeConstraint rangeConstraint)
Move the cursor forward and return the next record.
|
int |
hashCode() |
void |
incrementLNCount() |
boolean |
isClosed() |
boolean |
isInternalDbCursor() |
boolean |
isNotInitialized() |
BIN |
latchBIN() |
static void |
lockAfterLsnChange(DatabaseImpl dbImpl,
long oldLsn,
long newLsn,
Locker excludeLocker)
After logging a deferred-write LN during eviction/checkpoint or a
migrated LN during cleaning, for every existing lock on the old LSN held
by another locker, we must lock the new LSN on behalf of that locker.
|
boolean |
lockCurrent(LockType lockType) |
void |
lockEof(LockType lockType)
Locks the logical EOF node for the databaseImpl.
|
CursorImpl.LockStanding |
lockLN(LockType lockType)
Does not allow uncontended locks.
|
CursorImpl.LockStanding |
lockLN(LockType lockType,
boolean allowUncontended)
Locks the LN at the cursor position.
|
void |
lockNextKeyForInsert(DatabaseEntry key)
Search for the next key following the given key, and acquire a range
insert lock on it.
|
boolean |
positionFirstOrLast(boolean first)
Position the cursor at the first or last record of the databaseImpl.
|
OperationStatus |
put(DatabaseEntry key,
DatabaseEntry data,
LN ln,
PutMode putMode,
DatabaseEntry returnOldData,
DatabaseEntry returnNewData,
ReplicationContext repContext)
Performs all put operations except for CURRENT (use putCurrent instead).
|
OperationStatus |
putCurrent(byte[] key,
DatabaseEntry data,
DatabaseEntry foundKey,
DatabaseEntry foundData,
DatabaseEntry returnNewData,
ReplicationContext repContext)
Modify the current record with the given data, and optionally replace
the key.
|
OperationStatus |
putLN(byte[] key,
LN ln,
DatabaseEntry returnNewData,
ReplicationContext repContext)
Insert the given LN in the tree or return KEYEXIST if the key is already
present.
|
void |
releaseBIN() |
void |
reset()
Reset a cursor to an uninitialized state, but unlike close(), allow it
to be used further.
|
int |
searchAndPosition(DatabaseEntry matchKey,
CursorImpl.SearchMode searchMode,
LockType lockType) |
int |
searchAndPosition(DatabaseEntry matchKey,
CursorImpl.SearchMode searchMode,
LockType lockType,
java.util.Comparator<byte[]> searchComparator)
Position the cursor at the key.
|
void |
setAllowEviction(boolean allowed)
Disables or enables eviction during cursor operations.
|
void |
setBIN(BIN newBin) |
void |
setCacheMode(CacheMode mode)
Sets the effective cache mode to use for the next operation.
|
void |
setClosingLocker(CursorImpl closingCursor)
Called when a cursor has been duplicated prior to being moved.
|
void |
setIndex(int idx) |
void |
setTestHook(TestHook hook) |
void |
setTreeStatsAccumulator(TreeWalkerStatsAccumulator tSA) |
long |
skip(boolean forward,
long maxCount,
RangeConstraint rangeConstraint)
Skips over entries until a boundary condition is satisfied, either
because maxCount is reached or RangeConstraint.inBounds returns false.
|
static void |
traverseDbWithCursor(DatabaseImpl db,
LockType lockType,
boolean allowEviction,
CursorImpl.WithCursor withCursor)
Enumerates all records in a databaseImpl non-transactionally and calls
the withCursor method for each record.
|
void |
updateBin(int index) |
public static final int FOUND
public static final int EXACT_KEY
public static final int FOUND_LAST
public CursorImpl(DatabaseImpl database, Locker locker)
public CursorImpl(DatabaseImpl databaseImpl, Locker locker, boolean retainNonTxnLocks)
retainNonTxnLocks
- is true if non-transactional locks should be
retained (not released automatically) when the cursor is reset or
closed.public int hashCode()
hashCode
in class java.lang.Object
public void incrementLNCount()
public void setAllowEviction(boolean allowed)
public void criticalEviction()
public CursorImpl cloneCursor(boolean addCursor, CacheMode cacheMode) throws DatabaseException
DatabaseException
public CursorImpl cloneCursor(boolean addCursor, CacheMode cacheMode, CursorImpl usePosition) throws DatabaseException
addCursor
- If true, addCursor() is called to register the new
cursor with the BINs. This is done after the usePosition parameter is
applied, if any. There are two cases where you may not want addCursor()
to be called: 1) When creating a fresh uninitialized cursor as in when
Cursor.dup(false) is called, or 2) when the caller will call addCursor()
as part of a larger operation.usePosition
- Is null to duplicate the position of this cursor, or
non-null to duplicate the position of the given cursor.DatabaseException
public void setClosingLocker(CursorImpl closingCursor)
closingCursor
- the old cursor that will be closed if the new
cursor is moved successfully.public void clearClosingLocker()
public int getIndex()
public void setIndex(int idx)
public BIN getBIN()
public void setBIN(BIN newBin)
public BIN getBINToBeRemoved()
public CacheMode getCacheMode()
public void setCacheMode(CacheMode mode)
public void setTreeStatsAccumulator(TreeWalkerStatsAccumulator tSA)
public boolean advanceCursor(DatabaseEntry key, DatabaseEntry data)
key
- on return contains the key if available, or null.data
- on return contains the data if available, or null.public BIN latchBIN() throws DatabaseException
DatabaseException
public void releaseBIN()
public Locker getLocker()
void addCursor(BIN bin)
void addCursor()
public void updateBin(int index) throws DatabaseException
DatabaseException
public void dumpTree()
public boolean isClosed()
public boolean isNotInitialized()
public boolean isInternalDbCursor()
public void reset() throws DatabaseException
DatabaseException
public void close() throws DatabaseException
DatabaseException
public void close(CursorImpl newCursor) throws DatabaseException
newCursor
- is another cursor that is kept open by the parent
Cursor object, or null if no other cursor is kept open.DatabaseException
- if the cursor was previously closed.public CursorImpl dup(boolean samePosition) throws DatabaseException
samePosition
- If true, position the returned cursor at the same
position as this cursor; if false, return a new uninitialized cursor.DatabaseException
public void evict() throws DatabaseException
DatabaseException
public void evict(boolean alreadyLatched) throws DatabaseException
DatabaseException
public OperationStatus put(DatabaseEntry key, DatabaseEntry data, LN ln, PutMode putMode, DatabaseEntry returnOldData, DatabaseEntry returnNewData, ReplicationContext repContext)
public OperationStatus putLN(byte[] key, LN ln, DatabaseEntry returnNewData, ReplicationContext repContext) throws DatabaseException
This method is called directly internally for putting tree map LNs and file summary LNs. It should not be used otherwise, and in the future we should find a way to remove this special case.
returnNewData
- if non-null, is used to return a complete copy of
the resulting data after any partial data has been resolved.DatabaseException
public OperationStatus putCurrent(byte[] key, DatabaseEntry data, DatabaseEntry foundKey, DatabaseEntry foundData, DatabaseEntry returnNewData, ReplicationContext repContext)
key
- to overwrite, may be null. If non-null, must be previously
determined to be equal to the current key, according to the comparator.data
- to overwrite, may be partial.foundKey
- if non-null, is used to return a copy of the existing
key, may be partial.foundData
- if non-null, is used to return a copy of the existing
data, may be partial.returnNewData
- if non-null, is used to return a complete copy of
the resulting data after any partial data has been resolved.public OperationStatus delete(ReplicationContext repContext) throws DatabaseException
DatabaseException
public OperationStatus getCurrent(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType) throws DatabaseException
DatabaseException
public OperationStatus getCurrentAlreadyLatched(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType) throws DatabaseException
DatabaseException
public LN getCurrentLN(LockType lockType) throws DatabaseException
DatabaseException
public LN getCurrentLNAlreadyLatched(LockType lockType) throws DatabaseException
DatabaseException
public RecordVersion getCurrentVersion(boolean allowFetch)
allowFetch
- is true to fetch the LN to get the VLSN, or false to
return -1 for the VLSN if both the LN and VLSN are not cached.public OperationStatus getNext(DatabaseEntry foundKey, DatabaseEntry foundData, LockType lockType, boolean forward, boolean alreadyLatched, RangeConstraint rangeConstraint) throws DatabaseException
foundKey
- DatabaseEntry to use for returning keyfoundData
- DatabaseEntry to use for returning dataforward
- if true, move forward, else move backwardsalreadyLatched
- if true, the bin that we're on is already
latched.rangeConstraint
- if non-null, is called to determine whether a key
is out of range.DatabaseException
public long skip(boolean forward, long maxCount, RangeConstraint rangeConstraint)
forward
- is true to skip forward, false to skip backward.maxCount
- is the maximum number of non-deleted entries to skip,
and may be LTE zero if no maximum is enforced.rangeConstraint
- is a predicate that returns false at a position
where advancement should stop, or null if no predicate is enforced.public boolean positionFirstOrLast(boolean first) throws DatabaseException
DatabaseException
public int searchAndPosition(DatabaseEntry matchKey, CursorImpl.SearchMode searchMode, LockType lockType)
public int searchAndPosition(DatabaseEntry matchKey, CursorImpl.SearchMode searchMode, LockType lockType, java.util.Comparator<byte[]> searchComparator)
Note this returns with the BIN latched!
If this method returns without the FOUND bit set, the caller can assume that no match is possible. Otherwise, if the FOUND bit is set, the caller should check the EXACT_KEY bit. If EXACT_KEY is not set, an approximate match was found. In an approximate match, the cursor is always positioned before the target key/data. This allows the caller to perform a 'next' operation to advance to the value that is equal or higher than the target key/data.
Even if the search returns an exact result, the record may be deleted. The caller must therefore check for both an approximate match and for whether the cursor is positioned on a deleted record.
If SET is specified, the FOUND bit will only be returned if an exact match is found. However, the record found may be deleted.
There is one special case where this method may be called without checking the EXACT_KEY bit and without checking for a deleted record: If SearchMode.SET is specified then only the FOUND bit need be checked. When SET is specified and FOUND is returned, it is guaranteed to be an exact match on a non-deleted record. It is for this case only that this method is public.
If FOUND is set, FOUND_LAST may also be set if the cursor is positioned on the last record in the databaseImpl. Note that this state can only be counted on as long as the BIN is latched, so it is not set if this method must release the latch to lock the record. Therefore, it should only be used for optimizations. If FOUND_LAST is set, the cursor is positioned on the last record and the BIN is latched. If FOUND_LAST is not set, the cursor may or may not be positioned on the last record. Note that exact searches always perform an unlatch and a lock, so FOUND_LAST will only be set for inexact (range) searches.
Be aware that when an approximate match is returned, the index may be set to -1. This is done intentionally so that a 'next' operation will increment it.
searchMode
- SearchMode.SET (position on a key EQ matchKey) or
SearchMode.SET_RANGE (position on a key LTE matchKey).public byte[] getCurrentKey()
public void lockNextKeyForInsert(DatabaseEntry key) throws DatabaseException
DatabaseException
public CursorImpl.LockStanding lockLN(LockType lockType) throws LockConflictException
LockConflictException
public CursorImpl.LockStanding lockLN(LockType lockType, boolean allowUncontended) throws LockConflictException
lockType
- the type of lock requested.allowUncontended
- is true to return immediately (no lock is taken)
when no locker holds or waits for the lock.LockConflictException
- if the lsn is non-null, the lock is
contended, and a lock could not be obtained by blocking.public boolean lockCurrent(LockType lockType)
public static void lockAfterLsnChange(DatabaseImpl dbImpl, long oldLsn, long newLsn, Locker excludeLocker)
HandleLocker
,
lockLN(com.sleepycat.je.txn.LockType)
public void checkCursorState(boolean mustBeInitialized)
java.lang.IllegalStateException
- via all Cursor methods that call
Cursor.checkState (all get and put methods, plus more).public void lockEof(LockType lockType) throws DatabaseException
DatabaseException
public void checkEnv()
EnvironmentFailureException
- if the underlying environment is
invalid.public static void traverseDbWithCursor(DatabaseImpl db, LockType lockType, boolean allowEviction, CursorImpl.WithCursor withCursor) throws DatabaseException
db
- DatabaseImpl to traverse.lockType
- non-null LockType for reading records.allowEviction
- should normally be true to evict when performing
multiple operations, but may be false if eviction is disallowed in a
particular context.withCursor
- callback object.DatabaseException
public void dump(boolean verbose)
public void dump()
public java.lang.String dumpToString(boolean verbose)
public StatGroup getLockStats() throws DatabaseException
DatabaseException
public void setTestHook(TestHook hook)
Copyright (c) 2004-2012 Oracle. All rights reserved.