
public abstract class OIndexAbstract<T> extends Object implements OIndexInternal<T>, OOrientStartupListener, OOrientShutdownListener
OPartitionedLockManager, the
default one, or the OOneEntryPerKeyLockManager in case of distributed. This is to avoid deadlock situation between nodes
where keys have the same hash code.| Modifier and Type | Class and Description |
|---|---|
protected static class |
OIndexAbstract.IndexConfiguration |
protected static class |
OIndexAbstract.IndexTxSnapshot |
| Modifier and Type | Field and Description |
|---|---|
protected static String |
CONFIG_CLUSTERS |
protected static String |
CONFIG_MAP_RID |
protected OIndexAbstract.IndexConfiguration |
configuration |
protected int |
indexId |
protected OLockManager<Object> |
keyLockManager |
protected ODocument |
metadata |
protected OAbstractPaginatedStorage |
storage |
protected String |
type |
protected String |
valueContainerAlgorithm |
ALGORITHM, CONFIG_AUTOMATIC, CONFIG_KEYTYPE, CONFIG_NAME, CONFIG_TYPE, INDEX_DEFINITION, INDEX_DEFINITION_CLASS, INDEX_VERSION, METADATA, VALUE_CONTAINER_ALGORITHMMERGE_KEYS| Constructor and Description |
|---|
OIndexAbstract(String name,
String type,
String algorithm,
String valueContainerAlgorithm,
ODocument metadata,
int version,
OStorage storage) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acquireAtomicExclusiveLock(Object key)
Acquires exclusive lock in the active atomic operation running on the current thread for this index.
|
protected void |
acquireExclusiveLock() |
protected void |
acquireSharedLock() |
OIndexAbstract<T> |
addCluster(String clusterName)
Add given cluster to the list of clusters that should be automatically indexed.
|
void |
addTxOperation(OTransactionIndexChanges changes) |
ODocument |
checkEntry(OIdentifiable iRecord,
Object iKey)
For unique indexes it will throw exception if passed in key is contained in index.
|
OIndex<T> |
clear()
Clears the index removing all the entries in one shot.
|
protected void |
clearSnapshot(OIndexAbstract.IndexTxSnapshot indexTxSnapshot) |
void |
close() |
void |
commit() |
protected void |
commitSnapshot(Map<Object,Object> snapshot) |
int |
compareTo(OIndex<T> index) |
boolean |
contains(Object key)
Tells if a key is contained in the index.
|
long |
count(Object iKey)
Counts the entries for the key.
|
OIndexInternal<?> |
create(OIndexDefinition indexDefinition,
String clusterIndexName,
Set<String> clustersToIndex,
boolean rebuild,
OProgressListener progressListener,
OBinarySerializer valueSerializer)
Creates the index.
|
OIndexInternal<T> |
delete()
Delete the index.
|
protected abstract OBinarySerializer |
determineValueSerializer() |
protected void |
doReloadIndexEngine() |
boolean |
equals(Object o) |
void |
flush()
Flushes in-memory changes to disk.
|
String |
getAlgorithm()
Returns the engine of the index as string.
|
Set<String> |
getClusters()
Returns Names of clusters that will be indexed.
|
Object |
getCollatingValue(Object key) |
ODocument |
getConfiguration()
Returns the index configuration.
|
protected ODatabaseDocumentInternal |
getDatabase() |
String |
getDatabaseName() |
OIndexDefinition |
getDefinition() |
protected Map<String,String> |
getEngineProperties() |
Object |
getFirstKey() |
int |
getIndexId() |
String |
getIndexNameByKey(Object key)
Returns the index name for a key.
|
OIndexInternal<T> |
getInternal()
Returns the internal index used.
|
OType[] |
getKeyTypes()
Types of the keys that index can accept, if index contains composite key, list of types of elements from which this index
consist will be returned, otherwise single element (key type obviously) will be returned.
|
Object |
getLastKey() |
ODocument |
getMetadata() |
String |
getName()
Returns the index name.
|
long |
getRebuildVersion()
Returns amount of times when index was rebuilt since storage was opened.
|
String |
getType()
Returns the type of the index as string.
|
int |
getVersion()
Returns binary format version for this index.
|
int |
hashCode() |
boolean |
hasRangeQuerySupport() |
protected long[] |
indexCluster(String clusterName,
OProgressListener iProgressListener,
long documentNum,
long documentIndexed,
long documentTotal) |
protected OIndexAbstract.IndexConfiguration |
indexConfigurationInstance(ODocument document) |
protected Iterable<OTransactionIndexChangesPerKey.OTransactionIndexEntry> |
interpretTxKeyChanges(OTransactionIndexChangesPerKey changes)
Interprets transaction index changes for a certain key.
|
boolean |
isAutomatic()
Tells if the index is automatic.
|
boolean |
isRebuilding() |
boolean |
isUnique() |
OIndexKeyCursor |
keyCursor() |
boolean |
loadFromConfiguration(ODocument config)
Loads the index giving the configuration.
|
OIndexMetadata |
loadMetadata(ODocument config) |
static OIndexMetadata |
loadMetadataInternal(ODocument config,
String type,
String algorithm,
String valueContainerAlgorithm) |
Lock[] |
lockKeysForUpdate(Collection<Object> keys)
Applies exclusive lock on keys which prevents read/modification of this keys in following methods:
OIndex.put(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)
OIndex.checkEntry(com.orientechnologies.orient.core.db.record.OIdentifiable, Object)
OIndex.remove(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)
OIndex.remove(Object)
|
void |
lockKeysForUpdate(Object... key)
Applies exclusive lock on keys which prevents read/modification of this keys in following methods:
OIndex.put(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)
OIndex.checkEntry(com.orientechnologies.orient.core.db.record.OIdentifiable, Object)
OIndex.remove(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)
OIndex.remove(Object)
|
protected void |
onIndexEngineChange(int indexId) |
void |
onShutdown() |
void |
onStartup() |
protected void |
populateIndex(ODocument doc,
Object fieldValue) |
void |
postCommit() |
void |
preCommit() |
protected void |
putInSnapshot(Object key,
OIdentifiable value,
Map<Object,Object> snapshot) |
long |
rebuild()
Rebuilds an automatic index.
|
long |
rebuild(OProgressListener iProgressListener)
Populate the index with all the existent records.
|
protected void |
releaseExclusiveLock() |
void |
releaseKeysForUpdate(Object... key)
Release exclusive lock on keys which prevents read/modification of this keys in following methods:
OIndex.put(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)
OIndex.checkEntry(com.orientechnologies.orient.core.db.record.OIdentifiable, Object)
OIndex.remove(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)
OIndex.remove(Object)
This is internal method and cannot be used by end users. |
protected void |
releaseSharedLock() |
boolean |
remove(Object key)
Removes an entry by its key.
|
boolean |
remove(Object key,
OIdentifiable value)
Removes an entry by its key and value.
|
OIndexAbstract<T> |
removeCluster(String iClusterName)
Remove given cluster from the list of clusters that should be automatically indexed.
|
protected void |
removeFromSnapshot(Object key,
Map<Object,Object> snapshot) |
protected void |
removeFromSnapshot(Object key,
OIdentifiable value,
Map<Object,Object> snapshot) |
void |
setRebuildingFlag() |
void |
setType(OType type) |
String |
toString() |
ODocument |
updateConfiguration()
Saves the index configuration to disk.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitcanBeUsedInEqualityOperatorscreate, cursor, descCursor, get, getKeySize, getSize, iterateEntries, iterateEntriesBetween, iterateEntriesMajor, iterateEntriesMinor, put, supportsOrderedIterationsprotected static final String CONFIG_MAP_RID
protected static final String CONFIG_CLUSTERS
protected final String type
protected final OLockManager<Object> keyLockManager
protected volatile OIndexAbstract.IndexConfiguration configuration
protected final ODocument metadata
protected final OAbstractPaginatedStorage storage
protected String valueContainerAlgorithm
protected volatile int indexId
public static OIndexMetadata loadMetadataInternal(ODocument config, String type, String algorithm, String valueContainerAlgorithm)
public void onShutdown()
onShutdown in interface OOrientShutdownListenerpublic void onStartup()
onStartup in interface OOrientStartupListenerpublic void flush()
OIndexpublic boolean hasRangeQuerySupport()
hasRangeQuerySupport in interface OIndexInternal<T>public OIndexInternal<?> create(OIndexDefinition indexDefinition, String clusterIndexName, Set<String> clustersToIndex, boolean rebuild, OProgressListener progressListener, OBinarySerializer valueSerializer)
clusterIndexName - Cluster name where to place the TreeMapclustersToIndex - rebuild - progressListener - valueSerializer - protected void doReloadIndexEngine()
public long count(Object iKey)
OIndexpublic boolean loadFromConfiguration(ODocument config)
OIndexInternalloadFromConfiguration in interface OIndexInternal<T>config - ODocument instance containing the configurationpublic OIndexMetadata loadMetadata(ODocument config)
loadMetadata in interface OIndexInternal<T>public boolean contains(Object key)
OIndexpublic long rebuild()
rebuild in interface OIndex<T>OIndex.getRebuildVersion()public void setRebuildingFlag()
setRebuildingFlag in interface OIndexInternal<T>public void close()
close in interface OIndexInternal<T>public Object getFirstKey()
getFirstKey in interface OIndex<T>public Object getLastKey()
getLastKey in interface OIndex<T>public long getRebuildVersion()
It is used to support so called "live index rebuild" feature.
Value of this version is increased every time when index is going to be rebuild. So if two sequential calls of this method return different numbers it means that index at least started to rebuild itself.
If you use indexes to increase speed of fetching data from database you should follow following workflow:
OIndex.isRebuilding(), if it is true, do not use index and fetch data directly from
database clusters.
This approach works well ONLY if you do not use methods which return OIndexCursor instance.
In case of you work with cursors index rebuild may cause data inconsistency issues in both:
To detect last data inconsistency issue please use cursor wrapper
OIndexChangesWrapper which throws OIndexIsRebuildingException
in case of index rebuild.
Both of these approaches are used in implementation of support of "live index rebuild" for SELECT SQL queries.
SELECT query is rebuilding
we skip this index.OIndexIsRebuildingException exception
and retry whole query again.getRebuildVersion in interface OIndex<T>OCommandExecutorSQLSelect.searchForIndexes(com.orientechnologies.orient.core.metadata.schema.OClass),
OCommandExecutorSQLSelect.getIndexCursors(com.orientechnologies.orient.core.metadata.schema.OClass),
OCommandExecutorSQLSelect.getOptimizedSortCursor(com.orientechnologies.orient.core.metadata.schema.OClass),
OAbstractPaginatedStorage.command(com.orientechnologies.orient.core.command.OCommandRequestText),
OIndexChangesWrapper,
OIndexIsRebuildingException,
ORetryQueryExceptionpublic long rebuild(OProgressListener iProgressListener)
rebuild in interface OIndex<T>OIndex.getRebuildVersion()public boolean remove(Object key, OIdentifiable value)
OIndexpublic boolean remove(Object key)
OIndexpublic void lockKeysForUpdate(Object... key)
OIndexInternalOIndex.put(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)OIndex.checkEntry(com.orientechnologies.orient.core.db.record.OIdentifiable, Object)OIndex.remove(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)OIndex.remove(Object)If you want to lock several keys in single thread, you should pass all those keys in single method call. Several calls of this method in single thread are not allowed because it may lead to deadlocks.
This is internal method and cannot be used by end users.lockKeysForUpdate in interface OIndexInternal<T>key - Keys to lock.public Lock[] lockKeysForUpdate(Collection<Object> keys)
OIndexInternalOIndex.put(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)OIndex.checkEntry(com.orientechnologies.orient.core.db.record.OIdentifiable, Object)OIndex.remove(Object, com.orientechnologies.orient.core.db.record.OIdentifiable)OIndex.remove(Object)If you want to lock several keys in single thread, you should pass all those keys in single method call. Several calls of this method in single thread are not allowed because it may lead to deadlocks.
This is internal method and cannot be used by end users.lockKeysForUpdate in interface OIndexInternal<T>keys - Keys to lock.public void releaseKeysForUpdate(Object... key)
OIndexInternalreleaseKeysForUpdate in interface OIndexInternal<T>key - Keys to unlock.public OIndex<T> clear()
OIndexpublic OIndexInternal<T> delete()
OIndexpublic String getType()
OIndexpublic String getAlgorithm()
OIndexgetAlgorithm in interface OIndex<T>public OIndexInternal<T> getInternal()
OIndexgetInternal in interface OIndex<T>public Set<String> getClusters()
OIndexgetClusters in interface OIndex<T>public OIndexAbstract<T> addCluster(String clusterName)
OIndexInternaladdCluster in interface OIndexInternal<T>clusterName - Cluster to add.public OIndexAbstract<T> removeCluster(String iClusterName)
OIndexInternalremoveCluster in interface OIndexInternal<T>iClusterName - Cluster to remove.public ODocument checkEntry(OIdentifiable iRecord, Object iKey)
OIndexcheckEntry in interface OIndex<T>public ODocument updateConfiguration()
OIndexInternalupdateConfiguration in interface OIndexInternal<T>OIndex.getConfiguration()public void addTxOperation(OTransactionIndexChanges changes)
addTxOperation in interface OIndexInternal<T>protected Iterable<OTransactionIndexChangesPerKey.OTransactionIndexEntry> interpretTxKeyChanges(OTransactionIndexChangesPerKey changes)
ORecordDuplicatedException while applying index changes.changes - the changes to interpret.public void commit()
commit in interface OIndexInternal<T>public void preCommit()
preCommit in interface OIndexInternal<T>public void postCommit()
postCommit in interface OIndexInternal<T>public ODocument getConfiguration()
OIndexgetConfiguration in interface OIndex<T>public int getVersion()
OIndexgetVersion in interface OIndex<T>public ODocument getMetadata()
getMetadata in interface OIndex<T>public boolean isAutomatic()
OIndexisAutomatic in interface OIndex<T>public OType[] getKeyTypes()
OIndexgetKeyTypes in interface OIndex<T>public OIndexKeyCursor keyCursor()
public OIndexDefinition getDefinition()
getDefinition in interface OIndex<T>public int getIndexId()
getIndexId in interface OIndex<T>public String getDatabaseName()
getDatabaseName in interface OIndex<T>public boolean isRebuilding()
isRebuilding in interface OIndex<T>OIndex.getRebuildVersion()protected abstract OBinarySerializer determineValueSerializer()
public Object getCollatingValue(Object key)
getCollatingValue in interface OIndexInternal<T>protected void putInSnapshot(Object key, OIdentifiable value, Map<Object,Object> snapshot)
protected void removeFromSnapshot(Object key, OIdentifiable value, Map<Object,Object> snapshot)
protected void clearSnapshot(OIndexAbstract.IndexTxSnapshot indexTxSnapshot)
public int compareTo(OIndex<T> index)
compareTo in interface Comparable<OIndex<T>>public void setType(OType type)
setType in interface OIndexInternal<T>public String getIndexNameByKey(Object key)
OIndexInternalReturns the index name for a key. The name is always the current index name, but in cases where the index supports key-based sharding.
getIndexNameByKey in interface OIndexInternal<T>key - the index key.public boolean acquireAtomicExclusiveLock(Object key)
OIndexInternalAcquires exclusive lock in the active atomic operation running on the current thread for this index.
If this index supports a more narrow locking, for example key-based sharding, it may use the provided key to infer a
more narrow lock scope, but that is not a requirement.
acquireAtomicExclusiveLock in interface OIndexInternal<T>key - the index key to lock.true if this index was locked entirely, false if this index locking is sensitive to the provided key and only some subset of this index was locked.protected ODatabaseDocumentInternal getDatabase()
protected long[] indexCluster(String clusterName, OProgressListener iProgressListener, long documentNum, long documentIndexed, long documentTotal)
protected void releaseExclusiveLock()
protected void acquireExclusiveLock()
protected void releaseSharedLock()
protected void acquireSharedLock()
protected void onIndexEngineChange(int indexId)
protected OIndexAbstract.IndexConfiguration indexConfigurationInstance(ODocument document)
Copyright © 2009–2025 OrientDB. All rights reserved.