
public class OLocalHashTable<K,V> extends ODurableComponent implements OHashTable<K,V>
OHashTableDirectory class. Directory is not implemented according
to classic algorithm because of its big memory consumption in case of non-uniform data distribution instead it is implemented
according too "Multilevel Extendible Hashing Sven Helmer, Thomas Neumann, Guido Moerkotte April 17, 2002". Which has much less
memory consumption in case of nonuniform data distribution.
Index itself uses so called "multilevel schema" when first level contains 256 buckets, when bucket is split it is put at the end of other file which represents second level. So if data which are put has distribution close to uniform (this index was designed to be use as rid index for DHT storage) buckets split will be preformed in append only manner to speed up index write speed.
So hash index bucket itself has following structure:
So if 1-st and 2-nd fields are clear. We should discuss the last ones.
Entities in bucket are sorted by key's hash code so each entity has following storage format in bucket: key's hash code (8 bytes), key, value. Because entities are stored in sorted order it means that every time when we insert new entity old ones should be moved.
There are 2 reasons why it is bad:
To avoid disadvantages listed above entries ara appended to the end of bucket, but their offsets are stored at the beginning of bucket. Offsets are stored in sorted order (ordered by hash code of entity's key) so we need to move only small amount of memory to store entities in sorted order.
About indexes of parents of current bucket. When item is removed from bucket we check space which is needed to store all entities of this bucket, it's buddy bucket (bucket which was also created from parent bucket during split) and if space of single bucket is enough to save all entities from both buckets we remove these buckets and put all content in parent bucket. That is why we need indexes of parents of current bucket.
Also hash index has special file of one page long which contains information about state of each level of buckets in index. This information is stored as array index of which equals to file level. All array item has following structure:
OHashTable.BucketPath, OHashTable.BucketSplitResult, OHashTable.KeyHashCodeComparator<K>, OHashTable.NodeSplitResult| Modifier and Type | Field and Description |
|---|---|
static int |
HASH_CODE_SIZE |
static int |
LEVEL_MASK |
static int |
MAX_LEVEL_DEPTH |
static int |
MAX_LEVEL_SIZE |
atomicOperationsManager, extension, performanceStatisticManager, readCache, storage, writeCache| Constructor and Description |
|---|
OLocalHashTable(String name,
String metadataConfigurationFileExtension,
String treeStateFileExtension,
String bucketFileExtension,
String nullBucketFileExtension,
OHashFunction<K> keyHashFunction,
boolean durableInNonTxMode,
OAbstractPaginatedStorage abstractPaginatedStorage) |
| Modifier and Type | Method and Description |
|---|---|
void |
acquireAtomicExclusiveLock()
Acquires exclusive lock in the active atomic operation running on the current thread for this hash table.
|
OHashIndexBucket.Entry<K,V>[] |
ceilingEntries(K key) |
void |
clear() |
void |
close() |
void |
create(OBinarySerializer<K> keySerializer,
OBinarySerializer<V> valueSerializer,
OType[] keyTypes,
boolean nullKeyIsSupported) |
void |
delete() |
void |
deleteWithoutLoad(String name,
OAbstractPaginatedStorage storageLocal) |
OHashIndexBucket.Entry<K,V> |
firstEntry() |
OHashIndexBucket.Entry<K,V>[] |
floorEntries(K key) |
void |
flush() |
V |
get(K key) |
OBinarySerializer<K> |
getKeySerializer() |
OBinarySerializer<V> |
getValueSerializer() |
OHashIndexBucket.Entry<K,V>[] |
higherEntries(K key) |
OHashIndexBucket.Entry<K,V>[] |
higherEntries(K key,
int limit) |
boolean |
isNullKeyIsSupported() |
OHashIndexBucket.Entry<K,V> |
lastEntry() |
void |
load(String name,
OType[] keyTypes,
boolean nullKeyIsSupported) |
OHashIndexBucket.Entry<K,V>[] |
lowerEntries(K key) |
void |
put(K key,
V value) |
V |
remove(K key) |
void |
setKeySerializer(OBinarySerializer<K> keySerializer) |
void |
setValueSerializer(OBinarySerializer<V> valueSerializer) |
long |
size() |
protected void |
startOperation() |
boolean |
validatedPut(K key,
V value,
OIndexEngine.Validator<K,V> validator)
Puts the given value under the given key into this hash table.
|
acquireExclusiveLock, addFile, addPage, completeOperation, deleteFile, endAtomicOperation, getChanges, getExtension, getFilledUpTo, getFullName, getLockName, getName, isFileExists, isFileExists, loadPage, loadPage, openFile, pinPage, releasePage, setName, startAtomicOperation, truncateFileacquireSharedLock, addUser, assertExclusiveLockHold, assertSharedLockHold, getUsers, isConcurrent, releaseExclusiveLock, releaseSharedLock, removeUser, tryAcquireExclusiveLock, tryAcquireSharedLockclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetNamepublic static final int HASH_CODE_SIZE
public static final int MAX_LEVEL_DEPTH
public static final int MAX_LEVEL_SIZE
public static final int LEVEL_MASK
public OLocalHashTable(String name, String metadataConfigurationFileExtension, String treeStateFileExtension, String bucketFileExtension, String nullBucketFileExtension, OHashFunction<K> keyHashFunction, boolean durableInNonTxMode, OAbstractPaginatedStorage abstractPaginatedStorage)
public void create(OBinarySerializer<K> keySerializer, OBinarySerializer<V> valueSerializer, OType[] keyTypes, boolean nullKeyIsSupported)
create in interface OHashTable<K,V>public OBinarySerializer<K> getKeySerializer()
getKeySerializer in interface OHashTable<K,V>public void setKeySerializer(OBinarySerializer<K> keySerializer)
setKeySerializer in interface OHashTable<K,V>public OBinarySerializer<V> getValueSerializer()
getValueSerializer in interface OHashTable<K,V>public void setValueSerializer(OBinarySerializer<V> valueSerializer)
setValueSerializer in interface OHashTable<K,V>public boolean isNullKeyIsSupported()
isNullKeyIsSupported in interface OHashTable<K,V>public boolean validatedPut(K key, V value, OIndexEngine.Validator<K,V> validator)
OHashTablevalidatedPut in interface OHashTable<K,V>key - the key to put the value under.value - the value to put.validator - the operation validator.true if the validator allowed the put, false otherwise.OIndexEngine.Validator#validate(Object, Object, Object)public void clear()
clear in interface OHashTable<K,V>public OHashIndexBucket.Entry<K,V>[] higherEntries(K key)
higherEntries in interface OHashTable<K,V>public OHashIndexBucket.Entry<K,V>[] higherEntries(K key, int limit)
higherEntries in interface OHashTable<K,V>public void load(String name, OType[] keyTypes, boolean nullKeyIsSupported)
load in interface OHashTable<K,V>public void deleteWithoutLoad(String name, OAbstractPaginatedStorage storageLocal)
deleteWithoutLoad in interface OHashTable<K,V>public OHashIndexBucket.Entry<K,V>[] ceilingEntries(K key)
ceilingEntries in interface OHashTable<K,V>public OHashIndexBucket.Entry<K,V> firstEntry()
firstEntry in interface OHashTable<K,V>public OHashIndexBucket.Entry<K,V> lastEntry()
lastEntry in interface OHashTable<K,V>public OHashIndexBucket.Entry<K,V>[] lowerEntries(K key)
lowerEntries in interface OHashTable<K,V>public OHashIndexBucket.Entry<K,V>[] floorEntries(K key)
floorEntries in interface OHashTable<K,V>public long size()
size in interface OHashTable<K,V>public void close()
close in interface OHashTable<K,V>public void delete()
delete in interface OHashTable<K,V>public void flush()
flush in interface OHashTable<K,V>public void acquireAtomicExclusiveLock()
OHashTableacquireAtomicExclusiveLock in interface OHashTable<K,V>protected void startOperation()
startOperation in class ODurableComponentCopyright © 2009–2025 OrientDB. All rights reserved.